简体   繁体   English

自定义Eclipse内容辅助的键绑定

[英]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 ). 我已经将内容辅助提议计算机实现为eclipse插件(使用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. 我尝试通过扩展org.eclipse.ui.bindings做到这一点,但这需要定义org.eclipse.ui.commands ,一个handler ,以及可能更多的东西。

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. 似乎已经为我的自定义内容辅助计算机创建了一个命令,因为它出现在键绑定菜单下(在Windows->Preferences->Keys ),但我不知道这个命令的id是什么。 If that command is created at runtime, then can I even refer to its commandId in my plugin.xml? 如果该命令是在运行时创建的,那么我甚至commandId在plugin.xml中引用它的commandId吗?

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). 1)与自定义完成提议计算机相关联的命令是org.eclipse.jdt.ui.specific_content_assist.command ,它在org.eclipse.jdt.ui插件的plugin.xml中定义(由eclipse提供)。

2) This is a parametrized command, which means it takes a commandParameter with id=org.eclipse.jdt.ui.specific_content_assist.category_id . 2)这是一个参数化命令,这意味着它需要一个id=org.eclipse.jdt.ui.specific_content_assist.category_id的commandParameter。 The value of this parameter should be the id of the proposalCategory for your javaCompletionProposalComputer . 此参数的值应该是javaCompletionProposalComputerproposalCategory的id。

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! 无需定义新的命令或处理程序!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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