added default menu items for 'Edit' and 'Window' #2814

This commit is contained in:
mst128256 2017-03-09 16:01:33 +01:00
parent aaa8e81cd4
commit 8aba640250
3 changed files with 85 additions and 1 deletions

View file

@ -154,6 +154,73 @@ const roles = {
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
}
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) => {
if (!canExecuteRole(role)) return false