Key-Binding for a Custom Eclipse Content Assist

你说的曾经没有我的故事 提交于 2019-12-24 06:58:12

问题


I've implemented a content assist proposal computer as an eclipse plugin (using org.eclipse.jdt.ui.javaCompletionProposalComputer). I would now like to bind it to it's own key combination (otherwise the custom proposals appear at the bottom of the proposal list).

I tried doing this by extending org.eclipse.ui.bindings, but this requires defining org.eclipse.ui.commands, a handler, and possibly more things.

It seems that there is already a command created for my custom content assist computer, since it appears under the key binding menu (in Windows->Preferences->Keys), but I don't know what is the id of this command. If that command is created at runtime, then can I even refer to its commandId in my plugin.xml?

Is there another, simpler way of doing this?


回答1:


After experimenting with many different ways of implementing this I found that:

1) The command associated with custom completion proposal computers is org.eclipse.jdt.ui.specific_content_assist.command, and it is defined in the plugin.xml of the org.eclipse.jdt.ui plugin (provided by eclipse).

2) This is a parametrized command, which means it takes a commandParameter with id=org.eclipse.jdt.ui.specific_content_assist.category_id. The value of this parameter should be the id of the proposalCategory for your javaCompletionProposalComputer.

Here's an example of how I defined custom key-binding:

<extension point="org.eclipse.ui.bindings">   
    <key
        sequence="CTRL+ALT+SPACE"
        contextId="org.eclipse.ui.contexts.dialogAndWindow"
        schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
        commandId="org.eclipse.jdt.ui.specific_content_assist.command">
        <parameter
            id="org.eclipse.jdt.ui.specific_content_assist.category_id"
            value="YOUR_PROPOSAL_CATEGORY_GOES_HERE"/>
    </key>
</extension> 

No need to define a new command or handler!



来源:https://stackoverflow.com/questions/18519534/key-binding-for-a-custom-eclipse-content-assist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!