Menus
Import :
const Menus = brackets.getModule("command/Menus")
MenuItem
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
Param | Type | Description |
---|---|---|
id | string | |
command | string | Command | the Command this MenuItem will reflect. Use DIVIDER to specify a menu divider |
[options] | ||
options.hideWhenCommandDisabled | boolean | will not show the menu item if command is disabled. |
menuItem.getCommand() ⇒ Command
Gets the Command associated with a MenuItem
Kind: instance method of MenuItem
menuItem.getParentMenu() ⇒ Menu
Returns the parent Menu for this MenuItem
Kind: instance method of MenuItem
Menu
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.
Param | Type |
---|---|
id | string |
menu.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 Menu
Param | Type | Description |
---|---|---|
command | string | Command | command the menu would execute if we weren't deleting it. |
menu.removeMenuDivider(menuItemID)
Removes the specified menu divider from this Menu.
Kind: instance method of Menu
Param | Type | Description |
---|---|---|
menuItemID | string | the menu item id of the divider to remove. |
menu.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 Menu
Returns: MenuItem
- the newly created MenuItem
Param | Type | Description |
---|---|---|
command | string | Command | the command the menu will execute. Pass Menus.DIVIDER for a menu divider, or just call addMenuDivider() instead. |
[keyBindings] | string | Object | Register one or more key bindings to associate with the supplied command |
[position] | string | constant 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] | string | command id OR one of the MenuSection.* constants. Required for all position constants except FIRST and LAST. |
[options] | ||
options.hideWhenCommandDisabled | boolean | will not show the menu item if command is disabled. Helps to clear the clutter on greyed out menu items if not applicable to context. |
menu.addMenuDivider(position, relativeID) ⇒ MenuItem
Inserts divider item in menu.
Kind: instance method of Menu
Returns: MenuItem
- the newly created divider
Param | Type | Description |
---|---|---|
position | string | constant defining the position of new the divider relative to other MenuItems. Default is LAST. (see Insertion position constants). |
relativeID | string | id 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 |
menu.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 Menu
Returns: Menu
- the newly created submenu
Param | Type | Description |
---|---|---|
name | string | displayed in menu item of the submenu |
id | string | |
position | string | constant 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) |
relativeID | string | command id OR one of the MenuSection.* constants. Required for all position constants except FIRST and LAST. |
menu.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 Menu
Param | Type | Description |
---|---|---|
subMenuID | string | the menu id of the submenu to remove. |
menu.closeSubMenu()
Closes the submenu if the menu has a submenu open.
Kind: instance method of Menu
ContextMenu ⇐ Menu
Kind: global class
Extends: Menu
- ContextMenu ⇐
Menu
- new ContextMenu()
- instance
- .open(mouseOrLocation)
- .close()
- .isOpen()
- .removeMenuItem(command)
- .removeMenuDivider(menuItemID)
- .addMenuItem(command, [keyBindings], [position], [relativeID], [options]) ⇒
MenuItem
- .addMenuDivider(position, relativeID) ⇒
MenuItem
- .addSubMenu(name, id, position, relativeID) ⇒
Menu
- .removeSubMenu(subMenuID)
- .closeSubMenu()
- static
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
Param | Type | Description |
---|---|---|
mouseOrLocation | MouseEvent | Object | pass 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
Param | Type | Description |
---|---|---|
command | string | Command | command 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
Param | Type | Description |
---|---|---|
menuItemID | string | the 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
Param | Type | Description |
---|---|---|
command | string | Command | the command the menu will execute. Pass Menus.DIVIDER for a menu divider, or just call addMenuDivider() instead. |
[keyBindings] | string | Object | Register one or more key bindings to associate with the supplied command |
[position] | string | constant 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] | string | command id OR one of the MenuSection.* constants. Required for all position constants except FIRST and LAST. |
[options] | ||
options.hideWhenCommandDisabled | boolean | will 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
Param | Type | Description |
---|---|---|
position | string | constant defining the position of new the divider relative to other MenuItems. Default is LAST. (see Insertion position constants). |
relativeID | string | id 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
Param | Type | Description |
---|---|---|
name | string | displayed in menu item of the submenu |
id | string | |
position | string | constant 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) |
relativeID | string | command 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
Param | Type | Description |
---|---|---|
subMenuID | string | the 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
Name | Type | Default |
---|---|---|
FILE_MENU | string | "file-menu" |
EDIT_MENU | string | "edit-menu" |
FIND_MENU | string | "find-menu" |
VIEW_MENU | string | "view-menu" |
NAVIGATE_MENU | string | "navigate-menu" |
DEBUG_MENU | string | "debug-menu" |
HELP_MENU | string | "help-menu" |
ContextMenuIds : enum
Brackets Context Menu Constants
Kind: global enum
Properties
Name | Type | Default |
---|---|---|
EDITOR_MENU | string | "editor-context-menu" |
INLINE_EDITOR_MENU | string | "inline-editor-context-menu" |
PROJECT_MENU | string | "project-context-menu" |
WORKING_SET_CONTEXT_MENU | string | "workingset-context-menu" |
WORKING_SET_CONFIG_MENU | string | "workingset-configuration-menu" |
SPLITVIEW_MENU | string | "splitview-menu" |
MenuSection : enum
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
Name | Type | Default |
---|---|---|
FILE_OPEN_CLOSE_COMMANDS | string | "FILE_OPEN_CLOSE_COMMANDS" |
FILE_SAVE_COMMANDS | string | "FILE_SAVE_COMMANDS" |
FILE_LIVE | string | "FILE_LIVE" |
FILE_SETTINGS | string | "FILE_SETTINGS" |
FILE_EXTENSION_MANAGER | string | "FILE_EXTENSION_MANAGER" |
EDIT_UNDO_REDO_COMMANDS | string | "EDIT_UNDO_REDO_COMMANDS" |
EDIT_TEXT_COMMANDS | string | "EDIT_TEXT_COMMANDS" |
EDIT_SELECTION_COMMANDS | string | "EDIT_SELECTION_COMMANDS" |
EDIT_MODIFY_SELECTION | string | "EDIT_MODIFY_SELECTION" |
EDIT_COMMENT_SELECTION | string | "EDIT_COMMENT_SELECTION" |
EDIT_CODE_HINTS_COMMANDS | string | "EDIT_CODE_HINTS_COMMANDS" |
EDIT_TOGGLE_OPTIONS | string | "EDIT_TOGGLE_OPTIONS" |
FIND_FIND_COMMANDS | string | "FIND_FIND_COMMANDS" |
FIND_FIND_IN_COMMANDS | string | "FIND_FIND_IN_COMMANDS" |
FIND_REPLACE_COMMANDS | string | "FIND_REPLACE_COMMANDS" |
VIEW_HIDESHOW_COMMANDS | string | "VIEW_HIDESHOW_COMMANDS" |
VIEW_FONTSIZE_COMMANDS | string | "VIEW_FONTSIZE_COMMANDS" |
VIEW_TOGGLE_OPTIONS | string | "VIEW_TOGGLE_OPTIONS" |
NAVIGATE_GOTO_COMMANDS | string | "NAVIGATE_GOTO_COMMANDS" |
NAVIGATE_DOCUMENTS_COMMANDS | string | "NAVIGATE_DOCUMENTS_COMMANDS" |
NAVIGATE_OS_COMMANDS | string | "NAVIGATE_OS_COMMANDS" |
NAVIGATE_QUICK_EDIT_COMMANDS | string | "NAVIGATE_QUICK_EDIT_COMMANDS" |
NAVIGATE_QUICK_DOCS_COMMANDS | string | "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
Param | Type |
---|---|
id | string |
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
Param | Type |
---|---|
id | string |
getMenuItem(id) ⇒ MenuItem
Retrieves the MenuItem object for the corresponding id.
Kind: global function
Param | Type |
---|---|
id | string |
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
Param | Type | Description |
---|---|---|
name | string | display text for menu |
id | string | unique 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". |
position | string | constant defining the position of new the Menu relative to other Menus. Default is LAST (see Insertion position constants). |
relativeID | string | id 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
Param | Type | Description |
---|---|---|
id | string | unique 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
Param | Type | Description |
---|---|---|
id | string | unique 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