简体   繁体   中英

Alter properties of a menu item in Eclipse Plugin?

I am trying to modify the behaviour of File -> Refresh in the menu bar of my Eclispe plugin. I am effectively trying to override the activeWhen behaviour of the "org.eclipse.ui.file.refresh" command, so that it is always active.

There seems to be plenty of information on creating these menu items but very little on overriding them, any ideas?

Code I tried was:

ICommandService commandService = (ICommandService
     PlatformUI.getWorkbench().getService(ICommandService.class);
Command command = commandService.getCommand("com.example.command");
command.setEnabled(true);

But this doesn't do the trick

You cannot enable the command like that. The enablement of the command is done by the workbench, by consulting the active handler (if any). See this link for a more detailed information: http://www.eclipse-tips.com/tutorials/1-actions-vs-commands?start=1

The enablement of a command is calculated at runtime: you can read this article to get some tips

saluti

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM