在Eclipse中添加菜单项

时间:2011-10-29 19:50:11

标签: eclipse refactoring

我想编写一个Eclipse插件,将项目添加到Eclipse JDT中的 Refactor 菜单中?我怎么能这样做?

非常感谢

2 个答案:

答案 0 :(得分:3)

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

编写重构并不是太复杂,但弄清楚如何将菜单项正确添加到Refactor菜单中需要花费大量时间。

以下是正确的plugin.xml代码段:

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

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

可以通过查看org.eclipse.jdt.ui插件的plugin.xml来计算此信息。你可以在网上找到它(例如这里),或者你可以按照以下步骤导入你的eclipse构建的源代码:

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

答案 1 :(得分:-2)

您可以编写一个使用Platform Command Framework的插件。有关详细信息,请参阅官方维基页面,其中提供了几个教程链接:http://wiki.eclipse.org/index.php/Platform_Command_Framework

基本上,您定义了一个要执行的命令,一个菜单贡献(在哪里显示它)和一个命令处理程序(要执行的内容)。

相关问题