简体   繁体   English

将快捷方式添加到插件中定义的快捷方式 Eclipse 操作

[英]Adding shortcut to shortcutles Eclipse actions defined in plugins

There is a plugin that has an action (action itself is even placed on toolbar ie Tomcat runner and Vim editing mode).有一个具有动作的插件(动作本身甚至被放置在工具栏上,即 Tomcat 跑步者和 Vim 编辑模式)。

So is there any way to add conveniently shortcuts to these actions, which have no shortcuts implicitly defined, by say changing an XML configuration...那么有什么方法可以方便地为这些操作添加快捷方式,这些操作没有隐式定义快捷方式,比如更改 XML 配置......

Any advices are appreciated.任何建议表示赞赏。

There are two different ways to contribute to the Eclipse Workbench: Actions and Commands.有两种不同的方式可以为 Eclipse 工作台做出贡献:操作和命令。

Prefer using the command framework taht is newer & more complete than the action one and that allows to add key binding easily.更喜欢使用命令框架,它比操作框架更新、更完整,并且允许轻松添加键绑定。

Have a look to the org.eclipse.ui.bindings extension point to contribute a key binding for a given command: http://wiki.eclipse.org/FAQ_How_do_I_provide_a_keyboard_shortcut_for_my_action%3F Have a look to the org.eclipse.ui.bindings extension point to contribute a key binding for a given command: http://wiki.eclipse.org/FAQ_How_do_I_provide_a_keyboard_shortcut_for_my_action%3F

A more complete article about the Eclipse command framework: http://www.vogella.de/articles/EclipseCommands/article.html关于Eclipse命令框架的更完整的文章: http://www.vogella.de/articles/EclipseCommands/article.html

The answer is Yes you can do it.答案是肯定的,你可以做到。

  • Try window->preferences->keys now here you create new bindings or can change the old ones.现在尝试window->preferences->keys在这里您可以创建新绑定或更改旧绑定。

Example:例子:

>>Original >>原创

在此处输入图像描述

>>Setting it >>设置

在此处输入图像描述

>>Result >>结果

在此处输入图像描述

Note: There is a hard way as mentioned in @greydet answer.注意: @greydet 回答中提到了一种艰难的方式。 But, don't worry its not that hard.但是,不要担心它没有那么难。 Follow these steps:按着这些次序:

  1. Identify the plug-in contributing the action.确定促成该操作的插件。 Lets if its a Java related action then most probably you will find it in org.eclipse.jdt.ui .如果它是 Java 相关操作,那么您很可能会在org.eclipse.jdt.ui中找到它。 Mostly a well written plugin divides its UI and processing component in different plugins.大多数情况下,编写良好的插件会将其 UI 和处理组件划分为不同的插件。
  2. Now open its plugin.xml现在打开它的插件。xml
  3. Search for your action item which you want to modify with name or some fuzzy id etc.搜索您要使用name或一些模糊 ID 等修改的操作项。
  4. Mostly there has to be command.大多数情况下必须有命令。 If you find then good.如果你找到那么好。 Now write a very small plugin with a binding extension point.现在编写一个带有绑定扩展点的非常小的插件。 Use the values you have found earlier for the command extension.使用您之前为命令扩展找到的值。

For example for java getter and setter action following is the command extension point:例如对于 java getter 和 setter 操作,以下是命令扩展点:

  <command
        name="%ActionDefinition.getterSetter.name"
        description="%ActionDefinition.getterSetter.description"
        categoryId="org.eclipse.jdt.ui.category.source"
        id="org.eclipse.jdt.ui.edit.text.java.create.getter.setter">
  </command>

The corresponding binding extension I have written:我写的相应的绑定扩展:

<plugin>
   <extension
         point="org.eclipse.ui.bindings">
      <key
            commandId="org.eclipse.jdt.ui.edit.text.java.create.getter.setter"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            sequence="CTRL+T">
      </key>
   </extension>

</plugin>

The Problem: The command you earlier found is for package explorer view.问题:您之前找到的命令适用于package explorer视图。 There is a command contributed by the java editor also. java 编辑器也提供了一个命令。 You have to create a binding for that.您必须为此创建一个绑定。

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

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