首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Eclipse 4插件密钥绑定

Eclipse 4插件密钥绑定
EN

Stack Overflow用户
提问于 2016-08-09 22:32:49
回答 1查看 879关注 0票数 1

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

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

代码语言:javascript
复制
<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的模型片段。

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

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

这是我的frament.e4xmi文件

代码语言:javascript
复制
    <?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>

我做错什么了?如有任何帮助,我们不胜感激!

EN

回答 1

Stack Overflow用户

发布于 2016-08-12 17:35:47

我的问题解决了。我的键绑定的模型片段必须具有featurename = "bindingTables“。所以你不能像我想象的那样在这里随意命名为"keyBindings“。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38853656

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档