The previous section showed how to hide or show a specific keybinding depending on the open editor type. However, it doesn't stop the command being called via the menu, or from it showing up in the menu itself. Instead of just hiding the keybinding, the menu can be hidden as well by adding a visibleWhen
block to the command.
The expressions framework provides a number of variables, including activeContexts
, which contains a list of the active contexts at the time. Since many contexts can be active simultaneously, the active contexts is a list (for example, [dialogAndWindows,windows
, textEditor,javaEditor]
). So, to find an entry (in effect, a contains
operation) an iterate
operator with the equals
expression is used.
Open up the
plugin.xml
file, and update the theHello
command by adding avisibleWhen
expression.<extension point="org.eclipse.ui.menus"> <menuContribution allPopups="false" locationURI="menu:help?after=additions...