Merge pull request #8880 from mst128256/2814

Default menu items for 'Edit' and 'Window' #2814
This commit is contained in:
Kevin Sawicki 2017-03-29 12:31:58 -07:00 committed by GitHub
commit 57edc28b0d
4 changed files with 130 additions and 1 deletions

View file

@ -154,6 +154,68 @@ const roles = {
webContents.setZoomLevel(zoomLevel - 0.5)
})
}
},
// Edit submenu (should fit both Mac & Windows)
editMenu: {
label: 'Edit',
submenu: [
{
role: 'undo'
},
{
role: 'redo'
},
{
type: 'separator'
},
{
role: 'cut'
},
{
role: 'copy'
},
{
role: 'paste'
},
process.platform === 'darwin' ? {
role: 'pasteandmatchstyle'
} : null,
{
role: 'delete'
},
process.platform === 'win32' ? {
type: 'separator'
} : null,
{
role: 'selectall'
}
]
},
// Window submenu should be used for Mac only
windowMenu: {
label: 'Window',
submenu: [
{
role: 'minimize'
},
{
role: 'close'
},
process.platform === 'darwin' ? {
type: 'separator'
} : null,
process.platform === 'darwin' ? {
role: 'front'
} : null
]
}
}
@ -176,6 +238,19 @@ exports.getDefaultAccelerator = (role) => {
if (roles.hasOwnProperty(role)) return roles[role].accelerator
}
exports.getDefaultSubmenu = (role) => {
if (!roles.hasOwnProperty(role)) return
let {submenu} = roles[role]
// remove null items from within the submenu
if (Array.isArray(submenu)) {
submenu = submenu.filter((item) => item != null)
}
return submenu
}
exports.execute = (role, focusedWindow, focusedWebContents) => {
if (!canExecuteRole(role)) return false

View file

@ -11,7 +11,7 @@ const MenuItem = function (options) {
for (let key in options) {
if (!(key in this)) this[key] = options[key]
}
this.submenu = this.submenu || roles.getDefaultSubmenu(this.role)
if (this.submenu != null && this.submenu.constructor !== Menu) {
this.submenu = Menu.buildFromTemplate(this.submenu)
}