提交 a98afa69 编写于 作者: J Johannes Rieken

menu - move custom label logic to where it is used

上级 542e4bf0
......@@ -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<any> {
......
......@@ -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);
}
......
......@@ -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], <MenuItemAction[]>[]);
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
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册