Search code examples
eclipseeclipse-rcpperspective

Eclipse RCP: Command visibleWhen for a dynamic List of Perspectives


I know I can make a Command visible in a menu for a certain perspective by specifying a visibleWhen element in the plugin XML:

<visibleWhen checkEnabled="false">
    <with variable="activeWorkbenchWindow.activePerspective">
        <equals value="myperspective"/>
    </with>
</visibleWhen>

But how can I make a Command visible for a list of perspectives? Moreover, can I use regular expressions or wildmarks to match a group of perspectives that might be added dynamically?

Alternatively, how can I use the visibleWhen element to hide the Command for a certain perspective?


Solution

  • You can use the <or> element:

    <with variable="activeWorkbenchWindow.activePerspective">
      <or>
        <equals value="myperspective"/>
        <equals value="myperspective2"/>
        .... more
      </or>
    </with>
    

    There is also <not> which can be used to exclude something.

    There is no regular expression or wild card match. You could perhaps write a property tester using the org.eclipse.core.expressions.propertyTesters to do a match.