mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
Add default label/accelerator to role menu items
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user