1

I have menu that has menu items "Add File1", "Add File2, "Save". Each has an associated handler and command. Now I need to disable "Save" menu item, until both "Add File1" and "Add File2" are run atleast once. How can I achieve this?

I assume it can be done using Core expressions but I am unable to understand how to do it especially the plugin.xml modifications. I need a very simple example usage for the above mentioned case.

anjalli
  • 53
  • 6

1 Answers1

0

It would probably be simplest to use a @CanExecute method in your 'Save' handler to do this. Something like:

public class SaveHandler
{
  @CanExecute
  public boolean canExecute()
  {
    boolean enable;

    // TODO your code to test if the menus have run and set the enable flag

    return enable;
  }

  @Execute
  public void execute()
  {
    // TODO your execute code
  }
}
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • How can I test if the menu has run? I tried to see if the part is active using: IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart(); But it doesnot work. I get an error "Workbench has not been created". Is there a way to know if the menu item has been clicked atleast once. – anjalli Apr 29 '16 at 13:52
  • That code is 3.x compatibility mode you can't use that in e4. There is nothing that remembers menu items have been clicked, you will have to code that yourself. There are e4 ways to get the active part, but that is nothing to do with menu items. – greg-449 Apr 29 '16 at 15:25