提交 25dcdbb9 编写于 作者: J John Rothfels

Ensure workspace is read from WorkspaceContextService

上级 5d7ba476
......@@ -6,7 +6,7 @@
import { isPromiseCanceledError } from 'vs/base/common/errors';
import { ISearchService, QueryType } from 'vs/platform/search/common/search';
import { IWorkspaceContextService, IWorkspace } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { ICommonCodeEditor } from 'vs/editor/common/editorCommon';
......@@ -21,7 +21,7 @@ export class MainThreadWorkspace extends MainThreadWorkspaceShape {
private _activeSearches: { [id: number]: TPromise<Uri[]> } = Object.create(null);
private _searchService: ISearchService;
private _workspace: IWorkspace;
private _contextService: IWorkspaceContextService;
private _textFileService: ITextFileService;
private _editorService: IWorkbenchEditorService;
private _textModelResolverService: ITextModelResolverService;
......@@ -38,7 +38,7 @@ export class MainThreadWorkspace extends MainThreadWorkspaceShape {
super();
this._searchService = searchService;
this._workspace = contextService.getWorkspace();
this._contextService = contextService;
this._textFileService = textFileService;
this._editorService = editorService;
this._fileService = fileService;
......@@ -46,13 +46,13 @@ export class MainThreadWorkspace extends MainThreadWorkspaceShape {
}
$startSearch(include: string, exclude: string, maxResults: number, requestId: number): Thenable<Uri[]> {
if (!this._workspace) {
const workspace = this._contextService.getWorkspace();
if (!workspace) {
return;
}
const search = this._searchService.search({
folderResources: [this._workspace.resource],
folderResources: [workspace.resource],
type: QueryType.File,
maxResults,
includePattern: { [include]: true },
......
......@@ -145,7 +145,7 @@ function openWorkbench(environment: IWindowConfiguration, workspace: IWorkspace,
// Open Shell
timerService.beforeWorkbenchOpen = new Date();
const shell = new WorkbenchShell(document.body, workspace, {
const shell = new WorkbenchShell(document.body, {
configurationService,
contextService,
environmentService,
......
......@@ -66,7 +66,7 @@ import { ISearchService } from 'vs/platform/search/common/search';
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { CommandService } from 'vs/platform/commands/common/commandService';
import { IWorkspaceContextService, IWorkspace } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
import { MainThreadModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
import { IModeService } from 'vs/editor/common/services/modeService';
......@@ -130,14 +130,12 @@ export class WorkbenchShell {
private content: HTMLElement;
private contentsContainer: Builder;
private workspace: IWorkspace;
private options: IOptions;
private workbench: Workbench;
constructor(container: HTMLElement, workspace: IWorkspace, services: ICoreServices, options: IOptions) {
constructor(container: HTMLElement, services: ICoreServices, options: IOptions) {
this.container = container;
this.workspace = workspace;
this.options = options;
this.contextService = services.contextService;
......@@ -166,7 +164,7 @@ export class WorkbenchShell {
}
// Workbench
this.workbench = instantiationService.createInstance(Workbench, parent.getHTMLElement(), workbenchContainer.getHTMLElement(), this.workspace, this.options, serviceCollection);
this.workbench = instantiationService.createInstance(Workbench, parent.getHTMLElement(), workbenchContainer.getHTMLElement(), this.options, serviceCollection);
this.workbench.startup({
onWorkbenchStarted: (info: IWorkbenchStartedInfo) => {
......@@ -269,7 +267,7 @@ export class WorkbenchShell {
}, errors.onUnexpectedError);
// Storage Sevice
const disableWorkspaceStorage = this.environmentService.extensionTestsPath || (!this.workspace && !this.environmentService.isExtensionDevelopment); // without workspace or in any extension test, we use inMemory storage unless we develop an extension where we want to preserve state
const disableWorkspaceStorage = this.environmentService.extensionTestsPath || (!this.contextService.getWorkspace() && !this.environmentService.isExtensionDevelopment); // without workspace or in any extension test, we use inMemory storage unless we develop an extension where we want to preserve state
this.storageService = instantiationService.createInstance(StorageService, window.localStorage, disableWorkspaceStorage ? inMemoryLocalStorageInstance : window.localStorage);
serviceCollection.set(IStorageService, this.storageService);
......
......@@ -43,7 +43,7 @@ import { getServices } from 'vs/platform/instantiation/common/extensions';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { WorkbenchEditorService } from 'vs/workbench/services/editor/browser/editorService';
import { Position, Parts, IPartService, ILayoutOptions } from 'vs/workbench/services/part/common/partService';
import { IWorkspace, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { ContextMenuService } from 'vs/workbench/services/contextview/electron-browser/contextmenuService';
import { WorkbenchKeybindingService } from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
......@@ -94,7 +94,6 @@ export const InZenModeContext = new RawContextKey<boolean>('inZenMode', false);
export const NoEditorsVisibleContext: ContextKeyExpr = EditorsVisibleContext.toNegated();
interface WorkbenchParams {
workspace?: IWorkspace;
options: IOptions;
serviceCollection: ServiceCollection;
}
......@@ -185,7 +184,6 @@ export class Workbench implements IPartService {
constructor(
parent: HTMLElement,
container: HTMLElement,
workspace: IWorkspace,
options: IOptions,
serviceCollection: ServiceCollection,
@IInstantiationService private instantiationService: IInstantiationService,
......@@ -203,7 +201,6 @@ export class Workbench implements IPartService {
this.container = container;
this.workbenchParams = {
workspace: workspace,
options,
serviceCollection
};
......@@ -388,7 +385,7 @@ export class Workbench implements IPartService {
}
// Empty workbench: some first time users will not have an untiled file; returning users will always have one
else if (!this.workbenchParams.workspace && this.telemetryService.getExperiments().openUntitledFile) {
else if (!this.contextService.getWorkspace() && this.telemetryService.getExperiments().openUntitledFile) {
return this.backupFileService.hasBackups().then(hasBackups => {
if (hasBackups) {
return TPromise.as([]); // do not open any empty untitled file if we have backups to restore
......@@ -919,7 +916,7 @@ export class Workbench implements IPartService {
}
// Apply no-workspace state as CSS class
if (!this.workbenchParams.workspace) {
if (!this.contextService.getWorkspace()) {
this.workbench.addClass('no-workspace');
}
......
......@@ -8,7 +8,7 @@ import nls = require('vs/nls');
import { TPromise } from 'vs/base/common/winjs.base';
import * as DOM from 'vs/base/browser/dom';
import { Builder, $ } from 'vs/base/browser/builder';
import { IWorkspace, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { CollapsibleViewletView } from 'vs/workbench/browser/viewlet';
import { IAction, IActionRunner } from 'vs/base/common/actions';
import { IMessageService } from 'vs/platform/message/common/message';
......@@ -22,8 +22,6 @@ import { TreeExplorerViewletState, TreeDataSource, TreeRenderer, TreeController
import { RefreshViewExplorerAction } from 'vs/workbench/parts/explorers/browser/treeExplorerActions';
export class TreeExplorerView extends CollapsibleViewletView {
private workspace: IWorkspace;
constructor(
private viewletState: TreeExplorerViewletState,
private treeNodeProviderId: string,
......@@ -38,8 +36,6 @@ export class TreeExplorerView extends CollapsibleViewletView {
) {
super(actionRunner, false, nls.localize('treeExplorerViewlet.tree', "Tree Explorer Section"), messageService, keybindingService, contextMenuService, headerSize);
this.workspace = contextService.getWorkspace();
this.create();
}
......
......@@ -30,7 +30,7 @@ import { CollapseAction, CollapsibleViewletView } from 'vs/workbench/browser/vie
import { FileStat } from 'vs/workbench/parts/files/common/explorerViewModel';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { IWorkspaceContextService, IWorkspace } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceContextService } 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';
......@@ -49,8 +49,6 @@ export class ExplorerView extends CollapsibleViewletView {
private static MEMENTO_LAST_ACTIVE_FILE_RESOURCE = 'explorer.memento.lastActiveFileResource';
private static MEMENTO_EXPANDED_FOLDER_RESOURCES = 'explorer.memento.expandedFolderResources';
private workspace: IWorkspace;
private explorerViewer: ITree;
private filter: FileFilter;
private viewletState: FileViewletState;
......@@ -87,8 +85,6 @@ export class ExplorerView extends CollapsibleViewletView {
) {
super(actionRunner, false, nls.localize('explorerSection', "Files Explorer Section"), messageService, keybindingService, contextMenuService, headerSize);
this.workspace = contextService.getWorkspace();
this.settings = settings;
this.viewletState = viewletState;
this.actionRunner = actionRunner;
......@@ -103,7 +99,7 @@ export class ExplorerView extends CollapsibleViewletView {
public renderHeader(container: HTMLElement): void {
const titleDiv = $('div.title').appendTo(container);
$('span').text(this.workspace.name).title(labels.getPathLabel(this.workspace.resource.fsPath)).appendTo(titleDiv);
$('span').text(this.contextService.getWorkspace().name).title(labels.getPathLabel(this.contextService.getWorkspace().resource.fsPath)).appendTo(titleDiv);
super.renderHeader(container);
}
......@@ -667,7 +663,7 @@ export class ExplorerView extends CollapsibleViewletView {
// Load Root Stat with given target path configured
const options: IResolveFileOptions = { resolveTo: targetsToResolve };
const promise = this.fileService.resolveFile(this.workspace.resource, options).then(stat => {
const promise = this.fileService.resolveFile(this.contextService.getWorkspace().resource, options).then(stat => {
let explorerPromise: TPromise<void>;
// Convert to model
......@@ -706,7 +702,7 @@ export class ExplorerView extends CollapsibleViewletView {
*/
private getResolvedDirectories(stat: FileStat, resolvedDirectories: URI[]): void {
if (stat.isDirectoryResolved) {
if (stat.resource.toString() !== this.workspace.resource.toString()) {
if (stat.resource.toString() !== this.contextService.getWorkspace().resource.toString()) {
// Drop those path which are parents of the current one
for (let i = resolvedDirectories.length - 1; i >= 0; i--) {
......@@ -735,7 +731,7 @@ export class ExplorerView extends CollapsibleViewletView {
public select(resource: URI, reveal: boolean = this.autoReveal): TPromise<void> {
// Require valid path
if (!resource || resource.toString() === this.workspace.resource.toString()) {
if (!resource || resource.toString() === this.contextService.getWorkspace().resource.toString()) {
return TPromise.as(null);
}
......@@ -758,7 +754,7 @@ export class ExplorerView extends CollapsibleViewletView {
// Stat needs to be resolved first and then revealed
const options: IResolveFileOptions = { resolveTo: [resource] };
return this.fileService.resolveFile(this.workspace.resource, options).then(stat => {
return this.fileService.resolveFile(this.contextService.getWorkspace().resource, options).then(stat => {
// Convert to model
const modelStat = FileStat.create(stat, options.resolveTo);
......@@ -821,7 +817,7 @@ export class ExplorerView extends CollapsibleViewletView {
const root = this.getInput();
if (root) {
const expanded = this.explorerViewer.getExpandedElements()
.filter((e: FileStat) => e.resource.toString() !== this.workspace.resource.toString())
.filter((e: FileStat) => e.resource.toString() !== this.contextService.getWorkspace().resource.toString())
.map((e: FileStat) => e.resource.toString());
this.settings[ExplorerView.MEMENTO_EXPANDED_FOLDER_RESOURCES] = expanded;
......
......@@ -37,7 +37,7 @@ import { DragMouseEvent, IMouseEvent } from 'vs/base/browser/mouseEvent';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { IWorkspace, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceContextService } 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';
......@@ -51,17 +51,13 @@ import { IMenuService, IMenu, MenuId } from 'vs/platform/actions/common/actions'
import { fillInActions } from 'vs/platform/actions/browser/menuItemActionItem';
export class FileDataSource implements IDataSource {
private workspace: IWorkspace;
constructor(
@IProgressService private progressService: IProgressService,
@IMessageService private messageService: IMessageService,
@IFileService private fileService: IFileService,
@IPartService private partService: IPartService,
@IWorkspaceContextService contextService: IWorkspaceContextService
) {
this.workspace = contextService.getWorkspace();
}
@IWorkspaceContextService private contextService: IWorkspaceContextService
) { }
public getId(tree: ITree, stat: FileStat): string {
return stat.getId();
......@@ -113,7 +109,7 @@ export class FileDataSource implements IDataSource {
}
// Return if root reached
if (this.workspace && stat.resource.toString() === this.workspace.resource.toString()) {
if (this.contextService.getWorkspace() && stat.resource.toString() === this.contextService.getWorkspace().resource.toString()) {
return TPromise.as(null);
}
......@@ -379,14 +375,12 @@ export class FileController extends DefaultController {
private contributedContextMenu: IMenu;
private workspace: IWorkspace;
constructor(state: FileViewletState,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IContextMenuService private contextMenuService: IContextMenuService,
@IInstantiationService private instantiationService: IInstantiationService,
@ITelemetryService private telemetryService: ITelemetryService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IMenuService menuService: IMenuService,
@IContextKeyService contextKeyService: IContextKeyService,
@IKeybindingService private keybindingService: IKeybindingService
......@@ -395,8 +389,6 @@ export class FileController extends DefaultController {
this.contributedContextMenu = menuService.createMenu(MenuId.ExplorerContext, contextKeyService);
this.workspace = contextService.getWorkspace();
this.didCatchEnterDown = false;
this.downKeyBindingDispatcher.set(platform.isMacintosh ? KeyMod.CtrlCmd | KeyCode.DownArrow : KeyCode.Enter, this.onEnterDown.bind(this));
......@@ -439,7 +431,7 @@ export class FileController extends DefaultController {
}
// Handle root
if (this.workspace && stat.resource.toString() === this.workspace.resource.toString()) {
if (this.contextService.getWorkspace() && stat.resource.toString() === this.contextService.getWorkspace().resource.toString()) {
tree.clearFocus(payload);
tree.clearSelection(payload);
......
......@@ -20,7 +20,7 @@ import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IStringDictionary } from 'vs/base/common/collections';
import { ITerminalInstance, KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED, TERMINAL_PANEL_ID, IShell } from 'vs/workbench/parts/terminal/common/terminal';
import { IWorkspace } from 'vs/platform/workspace/common/workspace';
import { IWorkspace, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { TabFocus } from 'vs/editor/common/config/commonEditorConfig';
import { TerminalConfigHelper } from 'vs/workbench/parts/terminal/electron-browser/terminalConfigHelper';
......@@ -62,13 +62,13 @@ export class TerminalInstance implements ITerminalInstance {
private _terminalFocusContextKey: IContextKey<boolean>,
private _configHelper: TerminalConfigHelper,
private _container: HTMLElement,
workspace: IWorkspace,
name: string,
shell: IShell,
@IContextKeyService private _contextKeyService: IContextKeyService,
@IKeybindingService private _keybindingService: IKeybindingService,
@IMessageService private _messageService: IMessageService,
@IPanelService private _panelService: IPanelService
@IPanelService private _panelService: IPanelService,
@IWorkspaceContextService private _contextService: IWorkspaceContextService
) {
this._toDispose = [];
this._skipTerminalCommands = [];
......@@ -83,7 +83,7 @@ export class TerminalInstance implements ITerminalInstance {
this._onProcessIdReady = new Emitter<TerminalInstance>();
this._onTitleChanged = new Emitter<string>();
this._createProcess(workspace, name, shell);
this._createProcess(this._contextService.getWorkspace(), name, shell);
if (_container) {
this.attachToElement(_container);
......
......@@ -11,7 +11,6 @@ import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ITerminalInstance, ITerminalService, IShell, KEYBINDING_CONTEXT_TERMINAL_FOCUS, TERMINAL_PANEL_ID } from 'vs/workbench/parts/terminal/common/terminal';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { TPromise } from 'vs/base/common/winjs.base';
import { TerminalConfigHelper } from 'vs/workbench/parts/terminal/electron-browser/terminalConfigHelper';
import { TerminalInstance } from 'vs/workbench/parts/terminal/electron-browser/terminalInstance';
......@@ -44,8 +43,7 @@ export class TerminalService implements ITerminalService {
@IConfigurationService private _configurationService: IConfigurationService,
@IInstantiationService private _instantiationService: IInstantiationService,
@IPanelService private _panelService: IPanelService,
@IPartService private _partService: IPartService,
@IWorkspaceContextService private _workspaceContextService: IWorkspaceContextService
@IPartService private _partService: IPartService
) {
this._terminalInstances = [];
this._activeTerminalInstanceIndex = 0;
......@@ -72,7 +70,6 @@ export class TerminalService implements ITerminalService {
this._terminalFocusContextKey,
this._configHelper,
this._terminalContainer,
this._workspaceContextService.getWorkspace(),
name,
shell);
terminalInstance.addDisposable(terminalInstance.onTitleChanged(this._onInstanceTitleChanged.fire, this._onInstanceTitleChanged));
......
......@@ -10,11 +10,11 @@ import * as os from 'os';
import Uri from 'vs/base/common/uri';
import { IMessageService } from 'vs/platform/message/common/message';
import { IStringDictionary } from 'vs/base/common/collections';
import { IWorkspace } from 'vs/platform/workspace/common/workspace';
import { IWorkspace, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { TerminalInstance } from 'vs/workbench/parts/terminal/electron-browser/terminalInstance';
import { IShell } from 'vs/workbench/parts/terminal/common/terminal';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { TestMessageService } from 'vs/workbench/test/workbenchTestServices';
import { TestMessageService, TestContextService } from 'vs/workbench/test/workbenchTestServices';
import { MockKeybindingService, MockKeybindingService2 } from 'vs/platform/keybinding/test/common/mockKeybindingService';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
......@@ -85,6 +85,7 @@ suite('Workbench - TerminalInstance', () => {
let terminalFocusContextKey = contextKeyService.createKey('test', false);
instantiationService = new TestInstantiationService();
instantiationService.stub(IMessageService, new TestMessageService());
instantiationService.stub(IWorkspaceContextService, new TestContextService());
instantiationService.stub(IKeybindingService, keybindingService);
instantiationService.stub(IContextKeyService, contextKeyService);
configHelper = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册