Search code examples
javaeclipsepluginsswtrcp

Eclipse - How to contribute action to "New" section in "File" menu?


I develop Eclipse IDE based RCP application. I want to contribute action, for ex. "New Custom Project", and I want that action to be displayed in following way: File > New > New Custom Project. To be specific, I like to add my custom action somewhere like on that picture:

enter image description here

I know how to add action to File menu, but I don't have any idea how to place it "deeper", in "New" section.

Is there any way to obtain such thing? What locationURI should I use to place my action?


Solution

  • You use the org.eclipse.ui.newWizards extension point to contribute a 'File > New' wizard.

    <extension point="org.eclipse.ui.newWizards"> 
      <category 
        id="com.xyz.XYZ.Web" 
        name="Web Wizards" 
      </category> 
      <wizard 
          id="com.xyz.wizard1" 
          name="XYZ artifact" 
          category="com.xyz.XYZ.Web" 
          icon="./icons/XYZwizard1.png"
          class="com.xyz.XYZWizard1"> 
          <description> 
              Create a simple XYZ artifact and set initial content 
          </description> 
           <selection class="org.eclipse.core.resources.IResource"/>          
      </wizard> 
     </extension> 
    

    Once you have defined a new wizard you can add it to the 'shortcuts' list you show for a specific perspective using the newWizardShortcut element of the org.eclipse.ui.perspectiveExtensions extension point.

    <extension point="org.eclipse.ui.perspectiveExtensions"> 
        <perspectiveExtension 
            targetID="org.eclipse.ui.resourcePerspective"> 
            <newWizardShortcut id="com.xyz.wizard1"/> 
        </perspectiveExtension> 
    </extension> 
    

    Note that you might have to reset or customize the perspective to get the new definitions picked up.