简体   繁体   中英

Key-Binding for a Custom Eclipse Content Assist

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?

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!

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