|
| 1 | +--- |
| 2 | +title: "Migration Guide for Web Extensibility API Older Versions" |
| 3 | +linktitle: "Migration Guide" |
| 4 | +url: /apidocs-mxsdk/apidocs/web-extensibility-api-11/migration-guide/ |
| 5 | +weight: 2 |
| 6 | +--- |
| 7 | + |
| 8 | +## Introduction |
| 9 | + |
| 10 | +A breaking change was introduced in version 11.6 of the Extensibility API which changed the way [menus](/apidocs-mxsdk/apidocs/web-extensibility-api-11/menu/) are created. Here we will explain how to fix your extension code if you have upgraded to version 11.6 from an older version. |
| 11 | + |
| 12 | +## MenuItemActivated Event |
| 13 | +If your extension created menus using the `menuId` and the `menuItemActivated` event in order to trigger actions, you can now simply use the action that was called when the event was triggered as the actual `action` property of your menu. |
| 14 | + |
| 15 | +So if your code looked like this: |
| 16 | +```typescript |
| 17 | + |
| 18 | +const menuId = "myextension.menu"; |
| 19 | + |
| 20 | +await studioPro.ui.extensionsMenu.add({ |
| 21 | + menuId: menuId, |
| 22 | + caption: "My Menu", |
| 23 | + }); |
| 24 | + |
| 25 | +studioPro.ui.extensionsMenu.addEventListener( |
| 26 | + "menuItemActivated", |
| 27 | + async (args) => { |
| 28 | + if (args.menuId === menuId) { |
| 29 | + await studioPro.ui.messageBoxes.show("info", "My Menu was Clicked!") |
| 30 | + } |
| 31 | + } |
| 32 | +); |
| 33 | +``` |
| 34 | + |
| 35 | +The action called when the event triggers for your menu can now be used directly as the menu action: |
| 36 | + |
| 37 | +```typescript |
| 38 | +await studioPro.ui.extensionsMenu.add({ |
| 39 | + menuId: "myextension.menu", |
| 40 | + caption: "My Menu", |
| 41 | + action: async () => await studioPro.ui.messageBoxes.show("info", "My Menu was Clicked!") |
| 42 | + }); |
| 43 | +``` |
| 44 | + |
| 45 | +The `menuItemActivated` event no longer exist so you cannot listen to it anymore. |
| 46 | + |
| 47 | +## Registering Commands |
| 48 | +If your extension created menu by using a command id of a pre-registered command, the action that is sent to the command registration api when registering the command can now be used directly as the action of the menu. |
| 49 | + |
| 50 | +So if your code looked like this: |
| 51 | +```typescript |
| 52 | +const commandId = "myextension.menu-command"; |
| 53 | + |
| 54 | +await studioPro.app.commands.registerCommand( |
| 55 | + commandId, |
| 56 | + async () => await studioPro.ui.messageBoxes.show("info", "My Menu was Clicked!") |
| 57 | +); |
| 58 | +await studioPro.ui.extensionsMenu.add({ caption: "My Menu", menuId: "myextension.menu", commandId }); |
| 59 | +``` |
| 60 | + |
| 61 | +The same action sent to the command registration api can now instead become the `action` property value on the menu: |
| 62 | + |
| 63 | +```typescript |
| 64 | +await studioPro.ui.extensionsMenu.add({ |
| 65 | + menuId: "myextension.menu", |
| 66 | + caption: "My Menu", |
| 67 | + action: async () => await studioPro.ui.messageBoxes.show("info", "My Menu was Clicked!") |
| 68 | + }); |
| 69 | +``` |
| 70 | + |
| 71 | +The command registration API has also been removed and it is no longer available. |
| 72 | + |
| 73 | +# Action Arguments |
| 74 | +Action arguments are also possible in the new Menu API. Please read our [menus documentation](/apidocs-mxsdk/apidocs/web-extensibility-api-11/menu/) for an in-depth explanation. |
0 commit comments