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

multi root - introduce and use new method to retrieve last active file workspace

上级 f066fd48
...@@ -24,6 +24,7 @@ import { KeyMod, KeyCode } from 'vs/base/common/keyCodes'; ...@@ -24,6 +24,7 @@ import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry'; import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED } from 'vs/workbench/parts/terminal/common/terminal'; import { KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED } from 'vs/workbench/parts/terminal/common/terminal';
import { DEFAULT_TERMINAL_WINDOWS, DEFAULT_TERMINAL_LINUX_READY, DEFAULT_TERMINAL_OSX } from 'vs/workbench/parts/execution/electron-browser/terminal'; import { DEFAULT_TERMINAL_WINDOWS, DEFAULT_TERMINAL_LINUX_READY, DEFAULT_TERMINAL_OSX } from 'vs/workbench/parts/execution/electron-browser/terminal';
import { IHistoryService } from "vs/workbench/services/history/common/history";
DEFAULT_TERMINAL_LINUX_READY.then(defaultTerminalLinux => { DEFAULT_TERMINAL_LINUX_READY.then(defaultTerminalLinux => {
let configurationRegistry = <IConfigurationRegistry>Registry.as(Extensions.Configuration); let configurationRegistry = <IConfigurationRegistry>Registry.as(Extensions.Configuration);
...@@ -70,7 +71,8 @@ export class OpenConsoleAction extends Action { ...@@ -70,7 +71,8 @@ export class OpenConsoleAction extends Action {
label: string, label: string,
@ITerminalService private terminalService: ITerminalService, @ITerminalService private terminalService: ITerminalService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService, @IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IWorkspaceContextService private contextService: IWorkspaceContextService @IWorkspaceContextService private contextService: IWorkspaceContextService,
@IHistoryService private historyService: IHistoryService
) { ) {
super(id, label); super(id, label);
...@@ -86,8 +88,8 @@ export class OpenConsoleAction extends Action { ...@@ -86,8 +88,8 @@ export class OpenConsoleAction extends Action {
let pathToOpen: string; let pathToOpen: string;
// Try workspace path first // Try workspace path first
let workspace = this.contextService.getWorkspace(); const root = this.historyService.getLastActiveWorkspaceRoot();
pathToOpen = this.resource ? this.resource.fsPath : (workspace && workspace.resource.fsPath); pathToOpen = this.resource ? this.resource.fsPath : (root && root.fsPath);
// Otherwise check if we have an active file open // Otherwise check if we have an active file open
if (!pathToOpen) { if (!pathToOpen) {
......
...@@ -21,7 +21,7 @@ import { IPanelService } from 'vs/workbench/services/panel/common/panelService'; ...@@ -21,7 +21,7 @@ import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IStringDictionary } from 'vs/base/common/collections'; import { IStringDictionary } from 'vs/base/common/collections';
import { ITerminalInstance, KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED, TERMINAL_PANEL_ID, IShellLaunchConfig } from 'vs/workbench/parts/terminal/common/terminal'; import { ITerminalInstance, KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED, TERMINAL_PANEL_ID, IShellLaunchConfig } from 'vs/workbench/parts/terminal/common/terminal';
import { ITerminalProcessFactory } from 'vs/workbench/parts/terminal/electron-browser/terminal'; import { ITerminalProcessFactory } from 'vs/workbench/parts/terminal/electron-browser/terminal';
import { ILegacyWorkspace, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
...@@ -33,6 +33,7 @@ import { registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platf ...@@ -33,6 +33,7 @@ import { registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platf
import { scrollbarSliderBackground, scrollbarSliderHoverBackground, scrollbarSliderActiveBackground } from 'vs/platform/theme/common/colorRegistry'; import { scrollbarSliderBackground, scrollbarSliderHoverBackground, scrollbarSliderActiveBackground } from 'vs/platform/theme/common/colorRegistry';
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { IHistoryService } from "vs/workbench/services/history/common/history";
/** The amount of time to consider terminal errors to be related to the launch */ /** The amount of time to consider terminal errors to be related to the launch */
const LAUNCHING_DURATION = 500; const LAUNCHING_DURATION = 500;
...@@ -102,7 +103,8 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -102,7 +103,8 @@ export class TerminalInstance implements ITerminalInstance {
@IWorkspaceContextService private _contextService: IWorkspaceContextService, @IWorkspaceContextService private _contextService: IWorkspaceContextService,
@IWorkbenchEditorService private _editorService: IWorkbenchEditorService, @IWorkbenchEditorService private _editorService: IWorkbenchEditorService,
@IInstantiationService private _instantiationService: IInstantiationService, @IInstantiationService private _instantiationService: IInstantiationService,
@IClipboardService private _clipboardService: IClipboardService @IClipboardService private _clipboardService: IClipboardService,
@IHistoryService private _historyService: IHistoryService
) { ) {
this._instanceDisposables = []; this._instanceDisposables = [];
this._processDisposables = []; this._processDisposables = [];
...@@ -126,7 +128,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -126,7 +128,7 @@ export class TerminalInstance implements ITerminalInstance {
}); });
this._initDimensions(); this._initDimensions();
this._createProcess(this._contextService.getWorkspace(), this._shellLaunchConfig); this._createProcess(this._historyService.getLastActiveWorkspaceRoot(), this._shellLaunchConfig);
this._createXterm(); this._createXterm();
// Only attach xterm.js to the DOM if the terminal panel has been opened before. // Only attach xterm.js to the DOM if the terminal panel has been opened before.
...@@ -464,7 +466,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -464,7 +466,7 @@ export class TerminalInstance implements ITerminalInstance {
return typeof data === 'string' ? data.replace(TerminalInstance.WINDOWS_EOL_REGEX, '\r') : data; return typeof data === 'string' ? data.replace(TerminalInstance.WINDOWS_EOL_REGEX, '\r') : data;
} }
protected _getCwd(shell: IShellLaunchConfig, workspace: ILegacyWorkspace): string { protected _getCwd(shell: IShellLaunchConfig, root: Uri): string {
if (shell.cwd) { if (shell.cwd) {
return shell.cwd; return shell.cwd;
} }
...@@ -478,26 +480,26 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -478,26 +480,26 @@ export class TerminalInstance implements ITerminalInstance {
if (customCwd) { if (customCwd) {
if (path.isAbsolute(customCwd)) { if (path.isAbsolute(customCwd)) {
cwd = customCwd; cwd = customCwd;
} else if (workspace) { } else if (root) {
cwd = path.normalize(path.join(workspace.resource.fsPath, customCwd)); cwd = path.normalize(path.join(root.fsPath, customCwd));
} }
} }
} }
// If there was no custom cwd or it was relative with no workspace // If there was no custom cwd or it was relative with no workspace
if (!cwd) { if (!cwd) {
cwd = workspace ? workspace.resource.fsPath : os.homedir(); cwd = root ? root.fsPath : os.homedir();
} }
return TerminalInstance._sanitizeCwd(cwd); return TerminalInstance._sanitizeCwd(cwd);
} }
protected _createProcess(workspace: ILegacyWorkspace, shell: IShellLaunchConfig): void { protected _createProcess(root: Uri, shell: IShellLaunchConfig): void {
const locale = this._configHelper.config.setLocaleVariables ? platform.locale : undefined; const locale = this._configHelper.config.setLocaleVariables ? platform.locale : undefined;
if (!shell.executable) { if (!shell.executable) {
this._configHelper.mergeDefaultShellPathAndArgs(shell); this._configHelper.mergeDefaultShellPathAndArgs(shell);
} }
const env = TerminalInstance.createTerminalEnv(process.env, shell, this._getCwd(shell, workspace), locale, this._cols, this._rows); const env = TerminalInstance.createTerminalEnv(process.env, shell, this._getCwd(shell, root), locale, this._cols, this._rows);
this._title = shell.name || ''; this._title = shell.name || '';
this._process = cp.fork(Uri.parse(require.toUrl('bootstrap')).fsPath, ['--type=terminal'], { this._process = cp.fork(Uri.parse(require.toUrl('bootstrap')).fsPath, ['--type=terminal'], {
env, env,
...@@ -620,7 +622,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -620,7 +622,7 @@ export class TerminalInstance implements ITerminalInstance {
// Initialize new process // Initialize new process
const oldTitle = this._title; const oldTitle = this._title;
this._createProcess(this._contextService.getWorkspace(), shell); this._createProcess(this._historyService.getLastActiveWorkspaceRoot(), shell);
if (oldTitle !== this._title) { if (oldTitle !== this._title) {
this._onTitleChanged.fire(this._title); this._onTitleChanged.fire(this._title);
} }
......
...@@ -696,4 +696,27 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic ...@@ -696,4 +696,27 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
return void 0; return void 0;
}).filter(input => !!input); }).filter(input => !!input);
} }
public getLastActiveWorkspaceRoot(): URI {
if (!this.contextService.hasWorkspace()) {
return void 0;
}
const history = this.getHistory();
for (let i = 0; i < history.length; i++) {
const input = history[i];
if (input instanceof EditorInput) {
continue;
}
const resourceInput = input as IResourceInput;
const resourceWorkspace = this.contextService.getRoot(resourceInput.resource);
if (resourceWorkspace) {
return resourceWorkspace;
}
}
// fallback to first workspace
return this.contextService.getWorkspace2().roots[0];
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation'; import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { IEditorInput, ITextEditorOptions, IResourceInput } from 'vs/platform/editor/common/editor'; import { IEditorInput, ITextEditorOptions, IResourceInput } from 'vs/platform/editor/common/editor';
import URI from "vs/base/common/uri";
export const IHistoryService = createDecorator<IHistoryService>('historyService'); export const IHistoryService = createDecorator<IHistoryService>('historyService');
...@@ -53,4 +54,10 @@ export interface IHistoryService { ...@@ -53,4 +54,10 @@ export interface IHistoryService {
* Get the entire history of opened editors. * Get the entire history of opened editors.
*/ */
getHistory(): (IEditorInput | IResourceInput)[]; getHistory(): (IEditorInput | IResourceInput)[];
/**
* Looking at the editor history, returns the workspace root of the last file that was
* inside the workspace and part of the editor history.
*/
getLastActiveWorkspaceRoot(): URI;
} }
\ No newline at end of file
...@@ -30,6 +30,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti ...@@ -30,6 +30,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IMessageService, Severity } from 'vs/platform/message/common/message'; import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { ResourceMap } from 'vs/base/common/map'; import { ResourceMap } from 'vs/base/common/map';
import { Schemas } from "vs/base/common/network"; import { Schemas } from "vs/base/common/network";
import { IHistoryService } from "vs/workbench/services/history/common/history";
export interface IBackupResult { export interface IBackupResult {
didBackup: boolean; didBackup: boolean;
...@@ -58,17 +59,18 @@ export abstract class TextFileService implements ITextFileService { ...@@ -58,17 +59,18 @@ export abstract class TextFileService implements ITextFileService {
private configuredHotExit: string; private configuredHotExit: string;
constructor( constructor(
@ILifecycleService private lifecycleService: ILifecycleService, private lifecycleService: ILifecycleService,
@IWorkspaceContextService private contextService: IWorkspaceContextService, private contextService: IWorkspaceContextService,
@IConfigurationService private configurationService: IConfigurationService, private configurationService: IConfigurationService,
@ITelemetryService private telemetryService: ITelemetryService, private telemetryService: ITelemetryService,
@IFileService protected fileService: IFileService, protected fileService: IFileService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService, private untitledEditorService: IUntitledEditorService,
@IInstantiationService private instantiationService: IInstantiationService, private instantiationService: IInstantiationService,
@IMessageService private messageService: IMessageService, private messageService: IMessageService,
@IEnvironmentService protected environmentService: IEnvironmentService, protected environmentService: IEnvironmentService,
@IBackupFileService private backupFileService: IBackupFileService, private backupFileService: IBackupFileService,
@IWindowsService private windowsService: IWindowsService private windowsService: IWindowsService,
private historyService: IHistoryService
) { ) {
this.toUnbind = []; this.toUnbind = [];
...@@ -609,9 +611,9 @@ export abstract class TextFileService implements ITextFileService { ...@@ -609,9 +611,9 @@ export abstract class TextFileService implements ITextFileService {
} }
private suggestFileName(untitledResource: URI): string { private suggestFileName(untitledResource: URI): string {
const workspace = this.contextService.getWorkspace(); const root = this.historyService.getLastActiveWorkspaceRoot();
if (workspace) { if (root) {
return URI.file(paths.join(workspace.resource.fsPath, this.untitledEditorService.suggestFileName(untitledResource))).fsPath; return URI.file(paths.join(root.fsPath, this.untitledEditorService.suggestFileName(untitledResource))).fsPath;
} }
return this.untitledEditorService.suggestFileName(untitledResource); return this.untitledEditorService.suggestFileName(untitledResource);
......
...@@ -29,6 +29,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti ...@@ -29,6 +29,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IMessageService } from 'vs/platform/message/common/message'; import { IMessageService } from 'vs/platform/message/common/message';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup'; import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { IWindowsService } from 'vs/platform/windows/common/windows'; import { IWindowsService } from 'vs/platform/windows/common/windows';
import { IHistoryService } from "vs/workbench/services/history/common/history";
export class TextFileService extends AbstractTextFileService { export class TextFileService extends AbstractTextFileService {
...@@ -47,9 +48,10 @@ export class TextFileService extends AbstractTextFileService { ...@@ -47,9 +48,10 @@ export class TextFileService extends AbstractTextFileService {
@IEnvironmentService environmentService: IEnvironmentService, @IEnvironmentService environmentService: IEnvironmentService,
@IMessageService messageService: IMessageService, @IMessageService messageService: IMessageService,
@IBackupFileService backupFileService: IBackupFileService, @IBackupFileService backupFileService: IBackupFileService,
@IWindowsService windowsService: IWindowsService @IWindowsService windowsService: IWindowsService,
@IHistoryService historyService: IHistoryService
) { ) {
super(lifecycleService, contextService, configurationService, telemetryService, fileService, untitledEditorService, instantiationService, messageService, environmentService, backupFileService, windowsService); super(lifecycleService, contextService, configurationService, telemetryService, fileService, untitledEditorService, instantiationService, messageService, environmentService, backupFileService, windowsService, historyService);
} }
public resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise<IRawTextContent> { public resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise<IRawTextContent> {
......
...@@ -156,9 +156,10 @@ export class TestTextFileService extends TextFileService { ...@@ -156,9 +156,10 @@ export class TestTextFileService extends TextFileService {
@IInstantiationService instantiationService: IInstantiationService, @IInstantiationService instantiationService: IInstantiationService,
@IMessageService messageService: IMessageService, @IMessageService messageService: IMessageService,
@IBackupFileService backupFileService: IBackupFileService, @IBackupFileService backupFileService: IBackupFileService,
@IWindowsService windowsService: IWindowsService @IWindowsService windowsService: IWindowsService,
@IHistoryService historyService: IHistoryService
) { ) {
super(lifecycleService, contextService, configurationService, telemetryService, fileService, untitledEditorService, instantiationService, messageService, TestEnvironmentService, backupFileService, windowsService); super(lifecycleService, contextService, configurationService, telemetryService, fileService, untitledEditorService, instantiationService, messageService, TestEnvironmentService, backupFileService, windowsService, historyService);
} }
public setPromptPath(path: string): void { public setPromptPath(path: string): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册