插件开发或RCP中如何通过actions扩展点配置工具栏按钮(插入到指定的ToolBarManger中)

来源:互联网 发布:传智python视频百度云 编辑:程序博客网 时间:2024/05/15 16:12
 在插件或RCP开发中,我们通常使用org.eclipse.ui.actions扩展点配置菜单和工具按钮。
eg:
   <extension
         point="org.eclipse.ui.actionSets">
      <actionSet
            id="test.actionSet"
            label="Sample Action Set"
            visible="true">
         <action
               class="test.actions.SampleAction"
               icon="icons/sample.gif"
               id="test.actions.SampleAction"
               label="&amp;Sample Action"
               menubarPath="sampleMenu/sampleGroup"
               toolbarPath="start/additions"//重点看这里,start是在代码中指定的ToolBarManager的id,additions是插入点
               tooltip="Hello, Eclipse world">
         </action>
      </actionSet>
   </extension>
  
  
   我们这次主要看看toolBarPath。这个路径是以工具(id)开头,以"/"分隔的路径。
   在RCP开发中,我们可能会先定义一些ToolBarManager,同时在ToolBarManger中添加一些插入点(InsertPoint)。
   然后在actionSets扩展点中配置toolbarPath(形如toolbarMangerId/insertpointId)。
  
   我们在RCP中可能会定义成这个样子:
   IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
        toolbar.add(openViewAction);
        toolbar.add(messagePopupAction);
        //ToolBar中定义一个插入点,GroupMarker与Separator的区别在于,后者分加一条分隔线,前者不会
        toolbar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
        coolBar.add(new ToolBarContributionItem(toolbar,"start"));//将ToolBarManager加到CoolBar中,并以"start"进行标志
  
原创粉丝点击