Skip to content

Commit a98afa6

Browse files
committed
menu - move custom label logic to where it is used
1 parent 542e4bf commit a98afa6

3 files changed

Lines changed: 17 additions & 21 deletions

File tree

src/vs/platform/actions/common/actions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,17 @@ export class MenuItemAction extends ExecuteCommandAction {
161161

162162
constructor(
163163
item: ICommandAction,
164-
label: string,
165164
alt: ICommandAction,
166165
arg: any,
167166
@ICommandService commandService: ICommandService
168167
) {
169-
super(item.id, label, commandService);
168+
super(item.id, item.title, commandService);
170169
this._cssClass = item.iconClass;
171170
this._enabled = true;
172171
this._arg = arg;
173172

174173
this.item = item;
175-
this.alt = alt ? new MenuItemAction(alt, alt.title, undefined, arg, commandService) : undefined;
174+
this.alt = alt ? new MenuItemAction(alt, undefined, arg, commandService) : undefined;
176175
}
177176

178177
run(): TPromise<any> {

src/vs/platform/actions/common/menu.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import Event, { Emitter } from 'vs/base/common/event';
99
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
1010
import { TPromise } from 'vs/base/common/winjs.base';
11-
import { localize } from 'vs/nls';
1211
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1312
import { MenuId, MenuRegistry, MenuItemAction, IMenu, IMenuItem } from 'vs/platform/actions/common/actions';
1413
import { ICommandService } from 'vs/platform/commands/common/commands';
@@ -77,13 +76,7 @@ export class Menu implements IMenu {
7776
const activeActions: MenuItemAction[] = [];
7877
for (const item of items) {
7978
if (this._contextKeyService.contextMatchesRules(item.when)) {
80-
let title = item.command.title;
81-
82-
if (this.id === MenuId.CommandPalette && item.command.category) {
83-
title = localize('', "{0}: {1}", item.command.category, title);
84-
}
85-
86-
const action = new MenuItemAction(item.command, title, item.alt, arg, this._commandService);
79+
const action = new MenuItemAction(item.command, item.alt, arg, this._commandService);
8780
action.order = item.order; //TODO@Ben order is menu item property, not an action property
8881
activeActions.push(action);
8982
}

src/vs/workbench/parts/quickopen/browser/commandsHandler.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { toErrorMessage } from 'vs/base/common/errorMessage';
1616
import strings = require('vs/base/common/strings');
1717
import { Mode, IEntryRunContext, IAutoFocus } from 'vs/base/parts/quickopen/common/quickOpen';
1818
import { QuickOpenEntryGroup, IHighlight, QuickOpenModel, QuickOpenEntry } from 'vs/base/parts/quickopen/browser/quickOpenModel';
19-
import { SyncActionDescriptor, IMenuService, MenuId } from 'vs/platform/actions/common/actions';
19+
import { SyncActionDescriptor, IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions';
2020
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
2121
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';
2222
import { Registry } from 'vs/platform/platform';
@@ -277,8 +277,8 @@ export class CommandsHandler extends QuickOpenHandler {
277277

278278
// Other Actions
279279
const menu = this.menuService.createMenu(MenuId.CommandPalette, this.contextKeyService);
280-
const menuActions = menu.getActions().reduce((r, [, actions]) => [...r, ...actions], []);
281-
const commandEntries = this.commandActionsToEntries(menuActions, searchValue);
280+
const menuActions = menu.getActions().reduce((r, [, actions]) => [...r, ...actions], <MenuItemAction[]>[]);
281+
const commandEntries = this.menuItemActionsToEntries(menuActions, searchValue);
282282

283283
// Concat
284284
let entries = [...workbenchEntries, ...editorEntries, ...commandEntries];
@@ -355,17 +355,21 @@ export class CommandsHandler extends QuickOpenHandler {
355355
return entries;
356356
}
357357

358-
private commandActionsToEntries(actions: IAction[], searchValue: string): ActionCommandEntry[] {
358+
private menuItemActionsToEntries(actions: MenuItemAction[], searchValue: string): ActionCommandEntry[] {
359359
const entries: ActionCommandEntry[] = [];
360360

361361
for (let action of actions) {
362-
const [keybind] = this.keybindingService.lookupKeybindings(action.id);
362+
const label = action.item.category
363+
? nls.localize('cat.title', "{0}: {1}", action.item.category, action.item.title)
364+
: action.item.title;
365+
const highlights = wordFilter(searchValue, label);
366+
if (!highlights) {
367+
continue;
368+
}
369+
const [keybind] = this.keybindingService.lookupKeybindings(action.item.id);
363370
const keyLabel = keybind ? this.keybindingService.getLabelFor(keybind) : '';
364371
const keyAriaLabel = keybind ? this.keybindingService.getAriaLabelFor(keybind) : '';
365-
const highlights = wordFilter(searchValue, action.label);
366-
if (highlights) {
367-
entries.push(this.instantiationService.createInstance(ActionCommandEntry, keyLabel, keyAriaLabel, action.label, null, highlights, null, action));
368-
}
372+
entries.push(this.instantiationService.createInstance(ActionCommandEntry, keyLabel, keyAriaLabel, label, null, highlights, null, action));
369373
}
370374

371375
return entries;
@@ -398,4 +402,4 @@ export class EditorCommandsHandler extends CommandsHandler {
398402
protected includeWorkbenchCommands(): boolean {
399403
return false;
400404
}
401-
}
405+
}

0 commit comments

Comments
 (0)