Main Content

Disable Simulink and Stateflow Toolstrip and Context Menu Actions

You can disable the actions of the default widgets in the Simulink® Toolstrip and Context Menus. Hiding widgets is not supported, but you can specify when custom context menu widgets are visible. See Customize Simulink Context Menu Using Extension Points for details. In Stateflow®, you can hide toolstrip and context menu widgets and disable widget actions.

To disable or hide widget actions, take these steps.

  1. Get the action name.

  2. Create or edit a customization file.

  3. Create a filter function that disables the action or hides the widget.

  4. Register the filter function with the customization manager.

  5. Refresh the Simulink customization file (sl_customization.m).

For example, this code creates and registers a filter function to disable the action of the New Model button in the Simulink Toolstrip.

function sl_customization(cm)
  cm.addCustomFilterFcn('createNewModelAction',@myFilter);
end

function state = myFilter(callbackInfo)
  state = 'Disabled';
end

Get Action Names

Get Names of Simulink Toolstrip or Context Menu Actions

To get the name of an action in the Simulink Toolstrip or context menus, enter developer mode using the slUIDeveloperMode function. Enter this command in the MATLAB® Command Window.

slUIDeveloperMode("on")

Pause on an item in the toolstrip or context menu and press Ctrl (on macOS, press command ⌘ instead). For example, right-click a block. In the context menu, pause on the Block Parameters button and press Ctrl.

Reusable PushButton Action: #mw.simulink.editor.parametersAction
Reusable PushButton Icon: mw.simulink.editor.icons.blockParameters
-------------------

When you have identified the names you need, exit developer mode.

slUIDeveloperMode("off")

Get Names of Stateflow Context Menu Actions

To get the name of an action in the Stateflow context menus, enter these commands in the MATLAB Command Window.

cm = sl_customization_manager;
cm.showWidgetIdAsToolTip = true;

In the context menu, the action name is in parentheses next to the menu item text. For example, the action name for the Update Diagram action in the context menu is Simulink:UpdateDiagram.

Note

Disabling, enabling, or hiding an action using this action name format is not supported for all actions.

When you finish looking up action names, stop displaying the action names in the context menu.

cm.showWidgetIdAsToolTip = false;

Create Customization File

To register customizations, create a MATLAB function file named sl_customization.m. Place the function file in the current folder or on the MATLAB path. The function input is a handle to the customization manager object (cm).

function sl_customization(cm)

You can have more than one sl_customization.m file. If you specify priorities for libraries in multiple sl_customization.m files, only one takes effect. If you have two sl_customization.m files that both add the same menu item, it appears twice. To ensure that customizations load as expected, refresh the customizations as described in Read and Refresh Customization Files.

For more information, see Register Customizations with Simulink.

Create Filter Functions

In the sl_customization.m file, create a filter function. Your filter function must accept a callback info object and return the state that you want to assign to the item. Valid states are:

  • 'Hidden' — Hide context menu action. For toolstrip items, 'Hidden' disables the actions of the item instead of hiding the item.

  • 'Disabled' — Disable the action.

  • 'Enabled' — Enable the action.

For example, this filter function assigns the 'Disabled' state.

function state = myFilter(callbackInfo)
  state = 'Disabled';
end

Your filter function may have to compete with other filter functions and with the software to assign a state to an item.

  • The 'Hidden' state overrides the 'Enabled' and 'Disabled' states.

  • The 'Disabled' state overrides the 'Enabled' state.

Register Filter Functions

Use the customization manager addCustomFilterFcn method to register a filter function. The addCustomFilterFcn method takes two arguments: a tag that identifies the action to be filtered and a pointer to the filter function itself.

For example, this code registers a filter function for the New Model item on the Simulink Toolstrip.

function sl_customization(cm)
  cm.addCustomFilterFcn('createNewModelAction',@myFilter);
end

Read and Refresh Customization Files

The software reads the sl_customization.m file when Simulink starts. If you change the sl_customization.m file, either restart Simulink or enter this command to see the changes.

sl_refresh_customizations

This command runs all sl_customization.m files on the MATLAB path and in the current folder. Running sl_refresh_customizations also results in these actions:

  • Rebuilding the Simulink Toolstrip

  • Rebuilding all Simulink Editor menus

  • Rebuilding the Library Browser menus and toolbars

  • Clearing the Library Browser cache and refreshing the Library Browser

  • Reloading the Viewers and Generators Manager data

See Also

Topics