Main Content

mw.desktop.fileBrowser.contextMenu Extension Point (Beta)

Add items to Files panel context menu

Since R2024b

Note

Extension points are available only as part of the new desktop for MATLAB®. The new desktop for MATLAB is in beta development and should not be used for development or production activities. For more information, see Get Started with the New Desktop for MATLAB (Beta).

You can add items to the Files panel context menu using the mw.desktop.fileBrowser.contextMenu extension point.

To add items to the Files panel context menu:

  1. Create a JSON-formatted file named extensions.json and place it in a folder named resources.

  2. Add a set of JSON declarations to extensions.json that defines one or more context menu items. Define custom items in an "items" array within the "customSection" property of the extension point.

  3. Add the folder containing the resources folder to the MATLAB path. To add the folder to the path, use the addpath function or right-click the folder in the Files panel and select Add to Path > Selected Folders and Subfolders.

This JSON code shows the basic structure of the mw.desktop.fileBrowser.contextMenu extension point.

{
    "mw.desktop.fileBrowser.contextMenu": {
        "customSection": {
            "items": [
            {
                "name": "myMenuItem",
                "type": "MenuItem",
                "text": "Item 1",
                "description": "My menu item tooltip",
                "icon": "./myMenuItemIcon.png",
                "command": "myMenuItemFunction"
            },
            {
                "name": "myPopupMenuItem",
                "type": "PopupMenuItem",
                "text": "Item 2",
                "icon": "./myPopupMenuItemIcon.svg",
                "popup": {
                    "type": "Menu",
                    "name": "mySubmenu",
                    "items": [
                        {
                            "type": "MenuItem",
                            "name": "mySubmenuItem1",
                            "text": "Submenu Item 1",
                            "icon": "./mySubmenuItemIcon.svg",
                            "command": "mySubmenuItemFunction"
                        }]
                }
            }]
         }
     }
}

When you add items to the Files panel context menu, they appear a custom section at the bottom of the menu.

Files panel context menu with a custom section at the bottom containing the Open in Custom App item

For more information about using extension points, see Extend MATLAB Using Extension Points (Beta)

Properties

expand all

Required Properties

Unique identifier for the menu item, specified as a JSON string.

Type of item to add to the context menu, specified as one of these values:

  • "MenuItem" — Menu item that runs a specified command when clicked.

  • "PopupMenuItem" — Menu item that opens a submenu when clicked.

Menu item text, specified as a JSON string.

Menu item icon, specified as a JSON string. Specify icon as the path to a PNG, SVG, or JPG icon. The path must be relative to extensions.json.

Example: "icon": ".\icon.png"

User-defined MATLAB function to run when you click the menu item, specified as a JSON string. For more information on defining the MATLAB function, see Create User-Defined MATLAB Function.

Submenu item, specified as an object with these properties:

  • type — Submenu type. Supported types include "Menu".

  • name — Submenu name. For more information see name.

  • items — Array of items in submenu. Define each submenu item in the items array by specifying the name, type, text, icon, and command properties. For example:

    "items": [
      {
         "type": "MenuItem",
         "name": "mySubmenuItem1",
          "text": "Submenu Item 1",
          "icon": "./mySubmenuItem1Icon.svg", 
          "command": "mySubmenuItem1Function"
      },
      {
         "type": "MenuItem",
         "name": "mySubmenuItem2",
          "text": "Submenu Item 2",
          "icon": "./mySubmenuItem2Icon.svg", 
          "command": "mySubmenuItem2Function"
      }]

Optional Properties

Menu item tooltip, specified as a JSON string.

More About

expand all

Version History

Introduced in R2024b