From d5d020c91fca945776b2b666e6f50ff9c76d92f7 Mon Sep 17 00:00:00 2001 From: brrd Date: Tue, 26 Apr 2016 22:35:01 +0200 Subject: [PATCH] Show disabled menuItems and grey them out (OSX no window) 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. --- app/abr-application.js | 4 +-- app/abr-menu.js | 10 ++++-- app/menu-app.json | 72 ------------------------------------------ app/menu-window.json | 30 ++++++++++++------ 4 files changed, 29 insertions(+), 87 deletions(-) delete mode 100644 app/menu-app.json diff --git a/app/abr-application.js b/app/abr-application.js index c08ecb6..f51dd46 100644 --- a/app/abr-application.js +++ b/app/abr-application.js @@ -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"); @@ -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)); } diff --git a/app/abr-menu.js b/app/abr-menu.js index 0ddfe7c..c025eac 100644 --- a/app/abr-menu.js +++ b/app/abr-menu.js @@ -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; } @@ -39,6 +39,10 @@ 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); @@ -46,7 +50,7 @@ function preprocessTemplate (abrApp, element, config) { if (item.id === "exportHtml") { item.submenu = exportHtmlMenuGenerator(item.submenu, config); } - preprocessTemplate(abrApp, item.submenu, config); + preprocessTemplate(abrApp, item.submenu, config, abrWin); } return item; }; @@ -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); } diff --git a/app/menu-app.json b/app/menu-app.json deleted file mode 100644 index 4d3ecb3..0000000 --- a/app/menu-app.json +++ /dev/null @@ -1,72 +0,0 @@ -[ - { - "label": "Abricotine", - "platform": "darwin", - "submenu": [ - { - "label": "About Abricotine", - "command": "about" - }, - { - "type": "separator" - }, - { - "label": "Edit Preferences", - "accelerator": "CmdOrCtrl+,", - "command": "editConfigFile" - }, - { - "label": "Open Config Directory", - "command": "openConfigDir" - }, - { - "type": "separator" - }, - { - "label": "Hide Abricotine", - "role": "hide" - }, - { - "label": "Hide Others", - "role": "hideothers" - }, - { - "label": "Show All", - "role": "unhide" - }, - { - "type": "separator" - }, - { - "label": "Quit Abricotine", - "command": "quit", - "accelerator": "CmdOrCtrl+Q" - } - ] - }, - { - "label": "&File", - "submenu": [ - { - "label": "New Document", - "accelerator": "CmdOrCtrl+N", - "command": "new" - }, - { - "label": "Open", - "accelerator": "CmdOrCtrl+O", - "command": "open" - } - ] - }, - { - "label": "&Help", - "role": "help", - "submenu": [ - { - "label": "Visit Homepage", - "command": "homepage" - } - ] - } -] diff --git a/app/menu-window.json b/app/menu-window.json index 546de4d..878eadc 100644 --- a/app/menu-window.json +++ b/app/menu-window.json @@ -5,7 +5,8 @@ "submenu": [ { "label": "About Abricotine", - "command": "about" + "command": "about", + "permanent": true }, { "type": "separator" @@ -13,33 +14,39 @@ { "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 } ] }, @@ -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" @@ -699,7 +708,8 @@ }, { "label": "Visit Homepage", - "command": "homepage" + "command": "homepage", + "permanent": true } ] }