This commit is contained in:
Kevin Sawicki 2017-03-29 12:27:59 -07:00
parent 6ae198a625
commit 8b4bf1f29e
2 changed files with 14 additions and 11 deletions

View file

@ -155,7 +155,7 @@ const roles = {
})
}
},
// submenu Edit (should fit both Mac & Windows)
// Edit submenu (should fit both Mac & Windows)
editMenu: {
label: 'Edit',
submenu: [
@ -196,7 +196,7 @@ const roles = {
]
},
// submenu Window should be used for Mac only
// Window submenu should be used for Mac only
windowMenu: {
label: 'Window',
submenu: [
@ -239,18 +239,16 @@ exports.getDefaultAccelerator = (role) => {
}
exports.getDefaultSubmenu = (role) => {
if (roles.hasOwnProperty(role)) {
let submenu = roles[role].submenu
if (!roles.hasOwnProperty(role)) return
// remove empty objects from within the submenu
if (Array.isArray(submenu)) {
submenu = submenu.filter(function (n) {
return n != null
})
}
let {submenu} = roles[role]
return submenu
// remove null items from within the submenu
if (Array.isArray(submenu)) {
submenu = submenu.filter((item) => item != null)
}
return submenu
}
exports.execute = (role, focusedWindow, focusedWebContents) => {

View file

@ -465,17 +465,20 @@ describe('menu module', function () {
assert.equal(item.submenu.items[3].role, 'cut')
assert.equal(item.submenu.items[4].role, 'copy')
assert.equal(item.submenu.items[5].role, 'paste')
if (process.platform === 'darwin') {
assert.equal(item.submenu.items[6].role, 'pasteandmatchstyle')
assert.equal(item.submenu.items[7].role, 'delete')
assert.equal(item.submenu.items[8].role, 'selectall')
}
if (process.platform === 'win32') {
assert.equal(item.submenu.items[6].role, 'delete')
assert.equal(item.submenu.items[7].type, 'separator')
assert.equal(item.submenu.items[8].role, 'selectall')
}
})
it('overrides default layout when submenu is specified', function () {
var item = new MenuItem({role: 'editMenu', submenu: [{role: 'close'}]})
assert.equal(item.label, 'Edit')
@ -489,11 +492,13 @@ describe('menu module', function () {
assert.equal(item.label, 'Window')
assert.equal(item.submenu.items[0].role, 'minimize')
assert.equal(item.submenu.items[1].role, 'close')
if (process.platform === 'darwin') {
assert.equal(item.submenu.items[2].type, 'separator')
assert.equal(item.submenu.items[3].role, 'front')
}
})
it('overrides default layout when submenu is specified', function () {
var item = new MenuItem({role: 'windowMenu', submenu: [{role: 'copy'}]})
assert.equal(item.label, 'Window')