menu-item.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. "use strict";
  6. /**
  7. * A partial implementation of the MenuItem API provided by electron:
  8. * https://github.com/electron/electron/blob/master/docs/api/menu-item.md.
  9. *
  10. * Missing features:
  11. * - id String - Unique within a single menu. If defined then it can be used
  12. * as a reference to this item by the position attribute.
  13. * - role String - Define the action of the menu item; when specified the
  14. * click property will be ignored
  15. * - sublabel String
  16. * - accelerator Accelerator
  17. * - icon NativeImage
  18. * - position String - This field allows fine-grained definition of the
  19. * specific location within a given menu.
  20. *
  21. * Implemented features:
  22. * @param Object options
  23. * Function click
  24. * Will be called with click(menuItem, browserWindow) when the menu item
  25. * is clicked
  26. * String type
  27. * Can be normal, separator, submenu, checkbox or radio
  28. * String label
  29. * Boolean enabled
  30. * If false, the menu item will be greyed out and unclickable.
  31. * Boolean checked
  32. * Should only be specified for checkbox or radio type menu items.
  33. * Menu submenu
  34. * Should be specified for submenu type menu items. If submenu is specified,
  35. * the type: 'submenu' can be omitted. If the value is not a Menu then it
  36. * will be automatically converted to one using Menu.buildFromTemplate.
  37. * Boolean visible
  38. * If false, the menu item will be entirely hidden.
  39. */
  40. function MenuItem({
  41. accesskey = null,
  42. checked = false,
  43. click = () => {},
  44. disabled = false,
  45. label = "",
  46. id = null,
  47. submenu = null,
  48. type = "normal",
  49. visible = true,
  50. } = { }) {
  51. this.accesskey = accesskey;
  52. this.checked = checked;
  53. this.click = click;
  54. this.disabled = disabled;
  55. this.id = id;
  56. this.label = label;
  57. this.submenu = submenu;
  58. this.type = type;
  59. this.visible = visible;
  60. }
  61. module.exports = MenuItem;