Eclipse 4插件 - 键绑定

时间:2016-08-09 14:32:49

标签: java eclipse eclipse-plugin eclipse-rcp

我想迁移我的eclipse插件以使用Eclipse 4.这基本上意味着摆脱对兼容层的依赖? 我的插件有一个Activator类,一个带有附加处理程序的命令和一个用于触发此命令的键绑定。到目前为止我所做的是安装e4工具,并将fragment.e4xmi添加到我的plugin-project和org.eclipse.e4.workbench.model到plugin.xml中的扩展。按照这些说明http://www.vogella.com/tutorials/EclipsePlugin/article.html,我能够在eclipse的主菜单中添加菜单贡献,并将e4处理程序附加到此菜单(使用酷依赖注入的东西!)。

我的问题是键绑定。在我的plugin.xml中,它看起来像这样

<extension
         point="org.eclipse.ui.bindings">
      <key
            commandId="com.florian.regexfindandreplace.commands.FindAndReplaceCommand"
            contextId="org.eclipse.ui.textEditorScope"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            sequence="M1+F5">
      </key>

       <scheme
  name="Default"
  description="Default shortcuts for Eclipse"
  id="default.id" />
</extension>

在fragment.e4xmi中,我添加了一个带有扩展元素id的模型片段:org.eclipse.e4.legacy.ide.application,其特征是名称为keyBindings。

在该节点下,我创建了一个BindingContext,其ID为org.eclipse.ui.contexts.window(我导入了该绑定上下文)和一个BindingTable,使用此上下文和M1 + F5上的键绑定。

但是当我在插件运行时按Ctrl + F5(菜单可见并且可以从那里触发命令)时,不会触发命令。

这是我的frament.e4xmi文件

    <?xml version="1.0" encoding="ASCII"?>
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmi:id="_GxS4UF4xEea8x7AIe1PlrQ">
  <imports xsi:type="commands:BindingContext" xmi:id="_vgCiAF8lEea2fbkyfFHzhA" elementId="org.eclipse.ui.contexts.dialogAndWindow"/>
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_OX6rcF4xEea8x7AIe1PlrQ" featurename="commands" parentElementId="org.eclipse.e4.legacy.ide.application">
    <elements xsi:type="commands:Command" xmi:id="_XcrQgF4xEea8x7AIe1PlrQ" elementId="com.florian.regexfindandreplace.command.openfindreplacedialog" commandName="Open find/replace dialog" description="Opens the find/replace dialog"/>
  </fragments>
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_dc1cIF4xEea8x7AIe1PlrQ" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
    <elements xsi:type="commands:Handler" xmi:id="_ioC8wF4xEea8x7AIe1PlrQ" elementId="com.florian.regexfindandreplace.handler.openfindreplacedialog" contributionURI="bundleclass://com.florian.regexfindandreplace/com.florian.regexfindandreplace.handlers.OpenFindReplaceDialogE4Handler" command="_XcrQgF4xEea8x7AIe1PlrQ"/>
  </fragments>
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_ok-OMF4xEea8x7AIe1PlrQ" featurename="menuContributions" parentElementId="org.eclipse.e4.legacy.ide.application">
    <elements xsi:type="menu:MenuContribution" xmi:id="_1fot0F4xEea8x7AIe1PlrQ" elementId="com.florian.regexfindandreplace.menucontribution.firstmenu" positionInParent="after=additions" parentId="org.eclipse.ui.main.menu">
      <children xsi:type="menu:HandledMenuItem" xmi:id="_FTLfEF4yEea8x7AIe1PlrQ" elementId="id.openfindreplacedialog" label="Open find/replace dialog" command="_XcrQgF4xEea8x7AIe1PlrQ"/>
    </elements>
  </fragments>
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="__aNm8F45Eea8x7AIe1PlrQ" featurename="keyBindings" parentElementId="org.eclipse.e4.legacy.ide.application">
    <elements xsi:type="commands:BindingTable" xmi:id="_2seTgF8lEea2fbkyfFHzhA" elementId="com.florian.regexfindandreplace.bindingtable.0" bindingContext="_vgCiAF8lEea2fbkyfFHzhA">
      <bindings xmi:id="_3ySFAF8lEea2fbkyfFHzhA" elementId="com.florian.regexfindandreplace.keybinding.0" keySequence="CTRL+F5" command="_XcrQgF4xEea8x7AIe1PlrQ"/>
    </elements>
  </fragments>
</fragment:ModelFragments>

我做错了什么?任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:0)

我的问题解决了。我的键绑定的模型片段必须具有featurename =&#34; bindingTables&#34;。所以你不能在这里找到一个任意的名字,因为当我把它的名字和#34; keyBindings&#34;加入时,我想到了。

相关问题