Contenuto principale

Simulink® Context Menu Filter

R2026b

Disable widget actions or hide context menu widgets

Since R2026b

You can disable context menu widget actions and hide widgets. When you disable an action, the widgets that take the action remain visible but are dimmed and non-interactive. When you hide a widget, the context menu no longer displays it. You can hide specific widgets, or you can hide all widgets that take certain actions.

To disable widget actions or hide widgets, you define a filter in a JSON file. This page describes how to write the JSON declarations that define the filter.

Implement your customization with these steps.

  1. Decide which actions to disable and which widgets to hide. To learn about the widgets the context menu contains, see Simulink Context Menu Architecture.

  2. Create a folder named resources. In the folder, create a JSON-formatted file named extensions.json. You can create more than one extensions.json file, as long as they are in different resources folders.

  3. Add this template to the file.

    {
        "mw.studio.filters.<Filter Name>": 
        {
            "type": "Filter",
            "elements": 
            [
              <widget or action 1>,
              <widget or action 2>,
              <widget or action 3>,
              ...
              <widget or action N>
            ],
            "hideActions": <true or false>,
            "when": "<condition>"
        }
    }

    To learn how to fill in this template, see the Examples and Properties on this page.

    Code formatting mistakes such as missing brackets or incorrect line indentation can prevent your customizations from rendering as expected. To avoid formatting mistakes, consider writing the declarations in an integrated development environment (IDE) equipped to help you format code, for example, Visual Studio® Code.

  4. Enable your customizations. Add the parent folder of the resources folder to the MATLAB® path using the addpath function. Alternatively, right-click the folder in the Files panel and select Add to Path > Selected Folder(s) and Subfolders. Then, refresh the customizations using the slReloadStudioConfig function.

For more information about using extension points, see Customize Simulink Context Menu Using Extension Points.

Examples

expand all

In this example, you write the JSON declarations for disabling the action the Run button takes and hiding the Comment Out, Comment Through, and Uncomment buttons.

To disable an action, you need the action name. To hide a widget, you need the extension point name. To get the names you need, enter developer mode.

slUIDeveloperMode("on")

Open a Simulink model. In the model, add a Constant block. Right-click the block. Press Ctrl (command (⌘) on macOS) and pause your pointer on the Run button. The MATLAB Command Window displays the widget action and extension point names. Repeat this step for the Comment Out, Comment Through, and Uncomment buttons. The information you need is now in the Command Window.

Verify that each widget you want to hide and each action you want to disable is marked as a filterable element. If a widget or action is not marked as filterable, you cannot hide the widget or disable the action.

ButtonType of NameNameFilterable
RunActionmw.simulink.editor.runActionYes
Comment OutExtension Point mw.simulink.editor.commentOutToggleButtonYes
Comment ThroughExtension Pointmw.simulink.editor.commentThroughToggleButtonYes
UncommentExtension Pointmw.simulink.editor.uncommentPushButtonYes

In your extensions.json file, paste this filter template.

{
    "mw.studio.filters.<Filter Name>": 
    {
        "type": "Filter",
        "elements": 
        [
          <widget or action 1>,
          <widget or action 2>,
          <widget or action 3>,
          ...
          <widget or action N>
        ],
        "hideActions": <true or false>,
        "when": "<condition>"
    }
}

Name the filter. In the JSON array literal key, replace <Filter Name>.

{
  "mw.studio.filters.myFilter":
  {
    "type": "Filter",
    "elements":
    [
    ...

Set the elements property value to the names you obtained in developer mode, specified as comma-separated strings. The order does not matter.

{
    "mw.studio.filters.myFilter": 
    {
        "type": "Filter",
        "elements": 
        [
            "mw.simulink.editor.runAction",
            "mw.simulink.editor.commentOutToggleButton",
            "mw.simulink.editor.commentThroughToggleButton",
            "mw.simulink.editor.uncommentPushButton"
        ],
        "hideActions": <true or false>,
        "when": "<condition>"
    }
}

The hideActions property lets you hide all widgets that take a specified action. In this example, the goal is to disable the specified action, not to hide all the widgets taking that action. Therefore, set this property to false.

Then, set the filter to always apply by deleting the when value and the comma at the end of the preceding line. The when property lets you limit when to apply the filter, for example, to only apply the filter to the context menu that opens when you right-click a block. If you do not specify a value, the filter always applies.

{
    "mw.studio.filters.myFilter":
    {
        "type": "Filter",
        "elements":
        [
            "mw.simulink.editor.runAction",
            "mw.simulink.editor.commentOutToggleButton",
            "mw.simulink.editor.commentThroughToggleButton",
            "mw.simulink.editor.uncommentPushButton"
        ],
        "hideActions": false
    }
}

In this example, you write the JSON declarations for disabling the actions named mw.simulink.editor.createSubsystemAction and mw.simulink.editor.editMaskAction, and hiding all widgets that take these actions.

In your extensions.json file, paste this filter template.

{
    "mw.studio.filters.<Filter Name>": 
    {
        "type": "Filter",
        "elements": 
        [
          <widget or action 1>,
          <widget or action 2>,
          <widget or action 3>,
          ...
          <widget or action N>
        ],
        "hideActions": <true or false>,
        "when": "<condition>"
    }
}

Name the filter. In the JSON array literal key, replace <Filter Name>.

{
  "mw.studio.filters.myFilter":
  {
    "type": "Filter",
    "elements":
    [
    ...

Set the elements property value to the action names, specified as comma-separated strings.

{
    "mw.studio.filters.myFilter": 
    {
        "type": "Filter",
        "elements": 
        [
          "mw.simulink.editor.createSubsystemAction",
          "mw.simulink.editor.editMaskAction"
        ],
        "hideActions": <true or false>,
        "when": "<condition>"
    }
}

To hide all widgets that take the specified actions, set the hideActions property value to true.

Then, set the filter to always apply by deleting the when value and the comma at the end of the preceding line. The when property lets you limit when to apply the filter, for example, to only apply the filter to the context menu that opens when you right-click a block. If you do not specify a value, the filter always applies.

{
    "mw.studio.filters.myFilter":
    {
        "type": "Filter",
        "elements":
        [
          "mw.simulink.editor.createSubsystemAction",
          "mw.simulink.editor.editMaskAction"
        ],
        "hideActions": true
    }
}

In this example, you write the JSON declarations for disabling the action named mw.simulink.editor.openBlockInNewWindowAction in the Triggered Subsystem block context menu.

In your extensions.json file, paste this filter template.

{
    "mw.studio.filters.<Filter Name>": 
    {
        "type": "Filter",
        "elements": 
        [
          <widget or action 1>,
          <widget or action 2>,
          <widget or action 3>,
          ...
          <widget or action N>
        ],
        "hideActions": <true or false>,
        "when": "<condition>"
    }
}

Name the filter. In the JSON array literal key, replace <Filter Name>.

{
  "mw.studio.filters.myFilter":
  {
    "type": "Filter",
    "elements":
    [
    ...

Set the elements property value to the action name, specified as a string.

{
    "mw.studio.filters.myFilter": 
    {
        "type": "Filter",
        "elements": ["mw.simulink.editor.openBlockInNewWindowAction"],
        "hideActions": <true or false>,
        "when": "<condition>"
    }
}

The hideActions property lets you hide all widgets that take a particular action. In this example, the goal is to disable the specified action, not to hide all the widgets taking that action. Set the hideActions property value to false.

To limit the disabling of the action to the Triggered Subsystem block context menu, set the when property value to "selection.isTriggered".

{
    "mw.studio.filters.myFilter": 
    {
        "type": "Filter",
        "elements": ["mw.simulink.editor.openBlockInNewWindowAction"],
        "hideActions": false,
        "when": "selection.isTriggered"
    }
}

Properties

expand all

List of actions to disable and widgets to hide, specified as a string array.

To disable an action, you need the action name. To hide a widget, you need the extension point name. To get the names you need, enter developer mode.

slUIDeveloperMode("on")

Open the context menu containing the widget you want to hide or whose action you want to disable. Press Ctrl (command (⌘) on macOS) and pause your pointer on the widget. The MATLAB Command Window displays the widget action and extension point names.

Verify that each widget you want to hide and each action you want to disable is marked as a filterable element. If a widget or action is not marked as filterable, you cannot hide the widget or disable the action.

To hide all widgets that take the actions you specify in the filter, set this property value to true.

If you do not specify a value for the when property, the filter is always implemented. To implement the filter only when a certain condition is true, set the when property value to the programmatic name of the condition, specified as a JSON string. To combine conditions, set the value to an expression using the programmatic names of the conditions and logical operators, specified as a single JSON string.

The tables list the programmatic names of the conditions you can specify. Some conditions pertain to block parameter values. To get the value of a block parameter, use the get_param function.

Block Selection

When Condition Is TrueCondition
The current selection is a block."selection.isAnyBlock"
The current selection is a block of a type you specify.

"selection.is<BlockType>"

For example:

"selection.isGain"

The current selection is a masked block."selection.isMasked"
The current selection is a block that is linked to a library."selection.isLibraryLink"
The current selection contains only blocks whose Commented parameter has a value you specify, for example, the value 'on'.

"selection.Commented == <value>"

For example:

"selection.Commented == 'on'"

The current selection is a block whose Name parameter has a value you specify, for example, the value 'myGain'.

"selection.Name == <value>"

For example:

"selection.Name == 'Gain'"

Subsystem Block Selection

When Condition Is TrueCondition
The current selection is a type of subsystem block you specify, for example, a Resettable Subsystem block.
  • "selection.isAction"

  • "selection.isArrayProcessing"

  • "selection.isEnabled"

  • "selection.isEnabledAndTriggered"

  • "selection.isForEach"

  • "selection.isForIterator"

  • "selection.isFunctionCall"

  • "selection.isNeighborhoodProcessing"

  • "selection.isPixelProcessing"

  • "selection.isReferenced"

  • "selection.isResettable"

  • "selection.isSimulinkFunction"

  • "selection.isTriggered"

  • "selection.isWhileIterator"

The current selection is a virtual subsystem."selection.isVirtual"
The current selection is a Subsystem block whose Permissions parameter has a value you specify, for example, the value 'ReadOnly'.

"selection.Permissions == <value>"

For example:

"selection.Permissions == 'ReadOnly'"

The current selection is a Subsystem block whose ShowPortLabels parameter has a value you specify, for example, the value 'FromPortIcon'.

"selection.ShowPortLabels == <value>"

For example:

"selection.ShowPortLabels == 'FromPortIcon'"

Selecting Multiple Model Elements

When Condition Is TrueCondition
The current selection contains more than one model element."selection.isMultiselect"

Selecting Model Canvas

When Condition Is TrueCondition
The current selection is the model canvas."selection.isEmpty"

Editor

When Condition Is TrueCondition
The editor shows the root model. For example, if you add a subsystem to a blank model, the condition is true when the editor shows the model and false when the editor shows the subsystem."editor.isRoot"
The editor shows the top model. For example, if you add a model reference to a blank model, the condition is true when the editor shows the model and false when the editor shows the referenced model."editor.inTopModel"
The editor shows a referenced model."editor.inRefModel"
The editor shows a referenced subsystem."editor.inRefSubsystem"
The editor shows a type of subsystem you specify.
  • "editor.isAction"

  • "editor.isArrayProcessing"

  • "editor.isAtomic"

  • "editor.isEnabled"

  • "editor.isForIterator"

  • "editor.isForEach"

  • "editor.isFunctionCall"

  • "editor.isNeighborhoodProcessing"

  • "editor.isPixelProcessing"

  • "editor.isResettable"

  • "editor.isSimulinkFunction"

  • "editor.isTriggered"

  • "editor.isVirtual"

  • "editor.isWhileIterator"

Model

When Condition Is TrueCondition
The top model of the current system is a model, as opposed to a library model or a subsystem model."model.isModel"
The top model of the current system is a library model."model.isLibrary"
The top model of the current system is a subsystem model."model.isSubsystem"
The top model of the current system is a test harness model."model.isTestHarness"

Example: "selection.isConstant || selection.isMasked" is true when the selection is a Constant block or a masked block.

Version History

Introduced in R2026b