Eclipse 插件开发 - 工具栏(tool bar)增加下来菜单
2016-11-19 16:23
387 查看
在开发Eclipse 插件时, 想在工具栏中增加一个按钮图标是非常容易, 但是想在图标上增加子菜单就会比较麻烦, 例如想实现如下效果:
具体步骤如下:
首先在扩展点org.eclipse.ui.commands中增加三个指令
[html] view
plain copy
<extension
point="org.eclipse.ui.commands">
<command
name="Reference Command"
id="top.itart.plugin.smartboot.referenceCommand">
</command>
<command
name="Sub1 Command"
id="top.itart.plugin.smartboot.sub1Command">
</command>
<command
name="Sub2 Command"
id="top.itart.plugin.smartboot.sub2Command">
</command>
</extension>
其次在扩展点org.eclipse.ui.menus 增加两个menuContribution
[html] view
plain copy
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="top.itart.plugin.smartboot.toolbars">
<command
commandId="top.itart.plugin.smartboot.referenceCommand"
icon="icons/sample.gif"
tooltip="Pull down" style="pulldown">
</command>
</toolbar>
</menuContribution>
这个是定义显示在toolbar上的菜单. Command 中的commandId 为第一个指令的ID, 类型 type 为pulldown, 并且放在toolbar标签中
[html] view
plain copy
<menuContribution
locationURI="menu:top.itart.plugin.smartboot.referenceCommand">
<command
commandId="top.itart.plugin.smartboot.sub1Command"
icon="icons/sample.gif"
label = "Sub 1"
tooltip="Sub 1">
</command>
<command
commandId="top.itart.plugin.smartboot.sub2Command"
icon="icons/sample.gif"
tooltip="Sub2"
label = "Sub 2">
</command>
</menuContribution>
这个menuContribution是定义下拉的子菜单. 注意locationURI的值是menu: <Toolbar上的菜单ID>
最终的plugin.xml如下
[html] view
plain copy
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.commands">
<command
name="Reference Command"
id="top.itart.plugin.smartboot.referenceCommand">
</command>
<command
name="Sub1 Command"
id="top.itart.plugin.smartboot.sub1Command">
</command>
<command
name="Sub2 Command"
id="top.itart.plugin.smartboot.sub2Command">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="top.itart.plugin.smartboot.toolbars">
<command
commandId="top.itart.plugin.smartboot.referenceCommand"
icon="icons/sample.gif"
tooltip="Pull down" style="pulldown">
</command>
</toolbar>
</menuContribution>
<menuContribution
locationURI="menu:top.itart.plugin.smartboot.referenceCommand">
<command
commandId="top.itart.plugin.smartboot.sub1Command"
icon="icons/sample.gif"
label = "Sub 1"
tooltip="Sub 1">
</command>
<command
commandId="top.itart.plugin.smartboot.sub2Command"
icon="icons/sample.gif"
tooltip="Sub2"
label = "Sub 2">
</command>
</menuContribution>
</extension>
</plugin>
具体步骤如下:
首先在扩展点org.eclipse.ui.commands中增加三个指令
[html] view
plain copy
<extension
point="org.eclipse.ui.commands">
<command
name="Reference Command"
id="top.itart.plugin.smartboot.referenceCommand">
</command>
<command
name="Sub1 Command"
id="top.itart.plugin.smartboot.sub1Command">
</command>
<command
name="Sub2 Command"
id="top.itart.plugin.smartboot.sub2Command">
</command>
</extension>
其次在扩展点org.eclipse.ui.menus 增加两个menuContribution
[html] view
plain copy
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="top.itart.plugin.smartboot.toolbars">
<command
commandId="top.itart.plugin.smartboot.referenceCommand"
icon="icons/sample.gif"
tooltip="Pull down" style="pulldown">
</command>
</toolbar>
</menuContribution>
这个是定义显示在toolbar上的菜单. Command 中的commandId 为第一个指令的ID, 类型 type 为pulldown, 并且放在toolbar标签中
[html] view
plain copy
<menuContribution
locationURI="menu:top.itart.plugin.smartboot.referenceCommand">
<command
commandId="top.itart.plugin.smartboot.sub1Command"
icon="icons/sample.gif"
label = "Sub 1"
tooltip="Sub 1">
</command>
<command
commandId="top.itart.plugin.smartboot.sub2Command"
icon="icons/sample.gif"
tooltip="Sub2"
label = "Sub 2">
</command>
</menuContribution>
这个menuContribution是定义下拉的子菜单. 注意locationURI的值是menu: <Toolbar上的菜单ID>
最终的plugin.xml如下
[html] view
plain copy
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.commands">
<command
name="Reference Command"
id="top.itart.plugin.smartboot.referenceCommand">
</command>
<command
name="Sub1 Command"
id="top.itart.plugin.smartboot.sub1Command">
</command>
<command
name="Sub2 Command"
id="top.itart.plugin.smartboot.sub2Command">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="top.itart.plugin.smartboot.toolbars">
<command
commandId="top.itart.plugin.smartboot.referenceCommand"
icon="icons/sample.gif"
tooltip="Pull down" style="pulldown">
</command>
</toolbar>
</menuContribution>
<menuContribution
locationURI="menu:top.itart.plugin.smartboot.referenceCommand">
<command
commandId="top.itart.plugin.smartboot.sub1Command"
icon="icons/sample.gif"
label = "Sub 1"
tooltip="Sub 1">
</command>
<command
commandId="top.itart.plugin.smartboot.sub2Command"
icon="icons/sample.gif"
tooltip="Sub2"
label = "Sub 2">
</command>
</menuContribution>
</extension>
</plugin>
相关文章推荐
- eclipse plugin 插件开发 plugin.xml文件配置(菜单,工具栏,弹出菜单)
- Eclipse 插件开发 -- 深入理解菜单(Menu)功能及其扩展点
- Eclipse 插件开发 -- 深入理解菜单(Menu)功能及其扩展点( FROM IBM)
- eclipse插件开发--popMenu扩展点--找不到菜单项
- eclipse插件开发 -右键菜单 - popup menu
- Eclipse 插件开发 -- 深入理解菜单(Menu)功能及其扩展点
- Eclipse 插件开发 -- 深入理解菜单(Menu)功能及其扩展点
- 【eclipse插件开发】右键菜单获取选中文件以及文件的创建
- 插件开发――菜单和工具栏
- Eclipse 插件开发 之菜单
- Eclipse 插件开发 -- 深入理解菜单(Menu)功能及其扩展点
- Eclipse 插件开发 -- 深入理解菜单(Menu)功能及其扩展点
- eclipse的Android开发插件如何找到并复制下来给他人?
- Eclipse 插件开发
- 开发Eclipse插件
- 采用ActionSets创建插件菜单与工具栏
- RCP开发中,顶级菜单/顶级工具栏多出了一些无关的项?
- eclipse 插件开发中如何实现刷新和重编译
- Eclipse配置PyDev插件来实现python开发环境
- 程序猿必知--阿里巴巴Java开发规约插件集成Idea,Eclipse使用