我需要在Eclipse插件的视图工具栏中添加pulldown button。
实际上工具栏中的按钮添加如下:
<extension point="org.eclipse.ui.viewActions">
<viewContribution id="..." targetId="$MyViewId$">
<action id="..."
toolbarPath="action1"
class="Class extending Action and implementing IViewActionDelegate">
</action>
</viewContribution>
</extension>
答案 0 :(得分:9)
我已经弄清楚了。两种方式:一种使用org.eclipse.ui.viewActions
扩展名,另一种使用org.eclipse.ui.menus
org.eclipse.ui.viewActions
扩展名(eclipse&gt; = 3.5)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
(定义菜单行为)。 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
扩展点添加新的菜单贡献。 toolbar:IdOfYourView
pulldown
menu:IdOfThePullDownCommand