doc: add missing MenuItem roles (#19329)

This commit is contained in:
Shelley Vohr 2019-07-31 14:13:56 -07:00 committed by GitHub
parent bf66fe51f6
commit a5f87cee6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 14 deletions

View file

@ -14,7 +14,7 @@ See [`Menu`](menu.md) for examples.
* `menuItem` MenuItem * `menuItem` MenuItem
* `browserWindow` [BrowserWindow](browser-window.md) * `browserWindow` [BrowserWindow](browser-window.md)
* `event` [KeyboardEvent](structures/keyboard-event.md) * `event` [KeyboardEvent](structures/keyboard-event.md)
* `role` String (optional) - Can be `undo`, `redo`, `cut`, `copy`, `paste`, `pasteandmatchstyle`, `delete`, `selectall`, `reload`, `forcereload`, `toggledevtools`, `resetzoom`, `zoomin`, `zoomout`, `togglefullscreen`, `window`, `minimize`, `close`, `help`, `about`, `services`, `hide`, `hideothers`, `unhide`, `quit`, `startspeaking`, `stopspeaking`, `close`, `minimize`, `zoom`, `front`, `appMenu`, `fileMenu`, `editMenu`, `viewMenu` or `windowMenu` - Define the action of the menu item, when specified the * `role` String (optional) - Can be `undo`, `redo`, `cut`, `copy`, `paste`, `pasteAndMatchStyle`, `delete`, `selectAll`, `reload`, `forceReload`, `toggleDevTools`, `resetZoom`, `zoomIn`, `zoomOut`, `togglefullscreen`, `window`, `minimize`, `close`, `help`, `about`, `services`, `hide`, `hideOthers`, `unhide`, `quit`, `startSpeaking`, `stopSpeaking`, `close`, `minimize`, `zoom`, `front`, `appMenu`, `fileMenu`, `editMenu`, `viewMenu`, `recentDocuments`, `toggleTabBar`, `selectNextTab`, `selectPreviousTab`, `mergeAllWindows`, `clearRecentDocuments`, `moveTabToNewWindow` or `windowMenu` - Define the action of the menu item, when specified the
`click` property will be ignored. See [roles](#roles). `click` property will be ignored. See [roles](#roles).
* `type` String (optional) - Can be `normal`, `separator`, `submenu`, `checkbox` or * `type` String (optional) - Can be `normal`, `separator`, `submenu`, `checkbox` or
`radio`. `radio`.
@ -82,7 +82,7 @@ The `role` property can have following values:
* `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%.
@ -152,7 +152,7 @@ A `String` indicating the type of the item. Can be `normal`, `separator`, `subme
#### `menuItem.role` #### `menuItem.role`
A `String` (optional) indicating the item's role, if set. Can be `undo`, `redo`, `cut`, `copy`, `paste`, `pasteandmatchstyle`, `delete`, `selectall`, `reload`, `forcereload`, `toggledevtools`, `resetzoom`, `zoomin`, `zoomout`, `togglefullscreen`, `window`, `minimize`, `close`, `help`, `about`, `services`, `hide`, `hideothers`, `unhide`, `quit`, `startspeaking`, `stopspeaking`, `close`, `minimize`, `zoom`, `front`, `appMenu`, `fileMenu`, `editMenu`, `viewMenu` or `windowMenu` A `String` (optional) indicating the item's role, if set. Can be `undo`, `redo`, `cut`, `copy`, `paste`, `pasteAndMatchStyle`, `delete`, `selectAll`, `reload`, `forceReload`, `toggleDevTools`, `resetZoom`, `zoomIn`, `zoomOut`, `togglefullscreen`, `window`, `minimize`, `close`, `help`, `about`, `services`, `hide`, `hideOthers`, `unhide`, `quit`, `startSpeaking`, `stopSpeaking`, `close`, `minimize`, `zoom`, `front`, `appMenu`, `fileMenu`, `editMenu`, `viewMenu`, `recentDocuments`, `toggleTabBar`, `selectNextTab`, `selectPreviousTab`, `mergeAllWindows`, `clearRecentDocuments`, `moveTabToNewWindow` or `windowMenu`
#### `menuItem.accelerator` #### `menuItem.accelerator`

View file

@ -178,7 +178,7 @@ const roles = {
{ role: 'services' }, { role: 'services' },
{ type: 'separator' }, { type: 'separator' },
{ role: 'hide' }, { role: 'hide' },
{ role: 'hideothers' }, { role: 'hideOthers' },
{ role: 'unhide' }, { role: 'unhide' },
{ type: 'separator' }, { type: 'separator' },
{ role: 'quit' } { role: 'quit' }
@ -209,8 +209,8 @@ const roles = {
{ {
label: 'Speech', label: 'Speech',
submenu: [ submenu: [
{ role: 'startspeaking' }, { role: 'startSpeaking' },
{ role: 'stopspeaking' } { role: 'stopSpeaking' }
] ]
} }
] : [ ] : [
@ -225,12 +225,12 @@ const roles = {
label: 'View', label: 'View',
submenu: [ submenu: [
{ role: 'reload' }, { role: 'reload' },
{ role: 'forcereload' }, { role: 'forceReload' },
{ role: 'toggledevtools' }, { role: 'toggleDevTools' },
{ type: 'separator' }, { type: 'separator' },
{ role: 'resetzoom' }, { role: 'resetZoom' },
{ role: 'zoomin' }, { role: 'zoomIn' },
{ role: 'zoomout' }, { role: 'zoomOut' },
{ type: 'separator' }, { type: 'separator' },
{ role: 'togglefullscreen' } { role: 'togglefullscreen' }
] ]

View file

@ -40,9 +40,9 @@ const getEditMenuItems = function (): Electron.MenuItemConstructorOptions[] {
{ role: 'cut' }, { role: 'cut' },
{ role: 'copy' }, { role: 'copy' },
{ role: 'paste' }, { role: 'paste' },
{ role: 'pasteandmatchstyle' }, { role: 'pasteAndMatchStyle' },
{ role: 'delete' }, { role: 'delete' },
{ role: 'selectall' } { role: 'selectAll' }
] ]
} }

View file

@ -190,7 +190,7 @@ describe('MenuItems', () => {
it('execute roles with non-native role functions', () => { it('execute roles with non-native role functions', () => {
const win = new BrowserWindow({ show: false, width: 200, height: 200 }) const win = new BrowserWindow({ show: false, width: 200, height: 200 })
const item = new MenuItem({ role: 'resetzoom' }) const item = new MenuItem({ role: 'resetZoom' })
const canExecute = execute(item.role, win, win.webContents) const canExecute = execute(item.role, win, win.webContents)
expect(canExecute).to.be.true('can execute') expect(canExecute).to.be.true('can execute')

View file

@ -756,6 +756,54 @@ Menu.buildFromTemplate([
{ label: '3' } { label: '3' }
]) ])
// All possible MenuItem roles
Menu.buildFromTemplate([
{ role: 'undo' },
{ role: 'redo' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'pasteAndMatchStyle' },
{ role: 'delete' },
{ role: 'selectAll' },
{ role: 'reload' },
{ role: 'forceReload' },
{ role: 'toggleDevTools' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ role: 'togglefullscreen' },
{ role: 'window' },
{ role: 'minimize' },
{ role: 'close' },
{ role: 'help' },
{ role: 'about' },
{ role: 'services' },
{ role: 'hide' },
{ role: 'hideOthers' },
{ role: 'unhide' },
{ role: 'quit' },
{ role: 'startSpeaking' },
{ role: 'stopSpeaking' },
{ role: 'close' },
{ role: 'minimize' },
{ role: 'zoom' },
{ role: 'front' },
{ role: 'appMenu' },
{ role: 'fileMenu' },
{ role: 'editMenu' },
{ role: 'viewMenu' },
{ role: 'windowMenu' },
{ role: 'recentDocuments' },
{ role: 'clearRecentDocuments' },
{ role: 'toggleTabBar' },
{ role: 'selectNextTab' },
{ role: 'selectPreviousTab' },
{ role: 'mergeAllWindows' },
{ role: 'clearRecentDocuments' },
{ role : 'moveTabToNewWindow'}
])
// net // net
// https://github.com/electron/electron/blob/master/docs/api/net.md // https://github.com/electron/electron/blob/master/docs/api/net.md