added default menu items for 'Edit' and 'Window' #2814
This commit is contained in:
parent
aaa8e81cd4
commit
8aba640250
3 changed files with 85 additions and 1 deletions
|
@ -64,6 +64,9 @@ The `role` property can have following values:
|
||||||
* `zoomin` - Zoom in the focused page by 10%
|
* `zoomin` - Zoom in the focused page by 10%
|
||||||
* `zoomout` - Zoom out the focused page by 10%
|
* `zoomout` - Zoom out the focused page by 10%
|
||||||
|
|
||||||
|
* `menuEdit` - Whole default "Edit" menu (Undo,Copy, etc.)
|
||||||
|
* `menuWindow` - Whole default "Window" menu (Minimize, Close, etc.)
|
||||||
|
|
||||||
On macOS `role` can also have following additional values:
|
On macOS `role` can also have following additional values:
|
||||||
|
|
||||||
* `about` - Map to the `orderFrontStandardAboutPanel` action
|
* `about` - Map to the `orderFrontStandardAboutPanel` action
|
||||||
|
|
|
@ -154,6 +154,73 @@ const roles = {
|
||||||
webContents.setZoomLevel(zoomLevel - 0.5)
|
webContents.setZoomLevel(zoomLevel - 0.5)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
// submenu Edit (should fit both Mac & Windows)
|
||||||
|
menuEdit: {
|
||||||
|
label: 'Edit',
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
role: 'undo'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'redo'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'cut'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'copy'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'paste'
|
||||||
|
},
|
||||||
|
|
||||||
|
process.platform === 'darwin' ?
|
||||||
|
{
|
||||||
|
role: 'pasteandmatchstyle'
|
||||||
|
} : {},
|
||||||
|
|
||||||
|
{
|
||||||
|
role: 'delete'
|
||||||
|
},
|
||||||
|
|
||||||
|
process.platform === 'win32' ?
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
} : {},
|
||||||
|
|
||||||
|
{
|
||||||
|
role: 'selectall'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// submenu Window should be used for Mac only
|
||||||
|
menuWindow: {
|
||||||
|
label: 'Window',
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
role: 'minimize'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'close'
|
||||||
|
},
|
||||||
|
|
||||||
|
process.platform === 'darwin' ?
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
} : {},
|
||||||
|
|
||||||
|
process.platform === 'darwin' ?
|
||||||
|
{
|
||||||
|
label: 'Bring All to Front',
|
||||||
|
role: 'front'
|
||||||
|
} : {}
|
||||||
|
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,6 +243,20 @@ exports.getDefaultAccelerator = (role) => {
|
||||||
if (roles.hasOwnProperty(role)) return roles[role].accelerator
|
if (roles.hasOwnProperty(role)) return roles[role].accelerator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.getDefaultSubmenu = (role) => {
|
||||||
|
if (roles.hasOwnProperty(role)) {
|
||||||
|
submenu = roles[role].submenu
|
||||||
|
|
||||||
|
// remove empty objects from within the submenu
|
||||||
|
if (Array.isArray(submenu))
|
||||||
|
submenu = submenu.filter(function(n){
|
||||||
|
return n.constructor !== Object || Object.keys(n).length > 0
|
||||||
|
})
|
||||||
|
|
||||||
|
return submenu
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exports.execute = (role, focusedWindow, focusedWebContents) => {
|
exports.execute = (role, focusedWindow, focusedWebContents) => {
|
||||||
if (!canExecuteRole(role)) return false
|
if (!canExecuteRole(role)) return false
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ const MenuItem = function (options) {
|
||||||
for (let key in options) {
|
for (let key in options) {
|
||||||
if (!(key in this)) this[key] = options[key]
|
if (!(key in this)) this[key] = options[key]
|
||||||
}
|
}
|
||||||
|
this.submenu = this.submenu || roles.getDefaultSubmenu(this.role)
|
||||||
if (this.submenu != null && this.submenu.constructor !== Menu) {
|
if (this.submenu != null && this.submenu.constructor !== Menu) {
|
||||||
this.submenu = Menu.buildFromTemplate(this.submenu)
|
this.submenu = Menu.buildFromTemplate(this.submenu)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue