MenuItem roles camelCase-compatible
This commit is contained in:
parent
a161f6e368
commit
d45914c3f7
5 changed files with 30 additions and 27 deletions
|
@ -54,19 +54,19 @@ The `role` property can have following values:
|
||||||
* `cut`
|
* `cut`
|
||||||
* `copy`
|
* `copy`
|
||||||
* `paste`
|
* `paste`
|
||||||
* `pasteandmatchstyle`
|
* `pasteAndMatchStyle`
|
||||||
* `selectall`
|
* `selectAll`
|
||||||
* `delete`
|
* `delete`
|
||||||
* `minimize` - Minimize current window.
|
* `minimize` - Minimize current window.
|
||||||
* `close` - Close current window.
|
* `close` - Close current window.
|
||||||
* `quit`- Quit the application.
|
* `quit`- Quit the application.
|
||||||
* `reload` - Reload the current window.
|
* `reload` - Reload the current window.
|
||||||
* `forcereload` - Reload the current window ignoring the cache.
|
* `forceReload` - Reload the current window ignoring the cache.
|
||||||
* `toggledevtools` - Toggle developer tools in the current window.
|
* `toggleDevTools` - Toggle developer tools in the current window.
|
||||||
* `togglefullscreen`- Toggle full screen mode on the current window.
|
* `toggleFullScreen`- Toggle full screen mode on the current window.
|
||||||
* `resetzoom` - Reset the focused page's zoom level to the original size.
|
* `resetZoom` - Reset the focused page's zoom level to the original size.
|
||||||
* `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%.
|
||||||
* `editMenu` - Whole default "Edit" menu (Undo, Copy, etc.).
|
* `editMenu` - Whole default "Edit" menu (Undo, Copy, etc.).
|
||||||
* `windowMenu` - Whole default "Window" menu (Minimize, Close, etc.).
|
* `windowMenu` - Whole default "Window" menu (Minimize, Close, etc.).
|
||||||
|
|
||||||
|
@ -74,25 +74,26 @@ The following additional roles are available on _macOS_:
|
||||||
|
|
||||||
* `about` - Map to the `orderFrontStandardAboutPanel` action.
|
* `about` - Map to the `orderFrontStandardAboutPanel` action.
|
||||||
* `hide` - Map to the `hide` action.
|
* `hide` - Map to the `hide` action.
|
||||||
* `hideothers` - Map to the `hideOtherApplications` action.
|
* `hideOthers` - Map to the `hideOtherApplications` action.
|
||||||
* `unhide` - Map to the `unhideAllApplications` action.
|
* `unhide` - Map to the `unhideAllApplications` action.
|
||||||
* `startspeaking` - Map to the `startSpeaking` action.
|
* `startSpeaking` - Map to the `startSpeaking` action.
|
||||||
* `stopspeaking` - Map to the `stopSpeaking` action.
|
* `stopSpeaking` - Map to the `stopSpeaking` action.
|
||||||
* `front` - Map to the `arrangeInFront` action.
|
* `front` - Map to the `arrangeInFront` action.
|
||||||
* `zoom` - Map to the `performZoom` action.
|
* `zoom` - Map to the `performZoom` action.
|
||||||
* `toggletabbar` - Map to the `toggleTabBar` action.
|
* `toggleTabBar` - Map to the `toggleTabBar` action.
|
||||||
* `selectnexttab` - Map to the `selectNextTab` action.
|
* `selectNextTab` - Map to the `selectNextTab` action.
|
||||||
* `selectprevioustab` - Map to the `selectPreviousTab` action.
|
* `selectPreviousTab` - Map to the `selectPreviousTab` action.
|
||||||
* `mergeallwindows` - Map to the `mergeAllWindows` action.
|
* `mergeAllWindows` - Map to the `mergeAllWindows` action.
|
||||||
* `movetabtonewwindow` - Map to the `moveTabToNewWindow` action.
|
* `moveTabToNewWindow` - Map to the `moveTabToNewWindow` action.
|
||||||
* `window` - The submenu is a "Window" menu.
|
* `window` - The submenu is a "Window" menu.
|
||||||
* `help` - The submenu is a "Help" menu.
|
* `help` - The submenu is a "Help" menu.
|
||||||
* `services` - The submenu is a "Services" menu.
|
* `services` - The submenu is a "Services" menu.
|
||||||
* `recentdocuments` - The submenu is an "Open Recent" menu.
|
* `recentDocuments` - The submenu is an "Open Recent" menu.
|
||||||
* `clearrecentdocuments` - Map to the `clearRecentDocuments` action.
|
* `clearRecentDocuments` - Map to the `clearRecentDocuments` action.
|
||||||
|
|
||||||
When specifying a `role` on macOS, `label` and `accelerator` are the only
|
When specifying a `role` on macOS, `label` and `accelerator` are the only
|
||||||
options that will affect the menu item. All other options will be ignored.
|
options that will affect the menu item. All other options will be ignored.
|
||||||
|
Lowercase `role`, e.g. `toggledevtools`, is still supported.
|
||||||
|
|
||||||
### Instance Properties
|
### Instance Properties
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,7 @@ const roles = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Edit submenu (should fit both Mac & Windows)
|
// Edit submenu (should fit both Mac & Windows)
|
||||||
editMenu: {
|
editmenu: {
|
||||||
label: 'Edit',
|
label: 'Edit',
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
|
@ -185,7 +185,7 @@ const roles = {
|
||||||
},
|
},
|
||||||
|
|
||||||
process.platform === 'darwin' ? {
|
process.platform === 'darwin' ? {
|
||||||
role: 'pasteandmatchstyle'
|
role: 'pasteAndMatchStyle'
|
||||||
} : null,
|
} : null,
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -197,13 +197,13 @@ const roles = {
|
||||||
} : null,
|
} : null,
|
||||||
|
|
||||||
{
|
{
|
||||||
role: 'selectall'
|
role: 'selectAll'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
// Window submenu should be used for Mac only
|
// Window submenu should be used for Mac only
|
||||||
windowMenu: {
|
windowmenu: {
|
||||||
label: 'Window',
|
label: 'Window',
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,6 +11,8 @@ 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]
|
||||||
}
|
}
|
||||||
|
if (typeof this.role === 'string' || this.role instanceof String)
|
||||||
|
this.role = this.role.toLowerCase()
|
||||||
this.submenu = this.submenu || roles.getDefaultSubmenu(this.role)
|
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)
|
||||||
|
|
|
@ -94,13 +94,13 @@ const getEditMenuItems = function () {
|
||||||
role: 'paste'
|
role: 'paste'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
role: 'pasteandmatchstyle'
|
role: 'pasteAndMatchStyle'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
role: 'delete'
|
role: 'delete'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
role: 'selectall'
|
role: 'selectAll'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -591,15 +591,15 @@ describe('Menu module', () => {
|
||||||
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')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue