2016-05-02 03:01:47 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2016-05-03 17:42:20 +03:00
|
|
|
"use strict";
|
|
|
|
|
2016-05-02 03:01:47 +03:00
|
|
|
/**
|
|
|
|
* A partial implementation of the MenuItem API provided by electron:
|
|
|
|
* https://github.com/electron/electron/blob/master/docs/api/menu-item.md.
|
|
|
|
*
|
|
|
|
* Missing features:
|
|
|
|
* - id String - Unique within a single menu. If defined then it can be used
|
|
|
|
* as a reference to this item by the position attribute.
|
|
|
|
* - role String - Define the action of the menu item; when specified the
|
|
|
|
* click property will be ignored
|
|
|
|
* - sublabel String
|
|
|
|
* - accelerator Accelerator
|
|
|
|
* - position String - This field allows fine-grained definition of the
|
|
|
|
* specific location within a given menu.
|
|
|
|
*
|
|
|
|
* Implemented features:
|
|
|
|
* @param Object options
|
2018-04-05 04:13:21 +03:00
|
|
|
* String accelerator
|
|
|
|
* Text that appears beside the menu label to indicate the shortcut key
|
|
|
|
* (accelerator key) to use to invoke the command.
|
|
|
|
* Unlike the Electron API, this is a label only and does not actually
|
|
|
|
* register a handler for the key.
|
|
|
|
* String accesskey [non-standard]
|
|
|
|
* A single character used as the shortcut key. This should be one of the
|
|
|
|
* characters that appears in the label.
|
2016-05-02 03:01:47 +03:00
|
|
|
* Function click
|
2016-05-03 17:42:20 +03:00
|
|
|
* Will be called with click(menuItem, browserWindow) when the menu item
|
|
|
|
* is clicked
|
2016-05-02 03:01:47 +03:00
|
|
|
* String type
|
|
|
|
* Can be normal, separator, submenu, checkbox or radio
|
|
|
|
* String label
|
2019-12-04 00:10:28 +03:00
|
|
|
* String image
|
2016-05-03 17:42:20 +03:00
|
|
|
* Boolean enabled
|
|
|
|
* If false, the menu item will be greyed out and unclickable.
|
|
|
|
* Boolean checked
|
|
|
|
* Should only be specified for checkbox or radio type menu items.
|
|
|
|
* Menu submenu
|
|
|
|
* 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.
|
2016-05-03 17:40:33 +03:00
|
|
|
* Boolean visible
|
|
|
|
* If false, the menu item will be entirely hidden.
|
2016-05-02 03:01:47 +03:00
|
|
|
*/
|
|
|
|
function MenuItem({
|
2018-04-05 04:13:21 +03:00
|
|
|
accelerator = null,
|
2016-05-02 03:01:47 +03:00
|
|
|
accesskey = null,
|
2018-07-17 21:55:49 +03:00
|
|
|
l10nID = null,
|
2016-05-02 03:01:47 +03:00
|
|
|
checked = false,
|
|
|
|
click = () => {},
|
|
|
|
disabled = false,
|
2017-09-25 16:03:11 +03:00
|
|
|
hover = () => {},
|
2016-05-02 03:01:47 +03:00
|
|
|
id = null,
|
2017-09-25 16:03:11 +03:00
|
|
|
label = "",
|
2019-12-04 00:10:28 +03:00
|
|
|
image = null,
|
2016-05-02 03:01:47 +03:00
|
|
|
submenu = null,
|
|
|
|
type = "normal",
|
2016-05-03 17:40:33 +03:00
|
|
|
visible = true,
|
2016-05-02 03:01:47 +03:00
|
|
|
} = {}) {
|
2018-04-05 04:13:21 +03:00
|
|
|
this.accelerator = accelerator;
|
2016-05-02 03:01:47 +03:00
|
|
|
this.accesskey = accesskey;
|
2018-07-17 21:55:49 +03:00
|
|
|
this.l10nID = l10nID;
|
2016-05-02 03:01:47 +03:00
|
|
|
this.checked = checked;
|
|
|
|
this.click = click;
|
|
|
|
this.disabled = disabled;
|
2017-09-25 16:03:11 +03:00
|
|
|
this.hover = hover;
|
2016-05-02 03:01:47 +03:00
|
|
|
this.id = id;
|
|
|
|
this.label = label;
|
2019-12-04 00:10:28 +03:00
|
|
|
this.image = image;
|
2016-05-02 03:01:47 +03:00
|
|
|
this.submenu = submenu;
|
|
|
|
this.type = type;
|
2016-05-03 17:40:33 +03:00
|
|
|
this.visible = visible;
|
2016-05-02 03:01:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = MenuItem;
|