-
Notifications
You must be signed in to change notification settings - Fork 9
Menu bar
Giorgio Garofalo edited this page Jan 22, 2021
·
4 revisions
Prefer menu bar over drop menu? Chorus' API supports that too.
createMenuBarButton(name, id)
will create a button on the menu bar and return its instance. Note that id
is optional and, if not specified, will take the value of name
.
function onInit() {
const menu = createMenuBarButton('Hello', 'hello');
}
However, there are no sub-buttons. They can be added by calling its addButton(text, action, combination)
function, where combination
is optional.
function onInit() {
const menu = createMenuBarButton('Hello', 'hello');
menu.addButton('World', () => {
alert('Hello, world!');
})
}
If you want to get the instance of an existing button call getMenuBarButton(id)
(built-in IDs are file
, edit
, addons
and help
).
We can also set an accelerator (key combination) for the button by instantiating a KeyCombination
(see here).
Final example:
function onInit() {
const menu = createMenuBarButton('Hello', 'hello');
menu.addButton('World', () => alert('Hello, world!'), new KeyCombination('J', ['control', 'shift']));
}