Add item above “Project” in eclipse project explorer contextmenu

拜拜、爱过 提交于 2019-12-10 18:44:43

问题


I am working on an eclipse based customized IDE for our development environment.
In my new perspective I have included a "Project Explorer" and in that I am able to add commands in the context menu, but when I include a new Wizard (A project Wizard) in the "new" type it is shown beneath the "Project" wizard

and I'd want it to be above it.

The plugin.xml for this snippet is attached

<extension point="org.eclipse.ui.navigator.navigatorContent">
      <commonWizard
              type="new"
              wizardId="dev.xxx.wizard.XXXProject">
              <enablement></enablement>
      </commonWizard>
</extension>

It is being shown when I access New from Toolbar or MenuBar (after I added it as a shortcut in layout, in an implementation of IPerspectiveFactory

but for some reason it is not showing up under "Project Explorer". But its working fine under "Navigator View"


回答1:


Use the org.eclipse.ui.perspectiveExtensions extension point to define a newWizardShortcut entry for your new project wizard.

Something like:

<extension
     point="org.eclipse.ui.perspectiveExtensions">
  <perspectiveExtension
        targetID="org.eclipse.jdt.ui.JavaPerspective">
     <newWizardShortcut
           id="org.eclipse.jdt.junit.wizards.NewTestCaseCreationWizard">
     </newWizardShortcut>
  </perspectiveExtension>

You might have to do a 'reset perspective' to get the change picked up.

You can also set up these shortcuts in the 'Window > Customize Perspective' dialog in the 'Shortcuts' tab.




回答2:


As has been mentioned in NewActionProvider.java

there is no menugroupid to accomodate "My Project Wizard" in the "Project..." Group :(.

/**
 * Adds a submenu to the given menu with the name "group.new" see
 * {@link ICommonMenuConstants#GROUP_NEW}). The submenu contains the following structure:
 * 
 * <ul>
 * <li>a new generic project wizard shortcut action, </li>
 * <li>a separator, </li>
 * <li>a set of context senstive wizard shortcuts (as defined by
 * <b>org.eclipse.ui.navigator.commonWizard</b>), </li>
 * <li>another separator, </li>
 * <li>a generic examples wizard shortcut action, and finally </li>
 * <li>a generic "Other" new wizard shortcut action</li>
 * </ul>
 */

A "New" submenu for "Project Explorer" will allways be of this format so have to make my own implementation to add the project in the project group. Dear Greg thank you for your time. So iam off to creating an implementation of NewActionProvider as in https://cvalcarcel.wordpress.com/tag/commonwizard/




回答3:


The desired behaviour can be obtained when using the standard ResourceNavigator ( org.eclipse.ui.views.ResourceNavigator) view instead of the ProjectExplorer.

In there the New-wizards will be automatically split up in project- and non-project wizards wheras former are automatically added in the same group as the Project... wizard (They are actually added above it no matter what menuGroupId is set).

So if you want to properly achieve the behaviour stated in the question you have to either use the Navigator view or extend it.

(I know that the question was asked specifically about the ProjectExplorer but nevertheless I think my answer might come to into use for someone with a similar problem)



来源:https://stackoverflow.com/questions/30910813/add-item-above-project-in-eclipse-project-explorer-contextmenu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!