提交 cc57ada8 编写于 作者: I isidor

fix terminal commands

fixes #40909
上级 f467841b
......@@ -8,14 +8,12 @@ import * as nls from 'vs/nls';
import * as env from 'vs/base/common/platform';
import { TPromise } from 'vs/base/common/winjs.base';
import { Registry } from 'vs/platform/registry/common/platform';
import { Action } from 'vs/base/common/actions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import paths = require('vs/base/common/paths');
import uri from 'vs/base/common/uri';
import { ITerminalService } from 'vs/workbench/parts/execution/common/execution';
import { SyncActionDescriptor, MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { toResource } from 'vs/workbench/common/editor';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
......@@ -24,8 +22,9 @@ import { ITerminalService as IIntegratedTerminalService, KEYBINDING_CONTEXT_TERM
import { DEFAULT_TERMINAL_WINDOWS, DEFAULT_TERMINAL_LINUX_READY, DEFAULT_TERMINAL_OSX, ITerminalConfiguration } from 'vs/workbench/parts/execution/electron-browser/terminal';
import { WinTerminalService, MacTerminalService, LinuxTerminalService } from 'vs/workbench/parts/execution/electron-browser/terminalService';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
import { ResourceContextKey } from 'vs/workbench/common/resources';
import { IExplorerContext } from 'vs/workbench/parts/files/electron-browser/fileActions';
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
if (env.isWindows) {
registerSingleton(ITerminalService, WinTerminalService);
......@@ -75,53 +74,14 @@ DEFAULT_TERMINAL_LINUX_READY.then(defaultTerminalLinux => {
});
});
class OpenConsoleAction extends Action {
public static readonly ID = 'workbench.action.terminal.openNativeConsole';
public static readonly Label = env.isWindows ? nls.localize('globalConsoleActionWin', "Open New Command Prompt") :
nls.localize('globalConsoleActionMacLinux', "Open New Terminal");
public static readonly ScopedLabel = env.isWindows ? nls.localize('scopedConsoleActionWin', "Open in Command Prompt") :
nls.localize('scopedConsoleActionMacLinux', "Open in Terminal");
private resource: uri;
public setResource(resource: uri): void {
this.resource = resource;
this.enabled = !paths.isUNC(this.resource.fsPath);
}
constructor(
id: string,
label: string,
@ICommandService private commandService: ICommandService
) {
super(id, label);
}
public run(event?: any): TPromise<any> {
return this.commandService.executeCommand(OPEN_CONSOLE_COMMAND_ID, this.resource);
}
}
// Register Global Action to Open Console
Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions).registerWorkbenchAction(
new SyncActionDescriptor(
OpenConsoleAction,
OpenConsoleAction.ID,
OpenConsoleAction.Label,
{ primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_C },
KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED
),
env.isWindows ? 'Open New Command Prompt' : 'Open New Terminal'
);
const OPEN_CONSOLE_COMMAND_ID = 'workbench.command.terminal.openNativeConsole';
// TODO@Isidor Open in terminal does not seem to work
CommandsRegistry.registerCommand({
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: OPEN_CONSOLE_COMMAND_ID,
handler: (accessor, resource: uri) => {
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_C,
when: KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED,
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
handler: (accessor, resource: uri, context: IExplorerContext) => {
const configurationService = accessor.get(IConfigurationService);
const historyService = accessor.get(IHistoryService);
const editorService = accessor.get(IWorkbenchEditorService);
......@@ -130,6 +90,9 @@ CommandsRegistry.registerCommand({
// Try workspace path first
const root = historyService.getLastActiveWorkspaceRoot('file');
pathToOpen = resource ? resource.fsPath : (root && root.fsPath);
if (context && context.stat && !context.stat.isDirectory) {
pathToOpen = context.stat.parent.resource.fsPath;
}
// Otherwise check if we have an active file open
if (!pathToOpen) {
......@@ -162,6 +125,10 @@ const openConsoleCommand = {
nls.localize('scopedConsoleActionMacLinux', "Open in Terminal")
};
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: openConsoleCommand
});
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
group: 'navigation',
order: 30,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册