提交 ab09cff0 编写于 作者: B Benjamin Pasero

remove another getOptions() call

上级 d977e9cf
......@@ -305,7 +305,7 @@ export class TestEditorGroupService implements IEditorGroupService {
let inst = new InstantiationService(services);
this.stacksModel = inst.createInstance(EditorStacksModel);
this.stacksModel = inst.createInstance(EditorStacksModel, true);
}
public fireChange(): void {
......
......@@ -99,6 +99,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
constructor(
id: string,
restoreFromStorage: boolean,
@IMessageService private messageService: IMessageService,
@IEventService private eventService: IEventService,
@ITelemetryService private telemetryService: ITelemetryService,
......@@ -125,7 +126,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
this.pendingEditorInputsToClose = [];
this.pendingEditorInputCloseTimeout = null;
this.stacks = this.instantiationService.createInstance(EditorStacksModel);
this.stacks = this.instantiationService.createInstance(EditorStacksModel, restoreFromStorage);
const editorConfig = configurationService.getConfiguration<IWorkbenchEditorConfiguration>().workbench.editor;
this.previewEditors = editorConfig.enablePreview;
......
......@@ -12,7 +12,6 @@ import {IStorageService, StorageScope} from 'vs/platform/storage/common/storage'
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {ILifecycleService} from 'vs/platform/lifecycle/common/lifecycle';
import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
import {dispose, IDisposable} from 'vs/base/common/lifecycle';
import {Registry} from 'vs/platform/platform';
import {Position, Direction} from 'vs/platform/editor/common/editor';
......@@ -667,9 +666,9 @@ export class EditorStacksModel implements IEditorStacksModel {
private _onModelChanged: Emitter<IStacksModelChangeEvent>;
constructor(
private restoreFromStorage: boolean,
@IStorageService private storageService: IStorageService,
@ILifecycleService private lifecycleService: ILifecycleService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IInstantiationService private instantiationService: IInstantiationService
) {
this.toDispose = [];
......@@ -997,8 +996,7 @@ export class EditorStacksModel implements IEditorStacksModel {
}
private load(): void {
const options = this.contextService.getOptions();
if ((options.filesToCreate && options.filesToCreate.length) || (options.filesToOpen && options.filesToOpen.length) || (options.filesToDiff && options.filesToDiff.length)) {
if (!this.restoreFromStorage) {
return; // do not load from last session if the user explicitly asks to open a set of files
}
......
......@@ -8,11 +8,10 @@
import 'vs/css!./media/workbench';
import {TPromise, ValueCallback} from 'vs/base/common/winjs.base';
import types = require('vs/base/common/types');
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import strings = require('vs/base/common/strings');
import DOM = require('vs/base/browser/dom');
import {Box, Builder, withElementById, $} from 'vs/base/browser/builder';
import {Box, Builder, $} from 'vs/base/browser/builder';
import {Delayer} from 'vs/base/common/async';
import assert = require('vs/base/common/assert');
import timer = require('vs/base/common/timer');
......@@ -126,6 +125,7 @@ export class Workbench implements IPartService {
private editorBackgroundDelayer: Delayer<void>;
private messagesVisibleContext: IContextKey<boolean>;
private editorsVisibleContext: IContextKey<boolean>;
private hasFilesToCreateOpenOrDiff: boolean;
constructor(
container: HTMLElement,
......@@ -142,27 +142,16 @@ export class Workbench implements IPartService {
@IThreadService private threadService: IThreadService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
// Validate params
this.validateParams(container, options);
// If String passed in as container, try to find it in DOM
if (types.isString(container)) {
const element = withElementById(container.toString());
this.container = element.getHTMLElement();
}
// Otherwise use as HTMLElement
else {
this.container = container;
}
this.container = container;
this.workbenchParams = {
workspace: workspace,
options: options || {},
options,
serviceCollection
};
this.hasFilesToCreateOpenOrDiff = (options.filesToCreate && options.filesToCreate.length > 0) || (options.filesToOpen && options.filesToOpen.length > 0) || (options.filesToDiff && options.filesToDiff.length > 0);
this.toDispose = [];
this.toShutdown = [];
this.editorBackgroundDelayer = new Delayer<void>(50);
......@@ -172,16 +161,6 @@ export class Workbench implements IPartService {
});
}
private validateParams(container: HTMLElement, options: IOptions): void {
// Container
assert.ok(container, 'Workbench requires a container to be created with');
if (types.isString(container)) {
const element = withElementById(container.toString());
assert.ok(element, strings.format('Can not find HTMLElement with id \'{0}\'.', container));
}
}
/**
* Starts the workbench and creates the HTML elements on the container. A workbench can only be started
* once. Use the shutdown function to free up resources created by the workbench on startup.
......@@ -297,8 +276,8 @@ export class Workbench implements IPartService {
private resolveEditorsToOpen(): TPromise<{ input: EditorInput, options?: EditorOptions }[]> {
// Files to open, diff or create
const wbopt = this.workbenchParams.options;
if ((wbopt.filesToCreate && wbopt.filesToCreate.length) || (wbopt.filesToOpen && wbopt.filesToOpen.length) || (wbopt.filesToDiff && wbopt.filesToDiff.length)) {
if (this.hasFilesToCreateOpenOrDiff) {
const wbopt = this.workbenchParams.options;
const filesToCreate = wbopt.filesToCreate || [];
const filesToOpen = wbopt.filesToOpen || [];
const filesToDiff = wbopt.filesToDiff;
......@@ -383,7 +362,7 @@ export class Workbench implements IPartService {
serviceCollection.set(IActivityService, this.activitybarPart);
// Editor service (editor part)
this.editorPart = this.instantiationService.createInstance(EditorPart, Identifiers.EDITOR_PART);
this.editorPart = this.instantiationService.createInstance(EditorPart, Identifiers.EDITOR_PART, !this.hasFilesToCreateOpenOrDiff);
this.toDispose.push(this.editorPart);
this.toShutdown.push(this.editorPart);
this.editorService = this.instantiationService.createInstance(WorkbenchEditorService, this.editorPart);
......
......@@ -9,7 +9,7 @@ import * as assert from 'assert';
import {EditorStacksModel, EditorGroup} from 'vs/workbench/common/editor/editorStacksModel';
import {EditorInput, IFileEditorInput, IEditorIdentifier, IEditorGroup, IStacksModelChangeEvent, IEditorRegistry, Extensions as EditorExtensions, IEditorInputFactory} from 'vs/workbench/common/editor';
import URI from 'vs/base/common/uri';
import {TestStorageService, TestConfigurationService, TestLifecycleService, TestContextService, TestWorkspace} from 'vs/test/utils/servicesTestUtils';
import {TestStorageService, TestConfigurationService, TestLifecycleService, TestContextService} from 'vs/test/utils/servicesTestUtils';
import { TestInstantiationService } from 'vs/test/utils/instantiationTestUtils';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {IStorageService} from 'vs/platform/storage/common/storage';
......@@ -32,7 +32,7 @@ function create(): EditorStacksModel {
inst.stub(IConfigurationService, config);
return inst.createInstance(EditorStacksModel);
return inst.createInstance(EditorStacksModel, true);
}
interface ModelEvents {
......@@ -645,7 +645,7 @@ suite('Editor Stacks Model', () => {
config.setUserConfiguration('workbench', { editor: { openPositioning: 'left' } });
const model = inst.createInstance(EditorStacksModel);
const model = inst.createInstance(EditorStacksModel, true);
const group = model.openGroup('group');
const events = groupListener(group);
......@@ -1180,7 +1180,7 @@ suite('Editor Stacks Model', () => {
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).setInstantiationService(inst);
let model: EditorStacksModel = inst.createInstance(EditorStacksModel);
let model: EditorStacksModel = inst.createInstance(EditorStacksModel, true);
let group = model.openGroup('group');
const input1 = input();
......@@ -1196,7 +1196,7 @@ suite('Editor Stacks Model', () => {
lifecycle.fireShutdown();
// Create model again - should load from storage
model = inst.createInstance(EditorStacksModel);
model = inst.createInstance(EditorStacksModel, true);
assert.equal(model.groups.length, 1);
......@@ -1223,7 +1223,7 @@ suite('Editor Stacks Model', () => {
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).setInstantiationService(inst);
let model: EditorStacksModel = inst.createInstance(EditorStacksModel);
let model: EditorStacksModel = inst.createInstance(EditorStacksModel, true);
let group1 = model.openGroup('group1');
......@@ -1266,7 +1266,7 @@ suite('Editor Stacks Model', () => {
lifecycle.fireShutdown();
// Create model again - should load from storage
model = inst.createInstance(EditorStacksModel);
model = inst.createInstance(EditorStacksModel, true);
group1 = model.groups[0];
group2 = model.groups[1];
......@@ -1304,7 +1304,7 @@ suite('Editor Stacks Model', () => {
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).setInstantiationService(inst);
let model: EditorStacksModel = inst.createInstance(EditorStacksModel);
let model: EditorStacksModel = inst.createInstance(EditorStacksModel, true);
let group = model.openGroup('group1');
......@@ -1327,7 +1327,7 @@ suite('Editor Stacks Model', () => {
lifecycle.fireShutdown();
// Create model again - should load from storage
model = inst.createInstance(EditorStacksModel);
model = inst.createInstance(EditorStacksModel, true);
group = model.groups[0];
......@@ -1353,7 +1353,7 @@ suite('Editor Stacks Model', () => {
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).setInstantiationService(inst);
let model: EditorStacksModel = inst.createInstance(EditorStacksModel);
let model: EditorStacksModel = inst.createInstance(EditorStacksModel, true);
let group1 = model.openGroup('group1');
let group2 = model.openGroup('group1');
......@@ -1370,7 +1370,7 @@ suite('Editor Stacks Model', () => {
lifecycle.fireShutdown();
// Create model again - should load from storage
model = inst.createInstance(EditorStacksModel);
model = inst.createInstance(EditorStacksModel, true);
group1 = model.groups[0];
......@@ -1384,17 +1384,15 @@ suite('Editor Stacks Model', () => {
let inst = new TestInstantiationService();
inst.stub(IStorageService, new TestStorageService());
inst.stub(IWorkspaceContextService, new TestContextService(TestWorkspace, { filesToCreate: [true] }));
const lifecycle = new TestLifecycleService();
inst.stub(ILifecycleService, lifecycle);
const config = new TestConfigurationService();
config.setUserConfiguration('workbench', { editor: { openPositioning: 'right' } });
inst.stub(IConfigurationService, config);
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).setInstantiationService(inst);
let model: EditorStacksModel = inst.createInstance(EditorStacksModel);
let model: EditorStacksModel = inst.createInstance(EditorStacksModel, false);
let group1 = model.openGroup('group1');
let group2 = model.openGroup('group1');
......@@ -1411,7 +1409,7 @@ suite('Editor Stacks Model', () => {
lifecycle.fireShutdown();
// Create model again - should NOT load from storage
model = inst.createInstance(EditorStacksModel);
model = inst.createInstance(EditorStacksModel, false);
assert.equal(model.groups.length, 0);
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册