Disable Simulink Toolstrip and Context Menu Actions - MATLAB & Simulink (original) (raw)

You can disable actions that appear in the Simulink® Toolstrip and context menus. For context menus, you can also hide actions. To disable or hide an action, you must:

  1. Get the name of the built-in action that you want to disable or hide.
  2. Create or edit a customization file.
  3. Create a filter function that disables or hides the item.
  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 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

Determine Which Action Name Format to Use

You can specify the action name in two different formats: as the toolstrip action name, or as the context menu action name. Use the table to decide which format to use based on the task you want to accomplish.

Task Action Name Format
Disable or enable an action only in the toolstrip.If you previously hid the action in the context menu, this workflow unhides the option. Toolstrip action name
Disable or enable an action in both the toolstrip and the context menu.If you previously hid the action in the context menu, this workflow unhides the option. Context menu action name
Hide an action in the context menu.Hiding an action in the context menu disables the action in the toolstrip. Context menu action name

Get Toolstrip Action Names

To get the toolstrip action name, use theslToolstripDeveloperMode function.

In the MATLAB® Command Window, enter this command.

slToolstripDeveloperMode('on')

The command enables developer mode for the Simulink Toolstrip. The returned value indicates that developer mode was disabled before you entered the command.

You can view the toolstrip action name and corresponding icon in the MATLAB Command Window. Pause on an item in the Simulink Toolstrip and press Ctrl. On a Mac, press command (⌘) instead ofCtrl.

For example, pause on the Open button and pressCtrl.

Action: openModelAction Icon: open

To exit developer mode, enter this command.

slToolstripDeveloperMode('off')

Get Context Menu Action Names

To get the context menu action name, enter these commands in the MATLAB Command Window.

cm = sl_customization_manager; cm.showWidgetIdAsToolTip = true;

Then, open the context menu and find the action you want to disable. The action name is in parentheses next to the option text.

For example, to hide the Update Diagram action in the context menu, specify this action name:Simulink:UpdateDiagram.

Note

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

Once you have the context menu action name, enter this command to hide the action names in the context menu.

cm.showWidgetIdAsToolTip = false;

Create Customization File

To register customizations, use a MATLAB function file named sl_customization.m. Place the function file on the MATLAB path of the Simulink installation that you want to customize, or, place the file in the current folder.

You can have more than one sl_customization.m file. The customizations in each file take effect, with conflicts handled by each customization. For example, if you specify priorities for libraries in multiple sl_customization.m files, only one takes effect. If you add the same menu item twice, it appears twice. To ensure that customizations load as expected, refresh the customizations as described in Read and Refresh Customization Files.

The sl_customization function accepts one argument: a handle to the customization manager object (cm).

function sl_customization(cm)

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:

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 Simulink to assign a state to an item. Which one succeeds depends on the strength of the state that each assigns to the item.

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 menu or item to be filtered and a pointer to the filter function itself.

For example, this code registers a filter function for the 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. Runningsl_refresh_customizations also results in these actions:

See Also

Topics