I am looking for a way to add my own file template in Eclipse. How to do it?

When you right-click in a folder, Eclipse opens a context menu that allows you to create various types of files. I would like to add an option to add my own file (with some persistent data that I want to post there). Is there an easy way to do this?

thanks

enter image description here

+6
source share
2 answers

Well, I know two ways (one of them is checked, and the other I'm not sure), in which you can expand the pop-up menu. By default, new submenu .

A short, working and proven way is to use org.eclipse.ui.perspectiveExtensions .

β†’ Note. You will need a wizard to contribute to the pop-up menu. By default, new submenu . You can do this using this eSpeed ​​development link using the Eclipse wizards (same as provided by @Ed Burnette)

Stages:

  • In this example, I created a master dummy with id testwizard.wizards.TestWizard .
  • Now create the org.eclipse.ui.perspectiveExtensions extension. In this example, I am simply contributing to the development perspective of Java . You may have several instances for different points of view. Therefore, targetId org.eclipse.jdt.ui.JavaPerspective .
  • Now right click on the perspective Extension and select newWizardShortcut
  • Set id newWizardShortcut as your user id wizards ie testwizard.wizards.TestWizard in my case.
  • Reboot the application. Now do not forget to reset in perspective, otherwise your addition to the pop-up menu will not be visible.

β†’ plugin.xml

 <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.4"?> <plugin> <extension point="org.eclipse.ui.newWizards"> <category name="Test Wizards" id="TestWizard"> </category> <wizard name="HTML Test Wizard" icon="icons/sample.gif" category="TestWizard" class="testwizard.wizards.TestWizard" id="testwizard.wizards.TestWizard"> </wizard> </extension> <extension point="org.eclipse.ui.perspectiveExtensions"> <perspectiveExtension targetID="org.eclipse.jdt.ui.JavaPerspective"> <newWizardShortcut id="testwizard.wizards.TestWizard"> </newWizardShortcut> </perspectiveExtension> </extension> </plugin> 

β†’ Conclusion

Output

A long and untested way is to use org.eclipse.ui.navigator.navigatorContent . And I'm not sure if this will work or not. Providing it for reading and research purposes only

Use these links:

In the end, I suggest you use the first approach, because it is simple and elegant. Read and use the second method if you are writing a new perspective, viewing, etc.

Hope this helps.

+9
source

You need to create an Eclipse plug-in and create a wizard to create a new file. There's a great tutorial on how to do this on developerworks:

See also:

+2
source

Source: https://habr.com/ru/post/885625/


All Articles