如何在视图的工具栏中添加一个下拉按钮? [英] How to add a pulldown button in a view's toolbar?

查看:104
本文介绍了如何在视图的工具栏中添加一个下拉按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在视图的工具栏中添加下拉按钮在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


  • 动作风格必须设置为下拉菜单

  • action's style must set to 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) and IMenuCreator (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 扩展点

      • 将位置URI设置为工具栏:IdOfYourView

      • 向此扩展名添加工具栏,

      • 将命令样式更改为 pulldown

      • 创建一个新的菜单,并将locationURI设置为菜单:IdOfThePullDownCommand

      • 将命令添加到此菜单。

      • Using org.eclipse.ui.menus (eclipse >= 3.3)

        • 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.
        • 更多信息

          这篇关于如何在视图的工具栏中添加一个下拉按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆