Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put menu item rendering logic strictly in the menu #53214

Merged
merged 1 commit into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/vs/base/browser/ui/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,9 @@ export class Menu {
parent: this
};

const getActionItem = (action: IAction) => {
if (action instanceof Separator) {
return new ActionItem(options.context, action, { icon: true });
} else if (action instanceof SubmenuAction) {
return new SubmenuActionItem(action, action.entries, parentData, options);
} else {
const menuItemOptions: IActionItemOptions = {};
if (options.getKeyBinding) {
const keybinding = options.getKeyBinding(action);
if (keybinding) {
menuItemOptions.keybinding = keybinding.getLabel();
}
}

return new MenuActionItem(options.context, action, menuItemOptions);
}
};

this.actionBar = new ActionBar(menuContainer, {
orientation: ActionsOrientation.VERTICAL,
actionItemProvider: options.actionItemProvider ? options.actionItemProvider : getActionItem,
actionItemProvider: action => this.doGetActionItem(action, options, parentData),
context: options.context,
actionRunner: options.actionRunner,
isMenu: true,
Expand All @@ -83,6 +65,24 @@ export class Menu {
this.actionBar.push(actions, { icon: true, label: true, isMenu: true });
}

private doGetActionItem(action: IAction, options: IMenuOptions, parentData: ISubMenuData): ActionItem {
if (action instanceof Separator) {
return new ActionItem(options.context, action, { icon: true });
} else if (action instanceof SubmenuAction) {
return new SubmenuActionItem(action, action.entries, parentData, options);
} else {
const menuItemOptions: IActionItemOptions = {};
if (options.getKeyBinding) {
const keybinding = options.getKeyBinding(action);
if (keybinding) {
menuItemOptions.keybinding = keybinding.getLabel();
}
}

return new MenuActionItem(options.context, action, menuItemOptions);
}
}

public get onDidCancel(): Event<void> {
return this.actionBar.onDidCancel;
}
Expand Down
3 changes: 2 additions & 1 deletion src/vs/platform/contextview/browser/contextMenuHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export class ContextMenuHandler {
let menu = new Menu(container, actions, {
actionItemProvider: delegate.getActionItem,
context: delegate.getActionsContext ? delegate.getActionsContext() : null,
actionRunner: this.actionRunner
actionRunner: this.actionRunner,
getKeyBinding: delegate.getKeyBinding
});

let listener1 = menu.onDidCancel(() => {
Expand Down