You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos/menu-api.md
This how-to shows you how to create both a simple menu item and a menu item with subsidiary items beneath it using the web extension API.
9
+
This how-to describes how to create menus using the web extensibility API. In this example, you will:
10
+
11
+
* Create a simple menu item
12
+
* Add menu items with sub-menus
13
+
* Update a menu
10
14
11
15
## Prerequisites
12
16
13
-
This how-to uses the results of [Get Started with the Web Extensibility API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/getting-started/). Please complete that how-to before starting this one.
17
+
This how-to uses the results of [Get Started with the Web Extensibility API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/getting-started/). Make sure to complete that how-to before starting this one.
14
18
15
-
## Creating a Simple Menu
19
+
## Menu Properties
16
20
17
-
In this section, you will add a simple menu to your extension.
*`menuApi` from `studioPro.ui.extensionsMenu` to allow you to use the menu API
62
-
*`messageBoxApi` from `studioPro.ui.messageBoxes` to show a dialog.
79
+
When this code is added, it does the following:
63
80
64
-
It starts listening to the `menuItemActivated` endpoint which will notify the extension when **My First Menu** is clicked.
65
-
66
-
The `menuItemActivated` listener event handles the actual function of the menu. The arguments `args` contain the data returned by Studio Pro to the extension, notifying it which menu item was activated (clicked). This is passed as the `menuId` that was used when creating the menu item and the `menuId` in the `if` statement is used to identify this. In this example it is `"my-menu-unique-id"` and the handler calls the `messageBoxApi` to show an information dialog.
81
+
1. Studio Pro starts listening to the `menuItemActivated` endpoint. This notifies the extension when **My First Menu** is clicked.
82
+
2. The `args` parameter contains the information sent from Studio Pro to the extension, indicating which menu item was clicked.
83
+
3. The listener checks if the clicked `menuId` matches your defined ID. If it does, it calls `messageBoxApi.show()`.
84
+
4. Studio Pro displays an information dialog with the message you provided.
You can also have a number of submenus that branch out your menu.
92
+
You can also include multiple sub-menus to expand your menu structure.
88
93
89
-
To do so, add additional menu items to your code and add these to the `subMenus` array for the relevant menu item. These child menus can in turn have their own submenus, and so on. Only parent menus (menus that are not submenus to any others) should be added through the `await menuApi.add()` call, as shown in the code sample below.
94
+
To do this, add additional menu items to your code and add them to the `subMenus` array for the relevant menu item. These child menus can have their own sub-menus, and so on. Only parent menus (menus that are not sub-menus to any others) should be added through the `await menuApi.add()` call, as shown in the code sample below.
90
95
91
96
{{% alert color="info" %}}
92
-
Parent menus (with `subMenus`) do not create `menuItemActivated` events. These only get sent when a leaf menu (a menu that does not have any submenus) is clicked.
97
+
Parent menus (with `subMenus`) do not create `menuItemActivated` events. These are only sent when a leaf menu (a menu that does not have any sub-menus) is clicked.
93
98
{{% /alert %}}
94
99
95
-
The following `src/main/index.ts` generates one menu item with submenus and one menu item without submenus.
100
+
The following `src/main/index.ts` generates one menu item with sub-menus, and one menu item without sub-menus.
Sometimes you might want to disable a menu or update its caption depending on a condition. You can do so by calling the menu API's `updateMenu` method.
156
+
You can disable a menu or update its caption, depending on a condition. You can do this by calling the menu API's `updateMenu` method.
152
157
153
-
An example is shown in the code below. If you click on the menu item, it will be disabled and its caption will be updated.
158
+
An example is shown in the code below. If you click the menu item, it will be disabled and its caption will be updated.
Instead of listening to the `menuItemActivated` event, it is possible to register a command, then attach the `commandId` of the new command to your menu. When the menu is clicked, if its `commandId` property has been set, the backend will execute the command instead of firing the `menuItemActivated` event.
201
206
202
-
For a full explanation on how to register commands, see the [Commands API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/command-api/).
203
-
204
-
## Conclusion
205
-
206
-
You have seen how to create simple menu items and menu items with sub menus.
207
-
You can also dynamically change the enabled status and caption of a menu item.
207
+
For more information on how to register commands, see the [Commands API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/command-api/).
208
208
209
209
## Extensibility Feedback
210
210
211
-
If you would like to provide us with some additional feedback you can complete a small [Survey](https://survey.alchemer.eu/s3/90801191/Extensibility-Feedback)
211
+
If you would like to provide additional feedback, you can complete a small [survey](https://survey.alchemer.eu/s3/90801191/Extensibility-Feedback).
0 commit comments