From 80753fd224a42fc5eb19742a4dac3fde8c2a018d Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 27 Apr 2016 18:03:13 +0200 Subject: [PATCH] "Open New Terminal" does not work for empty workspace (fixes #5834) --- .../electron-browser/terminal.contribution.ts | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/parts/execution/electron-browser/terminal.contribution.ts b/src/vs/workbench/parts/execution/electron-browser/terminal.contribution.ts index 8fac1574a6e..9b290fa4e35 100644 --- a/src/vs/workbench/parts/execution/electron-browser/terminal.contribution.ts +++ b/src/vs/workbench/parts/execution/electron-browser/terminal.contribution.ts @@ -18,6 +18,8 @@ import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/c import {ITerminalService} from 'vs/workbench/parts/execution/common/execution'; import {SyncActionDescriptor} from 'vs/platform/actions/common/actions'; import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation'; +import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService'; +import {asFileEditorInput} from 'vs/workbench/common/editor'; import {KeyMod, KeyCode} from 'vs/base/common/keyCodes'; import {Extensions, IConfigurationRegistry} from 'vs/platform/configuration/common/configurationRegistry'; import {DEFAULT_TERMINAL_WINDOWS, DEFAULT_TERMINAL_LINUX} from 'vs/workbench/parts/execution/electron-browser/terminal'; @@ -56,6 +58,7 @@ export class OpenConsoleAction extends Action { id: string, label: string, @ITerminalService private terminalService: ITerminalService, + @IWorkbenchEditorService private editorService: IWorkbenchEditorService, @IWorkspaceContextService private contextService: IWorkspaceContextService ) { super(id, label); @@ -69,14 +72,24 @@ export class OpenConsoleAction extends Action { } public run(event?: any): TPromise { + let pathToOpen: string; + + // Try workspace path first let workspace = this.contextService.getWorkspace(); - let path = this.resource ? this.resource.fsPath : (workspace && workspace.resource.fsPath); + pathToOpen = this.resource ? this.resource.fsPath : (workspace && workspace.resource.fsPath); + + // Otherwise check if we have an active file open + if (!pathToOpen) { + const file = asFileEditorInput(this.editorService.getActiveEditorInput(), true); + if (file) { + pathToOpen = paths.dirname(file.getResource().fsPath); // take parent folder of file + } + } - if (!path) { - return TPromise.as(null); + if (pathToOpen) { + this.terminalService.openTerminal(pathToOpen); } - this.terminalService.openTerminal(path); return TPromise.as(null); } } -- GitLab