Menus
Menus are defined in one or more JSON files. A menu file can define or extend application menu and context menus. All menu files are loaded in alphabetical order.
{ "menu": [], "context-menu": {}}The menu JSON files should be placed in menus/ folder of the extension.
my-extension/└─ menus/ └─ menu.jsonApplication Menu
Section titled “Application Menu”Now we’re going to explain how to add menu items in application menu that is placed in the top of the screen except in Windows and Linux which placing on the top of the StarUML window.
Adding a top-level menu items
Section titled “Adding a top-level menu items”We will add a top-level menu item Menu1 and three sub menu items Sub Menu1, Sub Menu2 and Sub Menu3. There will be a separator between Sub Menu2 and Sub Menu3.
We assumes that the commands corresponds to menu items were already defined. To add commands, please refer Commands.
{ "menu": [ { "id": "menu1", "label": "Menu1", "submenu": [ { "label": "Sub Menu1", "id": "menu1.submenu1", "command": "example:function1" }, { "label": "Sub Menu2", "id": "menu1.submenu2", "command": "example:function2" }, { "type": "separator" }, { "label": "Sub Menu3", "id": "menu1.submenu3", "command": "example:function3", "command-arg": { "name": "StarUML" } } ] } ]}Each menu item may have following properties:
- id : Unique id of the menu item.
- label : Label for the menu item.
- command : A command id to be executed when the menu item selected.
- command-arg : An argument passed to the command handler when the menu item selected.
- submenu : Submenu items of this menu item.
- type : Type of the menu item. One of the values
separator|checkbox. - position : Position of the menu item to be added. One of the values
first|last(default) |before|after. - relative-id : Relative menu item id for position
beforeandafter. If there is no menu item of the id, the menu item is not added.
If you want to add a separator:
{ "type": "separator" }The key binding of the command is shown in the menu item automatically (see Keymaps).
Adding menu items in existing menu items
Section titled “Adding menu items in existing menu items”You can add menu items to an existing menu such as File, Edit, Tools, etc.
We’re going to add two sub menu items under the existing Tools menu item. All menu items have unique ID. If id matches an existing id of menu item, submenu items will be added under the existing menu item.
{ "menu": [ { "id": "tools", "submenu": [ { "label": "Tool Sub Menu1", "id": "tools.submenu1", "command": "example:function1" }, { "label": "Tool Sub Menu2", "id": "tools.submenu2", "command": "example:function2", "position": "after", "relative-id": "tools.extension-manager" } ] } ]}The IDs of the top-level menus are file, edit, format, model, tools, view, window and help (and app in MacOS).
Changing states of menu items
Section titled “Changing states of menu items”Context Menu
Section titled “Context Menu”Adding menu items to context menus is basically same with application menu. One difference is that there is only one application menu, but there may be multiple context menus. So the context menus are defined in the menu JSON files as follow:
{ "context-menu": { "<context-menu-name1>": [], "<context-menu-name2>": [], ... }}There are three predefined context menus.
diagram-canvas: Diagram Areamodel-explorer: Model Explorerworking-diagrams: Working Diagrams
Adding menu items in a predefined context menu
Section titled “Adding menu items in a predefined context menu”We’re going to add a menu item to a predefined context menu of Diagram Area.
{ "context-menu": { "diagram-canvas": [ { "label": "Submenu1 for Diagram Area", "id": "example.submenu1", "command": "example:function1" } ] }}Click mouse right button on diagram area, you will see the added menu item in the context menu.
Adding a new context menu
Section titled “Adding a new context menu”StarUML 8 does not support adding a new context menu to other parts of the user interface (e.g. Statusbar). Menu items can be added only to the predefined context menus.