Main Content

Disable and Hide Widgets in the Simulink and Stateflow Toolstrips and Context Menus

R2026b

In Simulink®, you can disable the actions of the default widgets in the toolstrip and context menus. Hiding context menu 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 the widgets in the toolstrip and context menus and disable their actions.

To disable Simulink context menu widgets, use the Simulink Context Menu Filter object.

To disable or hide Simulink Toolstrip widgets and to disable or hide Stateflow widgets, take these steps.

  1. Get the action name.

  2. Create or edit a customization file named sl_customization.m.

  3. Register and define filter functions that specify which widgets to disable and hide.

  4. Refresh the customization file.

Get Action Names

Get Toolstrip Action Names

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

slUIDeveloperMode("on")

Pause on an item in the toolstrip and press Ctrl (on macOS, press command ⌘ instead). For example, pause on the Run button and press Ctrl.

Reusable Action: playSimulationAction
Reusable Icon: play
-------------------

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 a Stateflow context menu action, enter these commands In the MATLAB Command Window.

cm = sl_customization_manager;
cm.showWidgetIdAsToolTip = true;

In the context menu, the action name is now in parentheses next to the menu item text. Take note of this name for the widgets you want to disable or hide. 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.

Register and Define Filter Functions

In the sl_customization.m file, register and define a filter functions that specify which widgets to disable and hide. The registration must precede the definition.

For example, this code registers and defines a filter function that disables the New Model button in the Simulink Toolstrip.

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

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

The addCustomFilterFcn function registers the customization. The addCustomFilterFcn function has two arguments:a tag that identifies the action to filter and a pointer to the filter function.

The filter function accepts a callback info object and returns the state that you want the filter to assign. 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.

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.

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

Objects

Topics