Skip to content

Commit

Permalink
electron: render menu items based on 'isEnabled'
Browse files Browse the repository at this point in the history
This commit updates the logic of rendering menu items with the
electron target to be based on a command being `enabled`. Since
electron does not support graying-out items (enable), we must rely
on hiding these items from the menus since they are no-op when
executed.

Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed May 25, 2020
1 parent 18b128c commit f1776cf
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ export class ElectronMainMenuFactory {

createContextMenu(menuPath: MenuPath, args?: any[]): Electron.Menu {
const menuModel = this.menuProvider.getMenu(menuPath);
const template = this.fillMenuTemplate([], menuModel, args);

const template = this.fillMenuTemplate([], menuModel, args, true);
return electron.remote.Menu.buildFromTemplate(template);
}

protected fillMenuTemplate(items: Electron.MenuItemConstructorOptions[],
menuModel: CompositeMenuNode,
args: any[] = []
args: any[] = [],
isContextMenu?: boolean,
): Electron.MenuItemConstructorOptions[] {
for (const menu of menuModel.children) {
if (menu instanceof CompositeMenuNode) {
Expand All @@ -92,7 +92,7 @@ export class ElectronMainMenuFactory {

if (menu.isSubmenu) { // submenu node

const submenu = this.fillMenuTemplate([], menu, args);
const submenu = this.fillMenuTemplate([], menu, args, isContextMenu);
if (submenu.length === 0) {
continue;
}
Expand All @@ -105,7 +105,7 @@ export class ElectronMainMenuFactory {
} else { // group node

// process children
const submenu = this.fillMenuTemplate([], menu, args);
const submenu = this.fillMenuTemplate([], menu, args, isContextMenu);
if (submenu.length === 0) {
continue;
}
Expand Down Expand Up @@ -136,6 +136,12 @@ export class ElectronMainMenuFactory {
continue;
}

// We should omit rendering context-menu items which are disabled.
console.log(`context menu: ${isContextMenu}`);
if (!this.commandRegistry.isEnabled(commandId, ...args) && !!isContextMenu) {
continue;
}

const bindings = this.keybindingRegistry.getKeybindingsForCommand(commandId);

let accelerator;
Expand Down

0 comments on commit f1776cf

Please sign in to comment.