且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Eclipse中添加菜单项

更新时间:2023-11-29 23:07:52

,我正在编写一个插件来执行一些重新分解。

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

编写重构并不是太复杂,而是弄清楚如何将菜单项正确添加到Refactor菜单中花了很多时间。

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.

这是正确的plugin.xml片段:

Here is the correct plugin.xml snippet:

Refactor菜单标签是来自org.eclipse.jdt.ui的原始Refactor菜单定义的副本。复制所有分隔符定义很重要。对于我的插件,我还添加了一个名为spartanGroup的新分隔符。

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.

Refactor菜单的路径是org.eclipse.jdt.ui.refactoring.menu。

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

可以通过查看org.eclipse.jdt.ui插件的plugin.xml来绘制这些信息。您可以在线查找(例如这里),或者您可以按照以下步骤导入eclipse版本的源代码:

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.