Refresh Eclipse Menu Item Status

I created a menu item in the File menu as a command. There is a handler for this command that implements the IHandler interface. This handler contains the isEnabled method. I try to use this method to enable / disable my menu item, but this method is only called once when I click on the File menu. When you click on the second, third, etc. The isEnabled method is not called again, even if I changed the state of the page (open / close editors) earlier.

What should I do? Maybe this method is not intended for control menu items?

+6
source share
2 answers

Are you subclassing org.eclipse.core.commands.AbstractHandler ? You should use setBaseEnabled(boolean) to update the state of your handler (which will update your command).

It is only valid for changing the enable state in your handler if you also run HandlerEvent . It's usually easier to call setBaseEnabled(boolean) , which will fire an event for you.

+3
source

If you are trying to enable / disable the menu, you should use basic expressions. I already explained how to do this in this answer:

Eclipse RCP Menus and Actions: Customize or Code?

The part that interests you begins with:

To activate / deactivate the menu [...]

Hope this is what you are looking for.

+2
source

Source: https://habr.com/ru/post/888702/


All Articles