Skip to main content

Menus

Import :

const Menus = brackets.getModule("command/Menus")

Kind: global class

new MenuItem(id, command, [options])

MenuItem represents a single menu item that executes a Command or a menu divider. MenuItems may have a sub-menu. A MenuItem may correspond to an HTML-based menu item or a native menu item if Brackets is running in a native application shell

Since MenuItems may have a native implementation clients should create MenuItems through addMenuItem() and should NOT construct a MenuItem object directly. Clients should also not access HTML content of a menu directly and instead use the MenuItem API to query and modify menus items.

MenuItems are views on to Command objects so modify the underlying Command to modify the name, enabled, and checked state of a MenuItem. The MenuItem will update automatically

ParamTypeDescription
idstring
commandstring | Commandthe Command this MenuItem will reflect. Use DIVIDER to specify a menu divider
[options]
options.hideWhenCommandDisabledbooleanwill not show the menu item if command is disabled.

Gets the Command associated with a MenuItem

Kind: instance method of MenuItem

Returns the parent Menu for this MenuItem

Kind: instance method of MenuItem

Kind: global class

new Menu(id)

Menu represents a top-level menu in the menu bar. A Menu may correspond to an HTML-based menu or a native menu if Brackets is running in a native application shell.

Since menus may have a native implementation clients should create Menus through addMenu() and should NOT construct a Menu object directly. Clients should also not access HTML content of a menu directly and instead use the Menu API to query and modify menus.

ParamType
idstring

Removes the specified menu item from this Menu. Key bindings are unaffected; use KeyBindingManager directly to remove key bindings if desired.

Kind: instance method of Menu

ParamTypeDescription
commandstring | Commandcommand the menu would execute if we weren't deleting it.

Removes the specified menu divider from this Menu.

Kind: instance method of Menu

ParamTypeDescription
menuItemIDstringthe menu item id of the divider to remove.

Adds a new menu item with the specified id and display text. The insertion position is specified via the relativeID and position arguments which describe a position relative to another MenuItem or MenuGroup. It is preferred that plug-ins insert new MenuItems relative to a menu section rather than a specific MenuItem (see Menu Section Constants).

TODO: Sub-menus are not yet supported, but when they are implemented this API will allow adding new MenuItems to sub-menus as well.

Note, keyBindings are bound to Command objects not MenuItems. The provided keyBindings will be bound to the supplied Command object rather than the MenuItem.

Kind: instance method of Menu
Returns: MenuItem - the newly created MenuItem

ParamTypeDescription
commandstring | Commandthe command the menu will execute. Pass Menus.DIVIDER for a menu divider, or just call addMenuDivider() instead.
[keyBindings]string | ObjectRegister one or more key bindings to associate with the supplied command
[position]stringconstant defining the position of new MenuItem relative to other MenuItems. Values: - With no relativeID, use Menus.FIRST or LAST (default is LAST) - Relative to a command id, use BEFORE or AFTER (required) - Relative to a MenuSection, use FIRST_IN_SECTION or LAST_IN_SECTION (required)
[relativeID]stringcommand id OR one of the MenuSection.* constants. Required for all position constants except FIRST and LAST.
[options]
options.hideWhenCommandDisabledbooleanwill not show the menu item if command is disabled. Helps to clear the clutter on greyed out menu items if not applicable to context.

Inserts divider item in menu.

Kind: instance method of Menu
Returns: MenuItem - the newly created divider

ParamTypeDescription
positionstringconstant defining the position of new the divider relative to other MenuItems. Default is LAST. (see Insertion position constants).
relativeIDstringid of menuItem, sub-menu, or menu section that the new divider will be positioned relative to. Required for all position constants except FIRST and LAST

Creates a new submenu and a menuItem and adds the menuItem of the submenu to the menu and returns the submenu.

A submenu will have the same structure of a menu with a additional field parentMenuItem which has the reference of the submenu's parent menuItem. A submenu will raise the following events:

  • beforeSubMenuOpen
  • beforeSubMenuClose

Note, This function will create only a context submenu.

TODO: Make this function work for Menus

Kind: instance method of Menu
Returns: Menu - the newly created submenu

ParamTypeDescription
namestringdisplayed in menu item of the submenu
idstring
positionstringconstant defining the position of new MenuItem of the submenu relative to other MenuItems. Values: - With no relativeID, use Menus.FIRST or LAST (default is LAST) - Relative to a command id, use BEFORE or AFTER (required) - Relative to a MenuSection, use FIRST_IN_SECTION or LAST_IN_SECTION (required)
relativeIDstringcommand id OR one of the MenuSection.* constants. Required for all position constants except FIRST and LAST.

Removes the specified submenu from this Menu.

Note, this function will only remove context submenus

TODO: Make this function work for Menus

Kind: instance method of Menu

ParamTypeDescription
subMenuIDstringthe menu id of the submenu to remove.

Closes the submenu if the menu has a submenu open.

Kind: instance method of Menu

ContextMenu ⇐ Menu

Kind: global class
Extends: Menu

new ContextMenu()

Represents a context menu that can open at a specific location in the UI.

Clients should not create this object directly and should instead use registerContextMenu() to create new ContextMenu objects.

Context menus in brackets may be HTML-based or native so clients should not reach into the HTML and should instead manipulate ContextMenus through the API.

Events:

  • beforeContextMenuOpen
  • beforeContextMenuClose

contextMenu.open(mouseOrLocation)

Displays the ContextMenu at the specified location and dispatches the "beforeContextMenuOpen" event or "beforeSubMenuOpen" event (for submenus). The menu location may be adjusted to prevent clipping by the browser window. All other menus and ContextMenus will be closed before a new menu will be closed before a new menu is shown (if the new menu is not a submenu).

In case of submenus, the parentMenu of the submenu will not be closed when the sub menu is open.

Kind: instance method of ContextMenu

ParamTypeDescription
mouseOrLocationMouseEvent | Objectpass a MouseEvent to display the menu near the mouse or pass in an object with page x/y coordinates for a specific location.This paramter is not used for submenus. Submenus are always displayed at a position relative to the parent menu.

contextMenu.close()

Closes the context menu.

Kind: instance method of ContextMenu

contextMenu.isOpen()

Detect if current context menu is already open

Kind: instance method of ContextMenu

contextMenu.removeMenuItem(command)

Removes the specified menu item from this Menu. Key bindings are unaffected; use KeyBindingManager directly to remove key bindings if desired.

Kind: instance method of ContextMenu

ParamTypeDescription
commandstring | Commandcommand the menu would execute if we weren't deleting it.

contextMenu.removeMenuDivider(menuItemID)

Removes the specified menu divider from this Menu.

Kind: instance method of ContextMenu

ParamTypeDescription
menuItemIDstringthe menu item id of the divider to remove.

contextMenu.addMenuItem(command, [keyBindings], [position], [relativeID], [options]) ⇒ MenuItem

Adds a new menu item with the specified id and display text. The insertion position is specified via the relativeID and position arguments which describe a position relative to another MenuItem or MenuGroup. It is preferred that plug-ins insert new MenuItems relative to a menu section rather than a specific MenuItem (see Menu Section Constants).

TODO: Sub-menus are not yet supported, but when they are implemented this API will allow adding new MenuItems to sub-menus as well.

Note, keyBindings are bound to Command objects not MenuItems. The provided keyBindings will be bound to the supplied Command object rather than the MenuItem.

Kind: instance method of ContextMenu
Returns: MenuItem - the newly created MenuItem

ParamTypeDescription
commandstring | Commandthe command the menu will execute. Pass Menus.DIVIDER for a menu divider, or just call addMenuDivider() instead.
[keyBindings]string | ObjectRegister one or more key bindings to associate with the supplied command
[position]stringconstant defining the position of new MenuItem relative to other MenuItems. Values: - With no relativeID, use Menus.FIRST or LAST (default is LAST) - Relative to a command id, use BEFORE or AFTER (required) - Relative to a MenuSection, use FIRST_IN_SECTION or LAST_IN_SECTION (required)
[relativeID]stringcommand id OR one of the MenuSection.* constants. Required for all position constants except FIRST and LAST.
[options]
options.hideWhenCommandDisabledbooleanwill not show the menu item if command is disabled. Helps to clear the clutter on greyed out menu items if not applicable to context.

contextMenu.addMenuDivider(position, relativeID) ⇒ MenuItem

Inserts divider item in menu.

Kind: instance method of ContextMenu
Returns: MenuItem - the newly created divider

ParamTypeDescription
positionstringconstant defining the position of new the divider relative to other MenuItems. Default is LAST. (see Insertion position constants).
relativeIDstringid of menuItem, sub-menu, or menu section that the new divider will be positioned relative to. Required for all position constants except FIRST and LAST

contextMenu.addSubMenu(name, id, position, relativeID) ⇒ Menu

Creates a new submenu and a menuItem and adds the menuItem of the submenu to the menu and returns the submenu.

A submenu will have the same structure of a menu with a additional field parentMenuItem which has the reference of the submenu's parent menuItem. A submenu will raise the following events:

  • beforeSubMenuOpen
  • beforeSubMenuClose

Note, This function will create only a context submenu.

TODO: Make this function work for Menus

Kind: instance method of ContextMenu
Returns: Menu - the newly created submenu

ParamTypeDescription
namestringdisplayed in menu item of the submenu
idstring
positionstringconstant defining the position of new MenuItem of the submenu relative to other MenuItems. Values: - With no relativeID, use Menus.FIRST or LAST (default is LAST) - Relative to a command id, use BEFORE or AFTER (required) - Relative to a MenuSection, use FIRST_IN_SECTION or LAST_IN_SECTION (required)
relativeIDstringcommand id OR one of the MenuSection.* constants. Required for all position constants except FIRST and LAST.

contextMenu.removeSubMenu(subMenuID)

Removes the specified submenu from this Menu.

Note, this function will only remove context submenus

TODO: Make this function work for Menus

Kind: instance method of ContextMenu

ParamTypeDescription
subMenuIDstringthe menu id of the submenu to remove.

contextMenu.closeSubMenu()

Closes the submenu if the menu has a submenu open.

Kind: instance method of ContextMenu

ContextMenu.assignContextMenuToSelector()

Associate a context menu to a DOM element. This static function take care of registering event handlers for the click event listener and passing the right "position" object to the Context#open method

Kind: static method of ContextMenu

DIVIDER

Other constants

Kind: global variable

AppMenuBar : enum

Brackets Application Menu Constants

Kind: global enum
Properties

NameTypeDefault
FILE_MENUstring"file-menu"
EDIT_MENUstring"edit-menu"
FIND_MENUstring"find-menu"
VIEW_MENUstring"view-menu"
NAVIGATE_MENUstring"navigate-menu"
DEBUG_MENUstring"debug-menu"
HELP_MENUstring"help-menu"

ContextMenuIds : enum

Brackets Context Menu Constants

Kind: global enum
Properties

NameTypeDefault
EDITOR_MENUstring"editor-context-menu"
INLINE_EDITOR_MENUstring"inline-editor-context-menu"
PROJECT_MENUstring"project-context-menu"
WORKING_SET_CONTEXT_MENUstring"workingset-context-menu"
WORKING_SET_CONFIG_MENUstring"workingset-configuration-menu"
SPLITVIEW_MENUstring"splitview-menu"

Brackets Application Menu Section Constants It is preferred that plug-ins specify the location of new MenuItems in terms of a menu section rather than a specific MenuItem. This provides looser coupling to Bracket's internal MenuItems and makes menu organization more semantic. Use these constants as the "relativeID" parameter when calling addMenuItem() and specify a position of FIRST_IN_SECTION or LAST_IN_SECTION.

Menu sections are denoted by dividers or the beginning/end of a menu

Kind: global enum
Properties

NameTypeDefault
FILE_OPEN_CLOSE_COMMANDSstring"FILE_OPEN_CLOSE_COMMANDS"
FILE_SAVE_COMMANDSstring"FILE_SAVE_COMMANDS"
FILE_LIVEstring"FILE_LIVE"
FILE_SETTINGSstring"FILE_SETTINGS"
FILE_EXTENSION_MANAGERstring"FILE_EXTENSION_MANAGER"
EDIT_UNDO_REDO_COMMANDSstring"EDIT_UNDO_REDO_COMMANDS"
EDIT_TEXT_COMMANDSstring"EDIT_TEXT_COMMANDS"
EDIT_SELECTION_COMMANDSstring"EDIT_SELECTION_COMMANDS"
EDIT_MODIFY_SELECTIONstring"EDIT_MODIFY_SELECTION"
EDIT_COMMENT_SELECTIONstring"EDIT_COMMENT_SELECTION"
EDIT_CODE_HINTS_COMMANDSstring"EDIT_CODE_HINTS_COMMANDS"
EDIT_TOGGLE_OPTIONSstring"EDIT_TOGGLE_OPTIONS"
FIND_FIND_COMMANDSstring"FIND_FIND_COMMANDS"
FIND_FIND_IN_COMMANDSstring"FIND_FIND_IN_COMMANDS"
FIND_REPLACE_COMMANDSstring"FIND_REPLACE_COMMANDS"
VIEW_HIDESHOW_COMMANDSstring"VIEW_HIDESHOW_COMMANDS"
VIEW_FONTSIZE_COMMANDSstring"VIEW_FONTSIZE_COMMANDS"
VIEW_TOGGLE_OPTIONSstring"VIEW_TOGGLE_OPTIONS"
NAVIGATE_GOTO_COMMANDSstring"NAVIGATE_GOTO_COMMANDS"
NAVIGATE_DOCUMENTS_COMMANDSstring"NAVIGATE_DOCUMENTS_COMMANDS"
NAVIGATE_OS_COMMANDSstring"NAVIGATE_OS_COMMANDS"
NAVIGATE_QUICK_EDIT_COMMANDSstring"NAVIGATE_QUICK_EDIT_COMMANDS"
NAVIGATE_QUICK_DOCS_COMMANDSstring"NAVIGATE_QUICK_DOCS_COMMANDS"

BEFORE : enum

Insertion position constants Used by addMenu(), addMenuItem(), and addSubMenu() to specify the relative position of a newly created menu object

Kind: global enum

getMenu(id) ⇒ Menu

Retrieves the Menu object for the corresponding id.

Kind: global function

ParamType
idstring

getAllMenuItemCommands() ⇒ Set.<string>

retruns a set containing all commands that has a menu item registered

Kind: global function

getAllMenus() ⇒ Object.<string, Menu>

Retrieves the map of all Menu objects.

Kind: global function

getContextMenu(id) ⇒ ContextMenu

Retrieves the ContextMenu object for the corresponding id.

Kind: global function

ParamType
idstring

getMenuItem(id) ⇒ MenuItem

Retrieves the MenuItem object for the corresponding id.

Kind: global function

ParamType
idstring

closeAll()

Closes all menus that are open

Kind: global function

openMenu(id) ⇒ null

Opens a menu with the given id

Kind: global function

Param
id

getOpenMenu() ⇒ null | string

returns the currently open menu id if present or null

Kind: global function

addMenu(name, id, position, relativeID) ⇒ Menu

Adds a top-level menu to the application menu bar which may be native or HTML-based.

Kind: global function
Returns: Menu - the newly created Menu

ParamTypeDescription
namestringdisplay text for menu
idstringunique identifier for a menu. Core Menus in Brackets use a simple title as an id, for example "file-menu". Extensions should use the following format: "author.myextension.mymenuname".
positionstringconstant defining the position of new the Menu relative to other Menus. Default is LAST (see Insertion position constants).
relativeIDstringid of Menu the new Menu will be positioned relative to. Required when position is AFTER or BEFORE, ignored when position is FIRST or LAST

removeMenu(id)

Removes a top-level menu from the application menu bar which may be native or HTML-based.

Kind: global function

ParamTypeDescription
idstringunique identifier for a menu. Core Menus in Brackets use a simple title as an id, for example "file-menu". Extensions should use the following format: "author.myextension.mymenuname".

registerContextMenu(id) ⇒ ContextMenu

Registers new context menu with Brackets. Extensions should generally use the predefined context menus built into Brackets. Use this API to add a new context menu to UI that is specific to an extension.

After registering a new context menu clients should:

  • use addMenuItem() to add items to the context menu
  • call open() to show the context menu. For example:
$("#my_ID").contextmenu(function (e) {
if (e.which === 3) {
my_cmenu.open(e);
}
});

To make menu items be contextual to things like selection, listen for the "beforeContextMenuOpen" to make changes to Command objects before the context menu is shown. MenuItems are views of Commands, which control a MenuItem's name, enabled state, and checked state.

Kind: global function
Returns: ContextMenu - the newly created context menu

ParamTypeDescription
idstringunique identifier for context menu. Core context menus in Brackets use a simple title as an id. Extensions should use the following format: "author.myextension.mycontextmenu name"

"EVENT_BEFORE_CONTEXT_MENU_OPEN"

Event triggered before the context menu opens.

Kind: event emitted

"EVENT_BEFORE_CONTEXT_MENU_CLOSE"

Event triggered before the context menu closes.

Kind: event emitted

"EVENT_BEFORE_SUB_MENU_OPEN"

Event triggered before a sub-menu opens.

Kind: event emitted

"EVENT_BEFORE_SUB_MENU_CLOSE"

Event triggered before a sub-menu closes.

Kind: event emitted