SelectionChanged () of IActionDelegate not called

I have an action class that I would like to include depending on the file extension.
I wrote this logic in the selectionChanged() of the action class.

But when I start my eclipse and click on the file for the context menu, this method is not called.
And when I click on an action, after each click on this file the selectionChanged() method is called.

How can I make the selectionChanged() method always be called when files are clicked in eclipse to disable actions before clicking on an action?

+4
source share
2 answers

There are many actions allowed / disabled depending on the type of item selected.
See, for example, the Copy action for an item that is not intended to be copied:

http://web.archive.org/web/20120503153234/http://img522.i_mageshack.us/img522/448/eclipseinactivecommand.png

This means that you can check how org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart manages its context menu and its associated actions.

Start with the menuAboutToShow() method using PackageExplorerActionGroup , including CCPActionGroup , which manage to copy, cut and paste actions.
This last class does not control the registration of actions, including CopyToClipboardAction :
It implements the selectionChanged method.

 public void selectionChanged(IStructuredSelection selection) { try { List JavaDoc elements= selection.toList(); IResource[] resources= ReorgUtils.getResources(elements); IJavaElement[] javaElements= ReorgUtils.getJavaElements(elements); if (elements.size() != resources.length + javaElements.length) setEnabled(false); else setEnabled(canEnable(resources, javaElements)); } catch (JavaModelException e) { //no ui here - this happens on selection changes // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 if (JavaModelUtil.isExceptionToBeLogged(e)) JavaPlugin.log(e); setEnabled(false); } } 
+1
source

It seems that you are "suffering" from loading false Eclipse plugins (like me). You can check out the Eclipse Plugin Book or Popup Guide (which I assume you are using). You must use the so-called declarative mechanism to include your element. In your case, it should be as simple as adding nameFilter . In this way, Eclipse can avoid loading your plugin until it is actually executed (decoupling menu items and executing the plugin).

0
source

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


All Articles