Disable Simulink Toolstrip and Context Menu Actions
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:
Get the name of the built-in action that you want to disable or hide.
Create or edit a customization file.
Create a filter function that disables or hides the item.
Register the filter function with the customization manager.
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 the
slToolstripDeveloperMode
function.
In the MATLAB® Command Window, enter this command.
slToolstripDeveloperMode('on')
ans = logical 0
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 of Ctrl.
For example, pause on the Open button and press Ctrl.
Action: openModelAction Icon: open -------------------
To exit developer mode, enter this command.
slToolstripDeveloperMode('off')
ans = logical 1
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:
'Hidden'
— Hide the action.'Disabled'
— Disable the action. If the action is hidden in the context menu, in addition to disabling the action, this state shows the action in the context menu.'Enabled'
— Enable the action. If the action is hidden in the context menu, in addition to enabling the action, this state shows the action in the context menu.
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.
'Hidden'
is the strongest state. If any filter function or Simulink assigns'Hidden'
to a menu item, it is hidden. For Simulink Toolstrip items, specifying'Hidden'
disables the item instead of hiding it.'Disabled'
overrides'Enabled'
, but is itself overridden by'Hidden'
.'Enabled'
is the weakest state. For an item to be enabled, all filter functions and the Simulink or Stateflow® products must assign'Enabled'
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 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