将项添加到Eclipse工具栏

时间:2014-12-08 09:48:04

标签: java eclipse eclipse-plugin

我创建了一个示例Eclipse插件项目,我需要在菜单和工具栏中的同一项目中添加多个项目。我成功地将项目添加到菜单栏中的项目,但是当我尝试将项目添加到工具栏中的项目时 - 它们都不适合我。

如何将项目添加到工具栏中的现有项目?

这是我的plugin.xml代码:

<plugin>

<extension
     point="org.eclipse.ui.commands">
  <category
        name="Sample Category"
        id="com.sample.example.commands.category">
  </category>
  <command
        name="Sample Command"
        categoryId="com.sample.example.commands.category"
        id="com.sample.example.commands.sampleCommand">
  </command>
</extension>
<extension
     point="org.eclipse.ui.handlers">
  <handler
        commandId="com.sample.example.commands.sampleCommand"
        class="com.sample.example.handlers.SampleHandler">
  </handler>
</extension>
<extension
     point="org.eclipse.ui.bindings">
  <key
        commandId="com.sample.example.commands.sampleCommand"
        contextId="org.eclipse.ui.contexts.window"
        sequence="M1+6"
        schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
  </key>
</extension>
<extension
     point="org.eclipse.ui.menus">
  <menuContribution
        locationURI="menu:org.eclipse.ui.main.menu?after=additions">
     <menu
           label="Sample Menu"
           mnemonic="M"
           id="com.sample.example.menus.sampleMenu">
        <command
              commandId="com.sample.example.commands.sampleCommand"
              mnemonic="S"
              id="com.sample.example.menus.sampleCommand">
        </command>
        <menu
           label="Sample Menu2"
           mnemonic="M"
           id="com.sample.example.menus.sampleMenu2">
        <command
              commandId="com.sample.example.commands.sampleCommand"
              mnemonic="S"
              id="com.sample.example.menus.sampleCommand2">
        </command>
     </menu>
     </menu>
   </menuContribution>
   <menuContribution
        locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
     <toolbar
           id="com.sample.example.toolbars.sampleToolbar">
        <command
              commandId="com.sample.example.commands.sampleCommand"
              icon="icons/sample.gif"
              tooltip="Say hello world"
              id="com.sample.example.toolbars.sampleCommand">
        </command>
     </toolbar>
  </menuContribution>
      </extension>

  </plugin>

我尝试将以下代码添加到xml中,但它也不适用于我。

<menuContribution
        locationURI="menu:com.sample.example.commands.sampleCommand?after=additions">
        <command
              commandId="com.sample.example.commands.sampleCommand"
              id="com.sample.example.commands.sampleCommand1">
        </command>
  </menuContribution>

1 个答案:

答案 0 :(得分:1)

我错过了style =&#34; pulldown&#34;。现在它的工作正常。 这是工作代码:

<menuContribution
    locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
 <toolbar
       id="com.sample.example.toolbars.sampleToolbar">
    <command
          commandId="com.sample.example.commands.sampleCommand"
          icon="icons/sample.gif"
          tooltip="Say hello world"
          style="pulldown"
          id="com.sample.example.toolbars.sampleCommand">
    </command>
 </toolbar>
</menuContribution>
<menuContribution
    locationURI="menu:com.sample.example.commands.sampleCommand?after=additions">
    <command
          commandId="com.sample.example.commands.sampleCommand"
          style="push"
          id="com.sample.example.commands.sampleCommand1">
    </command>
</menuContribution>