diff --git a/src/vs/editor/standalone/browser/simpleServices.ts b/src/vs/editor/standalone/browser/simpleServices.ts index d45c0f557cc..46cf48c9665 100644 --- a/src/vs/editor/standalone/browser/simpleServices.ts +++ b/src/vs/editor/standalone/browser/simpleServices.ts @@ -18,7 +18,7 @@ import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingReso import { IKeybindingEvent, KeybindingSource, IKeyboardEvent } from 'vs/platform/keybinding/common/keybinding'; import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IConfirmation, IMessageService } from 'vs/platform/message/common/message'; -import { IWorkspaceContextService, IWorkspace } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, IWorkspace, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import * as editorCommon from 'vs/editor/common/editorCommon'; import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser'; import { Selection } from 'vs/editor/common/core/selection'; @@ -539,6 +539,16 @@ export class SimpleWorkspaceContextService implements IWorkspaceContextService { return this.workspace; } + public getWorkspaceState(): WorkspaceState { + if (this.workspace) { + if (this.workspace.configuration) { + return WorkspaceState.WORKSPACE; + } + return WorkspaceState.FOLDER; + } + return WorkspaceState.EMPTY; + } + public getRoot(resource: URI): URI { return resource && resource.scheme === SimpleWorkspaceContextService.SCHEME ? this.workspace.roots[0] : void 0; } @@ -547,14 +557,6 @@ export class SimpleWorkspaceContextService implements IWorkspaceContextService { return true; } - public hasFolderWorkspace(): boolean { - return true; - } - - public hasMultiFolderWorkspace(): boolean { - return false; - } - public isInsideWorkspace(resource: URI): boolean { return resource && resource.scheme === SimpleWorkspaceContextService.SCHEME; } diff --git a/src/vs/platform/workspace/common/workspace.ts b/src/vs/platform/workspace/common/workspace.ts index 880388b24e9..a3144892141 100644 --- a/src/vs/platform/workspace/common/workspace.ts +++ b/src/vs/platform/workspace/common/workspace.ts @@ -14,24 +14,29 @@ import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platf export const IWorkspaceContextService = createDecorator('contextService'); +export enum WorkspaceState { + EMPTY = 1, + FOLDER, + WORKSPACE +} + export interface IWorkspaceContextService { _serviceBrand: any; + /** + * Return the state of the current workspace. + * + * WorkspaceState.EMPTY - if the application was opened with empty window or file + * WorkspaceState.FOLDER - if the application was opened with a folder + * WorkspaceState.WORKSPACE - if the application was opened with a workspace + */ + getWorkspaceState(): WorkspaceState; + /** * Returns if the application was opened with a workspace or not. */ hasWorkspace(): boolean; - /** - * Returns if the application was opened with a folder. - */ - hasFolderWorkspace(): boolean; - - /** - * Returns if the application was opened with a workspace that can have one or more folders. - */ - hasMultiFolderWorkspace(): boolean; - /** * Provides access to the workspace object the platform is running with. This may be null if the workbench was opened * without workspace (empty); diff --git a/src/vs/workbench/api/electron-browser/mainThreadConfiguration.ts b/src/vs/workbench/api/electron-browser/mainThreadConfiguration.ts index 36b5e975ef9..17c48b27a99 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadConfiguration.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadConfiguration.ts @@ -9,7 +9,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { IDisposable } from 'vs/base/common/lifecycle'; import { Registry } from 'vs/platform/registry/common/platform'; import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration'; import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing'; import { MainThreadConfigurationShape, MainContext, ExtHostContext, IExtHostContext } from '../node/extHost.protocol'; @@ -51,7 +51,7 @@ export class MainThreadConfiguration implements MainThreadConfigurationShape { } private deriveConfigurationTarget(key: string, resource: URI): ConfigurationTarget { - if (resource && this._workspaceContextService.hasMultiFolderWorkspace()) { + if (resource && this._workspaceContextService.getWorkspaceState() === WorkspaceState.WORKSPACE) { const configurationProperties = Registry.as(ConfigurationExtensions.Configuration).getConfigurationProperties(); if (configurationProperties[key] && configurationProperties[key].scope === ConfigurationScope.RESOURCE) { return ConfigurationTarget.FOLDER; diff --git a/src/vs/workbench/browser/actions/workspaceActions.ts b/src/vs/workbench/browser/actions/workspaceActions.ts index d67da02d0a5..b1c67b005fa 100644 --- a/src/vs/workbench/browser/actions/workspaceActions.ts +++ b/src/vs/workbench/browser/actions/workspaceActions.ts @@ -11,7 +11,7 @@ import nls = require('vs/nls'); import { distinct } from 'vs/base/common/arrays'; import { IWindowService, IWindowsService } from 'vs/platform/windows/common/windows'; import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing'; import URI from 'vs/base/common/uri'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; @@ -112,7 +112,7 @@ export class AddRootFolderAction extends BaseWorkspacesAction { return this.instantiationService.createInstance(NewWorkspaceAction, NewWorkspaceAction.ID, NewWorkspaceAction.LABEL, []).run(); } - if (this.contextService.hasFolderWorkspace()) { + if (this.contextService.getWorkspaceState() === WorkspaceState.FOLDER) { return this.instantiationService.createInstance(NewWorkspaceAction, NewWorkspaceAction.ID, NewWorkspaceAction.LABEL, this.contextService.getWorkspace().roots).run(); } @@ -199,41 +199,34 @@ export class SaveWorkspaceAsAction extends BaseWorkspacesAction { } public run(): TPromise { - if (!this.contextService.hasWorkspace()) { + const workspaceState = this.contextService.getWorkspaceState(); + if (workspaceState === WorkspaceState.EMPTY) { this.messageService.show(Severity.Info, nls.localize('saveEmptyWorkspaceNotSupported', "Please open a workspace first to save.")); return TPromise.as(null); } const configPath = this.getNewWorkspaceConfigPath(); if (configPath) { - if (this.contextService.hasFolderWorkspace()) { - return this.saveFolderWorkspace(configPath); - } + switch (workspaceState) { - if (this.contextService.hasMultiFolderWorkspace()) { - return this.saveWorkspace(configPath); + case WorkspaceState.FOLDER: + const workspaceFolders = this.contextService.getWorkspace().roots.map(root => root.fsPath); + return this.windowService.createAndOpenWorkspace(workspaceFolders, configPath); + + case WorkspaceState.WORKSPACE: + return this.windowService.saveAndOpenWorkspace(configPath); } } return TPromise.as(null); } - private saveWorkspace(configPath: string): TPromise { - return this.windowService.saveAndOpenWorkspace(configPath); - } - - private saveFolderWorkspace(configPath: string): TPromise { - const workspaceFolders = this.contextService.getWorkspace().roots.map(root => root.fsPath); - - return this.windowService.createAndOpenWorkspace(workspaceFolders, configPath); - } - private getNewWorkspaceConfigPath(): string { const workspace = this.contextService.getWorkspace(); let defaultPath: string; - if (this.contextService.hasMultiFolderWorkspace() && !this.isUntitledWorkspace(workspace.configuration.fsPath)) { + if (workspace.configuration && !this.isUntitledWorkspace(workspace.configuration.fsPath)) { defaultPath = workspace.configuration.fsPath; - } else if (workspace && workspace.roots.length > 0) { + } else if (workspace.roots.length > 0) { defaultPath = dirname(workspace.roots[0].fsPath); // pick the parent of the first root by default } @@ -281,7 +274,8 @@ export class OpenWorkspaceConfigFileAction extends Action { ) { super(id, label); - this.enabled = this.workspaceContextService.hasMultiFolderWorkspace(); + const workspace = this.workspaceContextService.getWorkspace(); + this.enabled = workspace && !!workspace.configuration; } public run(): TPromise { diff --git a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts index 15f9670b6c8..a0d4bee32ac 100644 --- a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts +++ b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts @@ -192,15 +192,8 @@ export class TitlebarPart extends Part implements ITitleService { const input = this.editorService.getActiveEditorInput(); const workspace = this.contextService.getWorkspace(); - // Compute root resource - // Single Root Workspace: always the single root workspace in this case - // Multi Root Workspace: workspace configuration file - let root: URI; - if (this.contextService.hasMultiFolderWorkspace()) { - root = workspace.configuration; - } else if (this.contextService.hasFolderWorkspace()) { - root = workspace.roots[0]; - } + // root resource is either workspace configuration file or the first root + let root: URI = workspace ? workspace.configuration || workspace.roots[0] : null; // Compute folder resource // Single Root Workspace: always the root single workspace in this case @@ -219,7 +212,7 @@ export class TitlebarPart extends Part implements ITitleService { const activeEditorMedium = input ? input.getTitle(Verbosity.MEDIUM) : activeEditorShort; const activeEditorLong = input ? input.getTitle(Verbosity.LONG) : activeEditorMedium; const rootName = workspace ? workspace.name : ''; - const rootPath = workspace ? labels.getPathLabel(root, void 0, this.environmentService) : ''; + const rootPath = root ? labels.getPathLabel(root, void 0, this.environmentService) : ''; const folderName = folder ? (paths.basename(folder.fsPath) || folder.fsPath) : ''; const folderPath = folder ? labels.getPathLabel(folder, void 0, this.environmentService) : ''; const dirty = input && input.isDirty() ? TitlebarPart.TITLE_DIRTY : ''; diff --git a/src/vs/workbench/electron-browser/main.ts b/src/vs/workbench/electron-browser/main.ts index fad53b83a01..e21601af993 100644 --- a/src/vs/workbench/electron-browser/main.ts +++ b/src/vs/workbench/electron-browser/main.ts @@ -16,7 +16,7 @@ import platform = require('vs/base/common/platform'); import paths = require('vs/base/common/paths'); import uri from 'vs/base/common/uri'; import strings = require('vs/base/common/strings'); -import { IWorkspaceContextService, Workspace } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, Workspace, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { EmptyWorkspaceServiceImpl, WorkspaceServiceImpl, WorkspaceService } from 'vs/workbench/services/configuration/node/configuration'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; @@ -153,26 +153,31 @@ function createStorageService(configuration: IWindowConfiguration, workspaceServ let workspaceId: string; let secondaryWorkspaceId: number; - // in multi root workspace mode we use the provided ID as key for workspace storage - if (workspaceService.hasMultiFolderWorkspace()) { - workspaceId = uri.from({ path: workspace.id, scheme: 'root' }).toString(); - } + switch (workspaceService.getWorkspaceState()) { - // in single folder mode we use the path of the opened folder as key for workspace storage - // the ctime is used as secondary workspace id to clean up stale UI state if necessary - else if (workspaceService.hasFolderWorkspace()) { - workspaceId = workspace.roots[0].toString(); - secondaryWorkspaceId = workspace.ctime; - } + // in multi root workspace mode we use the provided ID as key for workspace storage + case WorkspaceState.WORKSPACE: + workspaceId = uri.from({ path: workspace.id, scheme: 'root' }).toString(); + break; - // finaly, if we do not have a workspace open, we need to find another identifier for the window to store - // workspace UI state. if we have a backup path in the configuration we can use that because this - // will be a unique identifier per window that is stable between restarts as long as there are - // dirty files in the workspace. - // We use basename() to produce a short identifier, we do not need the full path. We use a custom - // scheme so that we can later distinguish these identifiers from the workspace one. - else if (configuration.backupPath) { - workspaceId = uri.from({ path: path.basename(configuration.backupPath), scheme: 'empty' }).toString(); + // in single folder mode we use the path of the opened folder as key for workspace storage + // the ctime is used as secondary workspace id to clean up stale UI state if necessary + case WorkspaceState.FOLDER: + workspaceId = workspace.roots[0].toString(); + secondaryWorkspaceId = workspace.ctime; + break; + + // finaly, if we do not have a workspace open, we need to find another identifier for the window to store + // workspace UI state. if we have a backup path in the configuration we can use that because this + // will be a unique identifier per window that is stable between restarts as long as there are + // dirty files in the workspace. + // We use basename() to produce a short identifier, we do not need the full path. We use a custom + // scheme so that we can later distinguish these identifiers from the workspace one. + case WorkspaceState.EMPTY: + if (configuration.backupPath) { + workspaceId = uri.from({ path: path.basename(configuration.backupPath), scheme: 'empty' }).toString(); + } + break; } const disableStorage = !!environmentService.extensionTestsPath; // never keep any state when running extension tests! diff --git a/src/vs/workbench/electron-browser/window.ts b/src/vs/workbench/electron-browser/window.ts index 947b60ef708..7dcdd449cae 100644 --- a/src/vs/workbench/electron-browser/window.ts +++ b/src/vs/workbench/electron-browser/window.ts @@ -39,7 +39,7 @@ import { IExtensionService } from 'vs/platform/extensions/common/extensions'; import { KeyboardMapperFactory } from 'vs/workbench/services/keybinding/electron-browser/keybindingService'; import { Themable } from 'vs/workbench/common/theme'; import { ipcRenderer as ipc, webFrame } from 'electron'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing'; const TextInputActions: IAction[] = [ @@ -288,7 +288,7 @@ export class ElectronWindow extends Themable { const foldersToAdd = request.foldersToAdd.map(folderToAdd => URI.file(folderToAdd.filePath)); // Workspace: just add to workspace config - if (this.contextService.hasMultiFolderWorkspace()) { + if (this.contextService.getWorkspaceState() === WorkspaceState.WORKSPACE) { this.workspaceEditingService.addRoots(foldersToAdd).done(null, errors.onUnexpectedError); } @@ -297,7 +297,7 @@ export class ElectronWindow extends Themable { const workspaceFolders: URI[] = []; // Folder of workspace is the first of multi root workspace, so add it - if (this.contextService.hasFolderWorkspace()) { + if (this.contextService.getWorkspaceState() === WorkspaceState.FOLDER) { workspaceFolders.push(...this.contextService.getWorkspace().roots); } diff --git a/src/vs/workbench/parts/debug/electron-browser/debugViewer.ts b/src/vs/workbench/parts/debug/electron-browser/debugViewer.ts index 4737247e86b..682ee4afeab 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugViewer.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugViewer.ts @@ -22,7 +22,7 @@ import { DefaultController, DefaultDragAndDrop, ClickBehavior } from 'vs/base/pa import { Constants } from 'vs/editor/common/core/uint'; import { IContextViewService, IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IMenuService, IMenu, MenuId } from 'vs/platform/actions/common/actions'; import { fillInActions } from 'vs/platform/actions/browser/menuItemActionItem'; @@ -524,7 +524,7 @@ export class CallStackRenderer implements IRenderer { private renderProcess(process: debug.IProcess, data: IProcessTemplateData): void { data.process.title = nls.localize({ key: 'process', comment: ['Process is a noun'] }, "Process"); - data.name.textContent = process.getName(this.contextService.hasMultiFolderWorkspace()); + data.name.textContent = process.getName(this.contextService.getWorkspaceState() === WorkspaceState.WORKSPACE); const stoppedThread = process.getAllThreads().filter(t => t.stopped).pop(); data.stateLabel.textContent = stoppedThread ? nls.localize('paused', "Paused") diff --git a/src/vs/workbench/parts/files/browser/views/explorerView.ts b/src/vs/workbench/parts/files/browser/views/explorerView.ts index e99e1d220a8..d642dd7adda 100644 --- a/src/vs/workbench/parts/files/browser/views/explorerView.ts +++ b/src/vs/workbench/parts/files/browser/views/explorerView.ts @@ -32,7 +32,7 @@ import { FileStat, Model } from 'vs/workbench/parts/files/common/explorerModel'; import { IListService } from 'vs/platform/list/browser/listService'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IPartService } from 'vs/workbench/services/part/common/partService'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; @@ -727,8 +727,8 @@ export class ExplorerView extends CollapsibleView { let targetsToExpand: URI[] = []; if (this.settings[ExplorerView.MEMENTO_EXPANDED_FOLDER_RESOURCES]) { targetsToExpand = this.settings[ExplorerView.MEMENTO_EXPANDED_FOLDER_RESOURCES].map((e: string) => URI.parse(e)); - } else if (this.contextService.hasFolderWorkspace() || (this.contextService.hasMultiFolderWorkspace() && this.model.roots.length === 1)) { - targetsToExpand = this.model.roots.map(root => root.resource); // always expand single folder workspace and multi folder workspace with only 1 root + } else if (this.model.roots.length === 1) { + targetsToExpand = this.model.roots.map(root => root.resource); // always expand if there is just one root } // First time refresh: Receive target through active editor input or selection and also include settings from previous session @@ -778,7 +778,7 @@ export class ExplorerView extends CollapsibleView { // Subsequent refresh: Merge stat into our local model and refresh tree modelStats.forEach((modelStat, index) => FileStat.mergeLocalWithDisk(modelStat, this.model.roots[index])); - const input = this.contextService.hasFolderWorkspace() ? this.model.roots[0] : this.model; + const input = this.contextService.getWorkspaceState() === WorkspaceState.FOLDER ? this.model.roots[0] : this.model; if (input === this.explorerViewer.getInput()) { return this.explorerViewer.refresh(); } diff --git a/src/vs/workbench/parts/files/browser/views/explorerViewer.ts b/src/vs/workbench/parts/files/browser/views/explorerViewer.ts index d67a2880f86..60c6519a6e2 100644 --- a/src/vs/workbench/parts/files/browser/views/explorerViewer.ts +++ b/src/vs/workbench/parts/files/browser/views/explorerViewer.ts @@ -35,7 +35,7 @@ import { FileStat, NewStatPlaceholder, Model } from 'vs/workbench/parts/files/co import { DragMouseEvent, IMouseEvent } from 'vs/base/browser/mouseEvent'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IPartService } from 'vs/workbench/services/part/common/partService'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IContextViewService, IContextMenuService } from 'vs/platform/contextview/browser/contextView'; @@ -829,7 +829,7 @@ export class FileDragAndDrop extends SimpleFileResourceDragAndDrop { // All (target = model) if (target instanceof Model) { - return this.contextService.hasMultiFolderWorkspace() ? DRAG_OVER_ACCEPT_BUBBLE_DOWN_COPY(false) : DRAG_OVER_REJECT; // can only drop folders to workspace + return this.contextService.getWorkspaceState() === WorkspaceState.WORKSPACE ? DRAG_OVER_ACCEPT_BUBBLE_DOWN_COPY(false) : DRAG_OVER_REJECT; // can only drop folders to workspace } // All (target = file/folder) @@ -883,7 +883,7 @@ export class FileDragAndDrop extends SimpleFileResourceDragAndDrop { return void 0; // TODO@Ben multi root } - if (this.contextService.hasMultiFolderWorkspace()) { + if (this.contextService.getWorkspaceState() === WorkspaceState.WORKSPACE) { return this.workspaceEditingService.addRoots(folders); } diff --git a/src/vs/workbench/parts/preferences/browser/preferencesActions.ts b/src/vs/workbench/parts/preferences/browser/preferencesActions.ts index 1cee1d5d6c2..d81800c8cfb 100644 --- a/src/vs/workbench/parts/preferences/browser/preferencesActions.ts +++ b/src/vs/workbench/parts/preferences/browser/preferencesActions.ts @@ -11,7 +11,7 @@ import { Action } from 'vs/base/common/actions'; import { IModeService } from 'vs/editor/common/services/modeService'; import { IQuickOpenService, IPickOpenEntry, IFilePickOpenEntry } from 'vs/platform/quickOpen/common/quickOpen'; import { IPreferencesService, getSettingsTargetName } from 'vs/workbench/parts/preferences/common/preferences'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing'; export class OpenGlobalSettingsAction extends Action { @@ -101,7 +101,7 @@ export class OpenFolderSettingsAction extends Action { @IQuickOpenService private quickOpenService: IQuickOpenService ) { super(id, label); - this.enabled = this.workspaceContextService.hasMultiFolderWorkspace(); + this.enabled = this.workspaceContextService.getWorkspaceState() === WorkspaceState.WORKSPACE; } public run(): TPromise { diff --git a/src/vs/workbench/parts/preferences/browser/preferencesRenderers.ts b/src/vs/workbench/parts/preferences/browser/preferencesRenderers.ts index ad7e9950cfe..85b89e72a96 100644 --- a/src/vs/workbench/parts/preferences/browser/preferencesRenderers.ts +++ b/src/vs/workbench/parts/preferences/browser/preferencesRenderers.ts @@ -31,7 +31,7 @@ import { IMessageService, Severity } from 'vs/platform/message/common/message'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { ICursorPositionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; import { ModelDecorationOptions } from 'vs/editor/common/model/textModelWithDecorations'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { MarkdownString } from 'vs/base/common/htmlContent'; export interface IPreferencesRenderer extends IDisposable { @@ -1064,7 +1064,7 @@ class WorkspaceConfigurationRenderer extends Disposable { } public render(): void { - if (this.workspaceContextService.hasMultiFolderWorkspace()) { + if (this.workspaceContextService.getWorkspaceState() === WorkspaceState.WORKSPACE) { this.editor.changeDecorations(changeAccessor => this.decorationIds = changeAccessor.deltaDecorations(this.decorationIds, [])); const ranges: IRange[] = []; diff --git a/src/vs/workbench/parts/preferences/browser/preferencesService.ts b/src/vs/workbench/parts/preferences/browser/preferencesService.ts index d37e517d962..e1ce90b0cc2 100644 --- a/src/vs/workbench/parts/preferences/browser/preferencesService.ts +++ b/src/vs/workbench/parts/preferences/browser/preferencesService.ts @@ -16,7 +16,7 @@ import { Disposable } from 'vs/base/common/lifecycle'; import { Emitter } from 'vs/base/common/event'; import { EditorInput } from 'vs/workbench/common/editor'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration'; import { Position as EditorPosition, IEditor } from 'vs/platform/editor/common/editor'; import { ICommonCodeEditor } from 'vs/editor/common/editorCommon'; @@ -179,7 +179,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic return this.createEditableSettingsEditorModel(ConfigurationTarget.WORKSPACE, workspaceSettingsUri); } - if (this.contextService.hasMultiFolderWorkspace()) { + if (this.contextService.getWorkspaceState() === WorkspaceState.WORKSPACE) { return this.createEditableSettingsEditorModel(ConfigurationTarget.FOLDER, uri); } @@ -299,7 +299,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic } private resolveSettingsContentFromWorkspaceConfiguration(): TPromise { - if (this.contextService.hasMultiFolderWorkspace()) { + if (this.contextService.getWorkspaceState() === WorkspaceState.WORKSPACE) { return this.textModelResolverService.createModelReference(this.contextService.getWorkspace().configuration) .then(reference => { const model = reference.object.textEditorModel; @@ -317,13 +317,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic return URI.file(this.environmentService.appSettingsPath); case ConfigurationTarget.WORKSPACE: const workspace = this.contextService.getWorkspace(); - if (this.contextService.hasFolderWorkspace()) { - return this.toResource(paths.join('.vscode', 'settings.json'), workspace.roots[0]); - } - if (this.contextService.hasMultiFolderWorkspace()) { - return workspace.configuration; - } - return null; + return workspace ? workspace.configuration || this.toResource(paths.join('.vscode', 'settings.json'), workspace.roots[0]) : null; case ConfigurationTarget.FOLDER: const root = this.contextService.getRoot(resource); return root ? this.toResource(paths.join('.vscode', 'settings.json'), root) : null; @@ -336,7 +330,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic } private createSettingsIfNotExists(target: ConfigurationTarget, resource: URI): TPromise { - if (this.contextService.hasMultiFolderWorkspace() && target === ConfigurationTarget.WORKSPACE) { + if (this.contextService.getWorkspaceState() === WorkspaceState.WORKSPACE && target === ConfigurationTarget.WORKSPACE) { if (!this.configurationService.keys().workspace.length) { return this.jsonEditingService.write(resource, { key: 'settings', value: {} }, true).then(null, () => { }); } diff --git a/src/vs/workbench/parts/preferences/browser/preferencesWidgets.ts b/src/vs/workbench/parts/preferences/browser/preferencesWidgets.ts index c2212fcb657..b6d575759aa 100644 --- a/src/vs/workbench/parts/preferences/browser/preferencesWidgets.ts +++ b/src/vs/workbench/parts/preferences/browser/preferencesWidgets.ts @@ -20,7 +20,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { IContextViewService, IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { ISettingsGroup, IPreferencesService, getSettingsTargetName } from 'vs/workbench/parts/preferences/common/preferences'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { IAction, IActionRunner } from 'vs/base/common/actions'; import { attachInputBoxStyler, attachStylerCallback, attachSelectBoxStyler } from 'vs/platform/theme/common/styler'; import { IThemeService } from 'vs/platform/theme/common/themeService'; @@ -293,7 +293,7 @@ export class SettingsTargetsWidget extends Widget { private create(parent: HTMLElement): void { this.settingsTargetsContainer = DOM.append(parent, DOM.$('.settings-targets-widget')); - this.settingsTargetsContainer.style.width = this.workspaceContextService.hasMultiFolderWorkspace() ? '200px' : '150px'; + this.settingsTargetsContainer.style.width = this.workspaceContextService.getWorkspaceState() === WorkspaceState.WORKSPACE ? '200px' : '150px'; const targetElement = DOM.append(this.settingsTargetsContainer, DOM.$('.settings-target')); this.targetLabel = DOM.append(targetElement, DOM.$('.settings-target-label')); @@ -348,7 +348,7 @@ export class SettingsTargetsWidget extends Widget { }); } - if (this.workspaceContextService.hasMultiFolderWorkspace()) { + if (this.workspaceContextService.getWorkspaceState() === WorkspaceState.WORKSPACE) { actions.push(new Separator()); actions.push(...this.workspaceContextService.getWorkspace().roots.map((root, index) => { return { diff --git a/src/vs/workbench/parts/search/browser/searchViewlet.ts b/src/vs/workbench/parts/search/browser/searchViewlet.ts index 6f6dce24526..6f27f6771ca 100644 --- a/src/vs/workbench/parts/search/browser/searchViewlet.ts +++ b/src/vs/workbench/parts/search/browser/searchViewlet.ts @@ -41,7 +41,7 @@ import { IContextViewService } from 'vs/platform/contextview/browser/contextView import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IMessageService, IConfirmation } from 'vs/platform/message/common/message'; import { IProgressService } from 'vs/platform/progress/common/progress'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { KeyCode } from 'vs/base/common/keyCodes'; @@ -468,7 +468,7 @@ export class SearchViewlet extends Viewlet { this.results = div; this.results.addClass('show-file-icons'); - let dataSource = new SearchDataSource(this.contextService.hasMultiFolderWorkspace()); + let dataSource = new SearchDataSource(this.contextService.getWorkspaceState() === WorkspaceState.WORKSPACE); let renderer = this.instantiationService.createInstance(SearchRenderer, this.getActionRunner(), this); let dnd = new SimpleFileResourceDragAndDrop(obj => obj instanceof FileMatch ? obj.resource() : void 0); @@ -872,7 +872,7 @@ export class SearchViewlet extends Viewlet { let folderPath = null; const workspace = this.contextService.getWorkspace(); if (workspace && resource) { - if (this.contextService.hasFolderWorkspace()) { + if (this.contextService.getWorkspaceState() === WorkspaceState.FOLDER) { // Show relative path from the root for single-root mode folderPath = paths.relative(workspace.roots[0].fsPath, resource.fsPath); if (folderPath && folderPath !== '.') { diff --git a/src/vs/workbench/parts/search/common/queryBuilder.ts b/src/vs/workbench/parts/search/common/queryBuilder.ts index 51e17c9a4fb..5c4ccaefcc8 100644 --- a/src/vs/workbench/parts/search/common/queryBuilder.ts +++ b/src/vs/workbench/parts/search/common/queryBuilder.ts @@ -12,7 +12,7 @@ import * as glob from 'vs/base/common/glob'; import * as paths from 'vs/base/common/paths'; import * as strings from 'vs/base/common/strings'; import uri from 'vs/base/common/uri'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { IPatternInfo, IQueryOptions, IFolderQuery, ISearchQuery, QueryType, ISearchConfiguration, getExcludes, pathIncludedInQuery } from 'vs/platform/search/common/search'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; @@ -213,7 +213,7 @@ export class QueryBuilder { } const workspace = this.workspaceContextService.getWorkspace(); - if (this.workspaceContextService.hasFolderWorkspace()) { + if (this.workspaceContextService.getWorkspaceState() === WorkspaceState.FOLDER) { // TODO: @Sandy Try checking workspace folders length instead. return [paths.normalize( paths.join(workspace.roots[0].fsPath, searchPath))]; } else if (searchPath === './') { diff --git a/src/vs/workbench/services/configuration/node/configuration.ts b/src/vs/workbench/services/configuration/node/configuration.ts index 5f3349926e5..4a621ea0883 100644 --- a/src/vs/workbench/services/configuration/node/configuration.ts +++ b/src/vs/workbench/services/configuration/node/configuration.ts @@ -18,7 +18,7 @@ import { RunOnceScheduler } from 'vs/base/common/async'; import { readFile, stat } from 'vs/base/node/pfs'; import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry'; import * as extfs from 'vs/base/node/extfs'; -import { IWorkspaceContextService, IWorkspace, Workspace } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, IWorkspace, Workspace, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { FileChangeType, FileChangesEvent } from 'vs/platform/files/common/files'; import { isLinux } from 'vs/base/common/platform'; import { ConfigWatcher } from 'vs/base/node/config'; @@ -198,18 +198,20 @@ export class WorkspaceService extends Disposable implements IWorkspaceConfigurat return this.workspace; } + public getWorkspaceState(): WorkspaceState { + if (this.workspace) { + if (this.workspace.configuration) { + return WorkspaceState.WORKSPACE; + } + return WorkspaceState.FOLDER; + } + return WorkspaceState.EMPTY; + } + public hasWorkspace(): boolean { return !!this.workspace; } - public hasFolderWorkspace(): boolean { - return this.workspace && !this.workspace.configuration; - } - - public hasMultiFolderWorkspace(): boolean { - return this.workspace && !!this.workspace.configuration; - } - public getRoot(resource: URI): URI { return this.workspace ? this.workspace.getRoot(resource) : null; } @@ -373,7 +375,7 @@ export class WorkspaceServiceImpl extends WorkspaceService { } public getUnsupportedWorkspaceKeys(): string[] { - return this.hasFolderWorkspace() ? this._configuration.getFolderConfigurationModel(this.workspace.roots[0]).workspaceSettingsConfig.unsupportedKeys : []; + return this.getWorkspaceState() === WorkspaceState.FOLDER ? this._configuration.getFolderConfigurationModel(this.workspace.roots[0]).workspaceSettingsConfig.unsupportedKeys : []; } public initialize(trigger: boolean = true): TPromise { @@ -382,7 +384,7 @@ export class WorkspaceServiceImpl extends WorkspaceService { .then(() => super.initialize(trigger)); } - if (this.hasMultiFolderWorkspace()) { + if (this.workspaceConfigPath) { return this.workspaceConfiguration.load(this.workspaceConfigPath) .then(() => super.initialize(trigger)); } @@ -536,7 +538,7 @@ export class WorkspaceServiceImpl extends WorkspaceService { private initCachesForFolders(folders: URI[]): void { for (const folder of folders) { - this.cachedFolderConfigs.set(folder, this._register(new FolderConfiguration(folder, this.workspaceSettingsRootFolder, this.hasMultiFolderWorkspace() ? ConfigurationScope.RESOURCE : ConfigurationScope.WINDOW))); + this.cachedFolderConfigs.set(folder, this._register(new FolderConfiguration(folder, this.workspaceSettingsRootFolder, this.getWorkspaceState() === WorkspaceState.WORKSPACE ? ConfigurationScope.RESOURCE : ConfigurationScope.WINDOW))); this.updateFolderConfiguration(folder, new FolderConfigurationModel(new FolderSettingsModel(null), [], ConfigurationScope.RESOURCE), false); } } @@ -605,7 +607,7 @@ export class WorkspaceServiceImpl extends WorkspaceService { private updateFolderConfiguration(folder: URI, folderConfiguration: FolderConfigurationModel, compare: boolean): boolean { let configurationChanged = this._configuration.updateFolderConfiguration(folder, folderConfiguration, compare); - if (this.hasFolderWorkspace()) { + if (this.getWorkspaceState() === WorkspaceState.FOLDER) { // Workspace configuration changed configurationChanged = this.updateWorkspaceConfiguration(compare) || configurationChanged; } @@ -613,7 +615,7 @@ export class WorkspaceServiceImpl extends WorkspaceService { } private updateWorkspaceConfiguration(compare: boolean): boolean { - const workspaceConfiguration = this.hasMultiFolderWorkspace() ? this.workspaceConfiguration.workspaceConfigurationModel.workspaceConfiguration : this._configuration.getFolderConfigurationModel(this.workspace.roots[0]); + const workspaceConfiguration = this.getWorkspaceState() === WorkspaceState.WORKSPACE ? this.workspaceConfiguration.workspaceConfigurationModel.workspaceConfiguration : this._configuration.getFolderConfigurationModel(this.workspace.roots[0]); return this._configuration.updateWorkspaceConfiguration(workspaceConfiguration, compare); } diff --git a/src/vs/workbench/services/configuration/node/configurationEditingService.ts b/src/vs/workbench/services/configuration/node/configurationEditingService.ts index e4568ab9394..cc950d2e3c3 100644 --- a/src/vs/workbench/services/configuration/node/configurationEditingService.ts +++ b/src/vs/workbench/services/configuration/node/configurationEditingService.ts @@ -21,7 +21,7 @@ import { EditOperation } from 'vs/editor/common/core/editOperation'; import { Registry } from 'vs/platform/registry/common/platform'; import { Range } from 'vs/editor/common/core/range'; import { Selection } from 'vs/editor/common/core/selection'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { IConfigurationService, IConfigurationOverrides } from 'vs/platform/configuration/common/configuration'; @@ -332,10 +332,10 @@ export class ConfigurationEditingService implements IConfigurationEditingService if (workspace) { if (target === ConfigurationTarget.WORKSPACE) { - return this.contextService.hasMultiFolderWorkspace() ? workspace.configuration : this.toResource(relativePath, workspace.roots[0]); + return workspace.configuration || this.toResource(relativePath, workspace.roots[0]); } - if (target === ConfigurationTarget.FOLDER && this.contextService.hasMultiFolderWorkspace()) { + if (target === ConfigurationTarget.FOLDER && this.contextService.getWorkspaceState() === WorkspaceState.WORKSPACE) { if (resource) { const root = this.contextService.getRoot(resource); if (root) { diff --git a/src/vs/workbench/services/workspace/node/workspaceEditingService.ts b/src/vs/workbench/services/workspace/node/workspaceEditingService.ts index 33cbf289a08..bd896c78398 100644 --- a/src/vs/workbench/services/workspace/node/workspaceEditingService.ts +++ b/src/vs/workbench/services/workspace/node/workspaceEditingService.ts @@ -53,10 +53,10 @@ export class WorkspaceEditingService implements IWorkspaceEditingService { } private isSupported(): boolean { - // TODO@Ben multi root + const workspace = this.contextService.getWorkspace(); return ( this.environmentService.appQuality !== 'stable' // not yet enabled in stable - && this.contextService.hasMultiFolderWorkspace() // we need a multi folder workspace to begin with + && workspace && !!workspace.configuration // we need a workspace configuration file to begin with ); } diff --git a/src/vs/workbench/services/workspace/node/workspaceMigrationService.ts b/src/vs/workbench/services/workspace/node/workspaceMigrationService.ts index 218ccc286d3..0ad6a488fae 100644 --- a/src/vs/workbench/services/workspace/node/workspaceMigrationService.ts +++ b/src/vs/workbench/services/workspace/node/workspaceMigrationService.ts @@ -9,7 +9,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; import URI from 'vs/base/common/uri'; import { once } from 'vs/base/common/event'; import { IDisposable } from 'vs/base/common/lifecycle'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { Registry } from 'vs/platform/registry/common/platform'; import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; @@ -62,7 +62,7 @@ export class WorkspaceMigrationService implements IWorkspaceMigrationService { } private migrateConfiguration(toWorkspaceId: IWorkspaceIdentifier): TPromise { - if (!this.contextService.hasFolderWorkspace()) { + if (this.contextService.getWorkspaceState() !== WorkspaceState.FOLDER) { return TPromise.as(void 0); // return early if not a folder workspace is opened } diff --git a/src/vs/workbench/test/electron-browser/api/mainThreadConfiguration.test.ts b/src/vs/workbench/test/electron-browser/api/mainThreadConfiguration.test.ts index effdeecbea4..95d7f71552a 100644 --- a/src/vs/workbench/test/electron-browser/api/mainThreadConfiguration.test.ts +++ b/src/vs/workbench/test/electron-browser/api/mainThreadConfiguration.test.ts @@ -10,7 +10,7 @@ import * as sinon from 'sinon'; import URI from 'vs/base/common/uri'; import { Registry } from 'vs/platform/registry/common/platform'; import { Extensions, IConfigurationRegistry, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock'; import { MainThreadConfiguration } from 'vs/workbench/api/electron-browser/mainThreadConfiguration'; import { ConfigurationTarget, IConfigurationEditingService } from 'vs/workbench/services/configuration/common/configurationEditing'; @@ -56,7 +56,7 @@ suite('ExtHostConfiguration', function () { }); test('update resource configuration without configuration target defaults to workspace in multi root workspace when no resource is provided', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => true }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.WORKSPACE }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$updateConfigurationOption(null, 'extHostConfiguration.resource', 'value', null); @@ -65,7 +65,7 @@ suite('ExtHostConfiguration', function () { }); test('update resource configuration without configuration target defaults to workspace in folder workspace when resource is provider', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => false }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.FOLDER }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$updateConfigurationOption(null, 'extHostConfiguration.resource', 'value', URI.file('abc')); @@ -74,7 +74,7 @@ suite('ExtHostConfiguration', function () { }); test('update resource configuration without configuration target defaults to workspace in folder workspace when no resource is provider', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => false }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.FOLDER }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$updateConfigurationOption(null, 'extHostConfiguration.resource', 'value', null); @@ -83,7 +83,7 @@ suite('ExtHostConfiguration', function () { }); test('update window configuration without configuration target defaults to workspace in multi root workspace when no resource is provided', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => true }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.WORKSPACE }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$updateConfigurationOption(null, 'extHostConfiguration.window', 'value', null); @@ -92,7 +92,7 @@ suite('ExtHostConfiguration', function () { }); test('update window configuration without configuration target defaults to workspace in multi root workspace when resource is provided', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => true }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.WORKSPACE }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$updateConfigurationOption(null, 'extHostConfiguration.window', 'value', URI.file('abc')); @@ -101,7 +101,7 @@ suite('ExtHostConfiguration', function () { }); test('update window configuration without configuration target defaults to workspace in folder workspace when resource is provider', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => false }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.FOLDER }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$updateConfigurationOption(null, 'extHostConfiguration.window', 'value', URI.file('abc')); @@ -110,7 +110,7 @@ suite('ExtHostConfiguration', function () { }); test('update window configuration without configuration target defaults to workspace in folder workspace when no resource is provider', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => false }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.FOLDER }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$updateConfigurationOption(null, 'extHostConfiguration.window', 'value', null); @@ -119,7 +119,7 @@ suite('ExtHostConfiguration', function () { }); test('update resource configuration without configuration target defaults to folder', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => true }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.WORKSPACE }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$updateConfigurationOption(null, 'extHostConfiguration.resource', 'value', URI.file('abc')); @@ -128,7 +128,7 @@ suite('ExtHostConfiguration', function () { }); test('update configuration with user configuration target', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => false }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.FOLDER }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$updateConfigurationOption(ConfigurationTarget.USER, 'extHostConfiguration.window', 'value', URI.file('abc')); @@ -137,7 +137,7 @@ suite('ExtHostConfiguration', function () { }); test('update configuration with workspace configuration target', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => false }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.FOLDER }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$updateConfigurationOption(ConfigurationTarget.WORKSPACE, 'extHostConfiguration.window', 'value', URI.file('abc')); @@ -146,7 +146,7 @@ suite('ExtHostConfiguration', function () { }); test('update configuration with folder configuration target', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => false }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.FOLDER }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$updateConfigurationOption(ConfigurationTarget.FOLDER, 'extHostConfiguration.window', 'value', URI.file('abc')); @@ -155,7 +155,7 @@ suite('ExtHostConfiguration', function () { }); test('remove resource configuration without configuration target defaults to workspace in multi root workspace when no resource is provided', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => true }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.WORKSPACE }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$removeConfigurationOption(null, 'extHostConfiguration.resource', null); @@ -164,7 +164,7 @@ suite('ExtHostConfiguration', function () { }); test('remove resource configuration without configuration target defaults to workspace in folder workspace when resource is provider', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => false }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.FOLDER }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$removeConfigurationOption(null, 'extHostConfiguration.resource', URI.file('abc')); @@ -173,7 +173,7 @@ suite('ExtHostConfiguration', function () { }); test('remove resource configuration without configuration target defaults to workspace in folder workspace when no resource is provider', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => false }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.FOLDER }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$removeConfigurationOption(null, 'extHostConfiguration.resource', null); @@ -182,7 +182,7 @@ suite('ExtHostConfiguration', function () { }); test('remove window configuration without configuration target defaults to workspace in multi root workspace when no resource is provided', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => true }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.WORKSPACE }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$removeConfigurationOption(null, 'extHostConfiguration.window', null); @@ -191,7 +191,7 @@ suite('ExtHostConfiguration', function () { }); test('remove window configuration without configuration target defaults to workspace in multi root workspace when resource is provided', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => true }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.WORKSPACE }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$removeConfigurationOption(null, 'extHostConfiguration.window', URI.file('abc')); @@ -200,7 +200,7 @@ suite('ExtHostConfiguration', function () { }); test('remove window configuration without configuration target defaults to workspace in folder workspace when resource is provider', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => false }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.FOLDER }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$removeConfigurationOption(null, 'extHostConfiguration.window', URI.file('abc')); @@ -209,7 +209,7 @@ suite('ExtHostConfiguration', function () { }); test('remove window configuration without configuration target defaults to workspace in folder workspace when no resource is provider', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => false }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.FOLDER }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$removeConfigurationOption(null, 'extHostConfiguration.window', null); @@ -218,7 +218,7 @@ suite('ExtHostConfiguration', function () { }); test('remove configuration without configuration target defaults to folder', function () { - instantiationService.stub(IWorkspaceContextService, { hasMultiFolderWorkspace: () => true }); + instantiationService.stub(IWorkspaceContextService, { getWorkspaceState: () => WorkspaceState.WORKSPACE }); const testObject: MainThreadConfiguration = instantiationService.createInstance(MainThreadConfiguration, OneGetThreadService(null)); testObject.$removeConfigurationOption(null, 'extHostConfiguration.resource', URI.file('abc')); diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index f9c8e2f2ddf..bdd3aed7bb9 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -27,7 +27,7 @@ import { ITextModelService } from 'vs/editor/common/services/resolverService'; import { IEditorInput, IEditorOptions, Position, Direction, IEditor, IResourceInput, ITextEditorSelection } from 'vs/platform/editor/common/editor'; import { IUntitledEditorService, UntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { IMessageService, IConfirmation } from 'vs/platform/message/common/message'; -import { IWorkspaceContextService, IWorkspace as IWorkbenchWorkspace } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, IWorkspace as IWorkbenchWorkspace, WorkspaceState } from 'vs/platform/workspace/common/workspace'; import { ILifecycleService, ShutdownEvent, ShutdownReason, StartupKind, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; import { EditorStacksModel } from 'vs/workbench/common/editor/editorStacksModel'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; @@ -94,18 +94,20 @@ export class TestContextService implements IWorkspaceContextService { return this.workspace ? this.workspace.roots : []; } + public getWorkspaceState(): WorkspaceState { + if (this.workspace) { + if (this.workspace.configuration) { + return WorkspaceState.WORKSPACE; + } + return WorkspaceState.FOLDER; + } + return WorkspaceState.EMPTY; + } + public hasWorkspace(): boolean { return !!this.workspace; } - public hasFolderWorkspace(): boolean { - return this.workspace && !this.workspace.configuration; - } - - public hasMultiFolderWorkspace(): boolean { - return this.workspace && !!this.workspace.configuration; - } - public getWorkspace(): IWorkbenchWorkspace { return this.workspace; }