diff --git a/src/vs/editor/browser/controller/coreCommands.ts b/src/vs/editor/browser/controller/coreCommands.ts index 05c024d8d8c0eba2659a14fe3f495fb1638fd49a..b6c64c1cc534d842d0cce4da47463c64f338852f 100644 --- a/src/vs/editor/browser/controller/coreCommands.ts +++ b/src/vs/editor/browser/controller/coreCommands.ts @@ -1620,7 +1620,7 @@ function findFocusedEditor(accessor: ServicesAccessor): ICodeEditor { } function registerCommand(command: Command) { - KeybindingsRegistry.registerCommandAndKeybindingRule(command.toCommandAndKeybindingRule(CORE_WEIGHT)); + command.register(CORE_WEIGHT); } /** diff --git a/src/vs/editor/browser/editorExtensions.ts b/src/vs/editor/browser/editorExtensions.ts index 6d9e1f04119e7fe154eb858850dad9bc56cd64ff..1327d5722fc0e67dcefc15afa741514ced7de3f4 100644 --- a/src/vs/editor/browser/editorExtensions.ts +++ b/src/vs/editor/browser/editorExtensions.ts @@ -31,11 +31,18 @@ export interface ICommandKeybindingsOptions extends IKeybindings { kbExpr?: ContextKeyExpr; weight?: number; } +// export interface ICommandMenubarOptions { +// group?: string; +// order?: number; +// when?: ContextKeyExpr; +// title?: string; +// } export interface ICommandOptions { id: string; precondition: ContextKeyExpr; kbOpts?: ICommandKeybindingsOptions; description?: ICommandHandlerDescription; + // menubarOpts?: ICommandMenubarOptions; } export abstract class Command { public readonly id: string; @@ -50,7 +57,7 @@ export abstract class Command { this._description = opts.description; } - public toCommandAndKeybindingRule(defaultWeight: number): ICommandAndKeybindingRule { + private _toCommandAndKeybindingRule(defaultWeight: number): ICommandAndKeybindingRule { const kbOpts = this._kbOpts || { primary: 0 }; let kbWhen = kbOpts.kbExpr; @@ -78,6 +85,10 @@ export abstract class Command { }; } + public register(defaultWeight: number): void { + KeybindingsRegistry.registerCommandAndKeybindingRule(this._toCommandAndKeybindingRule(defaultWeight)); + } + public abstract runCommand(accessor: ServicesAccessor, args: any): void | TPromise; } @@ -166,7 +177,7 @@ export abstract class EditorAction extends EditorCommand { this.menuOpts = opts.menuOpts; } - public toMenuItem(): IMenuItem { + private _toMenuItem(): IMenuItem { if (!this.menuOpts) { return null; } @@ -182,6 +193,16 @@ export abstract class EditorAction extends EditorCommand { }; } + public register(defaultWeight: number): void { + + let menuItem = this._toMenuItem(); + if (menuItem) { + MenuRegistry.appendMenuItem(MenuId.EditorContext, menuItem); + } + + super.register(defaultWeight); + } + public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | TPromise { this.reportTelemetry(accessor, editor); return this.run(accessor, editor, args || {}); @@ -295,14 +316,7 @@ class EditorContributionRegistry { } public registerEditorAction(action: EditorAction) { - - let menuItem = action.toMenuItem(); - if (menuItem) { - MenuRegistry.appendMenuItem(MenuId.EditorContext, menuItem); - } - - KeybindingsRegistry.registerCommandAndKeybindingRule(action.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib())); - + action.register(KeybindingsRegistry.WEIGHT.editorContrib()); this.editorActions.push(action); } @@ -315,7 +329,7 @@ class EditorContributionRegistry { } public registerEditorCommand(editorCommand: EditorCommand) { - KeybindingsRegistry.registerCommandAndKeybindingRule(editorCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib())); + editorCommand.register(KeybindingsRegistry.WEIGHT.editorContrib()); this.editorCommands[editorCommand.id] = editorCommand; } diff --git a/src/vs/workbench/parts/extensions/electron-browser/extensionEditor.ts b/src/vs/workbench/parts/extensions/electron-browser/extensionEditor.ts index d7f89ad89158bcc3b616f52afba2b5606abfa76e..26b1248599959679f6c05ba567c8411fd86cc89a 100644 --- a/src/vs/workbench/parts/extensions/electron-browser/extensionEditor.ts +++ b/src/vs/workbench/parts/extensions/electron-browser/extensionEditor.ts @@ -1124,4 +1124,4 @@ const showCommand = new ShowExtensionEditorFindCommand({ primary: KeyMod.CtrlCmd | KeyCode.KEY_F } }); -KeybindingsRegistry.registerCommandAndKeybindingRule(showCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib())); +showCommand.register(KeybindingsRegistry.WEIGHT.editorContrib()); diff --git a/src/vs/workbench/parts/preferences/electron-browser/preferences.contribution.ts b/src/vs/workbench/parts/preferences/electron-browser/preferences.contribution.ts index 3e2d2137832b5e7f5afe7cf8c47fc7acc9b91168..cb4dd53b20e836647946a07468fed77770bb3a52 100644 --- a/src/vs/workbench/parts/preferences/electron-browser/preferences.contribution.ts +++ b/src/vs/workbench/parts/preferences/electron-browser/preferences.contribution.ts @@ -353,7 +353,7 @@ const startSearchCommand = new StartSearchDefaultSettingsCommand({ precondition: ContextKeyExpr.and(CONTEXT_SETTINGS_EDITOR), kbOpts: { primary: KeyMod.CtrlCmd | KeyCode.KEY_F } }); -KeybindingsRegistry.registerCommandAndKeybindingRule(startSearchCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib())); +startSearchCommand.register(KeybindingsRegistry.WEIGHT.editorContrib()); class FocusSearchFromSettingsCommand extends SettingsCommand { @@ -369,7 +369,7 @@ const focusSearchFromSettingsCommand = new FocusSearchFromSettingsCommand({ precondition: ContextKeyExpr.and(CONTEXT_SETTINGS_EDITOR, CONTEXT_SETTINGS_FIRST_ROW_FOCUS), kbOpts: { primary: KeyCode.UpArrow } }); -KeybindingsRegistry.registerCommandAndKeybindingRule(focusSearchFromSettingsCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.workbenchContrib())); +focusSearchFromSettingsCommand.register(KeybindingsRegistry.WEIGHT.workbenchContrib()); class ClearSearchResultsCommand extends SettingsCommand { @@ -386,7 +386,7 @@ const clearSearchResultsCommand = new ClearSearchResultsCommand({ precondition: CONTEXT_SETTINGS_SEARCH_FOCUS, kbOpts: { primary: KeyCode.Escape } }); -KeybindingsRegistry.registerCommandAndKeybindingRule(clearSearchResultsCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib())); +clearSearchResultsCommand.register(KeybindingsRegistry.WEIGHT.editorContrib()); class FocusSettingsFileEditorCommand extends SettingsCommand { @@ -404,14 +404,14 @@ const focusSettingsFileEditorCommand = new FocusSettingsFileEditorCommand({ precondition: CONTEXT_SETTINGS_SEARCH_FOCUS, kbOpts: { primary: KeyCode.DownArrow } }); -KeybindingsRegistry.registerCommandAndKeybindingRule(focusSettingsFileEditorCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib())); +focusSettingsFileEditorCommand.register(KeybindingsRegistry.WEIGHT.editorContrib()); const focusSettingsFromSearchCommand = new FocusSettingsFileEditorCommand({ id: SETTINGS_EDITOR_COMMAND_FOCUS_SETTINGS_FROM_SEARCH, precondition: CONTEXT_SETTINGS_SEARCH_FOCUS, kbOpts: { primary: KeyCode.DownArrow } }); -KeybindingsRegistry.registerCommandAndKeybindingRule(focusSettingsFromSearchCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.workbenchContrib())); +focusSettingsFromSearchCommand.register(KeybindingsRegistry.WEIGHT.workbenchContrib()); class FocusNextSearchResultCommand extends SettingsCommand { @@ -427,7 +427,7 @@ const focusNextSearchResultCommand = new FocusNextSearchResultCommand({ precondition: CONTEXT_SETTINGS_SEARCH_FOCUS, kbOpts: { primary: KeyCode.Enter } }); -KeybindingsRegistry.registerCommandAndKeybindingRule(focusNextSearchResultCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib())); +focusNextSearchResultCommand.register(KeybindingsRegistry.WEIGHT.editorContrib()); class FocusPreviousSearchResultCommand extends SettingsCommand { @@ -443,7 +443,7 @@ const focusPreviousSearchResultCommand = new FocusPreviousSearchResultCommand({ precondition: CONTEXT_SETTINGS_SEARCH_FOCUS, kbOpts: { primary: KeyMod.Shift | KeyCode.Enter } }); -KeybindingsRegistry.registerCommandAndKeybindingRule(focusPreviousSearchResultCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib())); +focusPreviousSearchResultCommand.register(KeybindingsRegistry.WEIGHT.editorContrib()); class EditFocusedSettingCommand extends SettingsCommand { @@ -459,7 +459,7 @@ const editFocusedSettingCommand = new EditFocusedSettingCommand({ precondition: CONTEXT_SETTINGS_SEARCH_FOCUS, kbOpts: { primary: KeyMod.CtrlCmd | KeyCode.US_DOT } }); -KeybindingsRegistry.registerCommandAndKeybindingRule(editFocusedSettingCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib())); +editFocusedSettingCommand.register(KeybindingsRegistry.WEIGHT.editorContrib()); class EditFocusedSettingCommand2 extends SettingsCommand { @@ -476,7 +476,7 @@ const editFocusedSettingCommand2 = new EditFocusedSettingCommand2({ precondition: ContextKeyExpr.and(CONTEXT_SETTINGS_EDITOR, CONTEXT_SETTINGS_ROW_FOCUS), kbOpts: { primary: KeyCode.Enter } }); -KeybindingsRegistry.registerCommandAndKeybindingRule(editFocusedSettingCommand2.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.workbenchContrib())); +editFocusedSettingCommand2.register(KeybindingsRegistry.WEIGHT.workbenchContrib()); class FocusSettingsListCommand extends SettingsCommand { @@ -493,7 +493,7 @@ const focusSettingsListCommand = new FocusSettingsListCommand({ precondition: ContextKeyExpr.and(CONTEXT_SETTINGS_EDITOR, CONTEXT_TOC_ROW_FOCUS), kbOpts: { primary: KeyCode.Enter } }); -KeybindingsRegistry.registerCommandAndKeybindingRule(focusSettingsListCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.workbenchContrib())); +focusSettingsListCommand.register(KeybindingsRegistry.WEIGHT.workbenchContrib()); // Preferences menu diff --git a/src/vs/workbench/parts/webview/electron-browser/webview.contribution.ts b/src/vs/workbench/parts/webview/electron-browser/webview.contribution.ts index dbef116693fe683f1ecbb342fd9dc76a2a4c08fd..2dbb4818b3765b6ec00e9e0b5c6e4498fc3ff3a8 100644 --- a/src/vs/workbench/parts/webview/electron-browser/webview.contribution.ts +++ b/src/vs/workbench/parts/webview/electron-browser/webview.contribution.ts @@ -45,7 +45,7 @@ const showNextFindWdigetCommand = new ShowWebViewEditorFindWidgetCommand({ primary: KeyMod.CtrlCmd | KeyCode.KEY_F } }); -KeybindingsRegistry.registerCommandAndKeybindingRule(showNextFindWdigetCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib())); +showNextFindWdigetCommand.register(KeybindingsRegistry.WEIGHT.editorContrib()); const hideCommand = new HideWebViewEditorFindCommand({ id: HideWebViewEditorFindCommand.ID, @@ -56,7 +56,7 @@ const hideCommand = new HideWebViewEditorFindCommand({ primary: KeyCode.Escape } }); -KeybindingsRegistry.registerCommandAndKeybindingRule(hideCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib())); +hideCommand.register(KeybindingsRegistry.WEIGHT.editorContrib()); const selectAllCommand = new SelectAllWebviewEditorCommand({ id: SelectAllWebviewEditorCommand.ID, @@ -65,7 +65,7 @@ const selectAllCommand = new SelectAllWebviewEditorCommand({ primary: KeyMod.CtrlCmd | KeyCode.KEY_A } }); -KeybindingsRegistry.registerCommandAndKeybindingRule(selectAllCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib())); +selectAllCommand.register(KeybindingsRegistry.WEIGHT.editorContrib()); actionRegistry.registerWorkbenchAction( new SyncActionDescriptor(OpenWebviewDeveloperToolsAction, OpenWebviewDeveloperToolsAction.ID, OpenWebviewDeveloperToolsAction.LABEL),