【问题标题】:Key binding for Eclipse commandsEclipse 命令的键绑定
【发布时间】:2011-06-20 12:44:05
【问题描述】:

我想将 Toggle Breakpoint 命令 org.eclipse.debug.ui.commands.ToggleBreakpoint 绑定到 F9 键。

我是这样扩展org.eclipse.ui.bindings的:

<extension point="org.eclipse.ui.bindings">
  <scheme
        description="Default scheme for xvr"
        id="org.xvr.scheme"
        name="xvr.scheme"
        parentId="org.eclipse.ui.defaultAcceleratorConfiguration">
  </scheme>
  <key
        commandId="org.eclipse.debug.ui.commands.ToggleBreakpoint"
        contextId="org.eclipse.ui.contexts.window"
        schemeId="org.xvr.scheme"
        sequence="F9">
  </key>

但是当我启动我的 RCP 应用程序时,如果我按下 F9,什么也不会发生。

我做错了什么?

编辑

抱歉造成误会,但我正在从 eclipse 开发新产品,无法使用 eclipse 的偏好窗口。

我必须通过 org.eclipse.ui.bindings 扩展点提供绑定。

EDIT2

感谢 Paul,使用跟踪我看到按 F9

时引发了异常
COMMANDS >>> execute >>> starting: id=org.eclipse.debug.ui.commands.ToggleBreakpoint; event=ExecutionEvent(Command(org.eclipse.debug.ui.commands.ToggleBreakpoint,Toggle Breakpoint,
        Creates or removes a breakpoint,
        Category(org.eclipse.debug.ui.category.run,Run/Debug,Run/Debug command category,true),
        ,
        ,,true),{},Event {type=1 StyledText {} time=25349140 data=null x=0 y=0 width=0 height=0 detail=0},org.eclipse.core.expressions.EvaluationContext@ffa7e1)
COMMANDS >>> execute >>> not handled: id=org.eclipse.debug.ui.commands.ToggleBreakpoint; exception=org.eclipse.core.commands.NotHandledException: There is no handler to execute for command org.eclipse.debug.ui.commands.ToggleBreakpoint

【问题讨论】:

  • 您的错误日志中有什么内容吗? &lt;workspace&gt;/.metadata/.log 或者您可以将 -consoleLog 添加到您的启动参数中。您还可以设置一些跟踪选项以查看按 F9 时会发生什么 - wiki.eclipse.org/Platform_Command_Framework#Tracing_Option
  • 感谢 Paul!使用跟踪选项我看到抛出了一个异常......更多关于编辑
  • 这意味着在您的 RCP 中没有提供该命令的实现。在你的 Eclipse 中运行跟踪,你就会知道是什么在做这项工作。

标签: java eclipse eclipse-plugin eclipse-rcp


【解决方案1】:

您需要在plugin.xml 中添加以下内容,其中defaultHandler 是一个扩展AbstractHandler 并覆盖execute()

的类>
   <extension point="org.eclipse.ui.commands">
    <command name="Remove All Comments"
        defaultHandler="commentremover.actions.CommentRemover"
        description="Removes all comments in source code"
        categoryId="org.eclipse.jdt.ui.category.source"
        id="commentremover.removeallcomments">
   </command>
</extension>

另外,您需要添加以下内容,其中 commandId 等于您在上面定义的命令的 id

    <extension point="org.eclipse.ui.bindings">
    <key sequence="Ctrl+Shift+D"
        commandId="commentremover.removeallcomments"
        schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
        contextId="org.eclipse.jdt.ui.javaEditorScope"/>
</extension>

以上就是让我的插件工作所需的全部内容。如果它出现在“键”首选项菜单中,您将知道它正在工作。它是一个插件,当你按下 Ctrl+Shift+D 时,它会删除源代码中的所有 cmets。

【讨论】:

  • 如果我定义了命令,这将是真的..不是吗? ToggleBreakpoint 是 org.eclipse.debug.ui.commands.* 中定义的命令,我想使用该命令。我成功地绑定了来自 org.eclipse.debug.ui.commands.* 的其他命令,但没有绑定 ToggleBreakpoint。
  • 如果您想覆盖现有命令的行为,我之前通过隐藏整个 JDT 包来实现。但是,不能保证您的代码会运行而不是原始代码。我相信另一种方法是使用功能补丁。
【解决方案2】:

我建议你去

Windows首选项常规按键

并简单地将 F9 分配给 Toggle Breakpoint 命令。

【讨论】:

  • 您好,感谢您的回复,但事实并非如此。我更新了我的问题。
【解决方案3】:

您没有指定您正在使用哪个平台,但是...

一些平台 - 例如。 MacOS - F9F10 等的键分配无法更改:-(

您也可以在常规 Eclipse 中尝试,也可以从 Keys 首选项页面中进行尝试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-20
    • 2021-04-18
    相关资源
    最近更新 更多