move menu constructor docs to top of file
This commit is contained in:
parent
5979dab13c
commit
a7fdd04751
1 changed files with 80 additions and 79 deletions
159
docs/api/menu.md
159
docs/api/menu.md
|
@ -4,6 +4,86 @@
|
||||||
|
|
||||||
Process: [Main](../tutorial/quick-start.md#main-process)
|
Process: [Main](../tutorial/quick-start.md#main-process)
|
||||||
|
|
||||||
|
### `new Menu()`
|
||||||
|
|
||||||
|
Creates a new menu.
|
||||||
|
|
||||||
|
### Static Methods
|
||||||
|
|
||||||
|
The `menu` class has the following static methods:
|
||||||
|
|
||||||
|
#### `Menu.setApplicationMenu(menu)`
|
||||||
|
|
||||||
|
* `menu` Menu
|
||||||
|
|
||||||
|
Sets `menu` as the application menu on macOS. On Windows and Linux, the `menu`
|
||||||
|
will be set as each window's top menu.
|
||||||
|
|
||||||
|
**Note:** This API has to be called after the `ready` event of `app` module.
|
||||||
|
|
||||||
|
#### `Menu.getApplicationMenu()`
|
||||||
|
|
||||||
|
Returns `Menu` - The application menu, if set, or `null`, if not set.
|
||||||
|
|
||||||
|
#### `Menu.sendActionToFirstResponder(action)` _macOS_
|
||||||
|
|
||||||
|
* `action` String
|
||||||
|
|
||||||
|
Sends the `action` to the first responder of application. This is used for
|
||||||
|
emulating default Cocoa menu behaviors, usually you would just use the
|
||||||
|
`role` property of `MenuItem`.
|
||||||
|
|
||||||
|
See the [macOS Cocoa Event Handling Guide](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/10000060i-CH3-SW7)
|
||||||
|
for more information on macOS' native actions.
|
||||||
|
|
||||||
|
#### `Menu.buildFromTemplate(template)`
|
||||||
|
|
||||||
|
* `template` MenuItemConstructorOptions[]
|
||||||
|
|
||||||
|
Returns `Menu`
|
||||||
|
|
||||||
|
Generally, the `template` is just an array of `options` for constructing a
|
||||||
|
[MenuItem](menu-item.md). The usage can be referenced above.
|
||||||
|
|
||||||
|
You can also attach other fields to the element of the `template` and they
|
||||||
|
will become properties of the constructed menu items.
|
||||||
|
|
||||||
|
### Instance Methods
|
||||||
|
|
||||||
|
The `menu` object has the following instance methods:
|
||||||
|
|
||||||
|
#### `menu.popup([browserWindow, x, y, positioningItem])`
|
||||||
|
|
||||||
|
* `browserWindow` BrowserWindow (optional) - Default is `BrowserWindow.getFocusedWindow()`.
|
||||||
|
* `x` Number (optional) - Default is the current mouse cursor position.
|
||||||
|
* `y` Number (**required** if `x` is used) - Default is the current mouse cursor position.
|
||||||
|
* `positioningItem` Number (optional) _macOS_ - The index of the menu item to
|
||||||
|
be positioned under the mouse cursor at the specified coordinates. Default is
|
||||||
|
-1.
|
||||||
|
|
||||||
|
Pops up this menu as a context menu in the `browserWindow`.
|
||||||
|
|
||||||
|
#### `menu.append(menuItem)`
|
||||||
|
|
||||||
|
* `menuItem` MenuItem
|
||||||
|
|
||||||
|
Appends the `menuItem` to the menu.
|
||||||
|
|
||||||
|
#### `menu.insert(pos, menuItem)`
|
||||||
|
|
||||||
|
* `pos` Integer
|
||||||
|
* `menuItem` MenuItem
|
||||||
|
|
||||||
|
Inserts the `menuItem` to the `pos` position of the menu.
|
||||||
|
|
||||||
|
### Instance Properties
|
||||||
|
|
||||||
|
`menu` objects also have the following properties:
|
||||||
|
|
||||||
|
#### `menu.items`
|
||||||
|
|
||||||
|
A MenuItem[] array containing the menu's items.
|
||||||
|
|
||||||
Each `Menu` consists of multiple [`MenuItem`](menu-item.md)s and each `MenuItem`
|
Each `Menu` consists of multiple [`MenuItem`](menu-item.md)s and each `MenuItem`
|
||||||
can have a submenu.
|
can have a submenu.
|
||||||
|
|
||||||
|
@ -217,85 +297,6 @@ window.addEventListener('contextmenu', (e) => {
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
### `new Menu()`
|
|
||||||
|
|
||||||
Creates a new menu.
|
|
||||||
|
|
||||||
### Static Methods
|
|
||||||
|
|
||||||
The `menu` class has the following static methods:
|
|
||||||
|
|
||||||
#### `Menu.setApplicationMenu(menu)`
|
|
||||||
|
|
||||||
* `menu` Menu
|
|
||||||
|
|
||||||
Sets `menu` as the application menu on macOS. On Windows and Linux, the `menu`
|
|
||||||
will be set as each window's top menu.
|
|
||||||
|
|
||||||
**Note:** This API has to be called after the `ready` event of `app` module.
|
|
||||||
|
|
||||||
#### `Menu.getApplicationMenu()`
|
|
||||||
|
|
||||||
Returns `Menu` - The application menu, if set, or `null`, if not set.
|
|
||||||
|
|
||||||
#### `Menu.sendActionToFirstResponder(action)` _macOS_
|
|
||||||
|
|
||||||
* `action` String
|
|
||||||
|
|
||||||
Sends the `action` to the first responder of application. This is used for
|
|
||||||
emulating default Cocoa menu behaviors, usually you would just use the
|
|
||||||
`role` property of `MenuItem`.
|
|
||||||
|
|
||||||
See the [macOS Cocoa Event Handling Guide](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/10000060i-CH3-SW7)
|
|
||||||
for more information on macOS' native actions.
|
|
||||||
|
|
||||||
#### `Menu.buildFromTemplate(template)`
|
|
||||||
|
|
||||||
* `template` MenuItemConstructorOptions[]
|
|
||||||
|
|
||||||
Returns `Menu`
|
|
||||||
|
|
||||||
Generally, the `template` is just an array of `options` for constructing a
|
|
||||||
[MenuItem](menu-item.md). The usage can be referenced above.
|
|
||||||
|
|
||||||
You can also attach other fields to the element of the `template` and they
|
|
||||||
will become properties of the constructed menu items.
|
|
||||||
|
|
||||||
### Instance Methods
|
|
||||||
|
|
||||||
The `menu` object has the following instance methods:
|
|
||||||
|
|
||||||
#### `menu.popup([browserWindow, x, y, positioningItem])`
|
|
||||||
|
|
||||||
* `browserWindow` BrowserWindow (optional) - Default is `BrowserWindow.getFocusedWindow()`.
|
|
||||||
* `x` Number (optional) - Default is the current mouse cursor position.
|
|
||||||
* `y` Number (**required** if `x` is used) - Default is the current mouse cursor position.
|
|
||||||
* `positioningItem` Number (optional) _macOS_ - The index of the menu item to
|
|
||||||
be positioned under the mouse cursor at the specified coordinates. Default is
|
|
||||||
-1.
|
|
||||||
|
|
||||||
Pops up this menu as a context menu in the `browserWindow`.
|
|
||||||
|
|
||||||
#### `menu.append(menuItem)`
|
|
||||||
|
|
||||||
* `menuItem` MenuItem
|
|
||||||
|
|
||||||
Appends the `menuItem` to the menu.
|
|
||||||
|
|
||||||
#### `menu.insert(pos, menuItem)`
|
|
||||||
|
|
||||||
* `pos` Integer
|
|
||||||
* `menuItem` MenuItem
|
|
||||||
|
|
||||||
Inserts the `menuItem` to the `pos` position of the menu.
|
|
||||||
|
|
||||||
### Instance Properties
|
|
||||||
|
|
||||||
`menu` objects also have the following properties:
|
|
||||||
|
|
||||||
#### `menu.items`
|
|
||||||
|
|
||||||
A MenuItem[] array containing the menu's items.
|
|
||||||
|
|
||||||
## Notes on macOS Application Menu
|
## Notes on macOS Application Menu
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue