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

Commit

Permalink
Show disabled menuItems and grey them out (OSX no window)
Browse files Browse the repository at this point in the history
Remove menu-app.json. We use a single menu for the whole application by 
adding the "permanent" attribute which identify menu items to keep active when all 
windows are closed (OSX). 

Note: commands-main are still used when a command is triggered from the main 
process (ie no windows).

See #32.
  • Loading branch information
brrd committed Apr 26, 2016
1 parent bca016d commit d5d020c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 87 deletions.
4 changes: 2 additions & 2 deletions app/abr-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var AbrMenu = require.main.require("./abr-menu.js"),
commands = require.main.require("./commands-main.js"),
files = require.main.require("./files.js"),
ipcServer = require.main.require("./ipc-server.js"),
menuAppTemplate = require.main.require("./menu-app.json"),
menuTemplate = require.main.require("./menu-window.json"),
parsePath = require("parse-filepath"),
themeLoader = require.main.require("./theme-loader.js");

Expand All @@ -20,7 +20,7 @@ function AbrApplication (osxOpenFilePaths) {
// IPC get & set
this.ipcServer = new ipcServer(this);
// Light menu (used only on OSX when all windows closed)
this.menu = new AbrMenu(this, null, menuAppTemplate);
this.menu = new AbrMenu(this, null, menuTemplate);
// Compile LESS theme then open windows
themeLoader.load("abricotine", this.run.bind(this, osxOpenFilePaths));
}
Expand Down
10 changes: 7 additions & 3 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) {
function preprocessTemplate (abrApp, element, config, abrWin) {
if (element.constructor !== Array) {
return;
}
Expand All @@ -39,14 +39,18 @@ function preprocessTemplate (abrApp, element, config) {
if (item.type === "checkbox" && typeof item.checked === "string") {
item.checked = getConfig(config, item.checked);
}
if (!item.permanent && !abrWin) {
item.enabled = false;
delete item.permanent;
}
if (item.submenu) {
if (item.id === "spelling") {
item.submenu = spellingMenuGenerator(item.submenu, config);
}
if (item.id === "exportHtml") {
item.submenu = exportHtmlMenuGenerator(item.submenu, config);
}
preprocessTemplate(abrApp, item.submenu, config);
preprocessTemplate(abrApp, item.submenu, config, abrWin);
}
return item;
};
Expand Down Expand Up @@ -161,7 +165,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);
var preprocessedMenuTemplate = preprocessTemplate(abrApp, cloneTemplate, config, abrWin);
this.menu = Menu.buildFromTemplate(preprocessedMenuTemplate);
}

Expand Down
72 changes: 0 additions & 72 deletions app/menu-app.json

This file was deleted.

30 changes: 20 additions & 10 deletions app/menu-window.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,48 @@
"submenu": [
{
"label": "About Abricotine",
"command": "about"
"command": "about",
"permanent": true
},
{
"type": "separator"
},
{
"label": "Edit Preferences",
"accelerator": "CmdOrCtrl+,",
"command": "editConfigFile"
"command": "editConfigFile",
"permanent": true
},
{
"label": "Open Config Directory",
"command": "openConfigDir"
"command": "openConfigDir",
"permanent": true
},
{
"type": "separator"
},
{
"label": "Hide Abricotine",
"role": "hide"
"role": "hide",
"permanent": true
},
{
"label": "Hide Others",
"role": "hideothers"
"role": "hideothers",
"permanent": true
},
{
"label": "Show All",
"role": "unhide"
"role": "unhide",
"permanent": true
},
{
"type": "separator"
},
{
"label": "Quit Abricotine",
"accelerator": "CmdOrCtrl+Q"
"accelerator": "CmdOrCtrl+Q",
"permanent": true
}
]
},
Expand All @@ -49,12 +56,14 @@
{
"label": "New Document",
"accelerator": "CmdOrCtrl+N",
"command": "new"
"command": "new",
"permanent": true
},
{
"label": "Open",
"accelerator": "CmdOrCtrl+O",
"command": "open"
"command": "open",
"permanent": true
},
{
"type": "separator"
Expand Down Expand Up @@ -699,7 +708,8 @@
},
{
"label": "Visit Homepage",
"command": "homepage"
"command": "homepage",
"permanent": true
}
]
}
Expand Down

0 comments on commit d5d020c

Please # to comment.