Take the 2-minute tour ×

In my RCP application I have two types of editors (one is for *.xsd files and second for other text files). I have added new element to main menu and I want to show it only when xsd editor is active, when other editor is active it should be invisible (In Eclipse 'Refactor' option is visible when open is java file and invisible when open is xml file). How to make visible/invisible element in main menu depends of editor type?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Have a look at the org.eclipse.ui.menus extension point, specifically the visibleWhen element. You can add commands to the main menu sub-menus and make them visible when the activeEditorId == your editor id.

   <with variable="activeEditorId">
      <equals value="org.eclipse.example.my.editor"/>

See also Core Expressions.

share|improve this answer
org.eclipse.example.my.editor is editor id or qualified class name? –  Janusz Lece Jul 26 '12 at 14:14
the editor ID as defined in the org.eclipse.ui.editors extension. –  Paul Webster Jul 26 '12 at 16:08

As far as I know you can't alter the visibility of a menu item. What you have to do is not add the item in the first place, depending on that editor is active. If you can post your code as to how you added your menu item (since there are multiple ways to do this), I could help you further about exactly how to check.

share|improve this answer

If there is no active handler for the menu item's command, the item won't appear in your menu.

Have a look at this question for an example of using activeWhen to control the availability of a command in a menu based on the current selection.

share|improve this answer

Your Answer


