如何在视图的工具栏中添加下拉按钮? [英] How to add a pulldown button in a view's toolbar?
本文介绍了如何在视图的工具栏中添加下拉按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在视图的工具栏中添加一个 下拉按钮在 Eclipse 插件中.
I need to add a pulldown button to a view's toolbar in an Eclipse plugin.
实际上工具栏中的按钮是这样添加的:
Actually buttons in the toolbar are added like that :
<extension point="org.eclipse.ui.viewActions">
<viewContribution id="..." targetId="$MyViewId$">
<action id="..."
toolbarPath="action1"
class="Class extending Action and implementing IViewActionDelegate">
</action>
</viewContribution>
</extension>
推荐答案
我想通了.两种方式:一种使用 org.eclipse.ui.viewActions
扩展,另一种使用 org.eclipse.ui.menus
I've figured it out. Two ways: one using org.eclipse.ui.viewActions
extension, the other with org.eclipse.ui.menus
- 动作的样式必须设置为
pulldown
<extension point="org.eclipse.ui.viewActions">
<viewContribution id="..." targetId="$MyViewId$">
<action id="..."
toolbarPath="action1"
class="xxx.MyAction"
style="pulldown">
</action>
</viewContribution>
</extension>
- 动作类必须实现
IViewActionDelegate
(对视图工具栏有贡献的动作需要)和IMenuCreator
(定义菜单行为). - action class must implement
IViewActionDelegate
(required for an action contributing to a view toolbar) andIMenuCreator
(defines the menu behavior).
public class RetrieveViolationsViewActionDelegate implements IViewActionDelegate, IMenuCreator
{
private IAction action;
private Menu menu;
// IViewActionDelegate methods
...
// IMenuCreator methods
public void selectionChanged(IAction action, ISelection selection)
{
if (action != this.action)
{
action.setMenuCreator(this);
this.action = action;
}
}
public void dispose()
{
if (menu != null)
{
menu.dispose();
}
}
public Menu getMenu(Control parent)
{
Menu menu = new Menu(parent);
addActionToMenu(menu, new ClassImplemententingIAction());
return menu;
}
public Menu getMenu(Menu parent)
{
// Not use
return null;
}
private void addActionToMenu(Menu menu, IAction action)
{
ActionContributionItem item= new ActionContributionItem(action);
item.fill(menu, -1);
}
}
使用 org.eclipse.ui.menus (eclipse >= 3.3)
- 向
org.eclipse.ui.menus
扩展点添加一个新的 menucontribution. - 将位置 URI 设置为
toolbar:IdOfYourView
- 为此扩展添加一个工具栏,并为这个新工具栏添加一个新命令.
- 将命令样式改为
pulldown
- 创建一个新的 menucontribution 并将 locationURI 设置为
menu:IdOfThePullDownCommand
- 向此菜单添加命令.
- Add a new menucontribution to the
org.eclipse.ui.menus
extension point. - Set the location URI to
toolbar:IdOfYourView
- Add a toolbar to this extension and a new command to this new toolbar.
- Change the command style to
pulldown
- Create a new menucontribution and set the locationURI to
menu:IdOfThePullDownCommand
- Add commands to this menu.
Using org.eclipse.ui.menus (eclipse >= 3.3)
这篇关于如何在视图的工具栏中添加下拉按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文