diff --git a/src/vs/editor/browser/standalone/standaloneCodeEditor.ts b/src/vs/editor/browser/standalone/standaloneCodeEditor.ts index 61b60e346c8..9aba38a080d 100644 --- a/src/vs/editor/browser/standalone/standaloneCodeEditor.ts +++ b/src/vs/editor/browser/standalone/standaloneCodeEditor.ts @@ -9,6 +9,7 @@ import {IDisposable, dispose} from 'vs/base/common/lifecycle'; import {IContextViewService} from 'vs/platform/contextview/browser/contextView'; import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation'; import {AbstractKeybindingService} from 'vs/platform/keybinding/browser/keybindingServiceImpl'; +import {ICommandService} from 'vs/platform/commands/common/commands'; import {IKeybindingContextKey, IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; import {ICommandHandler} from 'vs/platform/commands/common/commands'; import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry'; @@ -68,6 +69,7 @@ export class StandaloneEditor extends CodeEditorWidget implements IStandaloneCod toDispose: IDisposable[], @IInstantiationService instantiationService: IInstantiationService, @ICodeEditorService codeEditorService: ICodeEditorService, + @ICommandService commandService: ICommandService, @IKeybindingService keybindingService: IKeybindingService, @ITelemetryService telemetryService: ITelemetryService, @IContextViewService contextViewService: IContextViewService @@ -77,7 +79,7 @@ export class StandaloneEditor extends CodeEditorWidget implements IStandaloneCod } options = options || {}; - super(domElement, options, instantiationService, codeEditorService, keybindingService, telemetryService); + super(domElement, options, instantiationService, codeEditorService, commandService, keybindingService, telemetryService); if (keybindingService instanceof StandaloneKeybindingService) { this._standaloneKeybindingService = keybindingService; diff --git a/src/vs/editor/browser/standalone/standaloneServices.ts b/src/vs/editor/browser/standalone/standaloneServices.ts index 1cd77e54697..04321cd42e5 100644 --- a/src/vs/editor/browser/standalone/standaloneServices.ts +++ b/src/vs/editor/browser/standalone/standaloneServices.ts @@ -260,7 +260,7 @@ export function getOrCreateStaticServices(services?: IEditorOverrideServices): I let codeEditorService = services.codeEditorService || new CodeEditorServiceImpl(); serviceCollection.set(ICodeEditorService, codeEditorService); - let menuService = services.menuService || new MenuService(extensionService); + let menuService = services.menuService || new MenuService(extensionService, commandService); serviceCollection.set(IMenuService, menuService); staticServices = { diff --git a/src/vs/editor/browser/view/viewController.ts b/src/vs/editor/browser/view/viewController.ts index 8296b7bc6f5..0b089cfde2e 100644 --- a/src/vs/editor/browser/view/viewController.ts +++ b/src/vs/editor/browser/view/viewController.ts @@ -9,7 +9,7 @@ import {IKeyboardEvent} from 'vs/base/browser/keyboardEvent'; import {Position} from 'vs/editor/common/core/position'; import * as editorCommon from 'vs/editor/common/editorCommon'; import {IEditorMouseEvent, IViewController, IMouseDispatchData} from 'vs/editor/browser/editorBrowser'; -import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; +import {ICommandService} from 'vs/platform/commands/common/commands'; import {IViewModel} from 'vs/editor/common/viewModel/viewModel'; import {Range} from 'vs/editor/common/core/range'; @@ -22,42 +22,42 @@ export class ViewController implements IViewController { private viewModel:IViewModel; private triggerCursorHandler:TriggerCursorHandler; private outgoingEventBus:EventEmitter; - private keybindingService:IKeybindingService; + private commandService:ICommandService; constructor( viewModel:IViewModel, triggerCursorHandler:TriggerCursorHandler, outgoingEventBus:EventEmitter, - keybindingService:IKeybindingService + commandService:ICommandService ) { this.viewModel = viewModel; this.triggerCursorHandler = triggerCursorHandler; this.outgoingEventBus = outgoingEventBus; - this.keybindingService = keybindingService; + this.commandService = commandService; } public paste(source:string, text:string, pasteOnNewLine:boolean): void { - this.keybindingService.executeCommand(editorCommon.Handler.Paste, { + this.commandService.executeCommand(editorCommon.Handler.Paste, { text: text, pasteOnNewLine: pasteOnNewLine, }); } public type(source:string, text:string): void { - this.keybindingService.executeCommand(editorCommon.Handler.Type, { + this.commandService.executeCommand(editorCommon.Handler.Type, { text: text }); } public replacePreviousChar(source: string, text: string, replaceCharCnt:number): void { - this.keybindingService.executeCommand(editorCommon.Handler.ReplacePreviousChar, { + this.commandService.executeCommand(editorCommon.Handler.ReplacePreviousChar, { text: text, replaceCharCnt: replaceCharCnt }); } public cut(source:string): void { - this.keybindingService.executeCommand(editorCommon.Handler.Cut, {}); + this.commandService.executeCommand(editorCommon.Handler.Cut, {}); } private _validateViewColumn(viewPosition:Position): Position { diff --git a/src/vs/editor/browser/view/viewImpl.ts b/src/vs/editor/browser/view/viewImpl.ts index 0b084443d77..c71b44ac374 100644 --- a/src/vs/editor/browser/view/viewImpl.ts +++ b/src/vs/editor/browser/view/viewImpl.ts @@ -12,6 +12,7 @@ import * as browser from 'vs/base/browser/browser'; import * as dom from 'vs/base/browser/dom'; import {StyleMutator} from 'vs/base/browser/styleMutator'; import {IKeybindingContextKey, IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; +import {ICommandService} from 'vs/platform/commands/common/commands'; import {Range} from 'vs/editor/common/core/range'; import * as editorCommon from 'vs/editor/common/editorCommon'; import {ViewEventHandler} from 'vs/editor/common/viewModel/viewEventHandler'; @@ -91,6 +92,7 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp constructor( keybindingService: IKeybindingService, + commandService: ICommandService, configuration:Configuration, model:IViewModel, triggerCursorHandler:TriggerCursorHandler @@ -100,7 +102,7 @@ export class View extends ViewEventHandler implements editorBrowser.IView, IDisp this._renderAnimationFrame = null; this.outgoingEventBus = new EventEmitter(); - var viewController = new ViewController(model, triggerCursorHandler, this.outgoingEventBus, keybindingService); + var viewController = new ViewController(model, triggerCursorHandler, this.outgoingEventBus, commandService); this.listenersToRemove = []; this.listenersToDispose = []; diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index b00b57998a6..9f65caf5bb3 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -11,6 +11,7 @@ import {IEventEmitter} from 'vs/base/common/eventEmitter'; import * as browser from 'vs/base/browser/browser'; import * as dom from 'vs/base/browser/dom'; import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation'; +import {ICommandService} from 'vs/platform/commands/common/commands'; import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry'; import {CommonCodeEditor} from 'vs/editor/common/commonCodeEditor'; @@ -74,10 +75,11 @@ export class CodeEditorWidget extends CommonCodeEditor implements editorBrowser. options:editorCommon.IEditorOptions, @IInstantiationService instantiationService: IInstantiationService, @ICodeEditorService codeEditorService: ICodeEditorService, + @ICommandService commandService: ICommandService, @IKeybindingService keybindingService: IKeybindingService, @ITelemetryService telemetryService: ITelemetryService ) { - super(domElement, options, instantiationService, codeEditorService, keybindingService, telemetryService); + super(domElement, options, instantiationService, codeEditorService, commandService, keybindingService, telemetryService); this._focusTracker = new CodeEditorWidgetFocusTracker(domElement); this._focusTracker.onChage(() => { @@ -489,6 +491,7 @@ export class CodeEditorWidget extends CommonCodeEditor implements editorBrowser. protected _createView(): void { this._view = new View( this._keybindingService, + this._commandService, this._configuration, this.viewModel, (source:string, handlerId:string, payload:any) => { diff --git a/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts b/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts index 867eae73882..c1bc8345d24 100644 --- a/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts +++ b/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts @@ -6,6 +6,7 @@ import * as objects from 'vs/base/common/objects'; import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation'; +import {ICommandService} from 'vs/platform/commands/common/commands'; import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry'; import {ICodeEditorWidgetCreationOptions, IConfigurationChangedEvent, IEditorOptions} from 'vs/editor/common/editorCommon'; @@ -24,10 +25,11 @@ export class EmbeddedCodeEditorWidget extends CodeEditorWidget { parentEditor:ICodeEditor, @IInstantiationService instantiationService: IInstantiationService, @ICodeEditorService codeEditorService: ICodeEditorService, + @ICommandService commandService: ICommandService, @IKeybindingService keybindingService: IKeybindingService, @ITelemetryService telemetryService: ITelemetryService ) { - super(domElement, parentEditor.getRawConfiguration(), instantiationService, codeEditorService, keybindingService, telemetryService); + super(domElement, parentEditor.getRawConfiguration(), instantiationService, codeEditorService, commandService, keybindingService, telemetryService); this._parentEditor = parentEditor; this._overwriteOptions = options; diff --git a/src/vs/editor/common/commonCodeEditor.ts b/src/vs/editor/common/commonCodeEditor.ts index cd2f2ff98e6..b99a57f8472 100644 --- a/src/vs/editor/common/commonCodeEditor.ts +++ b/src/vs/editor/common/commonCodeEditor.ts @@ -12,6 +12,7 @@ import * as timer from 'vs/base/common/timer'; import {TPromise} from 'vs/base/common/winjs.base'; import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation'; import {ServiceCollection} from 'vs/platform/instantiation/common/serviceCollection'; +import {ICommandService} from 'vs/platform/commands/common/commands'; import {IKeybindingContextKey, IKeybindingScopeLocation, IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry'; import {CommonEditorConfiguration} from 'vs/editor/common/config/commonEditorConfig'; @@ -101,6 +102,7 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom protected cursor:Cursor; protected _instantiationService: IInstantiationService; + protected _commandService: ICommandService; protected _keybindingService: IKeybindingService; /** @@ -123,6 +125,7 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom options:editorCommon.IEditorOptions, instantiationService: IInstantiationService, codeEditorService: ICodeEditorService, + commandService: ICommandService, keybindingService: IKeybindingService, telemetryService: ITelemetryService ) { @@ -138,6 +141,7 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom // listeners that are kept during the whole editor lifetime this._lifetimeDispose = []; + this._commandService = commandService; this._keybindingService = keybindingService.createScoped(domElement); this._editorIdContextKey = this._keybindingService.createKey('editorId', this.getId()); this._editorFocusContextKey = this._keybindingService.createKey(editorCommon.KEYBINDING_CONTEXT_EDITOR_FOCUS, undefined); diff --git a/src/vs/editor/contrib/codelens/browser/codelens.ts b/src/vs/editor/contrib/codelens/browser/codelens.ts index de1812abb2c..f68adc43132 100644 --- a/src/vs/editor/contrib/codelens/browser/codelens.ts +++ b/src/vs/editor/contrib/codelens/browser/codelens.ts @@ -13,7 +13,7 @@ import Severity from 'vs/base/common/severity'; import {format} from 'vs/base/common/strings'; import {TPromise} from 'vs/base/common/winjs.base'; import * as dom from 'vs/base/browser/dom'; -import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; +import {ICommandService} from 'vs/platform/commands/common/commands'; import {IMessageService} from 'vs/platform/message/common/message'; import {Range} from 'vs/editor/common/core/range'; import * as editorCommon from 'vs/editor/common/editorCommon'; @@ -60,7 +60,7 @@ class CodeLensContentWidget implements editorBrowser.IContentWidget { private _commands: { [id: string]: Command } = Object.create(null); public constructor(editor: editorBrowser.ICodeEditor, symbolRange: Range, - keybindingService: IKeybindingService, messageService: IMessageService) { + commandService: ICommandService, messageService: IMessageService) { this._id = 'codeLensWidget' + (++CodeLensContentWidget.ID); this._editor = editor; @@ -78,7 +78,7 @@ class CodeLensContentWidget implements editorBrowser.IContentWidget { let command = this._commands[element.id]; if (command) { editor.focus(); - keybindingService.executeCommand(command.id, ...command.arguments).done(undefined, err => { + commandService.executeCommand(command.id, ...command.arguments).done(undefined, err => { messageService.show(Severity.Error, err); }); } @@ -226,7 +226,7 @@ class CodeLens { public constructor(data: ICodeLensData[], editor: editorBrowser.ICodeEditor, helper: CodeLensHelper, viewZoneChangeAccessor: editorBrowser.IViewZoneChangeAccessor, - keybindingService: IKeybindingService, messageService: IMessageService) { + commandService: ICommandService, messageService: IMessageService) { this._editor = editor; this._data = data; @@ -251,7 +251,7 @@ class CodeLens { }); this._viewZone = new CodeLensViewZone(range.startLineNumber - 1); - this._contentWidget = new CodeLensContentWidget(editor, Range.lift(range), keybindingService, messageService); + this._contentWidget = new CodeLensContentWidget(editor, Range.lift(range), commandService, messageService); this._viewZoneId = viewZoneChangeAccessor.addZone(this._viewZone); this._editor.addContentWidget(this._contentWidget); @@ -351,7 +351,7 @@ export class CodeLensContribution implements editorCommon.IEditorContribution { constructor( private _editor: editorBrowser.ICodeEditor, @IModelService private _modelService: IModelService, - @IKeybindingService private _keybindingService: IKeybindingService, + @ICommandService private _commandService: ICommandService, @IMessageService private _messageService: IMessageService ) { this._isEnabled = this._editor.getConfiguration().contribInfo.referenceInfos; @@ -553,7 +553,7 @@ export class CodeLensContribution implements editorCommon.IEditorContribution { groupsIndex++; codeLensIndex++; } else { - this._lenses.splice(codeLensIndex, 0, new CodeLens(groups[groupsIndex], this._editor, helper, accessor, this._keybindingService, this._messageService)); + this._lenses.splice(codeLensIndex, 0, new CodeLens(groups[groupsIndex], this._editor, helper, accessor, this._commandService, this._messageService)); codeLensIndex++; groupsIndex++; } @@ -567,7 +567,7 @@ export class CodeLensContribution implements editorCommon.IEditorContribution { // Create extra symbols while (groupsIndex < groups.length) { - this._lenses.push(new CodeLens(groups[groupsIndex], this._editor, helper, accessor, this._keybindingService, this._messageService)); + this._lenses.push(new CodeLens(groups[groupsIndex], this._editor, helper, accessor, this._commandService, this._messageService)); groupsIndex++; } diff --git a/src/vs/editor/contrib/gotoError/browser/gotoError.ts b/src/vs/editor/contrib/gotoError/browser/gotoError.ts index 02689378a2d..ae5ac6e8e82 100644 --- a/src/vs/editor/contrib/gotoError/browser/gotoError.ts +++ b/src/vs/editor/contrib/gotoError/browser/gotoError.ts @@ -17,6 +17,7 @@ import URI from 'vs/base/common/uri'; import {TPromise} from 'vs/base/common/winjs.base'; import * as dom from 'vs/base/browser/dom'; import {renderHtml} from 'vs/base/browser/htmlContentRenderer'; +import {ICommandService} from 'vs/platform/commands/common/commands'; import {IKeybindingContextKey, IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; import {IMarker, IMarkerService} from 'vs/platform/markers/common/markers'; import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry'; @@ -204,7 +205,7 @@ class FixesWidget { constructor( container: HTMLElement, - @IKeybindingService private _keybindingService: IKeybindingService + @ICommandService private _commandService: ICommandService ) { this.domNode = document.createElement('div'); container.appendChild(this.domNode); @@ -274,14 +275,14 @@ class FixesWidget { entry.dataset['prev'] = String(idx > 0 ? idx - 1 : arr.length - 1); entry.appendChild(document.createTextNode(fix.command.title)); this._disposeOnUpdate.push(dom.addDisposableListener(entry, dom.EventType.CLICK, () => { - this._keybindingService.executeCommand(fix.command.id, ...fix.command.arguments); + this._commandService.executeCommand(fix.command.id, ...fix.command.arguments); return true; })); this._disposeOnUpdate.push(dom.addStandardDisposableListener(entry, 'keydown', (e) => { switch (e.asKeybinding()) { case CommonKeybindings.ENTER: case CommonKeybindings.SPACE: - this._keybindingService.executeCommand(fix.command.id, ...fix.command.arguments); + this._commandService.executeCommand(fix.command.id, ...fix.command.arguments); e.preventDefault(); e.stopPropagation(); } @@ -314,7 +315,7 @@ class MarkerNavigationWidget extends ZoneWidget { private _fixesWidget: FixesWidget; private _callOnDispose: IDisposable[] = []; - constructor(editor: ICodeEditor, private _model: MarkerModel, private _keybindingService: IKeybindingService) { + constructor(editor: ICodeEditor, private _model: MarkerModel, private _commandService: ICommandService) { super(editor, { showArrow: true, showFrame: true, isAccessible: true }); this.create(); this._wireModelAndView(); @@ -338,7 +339,7 @@ class MarkerNavigationWidget extends ZoneWidget { this._messages.setAttribute('role', 'alert'); this._container.appendChild(this._messages); - this._fixesWidget = new FixesWidget(this._container, this._keybindingService); + this._fixesWidget = new FixesWidget(this._container, this._commandService); this._fixesWidget.domNode.classList.add('fixes'); this._callOnDispose.push(this._fixesWidget); } @@ -442,7 +443,8 @@ class MarkerController implements editorCommon.IEditorContribution { constructor( editor: ICodeEditor, @IMarkerService private _markerService: IMarkerService, - @IKeybindingService private _keybindingService: IKeybindingService + @IKeybindingService private _keybindingService: IKeybindingService, + @ICommandService private _commandService: ICommandService ) { this._editor = editor; this._markersNavigationVisible = this._keybindingService.createKey(CONTEXT_MARKERS_NAVIGATION_VISIBLE, false); @@ -471,7 +473,7 @@ class MarkerController implements editorCommon.IEditorContribution { var markers = this._getMarkers(); this._model = new MarkerModel(this._editor, markers); - this._zone = new MarkerNavigationWidget(this._editor, this._model, this._keybindingService); + this._zone = new MarkerNavigationWidget(this._editor, this._model, this._commandService); this._markersNavigationVisible.set(true); this._callOnClose.push(this._model); diff --git a/src/vs/editor/contrib/quickFix/browser/quickFix.ts b/src/vs/editor/contrib/quickFix/browser/quickFix.ts index e18b313f910..cab1bb1c4ae 100644 --- a/src/vs/editor/contrib/quickFix/browser/quickFix.ts +++ b/src/vs/editor/contrib/quickFix/browser/quickFix.ts @@ -9,6 +9,7 @@ import {onUnexpectedError} from 'vs/base/common/errors'; import {KeyCode, KeyMod} from 'vs/base/common/keyCodes'; import {TPromise} from 'vs/base/common/winjs.base'; import {IEditorService} from 'vs/platform/editor/common/editor'; +import {ICommandService} from 'vs/platform/commands/common/commands'; import {IKeybindingContextKey, IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; import {IMarkerService} from 'vs/platform/markers/common/markers'; import {IMessageService} from 'vs/platform/message/common/message'; @@ -39,6 +40,7 @@ export class QuickFixController implements IEditorContribution { constructor(editor: ICodeEditor, @IMarkerService private _markerService: IMarkerService, @IKeybindingService private _keybindingService: IKeybindingService, + @ICommandService private _commandService: ICommandService, @ITelemetryService telemetryService: ITelemetryService, @IEditorService editorService: IEditorService, @IMessageService messageService: IMessageService @@ -63,7 +65,7 @@ export class QuickFixController implements IEditorContribution { var model = this.editor.getModel(); if (model) { let {command} = fix; - return this._keybindingService.executeCommand(command.id, ...command.arguments).done(void 0, onUnexpectedError); + return this._commandService.executeCommand(command.id, ...command.arguments).done(void 0, onUnexpectedError); } } diff --git a/src/vs/editor/test/common/mocks/mockCodeEditor.ts b/src/vs/editor/test/common/mocks/mockCodeEditor.ts index 021aae02236..919f47f7972 100644 --- a/src/vs/editor/test/common/mocks/mockCodeEditor.ts +++ b/src/vs/editor/test/common/mocks/mockCodeEditor.ts @@ -8,6 +8,7 @@ import {EventEmitter, IEventEmitter} from 'vs/base/common/eventEmitter'; import {ICodeEditorService} from 'vs/editor/common/services/codeEditorService'; import {ServiceCollection} from 'vs/platform/instantiation/common/serviceCollection'; import {InstantiationService} from 'vs/platform/instantiation/common/instantiationService'; +import {ICommandService, NullCommandService} from 'vs/platform/commands/common/commands'; import {IKeybindingService, IKeybindingScopeLocation} from 'vs/platform/keybinding/common/keybinding'; import {MockKeybindingService} from 'vs/platform/keybinding/test/common/mockKeybindingService'; import {ITelemetryService, NullTelemetryService} from 'vs/platform/telemetry/common/telemetry'; @@ -75,15 +76,17 @@ export function withMockCodeEditor(text:string[], options:editorCommon.ICodeEdit let codeEditorService = new MockCodeEditorService(); let keybindingService = new MockKeybindingService(); let telemetryService = NullTelemetryService; + let commandService = NullCommandService; let services = new ServiceCollection(); services.set(ICodeEditorService, codeEditorService); services.set(IKeybindingService, keybindingService); services.set(ITelemetryService, telemetryService); + services.set(ICommandService, commandService); let instantiationService = new InstantiationService(services); let model = Model.createFromString(text.join('\n')); - let editor = new MockCodeEditor(new MockScopeLocation(), options, instantiationService, codeEditorService, keybindingService, telemetryService); + let editor = new MockCodeEditor(new MockScopeLocation(), options, instantiationService, codeEditorService, commandService, keybindingService, telemetryService); editor.setModel(model); callback(editor, editor.getCursor()); diff --git a/src/vs/platform/actions/browser/menuService.ts b/src/vs/platform/actions/browser/menuService.ts index f65403f4009..2d91036540c 100644 --- a/src/vs/platform/actions/browser/menuService.ts +++ b/src/vs/platform/actions/browser/menuService.ts @@ -13,6 +13,7 @@ import {values} from 'vs/base/common/collections'; import {KbExpr, IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; import {MenuId, ICommandAction, MenuItemAction, IMenu, IMenuItem, IMenuService} from 'vs/platform/actions/common/actions'; import {IExtensionService} from 'vs/platform/extensions/common/extensions'; +import {ICommandService} from 'vs/platform/commands/common/commands'; import {ResourceContextKey} from 'vs/platform/actions/common/resourceContextKey'; @@ -58,13 +59,14 @@ export class MenuService implements IMenuService { serviceId = IMenuService; constructor( - @IExtensionService private _extensionService: IExtensionService + @IExtensionService private _extensionService: IExtensionService, + @ICommandService private _commandService: ICommandService ) { // } createMenu(id: MenuId, keybindingService: IKeybindingService): IMenu { - return new Menu(id, keybindingService, this._extensionService); + return new Menu(id, this._commandService, keybindingService, this._extensionService); } getCommandActions(): ICommandAction[] { @@ -82,6 +84,7 @@ class Menu implements IMenu { constructor( id: MenuId, + @ICommandService private _commandService: ICommandService, @IKeybindingService private _keybindingService: IKeybindingService, @IExtensionService private _extensionService: IExtensionService ) { @@ -100,7 +103,7 @@ class Menu implements IMenu { group = [groupName, []]; this._menuGroups.push(group); } - group[1].push(new MenuItemAction(item, this._keybindingService)); + group[1].push(new MenuItemAction(item, this._commandService)); // keep keys for eventing Menu._fillInKbExprKeys(item.when, keysFilter); diff --git a/src/vs/platform/actions/common/actions.ts b/src/vs/platform/actions/common/actions.ts index aa89a26e718..0308c7c8e05 100644 --- a/src/vs/platform/actions/common/actions.ts +++ b/src/vs/platform/actions/common/actions.ts @@ -10,6 +10,7 @@ import WinJS = require('vs/base/common/winjs.base'); import Descriptors = require('vs/platform/instantiation/common/descriptors'); import Instantiation = require('vs/platform/instantiation/common/instantiation'); import {KbExpr, IKeybindings, IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; +import {ICommandService} from 'vs/platform/commands/common/commands'; import {IDisposable} from 'vs/base/common/lifecycle'; import {createDecorator} from 'vs/platform/instantiation/common/instantiation'; import Event from 'vs/base/common/event'; @@ -64,7 +65,7 @@ export class MenuItemAction extends Actions.Action { constructor( private _item: IMenuItem, - @IKeybindingService private _keybindingService: IKeybindingService + @ICommandService private _commandService: ICommandService ) { super(MenuItemAction._getMenuItemId(_item), _item.command.title); @@ -93,7 +94,7 @@ export class MenuItemAction extends Actions.Action { run(alt: boolean) { const {id} = alt === true && this._item.alt || this._item.command; - return this._keybindingService.executeCommand(id, this._resource); + return this._commandService.executeCommand(id, this._resource); } } @@ -103,13 +104,13 @@ export class ExecuteCommandAction extends Actions.Action { constructor( id: string, label: string, - @IKeybindingService private _keybindingService: IKeybindingService) { + @ICommandService private _commandService: ICommandService) { super(id, label); } run(...args: any[]): WinJS.TPromise { - return this._keybindingService.executeCommand(this.id, ...args); + return this._commandService.executeCommand(this.id, ...args); } } diff --git a/src/vs/platform/commands/common/commands.ts b/src/vs/platform/commands/common/commands.ts index cddbd982849..0dbb3c3b313 100644 --- a/src/vs/platform/commands/common/commands.ts +++ b/src/vs/platform/commands/common/commands.ts @@ -94,3 +94,10 @@ export const CommandsRegistry: ICommandRegistry = new class implements ICommandR return this._commands; } }; + +export const NullCommandService: ICommandService = { + serviceId: undefined, + executeCommand() { + return TPromise.as(undefined); + } +}; \ No newline at end of file diff --git a/src/vs/platform/keybinding/browser/keybindingServiceImpl.ts b/src/vs/platform/keybinding/browser/keybindingServiceImpl.ts index 797e3e8b012..65a56475886 100644 --- a/src/vs/platform/keybinding/browser/keybindingServiceImpl.ts +++ b/src/vs/platform/keybinding/browser/keybindingServiceImpl.ts @@ -11,7 +11,6 @@ import {KeyCode, Keybinding} from 'vs/base/common/keyCodes'; import {IDisposable, dispose} from 'vs/base/common/lifecycle'; import Severity from 'vs/base/common/severity'; import {isFalsyOrEmpty} from 'vs/base/common/arrays'; -import {TPromise} from 'vs/base/common/winjs.base'; import * as dom from 'vs/base/browser/dom'; import {IKeyboardEvent, StandardKeyboardEvent} from 'vs/base/browser/keyboardEvent'; import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation'; @@ -207,11 +206,6 @@ export abstract class AbstractKeybindingService { } } - public hasCommand(commandId: string): boolean { - return !!CommandsRegistry.getCommands()[commandId]; - } - - public abstract executeCommand(commandId: string, args: any): TPromise; public abstract getLabelFor(keybinding: Keybinding): string; public abstract getHTMLLabelFor(keybinding: Keybinding): IHTMLContentElement[]; public abstract getAriaLabelFor(keybinding: Keybinding): string; @@ -412,10 +406,6 @@ export abstract class KeybindingService extends AbstractKeybindingService implem public disposeContext(contextId: number): void { delete this._contexts[String(contextId)]; } - - public executeCommand(commandId: string, ...args: any[]): TPromise { - return this._commandService.executeCommand(commandId, ...args); - } } KeybindingsRegistry.registerCommandDesc({ @@ -489,8 +479,4 @@ class ScopedKeybindingService extends AbstractKeybindingService { public disposeContext(contextId: number): void { this._parent.disposeContext(contextId); } - - public executeCommand(commandId: string, args: any): TPromise { - return this._parent.executeCommand(commandId, args); - } } diff --git a/src/vs/platform/keybinding/common/keybinding.ts b/src/vs/platform/keybinding/common/keybinding.ts index f32ee280094..2437b1e04b2 100644 --- a/src/vs/platform/keybinding/common/keybinding.ts +++ b/src/vs/platform/keybinding/common/keybinding.ts @@ -6,7 +6,6 @@ import {IHTMLContentElement} from 'vs/base/common/htmlContent'; import {Keybinding} from 'vs/base/common/keyCodes'; -import {TPromise} from 'vs/base/common/winjs.base'; import {ServiceIdentifier, createDecorator} from 'vs/platform/instantiation/common/instantiation'; import Event from 'vs/base/common/event'; @@ -466,10 +465,6 @@ export interface IKeybindingService { getAriaLabelFor(keybinding: Keybinding): string; getHTMLLabelFor(keybinding: Keybinding): IHTMLContentElement[]; getElectronAcceleratorFor(keybinding: Keybinding): string; - - executeCommand(commandId: string, ...args: any[]): TPromise; - executeCommand(commandId: string, ...args: any[]): TPromise; - hasCommand(commandId: string): boolean; } export const SET_CONTEXT_COMMAND_ID = 'setContext'; diff --git a/src/vs/platform/keybinding/test/common/mockKeybindingService.ts b/src/vs/platform/keybinding/test/common/mockKeybindingService.ts index 5fe63846566..2610f846bc2 100644 --- a/src/vs/platform/keybinding/test/common/mockKeybindingService.ts +++ b/src/vs/platform/keybinding/test/common/mockKeybindingService.ts @@ -6,7 +6,6 @@ import {IHTMLContentElement} from 'vs/base/common/htmlContent'; import {Keybinding} from 'vs/base/common/keyCodes'; -import {TPromise} from 'vs/base/common/winjs.base'; import Event from 'vs/base/common/event'; import {IKeybindingContextKey, IKeybindingService, KbExpr} from 'vs/platform/keybinding/common/keybinding'; @@ -34,8 +33,6 @@ export class MockKeybindingService implements IKeybindingService { public serviceId = IKeybindingService; public dispose(): void { } - public executeCommand(commandId: string, ...args: any[]): TPromise { return; } - public hasCommand(commandId) { return false; } public createKey(key: string, defaultValue: T): IKeybindingContextKey { return new MockKeybindingContextKey(key, defaultValue); diff --git a/src/vs/workbench/api/node/mainThreadCommands.ts b/src/vs/workbench/api/node/mainThreadCommands.ts index 08cc893704a..f6c26c2fd3f 100644 --- a/src/vs/workbench/api/node/mainThreadCommands.ts +++ b/src/vs/workbench/api/node/mainThreadCommands.ts @@ -6,48 +6,28 @@ import {IThreadService} from 'vs/workbench/services/thread/common/threadService'; import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry'; -import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; -import {CommandsRegistry, ICommandHandlerDescription} from 'vs/platform/commands/common/commands'; - +import {ICommandService, CommandsRegistry, ICommandHandlerDescription} from 'vs/platform/commands/common/commands'; import {TPromise} from 'vs/base/common/winjs.base'; import {ExtHostContext, ExtHostCommandsShape} from './extHostProtocol'; export class MainThreadCommands { - private _threadService: IThreadService; - private _keybindingService: IKeybindingService; private _proxy: ExtHostCommandsShape; constructor( - @IThreadService threadService: IThreadService, - @IKeybindingService keybindingService: IKeybindingService + @IThreadService private _threadService: IThreadService, + @ICommandService private _commandService: ICommandService ) { - this._threadService = threadService; - this._keybindingService = keybindingService; this._proxy = this._threadService.get(ExtHostContext.ExtHostCommands); } $registerCommand(id: string): TPromise { - - KeybindingsRegistry.registerCommandDesc({ - id, - handler: (serviceAccessor, ...args: any[]) => { - return this._proxy.$executeContributedCommand(id, ...args); - }, - weight: undefined, - when: undefined, - win: undefined, - mac: undefined, - linux: undefined, - primary: undefined, - secondary: undefined - }); - + CommandsRegistry.registerCommand(id, (accessor, ...args) => this._proxy.$executeContributedCommand(id, ...args)); return undefined; } $executeCommand(id: string, args: any[]): Thenable { - return this._keybindingService.executeCommand(id, ...args); + return this._commandService.executeCommand(id, ...args); } $getCommands(): Thenable { diff --git a/src/vs/workbench/browser/parts/statusbar/statusbarPart.ts b/src/vs/workbench/browser/parts/statusbar/statusbarPart.ts index 140a0ba36f9..638d559b900 100644 --- a/src/vs/workbench/browser/parts/statusbar/statusbarPart.ts +++ b/src/vs/workbench/browser/parts/statusbar/statusbarPart.ts @@ -15,7 +15,7 @@ import {dispose, IDisposable} from 'vs/base/common/lifecycle'; import {Builder, $} from 'vs/base/browser/builder'; import {OcticonLabel} from 'vs/base/browser/ui/octiconLabel/octiconLabel'; import {Registry} from 'vs/platform/platform'; -import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; +import {ICommandService} from 'vs/platform/commands/common/commands'; import {IAction} from 'vs/base/common/actions'; import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService'; import {Part} from 'vs/workbench/browser/part'; @@ -190,7 +190,7 @@ class StatusBarEntryItem implements IStatusbarItem { constructor( entry: IStatusbarEntry, - @IKeybindingService private keybindingService: IKeybindingService, + @ICommandService private commandService: ICommandService, @IInstantiationService private instantiationService: IInstantiationService, @IMessageService private messageService: IMessageService, @ITelemetryService private telemetryService: ITelemetryService, @@ -272,7 +272,7 @@ class StatusBarEntryItem implements IStatusbarItem { // Fallback to the keybinding service for any other case else { - this.keybindingService.executeCommand(id).done(undefined, err => this.messageService.show(Severity.Error, toErrorMessage(err))); + this.commandService.executeCommand(id).done(undefined, err => this.messageService.show(Severity.Error, toErrorMessage(err))); } } } \ No newline at end of file diff --git a/src/vs/workbench/electron-browser/integration.ts b/src/vs/workbench/electron-browser/integration.ts index e9d4f6fd22c..faaa4c2d47e 100644 --- a/src/vs/workbench/electron-browser/integration.ts +++ b/src/vs/workbench/electron-browser/integration.ts @@ -17,6 +17,7 @@ import {IMessageService} from 'vs/platform/message/common/message'; import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation'; import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry'; import {IContextMenuService} from 'vs/platform/contextview/browser/contextView'; +import {ICommandService} from 'vs/platform/commands/common/commands'; import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; import {IWorkspaceContextService}from 'vs/workbench/services/workspace/common/contextService'; import {IWindowService} from 'vs/workbench/services/window/electron-browser/windowService'; @@ -49,6 +50,7 @@ export class ElectronIntegration { @IWorkspaceContextService private contextService: IWorkspaceContextService, @ITelemetryService private telemetryService: ITelemetryService, @IConfigurationService private configurationService: IConfigurationService, + @ICommandService private commandService: ICommandService, @IKeybindingService private keybindingService: IKeybindingService, @IMessageService private messageService: IMessageService, @IContextMenuService private contextMenuService: IContextMenuService @@ -63,7 +65,7 @@ export class ElectronIntegration { // Support runAction event ipc.on('vscode:runAction', (event, actionId: string) => { - this.keybindingService.executeCommand(actionId, { from: 'menu' }).done(undefined, err => this.messageService.show(Severity.Error, err)); + this.commandService.executeCommand(actionId, { from: 'menu' }).done(undefined, err => this.messageService.show(Severity.Error, err)); }); // Support options change diff --git a/src/vs/workbench/parts/debug/electron-browser/debugActions.ts b/src/vs/workbench/parts/debug/electron-browser/debugActions.ts index aae155d7c07..2f56d1a9941 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugActions.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugActions.ts @@ -14,6 +14,7 @@ import { EditorAction } from 'vs/editor/common/editorAction'; import { Behaviour } from 'vs/editor/common/editorActionEnablement'; import { IEventService } from 'vs/platform/event/common/event'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; +import { ICommandService } from 'vs/platform/commands/common/commands'; import { EventType, CompositeEvent } from 'vs/workbench/common/events'; import debug = require('vs/workbench/parts/debug/common/debug'); import model = require('vs/workbench/parts/debug/common/debugModel'); @@ -121,12 +122,12 @@ export class StartDebugAction extends AbstractDebugAction { static ID = 'workbench.action.debug.start'; static LABEL = nls.localize('startDebug', "Start Debugging"); - constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService) { + constructor(id: string, label: string, @IDebugService debugService: IDebugService, @IKeybindingService keybindingService: IKeybindingService, @ICommandService private commandService: ICommandService) { super(id, label, 'debug-action start', debugService, keybindingService); } public run(): TPromise { - return this.keybindingService.executeCommand('_workbench.startDebug'); + return this.commandService.executeCommand('_workbench.startDebug'); } protected isEnabled(state: debug.State): boolean { diff --git a/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts b/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts index 4af83faa61f..bb5b7cb41ce 100644 --- a/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts +++ b/src/vs/workbench/parts/debug/node/debugConfigurationManager.ts @@ -23,7 +23,7 @@ import jsonContributionRegistry = require('vs/platform/jsonschemas/common/jsonCo import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IFileService } from 'vs/platform/files/common/files'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; -import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; +import { ICommandService } from 'vs/platform/commands/common/commands'; import debug = require('vs/workbench/parts/debug/common/debug'); import { SystemVariables } from 'vs/workbench/parts/lib/node/systemVariables'; import { Adapter } from 'vs/workbench/parts/debug/node/debugAdapter'; @@ -167,7 +167,7 @@ export class ConfigurationManager implements debug.IConfigurationManager { @IWorkbenchEditorService private editorService: IWorkbenchEditorService, @IConfigurationService private configurationService: IConfigurationService, @IQuickOpenService private quickOpenService: IQuickOpenService, - @IKeybindingService private keybindingService: IKeybindingService + @ICommandService private commandService: ICommandService ) { this._onDidConfigurationChange = new Emitter(); this.systemVariables = this.contextService.getWorkspace() ? new SystemVariables(this.editorService, this.contextService) : null; @@ -276,7 +276,7 @@ export class ConfigurationManager implements debug.IConfigurationManager { if (!commandId) { return TPromise.wrapError(nls.localize('interactiveVariableNotFound', "Adapter {0} does not contribute variable {1} that is specified in launch configuration.", this.adapter.type, interactiveVariable)); } else { - return this.keybindingService.executeCommand(commandId, this.configuration).then(result => { + return this.commandService.executeCommand(commandId, this.configuration).then(result => { if (!result) { this.configuration.silentlyAbort = true; } diff --git a/src/vs/workbench/parts/quickopen/browser/commandsHandler.ts b/src/vs/workbench/parts/quickopen/browser/commandsHandler.ts index 4b5e1f9ce8b..41b72533989 100644 --- a/src/vs/workbench/parts/quickopen/browser/commandsHandler.ts +++ b/src/vs/workbench/parts/quickopen/browser/commandsHandler.ts @@ -266,7 +266,10 @@ export class CommandsHandler extends QuickOpenHandler { let editorEntries = this.editorActionsToEntries(editorActions, searchValue); // Other Actions - let otherActions = this.menuService.getCommandActions().map(command => new ExecuteCommandAction(command.id, command.category ? nls.localize('', "{0}: {1}", command.category, command.title) : command.title, this.keybindingService)); + let otherActions = this.menuService.getCommandActions().map(command => { + return this.instantiationService.createInstance(ExecuteCommandAction, command.id, + command.category ? nls.localize('', "{0}: {1}", command.category, command.title) : command.title); + }); let otherEntries = this.otherActionsToEntries(otherActions, searchValue); // Concat diff --git a/src/vs/workbench/test/node/api/extHostApiCommands.test.ts b/src/vs/workbench/test/node/api/extHostApiCommands.test.ts index c0893e17cf0..ccf5af8b225 100644 --- a/src/vs/workbench/test/node/api/extHostApiCommands.test.ts +++ b/src/vs/workbench/test/node/api/extHostApiCommands.test.ts @@ -18,8 +18,7 @@ import {InstantiationService} from 'vs/platform/instantiation/common/instantiati import {MarkerService} from 'vs/platform/markers/common/markerService'; import {IMarkerService} from 'vs/platform/markers/common/markers'; import {IThreadService} from 'vs/workbench/services/thread/common/threadService'; -import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding'; -import {CommandsRegistry} from 'vs/platform/commands/common/commands'; +import {ICommandService, CommandsRegistry} from 'vs/platform/commands/common/commands'; import {IModelService} from 'vs/editor/common/services/modelService'; import {ExtHostLanguageFeatures} from 'vs/workbench/api/node/extHostLanguageFeatures'; import {MainThreadLanguageFeatures} from 'vs/workbench/api/node/mainThreadLanguageFeatures'; @@ -60,7 +59,8 @@ suite('ExtHostLanguageFeatureCommands', function() { let instantiationService = new InstantiationService(services); threadService = new TestThreadService(); - services.set(IKeybindingService, { + services.set(ICommandService, { + serviceId: undefined, executeCommand(id, args): any { let {handler} = CommandsRegistry.getCommands()[id]; return TPromise.as(instantiationService.invokeFunction(handler, args));