1

I have a menu item in my Eclipse IDE which is want to disable/non-visible if an editor is not currently open.

In the plugin.xml I can use the visibleWhen code to achieve that, however I don't know how to check if an editor is currently open or not.

This thread talks about a listener to track the editor. However there should be a simpler way to find the editor. For example with page.getEditorReferences(). However I can't seem to put all of it together.

So how to poll if the editor is open from the plugin.xml?

Community
  • 1
  • 1
2c00L
  • 495
  • 12
  • 29

1 Answers1

3

This is what the Ant editor uses.

First an org.eclipse.core.expressions.definitions definition:

<extension
       point="org.eclipse.core.expressions.definitions">
    <definition
          id="org.eclipse.ant.ui.activeAntEditor">
       <with
             variable="activeEditorId">
          <equals
                value="org.eclipse.ant.ui.internal.editor.AntEditor">
          </equals>
       </with>
    </definition>
</extension>

which defines an expression called org.eclipse.ant.ui.activeAntEditor which tests if the active editor is the Ant editor.

Then each menu command entry which wants to be visible when the editor is active uses:

<command
     commandId="org.eclipse.ant.ui.open.declaration.command"
     style="push">
   <visibleWhen
         checkEnabled="false">
     <reference
            definitionId="org.eclipse.ant.ui.activeAntEditor">
     </reference>
   </visibleWhen>
</command>

which references the org.eclipse.ant.ui.activeAntEditor expression to do the visibility test.

greg-449
  • 109,219
  • 232
  • 102
  • 145