4

plugin.xml通过配置文件,我已经部分成功地从 Commons Navigator Framework 中删除了几乎所有的弹出菜单。
有 2 个拒绝去的菜单:

  • group.edit
  • group.reorganize.

我的plugin.xml配置如下所示:

<extension
          point="org.eclipse.ui.navigator.viewer">
       <viewer
             viewerId="org.eclipse.ui.example.navigator.view">
             <popupMenu allowsPlatformContributions="false">
                <insertionPoint
                    name="group.edit" />

                <insertionPoint
                    name="group.reorganize" />
             </popupMenu>
       </viewer>
       <viewerContentBinding
             viewerId="org.eclipse.ui.thermo.navigator.view">
          <includes>
             <contentExtension
                   pattern="org.eclipse.ui.navigator.resourceContent"/>
          </includes>
       </viewerContentBinding> 
</extension>

将 设置allowsPlatformContribution为 false 确实会停止将贡献添加到上下文菜单中,除了group.editand group.reorganize... 这对我来说开始看起来像一个错误。

显而易见的解决方案是从 my 中删除插入点,<popUpMenu>但没有它们,应用程序会引发异常:

Throwable: java.lang.IllegalArgumentException: Group not found: group.edit

java.lang.IllegalArgumentException: Group not found: group.edit
at org.eclipse.jface.action.ContributionManager.addToGroup(ContributionManager.java:131)
at org.eclipse.jface.action.ContributionManager.appendToGroup(ContributionManager.java:138)
at org.eclipse.ui.internal.navigator.resources.actions.EditActionGroup.fillContextMenu(EditActionGroup.java:74)
at org.eclipse.ui.internal.navigator.resources.actions.EditActionProvider.fillContextMenu(EditActionProvider.java:50)
at org.eclipse.ui.navigator.NavigatorActionService.addCommonActionProviderMenu(NavigatorActionService.java:205)
at org.eclipse.ui.navigator.NavigatorActionService.fillContextMenu(NavigatorActionService.java:172)
at org.eclipse.ui.internal.navigator.CommonNavigatorManager.fillContextMenu(CommonNavigatorManager.java:258)
at org.eclipse.ui.internal.navigator.CommonNavigatorManager$4.menuAboutToShow(CommonNavigatorManager.java:273)
at org.eclipse.jface.action.MenuManager.fireAboutToShow(MenuManager.java:335)
at org.eclipse.jface.action.MenuManager.handleAboutToShow(MenuManager.java:463)
at org.eclipse.jface.action.MenuManager.access$1(MenuManager.java:459)
at org.eclipse.jface.action.MenuManager$2.menuShown(MenuManager.java:485)

它为重组组抛出相同的异常。

4

3 回答 3

4

我成功地删除了“group.edit”操作(复制/粘贴),并且我已经这样做了,使用 Common Navigator 扩展点:

   <extension
         point="org.eclipse.ui.navigator.viewer">
      <viewerActionBinding
            viewerId="org.eclipse.ui.navigator.ProjectExplorer">
         <includes>
            <actionExtension
                  pattern="my.app.client.actions.MyAppEditActionExtension">
            </actionExtension>
         </includes>
      </viewerActionBinding>    
   </extension>
   <extension
         point="org.eclipse.ui.navigator.navigatorContent">
      <actionProvider
            class="my.app.client.workshop.MyPasteActionProvider"
            id="my.app.client.actions.MyAppEditActionExtension"
            overrides="org.eclipse.ui.navigator.resources.actions.EditActions"
            priority="highest">
         <enablement>
         <!-- A hack to allways be enabled -->
         <not>
            <systemTest
                  property="MyApp"
                  value="WONT-EVER-BE-SET">
            </systemTest>
         </not>
         </enablement>
     </actionProvider>
   </extension>

而且,通过在我的插件依赖项中添加“org.eclipse.ui.navigator.resources”,我实现了“MyPasteActionProvider”,如下所示:

import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.internal.navigator.resources.actions.EditActionProvider;

/**
 * Create the Edit actions (Cut/Copy/Paste) 
 * and register then globally in the workbench using EditActionProvider.
 * <p/>
 * Then, removes the Copy/Paste contributions in the pop-up menu.
 */
public class MyPasteActionProvider extends EditActionProvider {
   public void fillContextMenu(IMenuManager menu) { super.fillContextMenu(menu);
   // remove Copy/Paste contributions
   IContributionItem copyItemRemoved = menu.remove("org.eclipse.ui.CopyAction");
   IContributionItem pasteItemRemoved = menu.remove("org.eclipse.ui.PasteAction");
   }
}

好吧,这是一个“不鼓励的访问”,但我让自己气馁;-) JM.D

于 2009-09-16T11:11:07.130 回答
1

线程建议首先删除导致菜单项出现的内容:

它们可能在动作集中,所以如果你能识别出导致攻击性贡献的动作集,你可以在你的WorkbenchAdvisor:

    ActionSetRegistry reg = WorkbenchPlugin.getDefault()
            .getActionSetRegistry();


    IActionSetDescriptor[] actionSets = reg.getActionSets();
    String[] removeActionSets = new String[] {
        "org.eclipse.ui.cheatsheets.actionSet",
        "org.eclipse.ui.edit.text.actionSet.annotationNavigation",
       "org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo",
          "org.eclipse.ui.WorkingSetActionSet",
        "org.eclipse.update.ui.softwareUpdates", };


    for (int i = 0; i < actionSets.length; i++)
    {
        boolean found = false;
        for (int j = 0; j < removeActionSets.length; j++)
        {
            if (removeActionSets[j].equals(actionSets[i].getId()))
                found = true;
        }


        if (!found)
            continue;
        IExtension ext = actionSets[i].getConfigurationElement()
                .getDeclaringExtension();
        reg.removeExtension(ext, new Object[] { actionSets[i] });
    }

我发现的最接近的错误是145233: Make more visible way to specify input (for RCP apps),具有类似的 hack
错误143430(CommonNavigator 要求 initialInput 是 Adaptable)是一个更通用的错误,表明 CNF 已通过 eclipse3.5 (Galileo) 进行了改进。
那么对于 3.5 和自定义 CNF 类,您是否也有这个问题?


正如文章“ Eclipse CNF:Navigator Content Extensions ”中所提到的,CNF 已经随着 eclipse3.5 的发展而发展,而且这篇文章似乎有一些真正的自定义上下文菜单条目的树。

替代文字

于 2009-08-17T18:24:42.260 回答
1

通常,您应该将Command Framework 与任何最新版本的 Eclipse(3.3 或更高版本)一起使用,这取代了在 Common Navigator 中提供弹出菜单的机制。

于 2009-09-28T12:18:54.670 回答