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

[#6891] Add support for setting the icon of a submenu #7091

Merged
merged 1 commit into from
Feb 7, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/src/browser/menu/browser-menu-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ class DynamicMenuWidget extends MenuWidget {
if (menu.label) {
this.title.label = menu.label;
}
if (menu.iconClass) {
this.title.iconClass = menu.iconClass;
}
this.updateSubMenus(this, this.menu, this.options.commands);
}

Expand Down
14 changes: 11 additions & 3 deletions packages/core/src/common/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export namespace MenuAction {
}
}

export interface SubMenuOptions {
iconClass: string
}

export type MenuPath = string[];

export const MAIN_MENU_BAR: MenuPath = ['menubar'];
Expand Down Expand Up @@ -79,7 +83,7 @@ export class MenuModelRegistry {
return parent.addNode(actionNode);
}

registerSubmenu(menuPath: MenuPath, label: string): Disposable {
registerSubmenu(menuPath: MenuPath, label: string, options?: SubMenuOptions): Disposable {
if (menuPath.length === 0) {
throw new Error('The sub menu path cannot be empty.');
}
Expand All @@ -89,14 +93,17 @@ export class MenuModelRegistry {
const parent = this.findGroup(groupPath);
let groupNode = this.findSubMenu(parent, menuId);
if (!groupNode) {
groupNode = new CompositeMenuNode(menuId, label);
groupNode = new CompositeMenuNode(menuId, label, options ? options.iconClass : undefined);
return parent.addNode(groupNode);
} else {
if (!groupNode.label) {
groupNode.label = label;
} else if (groupNode.label !== label) {
throw new Error("The group '" + menuPath.join('/') + "' already has a different label.");
}
if (!groupNode.iconClass && options) {
groupNode.iconClass = options.iconClass;
}
return { dispose: () => { } };
}
}
Expand Down Expand Up @@ -182,7 +189,8 @@ export class CompositeMenuNode implements MenuNode {
protected readonly _children: MenuNode[] = [];
constructor(
public readonly id: string,
public label?: string
public label?: string,
public iconClass?: string
) { }

get children(): ReadonlyArray<MenuNode> {
Expand Down