Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

JEP Menuitems

Erik Vold edited this page Aug 20, 2013 · 9 revisions

Proposal

It should be possible to create menuitems for browser windows on Firefox and Fennec.

Use Cases

Sidebars and Toolbars require menuitems in the (View - > Sidebar/Toolbar) menu. DevTools require a menuitem in Tools -> Web Developer. Firefox itself, and many add-ons, provide toolbarbutton-menus for which other add-ons would like to extend (example: the Bookmarks toolbar button).

Implementation

The design would closely match that for Context Menuitems, but leave out all of the extra context related events and message passing.

API

Constructors

Menuitem
  • options
    • String label: the text displayed in the menuitem.
    • Array Integer or String menu: describes menu which the menuitem will live under. If a array is used then the first valid parent in the array will be used.
    • Boolean [enabled]: this should be false if you want the menuitem to be displayed and unclickable.
    • Boolean [visible]: this should be false if you want the menuitem to be hidden, default is true.
Properties
  • String id (only getter): the id for the menuitem.
  • String label (only getter): the text displayed in the menuitem.
  • Boolean enabled (getter and setter): the enabled state of the menuitem.
  • Boolean visible (getter and setter): the visible state of the menuitem.
Methods
  • destroy: destroys the menuitem
Events
  • click

Examples

Using Menuitem constants for attachTo

var { Menuitem } = require('sdk/ui');

var menuitem = Menuitem({
  label: "Not Checked",
  menu: [ Menuitem.FILE_MENU, Menuitem.APP_MENU ],
  onClick: function() {
    // do something..
  }
})

Using Strings in menu

var { Menuitem } = require('sdk/ui');

var menuitem = Menuitem({
  label: "Not Checked",
  menu: [ 'file', 'application' ],
  onClick: function() {
    // do something..
  }
})

Prior Art