🎨
This commit is contained in:
parent
6ae198a625
commit
8b4bf1f29e
2 changed files with 14 additions and 11 deletions
|
@ -155,7 +155,7 @@ const roles = {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// submenu Edit (should fit both Mac & Windows)
|
// Edit submenu (should fit both Mac & Windows)
|
||||||
editMenu: {
|
editMenu: {
|
||||||
label: 'Edit',
|
label: 'Edit',
|
||||||
submenu: [
|
submenu: [
|
||||||
|
@ -196,7 +196,7 @@ const roles = {
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
// submenu Window should be used for Mac only
|
// Window submenu should be used for Mac only
|
||||||
windowMenu: {
|
windowMenu: {
|
||||||
label: 'Window',
|
label: 'Window',
|
||||||
submenu: [
|
submenu: [
|
||||||
|
@ -239,18 +239,16 @@ exports.getDefaultAccelerator = (role) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getDefaultSubmenu = (role) => {
|
exports.getDefaultSubmenu = (role) => {
|
||||||
if (roles.hasOwnProperty(role)) {
|
if (!roles.hasOwnProperty(role)) return
|
||||||
let submenu = roles[role].submenu
|
|
||||||
|
|
||||||
// remove empty objects from within the submenu
|
let {submenu} = roles[role]
|
||||||
if (Array.isArray(submenu)) {
|
|
||||||
submenu = submenu.filter(function (n) {
|
|
||||||
return n != null
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
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) => {
|
exports.execute = (role, focusedWindow, focusedWebContents) => {
|
||||||
|
|
|
@ -465,17 +465,20 @@ describe('menu module', function () {
|
||||||
assert.equal(item.submenu.items[3].role, 'cut')
|
assert.equal(item.submenu.items[3].role, 'cut')
|
||||||
assert.equal(item.submenu.items[4].role, 'copy')
|
assert.equal(item.submenu.items[4].role, 'copy')
|
||||||
assert.equal(item.submenu.items[5].role, 'paste')
|
assert.equal(item.submenu.items[5].role, 'paste')
|
||||||
|
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
assert.equal(item.submenu.items[6].role, 'pasteandmatchstyle')
|
assert.equal(item.submenu.items[6].role, 'pasteandmatchstyle')
|
||||||
assert.equal(item.submenu.items[7].role, 'delete')
|
assert.equal(item.submenu.items[7].role, 'delete')
|
||||||
assert.equal(item.submenu.items[8].role, 'selectall')
|
assert.equal(item.submenu.items[8].role, 'selectall')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
assert.equal(item.submenu.items[6].role, 'delete')
|
assert.equal(item.submenu.items[6].role, 'delete')
|
||||||
assert.equal(item.submenu.items[7].type, 'separator')
|
assert.equal(item.submenu.items[7].type, 'separator')
|
||||||
assert.equal(item.submenu.items[8].role, 'selectall')
|
assert.equal(item.submenu.items[8].role, 'selectall')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('overrides default layout when submenu is specified', function () {
|
it('overrides default layout when submenu is specified', function () {
|
||||||
var item = new MenuItem({role: 'editMenu', submenu: [{role: 'close'}]})
|
var item = new MenuItem({role: 'editMenu', submenu: [{role: 'close'}]})
|
||||||
assert.equal(item.label, 'Edit')
|
assert.equal(item.label, 'Edit')
|
||||||
|
@ -489,11 +492,13 @@ describe('menu module', function () {
|
||||||
assert.equal(item.label, 'Window')
|
assert.equal(item.label, 'Window')
|
||||||
assert.equal(item.submenu.items[0].role, 'minimize')
|
assert.equal(item.submenu.items[0].role, 'minimize')
|
||||||
assert.equal(item.submenu.items[1].role, 'close')
|
assert.equal(item.submenu.items[1].role, 'close')
|
||||||
|
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
assert.equal(item.submenu.items[2].type, 'separator')
|
assert.equal(item.submenu.items[2].type, 'separator')
|
||||||
assert.equal(item.submenu.items[3].role, 'front')
|
assert.equal(item.submenu.items[3].role, 'front')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('overrides default layout when submenu is specified', function () {
|
it('overrides default layout when submenu is specified', function () {
|
||||||
var item = new MenuItem({role: 'windowMenu', submenu: [{role: 'copy'}]})
|
var item = new MenuItem({role: 'windowMenu', submenu: [{role: 'copy'}]})
|
||||||
assert.equal(item.label, 'Window')
|
assert.equal(item.label, 'Window')
|
||||||
|
|
Loading…
Reference in a new issue