Skip to content

Commit

Permalink
[#6891] Add support for setting the icon of a submenu
Browse files Browse the repository at this point in the history
Signed-off-by: Vivien Jovet <[email protected]>
  • Loading branch information
Hanksha authored and Vivien Jovet committed Feb 7, 2020
1 parent 8cf1dec commit 04eac17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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

0 comments on commit 04eac17

Please sign in to comment.