Skip to content

Commit

Permalink
doc: add missing MenuItem roles (#19555)
Browse files Browse the repository at this point in the history
  • Loading branch information
trop[bot] authored and codebytere committed Aug 1, 2019
1 parent a960268 commit c6061cc
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 14 deletions.
6 changes: 3 additions & 3 deletions docs/api/menu-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See [`Menu`](menu.md) for examples.
* `menuItem` MenuItem
* `browserWindow` [BrowserWindow](browser-window.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).
* `type` String (optional) - Can be `normal`, `separator`, `submenu`, `checkbox` or
`radio`.
Expand Down Expand Up @@ -82,7 +82,7 @@ The `role` property can have following values:
* `reload` - Reload the current window.
* `forceReload` - Reload the current window ignoring the cache.
* `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.
* `zoomIn` - Zoom in the focused page by 10%.
* `zoomOut` - Zoom out the focused page by 10%.
Expand Down Expand Up @@ -152,7 +152,7 @@ A `String` indicating the type of the item. Can be `normal`, `separator`, `subme

#### `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`

Expand Down
16 changes: 8 additions & 8 deletions lib/browser/api/menu-item-roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const roles = {
{ role: 'services' },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideothers' },
{ role: 'hideOthers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' }
Expand Down Expand Up @@ -209,8 +209,8 @@ const roles = {
{
label: 'Speech',
submenu: [
{ role: 'startspeaking' },
{ role: 'stopspeaking' }
{ role: 'startSpeaking' },
{ role: 'stopSpeaking' }
]
}
] : [
Expand All @@ -225,12 +225,12 @@ const roles = {
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'forcereload' },
{ role: 'toggledevtools' },
{ role: 'forceReload' },
{ role: 'toggleDevTools' },
{ type: 'separator' },
{ role: 'resetzoom' },
{ role: 'zoomin' },
{ role: 'zoomout' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
Expand Down
4 changes: 2 additions & 2 deletions lib/browser/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ const getEditMenuItems = function (): Electron.MenuItemConstructorOptions[] {
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'pasteandmatchstyle' },
{ role: 'pasteAndMatchStyle' },
{ role: 'delete' },
{ role: 'selectall' }
{ role: 'selectAll' }
]
}

Expand Down
2 changes: 1 addition & 1 deletion spec-main/api-menu-item-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ describe('MenuItems', () => {

it('execute roles with non-native role functions', () => {
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)
expect(canExecute).to.be.true('can execute')
Expand Down
48 changes: 48 additions & 0 deletions spec/ts-smoke/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,54 @@ Menu.buildFromTemplate([
{ 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
// https://github.com/electron/electron/blob/master/docs/api/net.md

Expand Down

0 comments on commit c6061cc

Please sign in to comment.