Revert back on terminal related explorer context actions registration point. Move them back to parts/execution. Dan may want to refactor it and merge with Terminal.

This commit is contained in:
rebornix 2017-07-11 11:11:00 -07:00
parent 3f3bfcf408
commit 06f0b2ced8
7 changed files with 180 additions and 190 deletions

View file

@ -1,171 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import nls = require('vs/nls');
import { TPromise } from 'vs/base/common/winjs.base';
import { Registry } from 'vs/platform/registry/common/platform';
import baseplatform = require('vs/base/common/platform');
import { IAction, Action } from 'vs/base/common/actions';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';
import paths = require('vs/base/common/paths');
import { ActionBarContributor } from 'vs/workbench/browser/actions';
import uri from 'vs/base/common/uri';
import { explorerItemToFileResource, IFilesConfiguration } from 'vs/workbench/parts/files/common/files';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { ITerminalService } from 'vs/workbench/parts/execution/common/execution';
import { ITerminalService as IIntegratedTerminalService, KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED } from 'vs/workbench/parts/terminal/common/terminal';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { toResource } from 'vs/workbench/common/editor';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
export abstract class AbstarctOpenInTerminalAction extends Action {
private resource: uri;
constructor(
id: string,
label: string,
@IWorkbenchEditorService protected editorService: IWorkbenchEditorService,
@IWorkspaceContextService protected contextService: IWorkspaceContextService,
@IHistoryService protected historyService: IHistoryService
) {
super(id, label);
this.order = 49; // Allow other actions to position before or after
}
public setResource(resource: uri): void {
this.resource = resource;
this.enabled = !paths.isUNC(this.resource.fsPath);
}
public getPathToOpen(): string {
let pathToOpen: string;
// Try workspace path first
const root = this.historyService.getLastActiveWorkspaceRoot();
pathToOpen = this.resource ? this.resource.fsPath : (root && root.fsPath);
// Otherwise check if we have an active file open
if (!pathToOpen) {
const file = toResource(this.editorService.getActiveEditorInput(), { supportSideBySide: true, filter: 'file' });
if (file) {
pathToOpen = paths.dirname(file.fsPath); // take parent folder of file
}
}
return pathToOpen;
}
}
export class OpenConsoleAction extends AbstarctOpenInTerminalAction {
public static ID = 'workbench.action.terminal.openNativeConsole';
public static Label = baseplatform.isWindows ? nls.localize('globalConsoleActionWin', "Open New Command Prompt") :
nls.localize('globalConsoleActionMacLinux', "Open New Terminal");
public static ScopedLabel = baseplatform.isWindows ? nls.localize('scopedConsoleActionWin', "Open in Command Prompt") :
nls.localize('scopedConsoleActionMacLinux', "Open in Terminal");
constructor(
id: string,
label: string,
@ITerminalService private terminalService: ITerminalService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IHistoryService historyService: IHistoryService
) {
super(id, label, editorService, contextService, historyService);
}
public run(event?: any): TPromise<any> {
let pathToOpen = this.getPathToOpen();
this.terminalService.openTerminal(pathToOpen);
return TPromise.as(null);
}
}
export class OpenIntegratedTerminalAction extends AbstarctOpenInTerminalAction {
public static ID = 'workbench.action.terminal.openFolderInIntegratedTerminal';
public static Label = nls.localize('openFolderInIntegratedTerminal', "Open in Integrated Terminal");
constructor(
id: string,
label: string,
@IIntegratedTerminalService private integratedTerminalService: IIntegratedTerminalService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IHistoryService historyService: IHistoryService
) {
super(id, label, editorService, contextService, historyService);
}
public run(event?: any): TPromise<any> {
let pathToOpen = this.getPathToOpen();
var instance = this.integratedTerminalService.createInstance({ cwd: pathToOpen }, true);
if (instance) {
this.integratedTerminalService.setActiveInstance(instance);
this.integratedTerminalService.showPanel(true);
}
return TPromise.as(null);
}
}
export class ExplorerViewerActionContributor extends ActionBarContributor {
constructor(
@IInstantiationService private instantiationService: IInstantiationService,
@IConfigurationService private configurationService: IConfigurationService
) {
super();
}
public hasSecondaryActions(context: any): boolean {
return !!explorerItemToFileResource(context.element);
}
public getSecondaryActions(context: any): IAction[] {
let fileResource = explorerItemToFileResource(context.element);
let resource = fileResource.resource;
// We want the parent unless this resource is a directory
if (!fileResource.isDirectory) {
resource = uri.file(paths.dirname(resource.fsPath));
}
const configuration = this.configurationService.getConfiguration<IFilesConfiguration>();
const terminalKind = configuration.explorer.openInTerminalKind;
if (terminalKind === 'integrated') {
let action = this.instantiationService.createInstance(OpenIntegratedTerminalAction, OpenIntegratedTerminalAction.ID, OpenIntegratedTerminalAction.Label);
action.setResource(resource);
return [action];
} else {
let action = this.instantiationService.createInstance(OpenConsoleAction, OpenConsoleAction.ID, OpenConsoleAction.ScopedLabel);
action.setResource(resource);
return [action];
}
}
}
// 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
),
baseplatform.isWindows ? 'Open New Command Prompt' : 'Open New Terminal'
);

View file

@ -6,13 +6,28 @@
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 { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { IAction, Action } from 'vs/base/common/actions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { DEFAULT_TERMINAL_WINDOWS, DEFAULT_TERMINAL_LINUX_READY, DEFAULT_TERMINAL_OSX } from 'vs/workbench/parts/execution/electron-browser/terminal';
import { WinTerminalService, MacTerminalService, LinuxTerminalService } from 'vs/workbench/parts/execution/electron-browser/terminalService';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';
import paths = require('vs/base/common/paths');
import { Scope, IActionBarRegistry, Extensions as ActionBarExtensions, ActionBarContributor } from 'vs/workbench/browser/actions';
import uri from 'vs/base/common/uri';
import { explorerItemToFileResource } from 'vs/workbench/parts/files/common/files';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { ITerminalService } from 'vs/workbench/parts/execution/common/execution';
import 'vs/workbench/parts/execution/browser/terminal.contribution';
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 { toResource } from 'vs/workbench/common/editor';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { ITerminalService as IIntegratedTerminalService, KEYBINDING_CONTEXT_TERMINAL_NOT_FOCUSED } from 'vs/workbench/parts/terminal/common/terminal';
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';
if (env.isWindows) {
registerSingleton(ITerminalService, WinTerminalService);
@ -30,6 +45,16 @@ DEFAULT_TERMINAL_LINUX_READY.then(defaultTerminalLinux => {
'title': nls.localize('terminalConfigurationTitle', "External Terminal"),
'type': 'object',
'properties': {
'terminal.explorerKind': {
'type': 'string',
'enum': [
'integrated',
'external'
],
'description': nls.localize('explorer.openInTerminalKind', "Customizes what kind of terminal to launch."),
'default': 'integrated',
'isExecutable': false
},
'terminal.external.windowsExec': {
'type': 'string',
'description': nls.localize('terminal.external.windowsExec', "Customizes which terminal to run on Windows."),
@ -52,3 +77,151 @@ DEFAULT_TERMINAL_LINUX_READY.then(defaultTerminalLinux => {
});
});
export abstract class AbstarctOpenInTerminalAction extends Action {
private resource: uri;
constructor(
id: string,
label: string,
@IWorkbenchEditorService protected editorService: IWorkbenchEditorService,
@IWorkspaceContextService protected contextService: IWorkspaceContextService,
@IHistoryService protected historyService: IHistoryService
) {
super(id, label);
this.order = 49; // Allow other actions to position before or after
}
public setResource(resource: uri): void {
this.resource = resource;
this.enabled = !paths.isUNC(this.resource.fsPath);
}
public getPathToOpen(): string {
let pathToOpen: string;
// Try workspace path first
const root = this.historyService.getLastActiveWorkspaceRoot();
pathToOpen = this.resource ? this.resource.fsPath : (root && root.fsPath);
// Otherwise check if we have an active file open
if (!pathToOpen) {
const file = toResource(this.editorService.getActiveEditorInput(), { supportSideBySide: true, filter: 'file' });
if (file) {
pathToOpen = paths.dirname(file.fsPath); // take parent folder of file
}
}
return pathToOpen;
}
}
export class OpenConsoleAction extends AbstarctOpenInTerminalAction {
public static ID = 'workbench.action.terminal.openNativeConsole';
public static Label = env.isWindows ? nls.localize('globalConsoleActionWin', "Open New Command Prompt") :
nls.localize('globalConsoleActionMacLinux', "Open New Terminal");
public static ScopedLabel = env.isWindows ? nls.localize('scopedConsoleActionWin', "Open in Command Prompt") :
nls.localize('scopedConsoleActionMacLinux', "Open in Terminal");
constructor(
id: string,
label: string,
@ITerminalService private terminalService: ITerminalService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IHistoryService historyService: IHistoryService
) {
super(id, label, editorService, contextService, historyService);
}
public run(event?: any): TPromise<any> {
let pathToOpen = this.getPathToOpen();
this.terminalService.openTerminal(pathToOpen);
return TPromise.as(null);
}
}
export class OpenIntegratedTerminalAction extends AbstarctOpenInTerminalAction {
public static ID = 'workbench.action.terminal.openFolderInIntegratedTerminal';
public static Label = nls.localize('openFolderInIntegratedTerminal', "Open in Integrated Terminal");
constructor(
id: string,
label: string,
@IIntegratedTerminalService private integratedTerminalService: IIntegratedTerminalService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IHistoryService historyService: IHistoryService
) {
super(id, label, editorService, contextService, historyService);
}
public run(event?: any): TPromise<any> {
let pathToOpen = this.getPathToOpen();
var instance = this.integratedTerminalService.createInstance({ cwd: pathToOpen }, true);
if (instance) {
this.integratedTerminalService.setActiveInstance(instance);
this.integratedTerminalService.showPanel(true);
}
return TPromise.as(null);
}
}
export class ExplorerViewerActionContributor extends ActionBarContributor {
constructor(
@IInstantiationService private instantiationService: IInstantiationService,
@IConfigurationService private configurationService: IConfigurationService
) {
super();
}
public hasSecondaryActions(context: any): boolean {
return !!explorerItemToFileResource(context.element);
}
public getSecondaryActions(context: any): IAction[] {
let fileResource = explorerItemToFileResource(context.element);
let resource = fileResource.resource;
// We want the parent unless this resource is a directory
if (!fileResource.isDirectory) {
resource = uri.file(paths.dirname(resource.fsPath));
}
const configuration = this.configurationService.getConfiguration<ITerminalConfiguration>();
const explorerKind = configuration.terminal.explorerKind;
if (explorerKind === 'integrated') {
let action = this.instantiationService.createInstance(OpenIntegratedTerminalAction, OpenIntegratedTerminalAction.ID, OpenIntegratedTerminalAction.Label);
action.setResource(resource);
return [action];
} else {
let action = this.instantiationService.createInstance(OpenConsoleAction, OpenConsoleAction.ID, OpenConsoleAction.ScopedLabel);
action.setResource(resource);
return [action];
}
}
}
const actionBarRegistry = Registry.as<IActionBarRegistry>(ActionBarExtensions.Actionbar);
actionBarRegistry.registerActionBarContributor(Scope.VIEWER, ExplorerViewerActionContributor);
// 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'
);

View file

@ -37,7 +37,7 @@ export const DEFAULT_TERMINAL_WINDOWS = `${process.env.windir}\\${process.env.ha
export interface ITerminalConfiguration {
terminal: {
terminalKind: 'integrated' | 'external',
explorerKind: 'integrated' | 'external',
external: {
linuxExec: string,
osxExec: string,

View file

@ -17,6 +17,7 @@ suite('Execution - TerminalService', () => {
setup(() => {
mockConfig = {
terminal: {
explorerKind: 'external',
external: {
windowsExec: 'testWindowsShell',
osxExec: 'testOSXShell',

View file

@ -21,7 +21,6 @@ import { FileStat, Model } from 'vs/workbench/parts/files/common/explorerModel';
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
import { OpenFolderAction, OpenFileFolderAction, AddRootFolderAction, RemoveRootFolderAction } from 'vs/workbench/browser/actions/fileActions';
import { copyFocusedFilesExplorerViewItem, revealInOSFocusedFilesExplorerItem, openFocusedExplorerItemSideBySideCommand, copyPathOfFocusedExplorerItem, copyPathCommand, revealInExplorerCommand, revealInOSCommand, openFolderPickerCommand, openWindowCommand, openFileInNewWindowCommand, deleteFocusedFilesExplorerViewItemCommand, moveFocusedFilesExplorerViewItemToTrashCommand, renameFocusedFilesExplorerViewItemCommand } from 'vs/workbench/parts/files/browser/fileCommands';
import { ExplorerViewerActionContributor as TerminalExplorerViewerActionContributor } from 'vs/workbench/parts/execution/browser/terminal.contribution';
import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
@ -186,7 +185,6 @@ class ExplorerViewersActionContributor extends ActionBarContributor {
const actionBarRegistry = Registry.as<IActionBarRegistry>(ActionBarExtensions.Actionbar);
actionBarRegistry.registerActionBarContributor(Scope.VIEWER, FilesViewerActionContributor);
actionBarRegistry.registerActionBarContributor(Scope.VIEWER, ExplorerViewersActionContributor);
actionBarRegistry.registerActionBarContributor(Scope.VIEWER, TerminalExplorerViewerActionContributor);
// Contribute Global Actions
const category = nls.localize('filesCategory', "Files");

View file

@ -334,16 +334,6 @@ configurationRegistry.registerConfiguration({
nls.localize('sortOrder.modified', 'Files and directories are sorted by last modified date, in descending order. Directories are displayed before files.')
],
'description': nls.localize('sortOrder', "Controls the way of sorting files and directories in the explorer.")
},
'explorer.openInTerminalKind': {
'type': 'string',
'enum': [
'external',
'integrated'
],
'description': nls.localize('explorer.openInTerminalKind', "Customizes what kind of terminal to launch."),
'default': 'external',
'isExecutable': false
},
}
}
});

View file

@ -61,7 +61,6 @@ export interface IFilesConfiguration extends IFilesConfiguration, IWorkbenchEdit
autoReveal: boolean;
enableDragAndDrop: boolean;
sortOrder: SortOrder;
openInTerminalKind: string;
};
editor: IEditorOptions;
}