RCP学习:增加菜单项

1、增加菜单项,需要扩展org.eclipse.ui.actionSets,该扩展点的说明如下:

This extension point is used to add menus, menu items and toolbar buttons to the common areas in the Workbench window. These contributions are collectively known as an action set and appear within the Workbench window by the user customizing a perspective.

本扩展点是用来在工作台窗口的“常用区域”中添加菜单、菜单项以及工具条按钮。这些增加的项被称为“action set”,他们会出现在用户定义的工作台窗口位置。

2、actionSets下创建actionSet,设置actionSet的ID。

3、actionSet下创建menu,menu的id需要唯一,label为展示的字符串。menu下可以创建separate和groupMaker

4、actionSet下创建action,注意action的menubarPath决定了该action在menu中的位置,action的toolbarPath决定该action在toolbar中位置(格式:menu_id/separator_name)。

5、创建子菜单,和创建menu的流程一致,但子菜单的path应该为父菜单_id/separate_name。需要添加到子菜单的action的path属性则不需要写父菜单的separate。

    <extension
point="org.eclipse.ui.actionSets">
<actionSet
label="tool"
visible
="true"
id
="com.anrainie.ide.workbench.actionSet">
<menu
id="toolmenu"
label
="%Tool.title"
>
<separator
name="slot1">
</separator>
<separator
name="slot2">
</separator>
</menu>

<menu
id="exportdoc"
label
="%Tool.exportDocumentTool"
path
="toolmenu/slot1">
<separator
name="slot3">
</separator>
</menu>
<action
class="com.anrainie.ide.workbench.actions.ExportTrdAction"
icon
="icons/trd.gif"
id
="com.anrainie.ide.workbench.actions.ExportTrdAction"
label
="%Tool.exportDocumentTool.Trd"
menubarPath
="toolmenu/exportdoc/slot3"
tooltip
="%Tool.exportDocumentTool.Trd">
</action>
<action
class="com.anrainie.ide.workbench.actions.ExportTwfAction"
icon
="icons/twf.gif"
id
="com.anrainie.ide.workbench.actions.ExportTwfAction"
label
="%Tool.exportDocumentTool.Twf"
menubarPath
="toolmenu/exportdoc/slot3"
tooltip
="%Tool.exportDocumentTool.Trd">
</action>
<action
class="com.anrainie.ide.workbench.actions.ExportBcdAction"
icon
="icons/bcd.gif"
id
="com.anrainie.ide.workbench.actions.ExportBcdAction"
label
="%Tool.exportDocumentTool.Bcd"
menubarPath
="toolmenu/exportdoc/slot3"
style
="push"
tooltip
="%Tool.exportDocumentTool.Bcd">
</action>
<action
class="com.anrainie.ide.workbench.actions.ExportTcdAction"
icon
="icons/tcd.gif"
id
="com.anrainie.ide.workbench.actions.ExportTcdAction"
label
="%Tool.exportDocumentTool.Tcd"
menubarPath
="toolmenu/exportdoc/slot3"
style
="push"
tooltip
="%Tool.exportDocumentTool.Bcd">
</action>

</actionSet>

这是一份相对完整的,包含多级菜单的actionSet。



posted @ 2012-03-07 17:04  荒土  阅读(2261)  评论(0编辑  收藏  举报