From 13a6d32ee9ab48fdb5d81d6e5c5a2d106a9e7c20 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 22 Jun 2016 10:45:01 -0700 Subject: [PATCH] Add default label/accelerator to role menu items --- lib/browser/api/menu-item-roles.js | 14 +++++++++++++- lib/browser/api/menu-item.js | 6 ++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/browser/api/menu-item-roles.js b/lib/browser/api/menu-item-roles.js index 13484e5da9..f26e9c5a5a 100644 --- a/lib/browser/api/menu-item-roles.js +++ b/lib/browser/api/menu-item-roles.js @@ -1,4 +1,4 @@ -module.exports = { +const roles = { undo: { label: 'Undo', accelerator: 'CmdOrCtrl+Z', @@ -63,3 +63,15 @@ module.exports = { method: 'toggleFullScreen' } } + +exports.getDefaultLabel = function (role) { + if (roles.hasOwnProperty(role)) { + return roles[role].label + } else { + return '' + } +} + +exports.getDefaultAccelerator = function (role) { + if (roles.hasOwnProperty(role)) return roles[role].accelerator +} diff --git a/lib/browser/api/menu-item.js b/lib/browser/api/menu-item.js index 264be81790..ba980960b5 100644 --- a/lib/browser/api/menu-item.js +++ b/lib/browser/api/menu-item.js @@ -1,5 +1,7 @@ 'use strict' +const roles = require('./menu-item-roles') + let nextCommandId = 0 // Maps role to methods of webContents @@ -58,11 +60,11 @@ const MenuItem = function (options) { this.overrideReadOnlyProperty('type', 'normal') this.overrideReadOnlyProperty('role') - this.overrideReadOnlyProperty('accelerator') + this.overrideReadOnlyProperty('accelerator', roles.getDefaultAccelerator(this.role)) this.overrideReadOnlyProperty('icon') this.overrideReadOnlyProperty('submenu') - this.overrideProperty('label', '') + this.overrideProperty('label', roles.getDefaultLabel(this.role)) this.overrideProperty('sublabel', '') this.overrideProperty('enabled', true) this.overrideProperty('visible', true)