Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[pde-dev] Dynamically changing state of menus and toolbuttons

Hi,

I've added a menu item and toolbutton in my plugin.  What I want is
that the menu (and the toolbutton) be available only when a certain
file type is open in the workbench window.

Below is the snippet from plugin.xml

<extension
     point="org.eclipse.ui.actionSets">
  <actionSet
        label="My action set"
        visible="true"
        id="com.plugin.test.my.actionSet">
      <menu
             label="Plugin Menu"
             id="PluginMenu">
          <separator
                name="PluginMenuGroup">
          </separator>
      </menu>
      <action>
             label="Command menu"
             tooltip="This is my command menu"
             class="com.plugin.test.my.action.ExecuteDelegate"
             menubarPath="PluginMenu/PluginMenuGroup"
             toolbarPath="PluginMenuGroup"
             id="com.plugin.test.my.action.Execute">
          <enablement>
                <and>
                   <objectClass name="org.eclipse.core.resources.IFile"/>
                   <objectState name="extension" value="foobar"/>
                </and>
          </enablement>
      </action>
  </actionSet>
</extension>


Upon running the plugin, the behavior is:

- Until no file with extension .foobar is opened in the workbench
window, the added toolbutton and menu item remain disabled as
expected.

- The toolbutton and menu item dynamically change their state
depending upon the selected file in the package explorer UNTIL no file
with extension .foobar is opened in the workbench window.

- The moment a file .foobar is opened in the workbench window, both
the added menu item and toolbutton become active (enabled).  Now even
if any other file is opened in the workbench window, or any file is
selected in the package explorer, the toolbutton and menu item always
remain active.


Could someone kindly suggest what am I missing here?

I want the toolbutton and menu item to be active (enabled/highlighted)
only when a file with extension .foobar is open in the workbench
window.

Thanks for your suggestions.

Dave


Back to the top