【问题标题】:Add items to the Eclipse toolbar将项目添加到 Eclipse 工具栏
【发布时间】:2014-12-08 09:48:03
【问题描述】:

我创建了一个示例 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>

【问题讨论】:

  • 您使用哪个 Eclipse 版本? 3.x 还是 4.x?

标签: java eclipse eclipse-plugin


【解决方案1】:

我错过了 style="pulldown"。现在它工作正常。 这是工作代码:

<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>

【讨论】:

  • 请编辑您的帖子并在此处添加缺少的信息。目前还不清楚“style=pulldown”应该去哪里。
  • 嗨!您是否知道如果解决了您的问题,您应该将自己的答案标记为“已接受”?这使得其他人更容易看到已经有解决方案。请参阅Help Center 了解更多信息。
猜你喜欢
  • 1970-01-01
  • 2016-10-15
  • 2016-09-05
  • 1970-01-01
  • 2014-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多