selectionChanged()的IActionDelegate未被调用 [英] selectionChanged() of IActionDelegate in not getting invoked

查看:158
本文介绍了selectionChanged()的IActionDelegate未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动作类,我想根据文件扩展名启用。

我在 selectionChanged()中写了这个逻辑,的操作类。

I have an action class which I would like to enable depending on the file extension.
I have written this logic in the selectionChanged() of the action class.

但是当我启动我的eclipse,并单击该文件的上下文菜单,这种方法没有被调用。

当我点击任何动作时,点击文件后,会调用 selectionChanged()方法。

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

如何使 selectChanged()方法始终在eclipse中单击文件,以便在单击操作之前禁用该操作?

How can I make the selectionChanged() method to be called always on click of files in eclipse in order to disable the actions before clicking on the action?

推荐答案

根据当前选择的元素类型,启用/禁用了大量操作。

参见例如Copy 对不想复制的元素的操作:

There are plenty of actions enabled/disabled based on the type of element currently selected.
See for instance the "Copy" actions on an element not meant to be copied:

这意味着你可以检查一个 org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart / strong> 管理自己的上下文菜单及其关联的操作。

That means you can check how a org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart manages its own contextual menu and their associated actions.

从方法开始 menuAboutToShow() ,使用 PackageExplorerActionGroup 类,包括一个 CCPActionGroup ,它们可以复制,剪切和粘贴操作。

最后这个类似于注册操作,其中包括 CopyToClipboardAction

它实现了一个 selectionChanged 方法

Start from the method menuAboutToShow(), using a PackageExplorerActionGroup class, including a CCPActionGroup which manage to Copy, Cut and Paste actions.
That last class illistrates the registration of Actions, amongst them the CopyToClipboardAction:
It does implement a 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);
  }
}

这篇关于selectionChanged()的IActionDelegate未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆