Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding menu item in Eclipse

I want to write an Eclipse plug-in that adds an item to the Refactor menu in Eclipse JDT? How can I do this?

Thanks a lot

like image 692
user807496 Avatar asked Oct 29 '11 19:10

user807496


1 Answers

Recently, I was writing a plug-in that performs some re factoring.

Writing the refactoring was not too complicated, but figuring out how add the menu items correctly into the Refactor menu took a lot of time.

Here is the correct plugin.xml snippet:

The Refactor menu tag is a copy of the original "Refactor" menu definition from org.eclipse.jdt.ui. It is important to copy all the separator definitions. For my plug-in, I have also added a new separator called spartanGroup.

The path for the Refactor menu is org.eclipse.jdt.ui.refactoring.menu.

It is possible to figure this information by looking at plugin.xml of the org.eclipse.jdt.ui plug-in. You can find it online (for example here) or you can import the source code of your eclipse build following these steps:

1 File -> Import
2 Select Plug-ins and Fragments and click next.
3 In the "Import From" section choose "The active target platform".
4 In the "Import As" section choose "Project with source folders"
5 In the next screen, locate your plug-in (org.eclipse.jdt.ui) and add it.
6 Click finish and the source code of the plug-in will be imported into your workspace.

plugin.xml

like image 83
Sagar007 Avatar answered Sep 30 '22 14:09

Sagar007