Electron参考手册
MenuItem
MenuItem
添加项目到本机应用程序菜单和环境菜单。
过程:Main
Menu举例来看。
new MenuItem(options)
-
options目的-
click功能(可选) - 将click(menuItem, browserWindow, event)在菜单项被点击时调用。-
menuItem菜单项 -
browserWindow浏览器窗口 -
event事件
-
-
- `role` String (optional) - Define the action of the menu item, when specified the `click` property will be ignored. See [roles](about:blank#roles).
- `type` String (optional) - Can be `normal`, `separator`, `submenu`, `checkbox` or `radio`.
- `label` String - (optional)
- `sublabel` String - (optional)
- `accelerator` [Accelerator](../accelerator/index) (optional)
- `icon` ([NativeImage](../native-image/index) | String) (optional)
- `enabled` Boolean (optional) - If false, the menu item will be greyed out and unclickable.
- `visible` Boolean (optional) - If false, the menu item will be entirely hidden.
- `checked` Boolean (optional) - Should only be specified for `checkbox` or `radio` type menu items.
- `submenu` (MenuItemConstructorOptions[] | Menu) (optional) - Should be specified for `submenu` type menu items. If `submenu` is specified, the `type: 'submenu'` can be omitted. If the value is not a `Menu` then it will be automatically converted to one using `Menu.buildFromTemplate`.
- `id` String (optional) - Unique within a single menu. If defined then it can be used as a reference to this item by the position attribute.
- `position` String (optional) - This field allows fine-grained definition of the specific location within a given menu.
角色
角色允许菜单项具有预定义的行为。
最好指定role与标准角色相匹配的任何菜单项,而不是尝试手动实现click函数中的行为。内置role行为将提供最佳的本地体验。
在使用role和时,label和accelerator值是可选的,并且将默认为每个平台的适当值。
role属性可以具有以下值:
undoredocutcopypastepasteandmatchstyleselectalldelete-
minimize- Minimize current window -
close- Close current window -
quit- Quit the application -
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 -
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% -
editMenu- Whole default “Edit” menu (Undo, Copy, etc.) -
windowMenu- Whole default “Window” menu (Minimize, Close, etc.)
macOS 上提供以下其他角色:
-
about- 映射到orderFrontStandardAboutPanel行动 -
hide- 映射到hide行动 -
hideothers- 映射到hideOtherApplications行动 -
unhide- 映射到unhideAllApplications行动 -
startspeaking- 映射到startSpeaking行动 -
stopspeaking- 映射到stopSpeaking行动 -
front- 映射到arrangeInFront行动 -
zoom- 映射到performZoom行动 -
window- 子菜单是一个“窗口”菜单 -
help- 子菜单是一个“帮助”菜单 -
services- 子菜单是“服务”菜单
当在 MacOS 指定role,label和accelerator是会影响菜单项的唯一选择。所有其他选项将被忽略。
实例属性
以下属性可用于以下MenuItem实例:
menuItem.enabled
一个 Boolean指示是否启用该项目,此属性可以动态更改。
menuItem.visible
一个Boolean指示项目是否可见,此属性可以动态更改。
menuItem.checked
一个 Boolean表示是否选中该项目,该属性可以动态更改。
一个checkbox菜单项将切换checked上,并选择关闭属性。
一个radio菜单项checked在点击时会打开它的属性,并将关闭同一菜单中所有相邻项目的属性。
您可以添加一个click函数来执行其他行为。
menuItem.label
一个String代表菜单项可见标签
menuItem.click
一个Function,当菜单项获得的点击事件被触发
MenuItem相关
Electron 是一个使用 JavaScript, HTML 和 CSS 等 Web 技术创建原生程序的框架,它负责比较难搞的部分,你只需把精力放在你的应用的核心上即可。
| 主页 | https://electron.atom.io/ |
| 源码 | https://github.com/electron/electron |
| 发布版本 | 1.7.9 |
加载中,请稍侯......