我一直在仅通过配置即可从Commons Navigator框架中删除几乎所有弹出菜单的部分成功 plugin.xml 文件。
有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.editgroup.reorganize...对我来说,这看起来像是一个错误。

明显的解决方案是从我的 <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)

它给重组组带来了相同的例外。

有帮助吗?

解决方案

我成功地删除了“ group.edit”操作(复制/粘贴),我使用了通用导航器扩展点:

   <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");
   }
}

好吧,这是一个“灰心的访问”,但我灰心丧气;-) J.D

其他提示

通常,您应该使用 命令框架 借助任何最近版本的Eclipse(3.3或更高),这将取代在公共导航器中提供弹出菜单的机制。

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

它们可能正在采取行动,因此,如果您可以识别导致进攻性贡献的动作集,则可以在您的中做类似的事情 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:采取更明显的方法来指定输入(对于RCP应用程序), , 类似的黑客.
漏洞 143430(CommonNavigator需要适应性的初始输入) 是一个更通用的,它将表明当时CNF已通过Eclipse3.5(Galileo)改进。
那么,您还可以使用3.5和自定义CNF类遇到这个问题吗?


如文章中所述Eclipse CNF:导航器内容扩展“,CNF随着Eclipse3.5的发展而演变,本文似乎有一些带有真正自定义上下文菜单条目的树。

alt text

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top