diff --git a/packages/core/src/browser/menu/browser-menu-plugin.ts b/packages/core/src/browser/menu/browser-menu-plugin.ts index 61e092e1ecc02..5784968aed67d 100644 --- a/packages/core/src/browser/menu/browser-menu-plugin.ts +++ b/packages/core/src/browser/menu/browser-menu-plugin.ts @@ -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); } diff --git a/packages/core/src/common/menu.ts b/packages/core/src/common/menu.ts index f9f025e3a3bd2..d3250ba7ee2c2 100644 --- a/packages/core/src/common/menu.ts +++ b/packages/core/src/common/menu.ts @@ -40,6 +40,10 @@ export namespace MenuAction { } } +export interface SubMenuOptions { + iconClass: string +} + export type MenuPath = string[]; export const MAIN_MENU_BAR: MenuPath = ['menubar']; @@ -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.'); } @@ -89,7 +93,7 @@ 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) { @@ -97,6 +101,9 @@ export class MenuModelRegistry { } 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: () => { } }; } } @@ -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 {