简体   繁体   中英

Eclipse 4 plugin - key bindings

I want to migrate my eclipse plugin to use Eclipse 4. That basically means to get rid of the dependency on the compatibility layer? My plugin has an Activator class, a command with an attached handler and a key binding to trigger this command. What I did so far is install the e4 tools, and add fragment.e4xmi to my plugin-project and org.eclipse.e4.workbench.model to the extensions in plugin.xml. Following these instructions http://www.vogella.com/tutorials/EclipsePlugin/article.html , I was able to add a menu contribution to the main menu of eclipse and attach an e4 handler to this menu (That uses the cool dependency injection stuff!).

My problem is the key binding. In my plugin.xml, it looked this way

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

In fragment.e4xmi, I added a model fragment with Extended Element id: org.eclipse.e4.legacy.ide.application and with Feature name keyBindings.

Under that node I created a BindingContext with Id org.eclipse.ui.contexts.window (I imported that binding context) and a BindingTable using this context and a key binding on M1 + F5.

But when I press Ctrl + F5 when the plugin is running (the menu is visible and the command can be triggered from there), the command isn't triggered.

Here is my frament.e4xmi file

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

What did I do wrong? Any help is appreciated!

I got my problem solved. The model fragment for my key bindings had to have the featurename = "bindingTables". So you can't have an arbitrary name here as I thought when I gabe it the name "keyBindings".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM