From ab09cff06d1cf9ba671d3194e230dfd12bf5b2be Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 18 Aug 2016 16:48:35 +0200 Subject: [PATCH] remove another getOptions() call --- src/vs/test/utils/servicesTestUtils.ts | 2 +- .../browser/parts/editor/editorPart.ts | 3 +- .../common/editor/editorStacksModel.ts | 6 +-- .../workbench/electron-browser/workbench.ts | 39 +++++-------------- .../common/editor/editorStacksModel.test.ts | 28 +++++++------ 5 files changed, 27 insertions(+), 51 deletions(-) diff --git a/src/vs/test/utils/servicesTestUtils.ts b/src/vs/test/utils/servicesTestUtils.ts index 9a9a9b6755f..11830ff3d51 100644 --- a/src/vs/test/utils/servicesTestUtils.ts +++ b/src/vs/test/utils/servicesTestUtils.ts @@ -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 { diff --git a/src/vs/workbench/browser/parts/editor/editorPart.ts b/src/vs/workbench/browser/parts/editor/editorPart.ts index ef66b40513c..b9bb677bf26 100644 --- a/src/vs/workbench/browser/parts/editor/editorPart.ts +++ b/src/vs/workbench/browser/parts/editor/editorPart.ts @@ -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().workbench.editor; this.previewEditors = editorConfig.enablePreview; diff --git a/src/vs/workbench/common/editor/editorStacksModel.ts b/src/vs/workbench/common/editor/editorStacksModel.ts index d7e563bd295..7d5ce5cf673 100644 --- a/src/vs/workbench/common/editor/editorStacksModel.ts +++ b/src/vs/workbench/common/editor/editorStacksModel.ts @@ -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; 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 } diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts index fd68a69594f..43386162e8d 100644 --- a/src/vs/workbench/electron-browser/workbench.ts +++ b/src/vs/workbench/electron-browser/workbench.ts @@ -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; private messagesVisibleContext: IContextKey; private editorsVisibleContext: IContextKey; + 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(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); diff --git a/src/vs/workbench/test/common/editor/editorStacksModel.test.ts b/src/vs/workbench/test/common/editor/editorStacksModel.test.ts index 42ef4ef58d9..c6792aaf33e 100644 --- a/src/vs/workbench/test/common/editor/editorStacksModel.test.ts +++ b/src/vs/workbench/test/common/editor/editorStacksModel.test.ts @@ -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', () => { (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', () => { (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', () => { (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', () => { (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); - (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); });