Main Content

mw.desktop.fileBrowsers.contextMenu Extension Point

Add items to Files panel context menu

Since R2025a

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

Files panel context menu with a custom section at the bottom containing the custom item Item 1

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 sections in a "sections" array within the extension point. Define custom menu items in an "items" array within the "sections" array.

  3. Add the folder containing the resources folder with the extensions.json file 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.fileBrowsers.contextMenu extension point.

{
    "mw.desktop.fileBrowsers.contextMenu": {
        "sections": [
            {
                "name": "myToolbox.myCustomSection",
                "type": "SimpleMenuSection",
                "items": [
                    {
                        "name": "myToolbox.myItem1",
                        "type": "SimpleMenuItem",
                        "when": "selection.isEmpty",
                        "action": {
                            "name": "myToolbox.myItem1Action",
                            "type": "Action",
                            "text": "Item 1",
                            "icon": "icons/myMenuItemIcon.svg",
                            "callback": "displayFileAttributes"
                        }
                    }
                ]
            }
        ]
    }
}

For more information about using extension points, see Extend MATLAB Using Extension Points.

Properties

expand all

"sections" Array Object Properties

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

Type of section to add, specified as "SimpleMenuSection".

Menu items, specified as an array of menu item objects.

For more information about the properties of a menu item object, see "items" Array Object Properties.

Example:

"items": [
    {
        "name": "myToolbox.myItem1",
        "type": "SimpleMenuItem",
        "when": "selection.isEmpty",
        "action": {
            "name": "myToolbox.myItem1Action",
            "type": "Action",
            "text": "Item 1",
            "icon": "icons/myMenuItemIcon.svg",
            "callback": "displayFileAttributes"
        }
    }
]

"items" Array Object Properties

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

Type of item to add, specified as "SimpleMenuItem".

When the menu item is visible in the context menu, specified as the following values. If you do not specify when, the menu item is always visible.

  • "selection.isEmpty" — Show the menu item if there is no selection in the Files panel.

  • "selection.isMultiSelect" — Show the menu item if there are multiple files selected in the Files panel.

  • "selection.containsFiles" — Show the menu item if one or more files are selected in the Files panel.

  • "selection.containsFolders" — Show the menu item if one or more folders are selected in the Files panel.

  • "selection.containsFileType.filetype" — Show the menu item if one or more files of type filetype are selected in the Files panel. Specify filetype as the extension of the file type. For example, to show the menu item only if one or more files with a .txt extension are selected, specify when as "selection.containsFileType.txt".

You also can use the ! logical operator to specify the inverse of the value. For example, to show the menu item if there is a selection in the Files panel, specify when as "!selection.isEmpty".

To specify more than one value, use the && and || logical operators. For example, to show the menu item if one or more files or folders are selected, specify when as "selection.containsFiles || selection.containsFolders". To show the menu item if one or more files and folders are selected, specify when as "selection.containsFiles && selection.containsFolders".

This property is optional.

Menu item action, specified as an "action" object.

For more information about the properties of an "action" object, see "action" Object Properties.

Example:

"action": {
    "name": "myToolbox.myItem1Action",
    "type": "Action",
    "text": "Item 1",
    "description": "Item 1 tooltip",
    "icon": "icons/myMenuItem1Icon.png",
    "callback": "displayFileAttributes"
}

Submenu, specified as a "popup" object. Place the "popup" object inside the "items" array object that you want to attach the submenu to.

For more information about the properties of a "popup" object, see "popup" Object Properties.

This property is optional.

Example:

"items": [
    {
        ...
        "popup": {
            "name": "myToolbox.myToolboxPopupMenu",
            "type": "SimpleMenu",
            "sections": [
                {
                    "name": "myToolbox.mySubmenuSection",
                    "type": "SimpleMenuSection",
                    "items": [
                        {
                            "name": "myToolbox.mySubmenuItem1",
                            "type": "MenuItem",
                            "action": {
                                "type": "Action",
                                "name": "myToolbox.mySubmenuItem1Action",
                                "text": "Submenu Item 1",
                                "callback": "mySubmenuItem1Function"
                            }
                        }
                    ]
                }
            ]
        }
    }
]

Files panel context menu with a custom section at the bottom containing the custom item Item 1 and the custom submenu item Submenu Item 1

"action" Object Properties

Unique identifier for the action, specified as a JSON string.

Object type, specified as "Action".

Menu item display text, specified as a JSON string.

Menu item tooltip text, specified as a JSON string.

This property is optional.

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.

This property is optional.

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

This property is optional.

"popup" Object Properties

Unique identifier for the submenu, specified as a JSON string.

Object type, specified as "SimpleMenu".

Submenu sections, specified as a "sections" array.

For more information about the properties of a "sections" array, see "sections" Array Object Properties.

More About

expand all

Version History

Introduced in R2025a