From a98afa69a823a79c14bc8e2efd93cc42b6acaec9 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 15 Feb 2017 16:29:40 +0100 Subject: [PATCH] menu - move custom label logic to where it is used --- src/vs/platform/actions/common/actions.ts | 5 ++-- src/vs/platform/actions/common/menu.ts | 9 +------ .../quickopen/browser/commandsHandler.ts | 24 +++++++++++-------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/vs/platform/actions/common/actions.ts b/src/vs/platform/actions/common/actions.ts index 23da584e1a1..590fd423b9e 100644 --- a/src/vs/platform/actions/common/actions.ts +++ b/src/vs/platform/actions/common/actions.ts @@ -161,18 +161,17 @@ export class MenuItemAction extends ExecuteCommandAction { constructor( item: ICommandAction, - label: string, alt: ICommandAction, arg: any, @ICommandService commandService: ICommandService ) { - super(item.id, label, commandService); + super(item.id, item.title, commandService); this._cssClass = item.iconClass; this._enabled = true; this._arg = arg; this.item = item; - this.alt = alt ? new MenuItemAction(alt, alt.title, undefined, arg, commandService) : undefined; + this.alt = alt ? new MenuItemAction(alt, undefined, arg, commandService) : undefined; } run(): TPromise { diff --git a/src/vs/platform/actions/common/menu.ts b/src/vs/platform/actions/common/menu.ts index 3f0c14e8bc8..e4b241d8bb8 100644 --- a/src/vs/platform/actions/common/menu.ts +++ b/src/vs/platform/actions/common/menu.ts @@ -8,7 +8,6 @@ import Event, { Emitter } from 'vs/base/common/event'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { TPromise } from 'vs/base/common/winjs.base'; -import { localize } from 'vs/nls'; import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { MenuId, MenuRegistry, MenuItemAction, IMenu, IMenuItem } from 'vs/platform/actions/common/actions'; import { ICommandService } from 'vs/platform/commands/common/commands'; @@ -77,13 +76,7 @@ export class Menu implements IMenu { const activeActions: MenuItemAction[] = []; for (const item of items) { if (this._contextKeyService.contextMatchesRules(item.when)) { - let title = item.command.title; - - if (this.id === MenuId.CommandPalette && item.command.category) { - title = localize('', "{0}: {1}", item.command.category, title); - } - - const action = new MenuItemAction(item.command, title, item.alt, arg, this._commandService); + const action = new MenuItemAction(item.command, item.alt, arg, this._commandService); action.order = item.order; //TODO@Ben order is menu item property, not an action property activeActions.push(action); } diff --git a/src/vs/workbench/parts/quickopen/browser/commandsHandler.ts b/src/vs/workbench/parts/quickopen/browser/commandsHandler.ts index ad7f6340bae..19393709f9a 100644 --- a/src/vs/workbench/parts/quickopen/browser/commandsHandler.ts +++ b/src/vs/workbench/parts/quickopen/browser/commandsHandler.ts @@ -16,7 +16,7 @@ import { toErrorMessage } from 'vs/base/common/errorMessage'; import strings = require('vs/base/common/strings'); import { Mode, IEntryRunContext, IAutoFocus } from 'vs/base/parts/quickopen/common/quickOpen'; import { QuickOpenEntryGroup, IHighlight, QuickOpenModel, QuickOpenEntry } from 'vs/base/parts/quickopen/browser/quickOpenModel'; -import { SyncActionDescriptor, IMenuService, MenuId } from 'vs/platform/actions/common/actions'; +import { SyncActionDescriptor, IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry'; import { Registry } from 'vs/platform/platform'; @@ -277,8 +277,8 @@ export class CommandsHandler extends QuickOpenHandler { // Other Actions const menu = this.menuService.createMenu(MenuId.CommandPalette, this.contextKeyService); - const menuActions = menu.getActions().reduce((r, [, actions]) => [...r, ...actions], []); - const commandEntries = this.commandActionsToEntries(menuActions, searchValue); + const menuActions = menu.getActions().reduce((r, [, actions]) => [...r, ...actions], []); + const commandEntries = this.menuItemActionsToEntries(menuActions, searchValue); // Concat let entries = [...workbenchEntries, ...editorEntries, ...commandEntries]; @@ -355,17 +355,21 @@ export class CommandsHandler extends QuickOpenHandler { return entries; } - private commandActionsToEntries(actions: IAction[], searchValue: string): ActionCommandEntry[] { + private menuItemActionsToEntries(actions: MenuItemAction[], searchValue: string): ActionCommandEntry[] { const entries: ActionCommandEntry[] = []; for (let action of actions) { - const [keybind] = this.keybindingService.lookupKeybindings(action.id); + const label = action.item.category + ? nls.localize('cat.title', "{0}: {1}", action.item.category, action.item.title) + : action.item.title; + const highlights = wordFilter(searchValue, label); + if (!highlights) { + continue; + } + const [keybind] = this.keybindingService.lookupKeybindings(action.item.id); const keyLabel = keybind ? this.keybindingService.getLabelFor(keybind) : ''; const keyAriaLabel = keybind ? this.keybindingService.getAriaLabelFor(keybind) : ''; - const highlights = wordFilter(searchValue, action.label); - if (highlights) { - entries.push(this.instantiationService.createInstance(ActionCommandEntry, keyLabel, keyAriaLabel, action.label, null, highlights, null, action)); - } + entries.push(this.instantiationService.createInstance(ActionCommandEntry, keyLabel, keyAriaLabel, label, null, highlights, null, action)); } return entries; @@ -398,4 +402,4 @@ export class EditorCommandsHandler extends CommandsHandler { protected includeWorkbenchCommands(): boolean { return false; } -} \ No newline at end of file +} -- GitLab