Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Hide disabled (not permanent) menus
Browse files Browse the repository at this point in the history
  • Loading branch information
brrd committed Apr 27, 2016
1 parent 4a6a90f commit e6e97dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/abr-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function getConfig (config, key) {
return false;
}

function preprocessTemplate (abrApp, element, config, abrWin) {
function preprocessTemplate (abrApp, element, config, abrWin, isRoot) {
if (element.constructor !== Array) {
return;
}
Expand Down Expand Up @@ -50,17 +50,18 @@ function preprocessTemplate (abrApp, element, config, abrWin) {
if (item.id === "exportHtml") {
item.submenu = exportHtmlMenuGenerator(item.submenu, config);
}
preprocessTemplate(abrApp, item.submenu, config, abrWin);
preprocessTemplate(abrApp, item.submenu, config, abrWin, false);
}
return item;
};
// Process menuItem
for (var i=0; i<element.length; i++) {
var el = element[i],
hiddenWithThisConfig = el.condition && !getConfig(config, el.condition),
hiddenWithThisPlatform = el.platform && el.platform.indexOf(process.platform) === -1;
if (hiddenWithThisConfig || hiddenWithThisPlatform) {
// Remove elements that should not be displayed (config --debug or platform-specific menuItems)
hiddenWithThisPlatform = el.platform && el.platform.indexOf(process.platform) === -1,
hiddenNotPermanentAtRoot = el.submenu && !el.permanent && isRoot && !abrWin;
if (hiddenWithThisConfig || hiddenWithThisPlatform || hiddenNotPermanentAtRoot) {
// Remove elements that should not be displayed (config --debug, platform-specific menuItems, root menus not permanent)
element.splice(i, 1);
i--;
} else {
Expand Down Expand Up @@ -165,7 +166,7 @@ function exportHtmlMenuGenerator (submenu, config) {
function AbrMenu (abrApp, abrWin, menuTemplate, config) {
this.abrWin = abrWin;
var cloneTemplate = JSON.parse(JSON.stringify(menuTemplate)); // Electron modifies the template while building the menu so we need to clone it before
var preprocessedMenuTemplate = preprocessTemplate(abrApp, cloneTemplate, config, abrWin);
var preprocessedMenuTemplate = preprocessTemplate(abrApp, cloneTemplate, config, abrWin, true);
this.menu = Menu.buildFromTemplate(preprocessedMenuTemplate);
}

Expand Down
3 changes: 3 additions & 0 deletions app/menu-window.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
"label": "Abricotine",
"platform": "darwin",
"permanent": true,
"submenu": [
{
"label": "About Abricotine",
Expand Down Expand Up @@ -52,6 +53,7 @@
},
{
"label": "&File",
"permanent": true,
"submenu": [
{
"label": "New Document",
Expand Down Expand Up @@ -700,6 +702,7 @@
{
"label": "&Help",
"role": "help",
"permanent": true,
"submenu": [
{
"label": "About Abricotine",
Expand Down

0 comments on commit e6e97dd

Please sign in to comment.