Menu
Класс: Menu
Создайте меню приложения и контекстное меню.
Process: Main
[!TIP] See also: A detailed guide about how to implement menus in your application.
[!WARNING] Electron's built-in classes cannot be subclassed in user code. For more information, see the FAQ.
new Menu()
Создает новое меню.
Статические методы
Класс Menu имеет следующие статические методы:
Menu.setApplicationMenu(menu)
menuMenu | null
Устанавливает меню в качестве меню приложения на macOS. On Windows and Linux, the menu will be set as each window's top menu.
Также на Windows и Linux, Вы можете использовать & в названии подменю верхнего списка, чтобы указать, какая буква должна получить сгенерированный акселератор( Accelerator ). Для примера, использование &File для меню файла в результате сгенерирует акселератор( Accelerator ) Alt-F, который открывает соответствующее меню. The indicated character in the button label then gets an underline, and the & character is not displayed on the button label.
In order to escape the & character in an item name, add a proceeding &. For example, &&File would result in &File displayed on the button label.
Passing null will suppress the default menu. On Windows and Linux, this has the additional effect of removing the menu bar from the window.
[!NOTE] The default menu will be created automatically if the app does not set one. It contains standard items such as
File,Edit,View,WindowandHelp.
Menu.getApplicationMenu()
Возвращает Menu | null - меню приложения, если установлено, иначе null.
[!NOTE] The returned
Menuinstance doesn't support dynamic addition or removal of menu items. Instance properties can still be dynamically modified.
Menu.sendActionToFirstResponder(action) macOS
actionstring
Посылает action первому ответчику приложения. Это используется для эмуляции поведения меню macOS. Usually you would use the role property of a MenuItem.
See the macOS Cocoa Event Handling Guide for more information on macOS' native actions.
Menu.buildFromTemplate(template)
template(MenuItemConstructorOptions | MenuItem)[]
Returns Menu
Generally, the template is an array of options for constructing a MenuItem. The usage can be referenced above.
Вы также можете прикрепить другие поля к элементу template и они станут свойствами элементов созданного меню.
Методы экземпляра
Объект меню имеет следующие методы экземпляра:
menu.popup([options])
Pops up this menu as a context menu in the BaseWindow.
[!TIP] For more details, see the Context Menu guide.
menu.closePopup([window])
windowBaseWindow (optional) - Default is the focused window.
Closes the context menu in the window.
menu.append(menuItem)
menuItemMenuItem
Добавляет menuItem в меню.
menu.getMenuItemById(id)
idstring
Возвращает элемент MenuItem с указанным id
menu.insert(pos, menuItem)
portIntegermenuItemMenuItem
Вставляет menuItem в меню на позицию pos.
События экземпляра
Объекты созданные с помощью new Menu или возвращенные из Menu.buildFromTemplate вызывают следующие события:
[!NOTE] Some events are only available on specific operating systems and are labeled as such.
Событие: 'menu-will-show'
Возвращает:
eventEvent
Вызывается при вызове menu.popup().
Событие: 'menu-will-close'
Возвращает:
eventEvent
Вызывается, когда всплывающее окно закрывается вручную или с помощью menu.closePopup().
Свойства экземпляра
Объекты menu также имеют следующие свойства:
menu.items
Массив MenuItem[] содержит элементы меню.
Each Menu consists of multiple MenuItem instances and each MenuItem can nest a Menu into its submenu property.