Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Defining key shortcut for completion engine via extension point
Defining key shortcut for completion engine via extension point [message #772618] Fri, 30 December 2011 08:01 Go to next message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 286
Registered: July 2009
Senior Member

HI,

I'm looking for a way to specify a key shortcut for a completion engine via extension points.

In preference page > General > Keys I can specify shortcuts like "Ctrl+Shift+Space" which triggers the completion in my current editor. But how can I do that if I want to preconfigure this shortcut as plug-in developer?

I tried:
<extension point="org.eclipse.ui.bindings">
<key sequence="Ctrl+7"
commandId="org.eclipse.recommenders.completion.rcp.chain.category"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
contextId="org.eclipse.jdt.ui.javaEditorScope"/>
</extension>

but giving the completion context id as commandId does not work. I assume that I have to specify a command before. But how do I specify that this command is bound to the particular code completion?

Thanks in advance for some hints.
Re: Defining key shortcut for completion engine via extension point [message #775583 is a reply to message #772618] Fri, 06 January 2012 10:01 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3801
Registered: July 2009
Senior Member
On 30.12.2011 09:01, Marcel Bruch wrote:
> HI,
>
> I'm looking for a way to specify a key shortcut for a completion
> engine via extension points.
Are you talking about your own engine or the existing content assist
(Ctrl+Space)?
>
> In preference page > General > Keys I can specify shortcuts like
> "Ctrl+Shift+Space" which triggers the completion in my current editor.
> But how can I do that if I want to preconfigure this shortcut as
> plug-in developer?
>
> I tried:
> <extension point="org.eclipse.ui.bindings">
> <key sequence="Ctrl+7"
>
> commandId="org.eclipse.recommenders.completion.rcp.chain.category"
> schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
> contextId="org.eclipse.jdt.ui.javaEditorScope"/>
> </extension>
>
> but giving the completion context id as commandId does not work. I
> assume that I have to specify a command before.
Yes.
> But how do I specify that this command is bound to the particular code
> completion?
Either you bind an action or a handler to the command.

Dani
>
> Thanks in advance for some hints.
Re: Defining key shortcut for completion engine via extension point [message #775687 is a reply to message #775583] Fri, 06 January 2012 14:18 Go to previous messageGo to next message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 49
Registered: July 2009
Member
On 06.01.12 11:01, Daniel Megert wrote:
> On 30.12.2011 09:01, Marcel Bruch wrote:
>> HI,
>>
>> I'm looking for a way to specify a key shortcut for a completion
>> engine via extension points.
> Are you talking about your own engine or the existing content assist
> (Ctrl+Space)?

My own.

>> but giving the completion context id as commandId does not work. I
>> assume that I have to specify a command before.
> Yes.
>> But how do I specify that this command is bound to the particular code
>> completion?
> Either you bind an action or a handler to the command.

I apologize, but I've yet no exact idea how to execute code completion
than. When registering a handler, I'm supposed to trigger completion for
the active editor contents than?

e.g. by something like this?:

public class SampleHandler extends AbstractHandler {
public Object execute(ExecutionEvent event) throws Exception {
// should I trigger code completion in here manually?
ICompilationUnit cu = ...
cu.codeComplete(...); // how can I specify that
// code completion to use is my own one?
}

I'm obviously missing one important detail here... ;)
Re: Defining key shortcut for completion engine via extension point [message #776014 is a reply to message #775687] Sat, 07 January 2012 06:48 Go to previous message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 286
Registered: July 2009
Senior Member

Found a gem that showed how to trigger code completion from a handler ( org.eclipse.jdt.internal.ui.text.java.JavaContentAssistHandler):

    private static final String CHAIN_COMPLETION_CATEGORY = "org.eclipse.recommenders.completion.rcp.chain.category";
    private final CompletionProposalComputerRegistry registry = CompletionProposalComputerRegistry.getDefault();
    private final SpecificContentAssistExecutor executor = new SpecificContentAssistExecutor(registry);

    @Override
    public Object execute(final ExecutionEvent event) throws ExecutionException {
        Optional<JavaEditor> opt = JdtUtils.getActiveJavaEditor();
        if (opt.isPresent()) {
            executor.invokeContentAssist(opt.get(), CHAIN_COMPLETION_CATEGORY);
        }
        return null;
    }


Despite that it works. It's unclear to me how to make this shortcut appear in "Preferences >> Java >> Editor >> Content Assist >> Advanced". Am _I_ (my code) supposed to keep the shortcut in sync between JDT UI and the 'official' key binding specified for the handler in plug-in XML somehow?

For instance, on plug-in startup check which shortcut is currently defined for my command and than update JDT preferences accordingly? If I have to do this, can't I just set the JDT preference for my category to Ctrl+Shift+Space?

Thanks for a short note on this.
Marcel

index.php/fa/6659/0/


[Updated on: Sat, 07 January 2012 06:49]

Report message to a moderator

Previous Topic:Accessing the latest jdt.core.dom.CompilationUnit from completion context
Next Topic:Creating runnable JAR file with external library
Goto Forum:
  


Current Time: Sun Oct 21 00:15:23 GMT 2018

Powered by FUDForum. Page generated in 0.02764 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top