快捷键在 eclipse RCP java 项目中不起作用

Shortcut key is not working in eclipse RCP java project

我有 eclipse RCP java 项目,其中我启用了快捷键 Ctrl+Hctrl+S 用于保存和其他活动。在我将我的项目导入 64 位 Eclipse indigo 之前,它工作正常。大多数键都在工作,但这两个键没有。我检查过 Ctrl+S 是否与 defaultHandler 关联。

现在抛出以下异常:

ENTRY org.eclipse.ui.workbench 2 0 2015-01-21 15:07:08.646
!MESSAGE A handler conflict occurred.  This may disable some commands.
!SUBENTRY 1 org.eclipse.ui.workbench 2 0 2015-01-21 15:07:08.646
!MESSAGE Conflict for 'org.eclipse.ui.file.save':
HandlerActivation(commandId=org.eclipse.ui.file.save,
    handler=org.eclipse.ui.internal.handlers.SaveHandler@4e65ad52,
    expression=,sourcePriority=0)

更新:

public class KBShortcutsHandler extends AbstractHandler {

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {

        if (event.getCommand().getId().equals("org.eclipse.ui.file.save")) {
                        new XyzHandler(XConstants.SAVE_EDITOR_ID)
                .run();
        }
    }

}

在plugin.xml

     <command
            defaultHandler="KBShortcutsHandler"
            id="org.eclipse.ui.file.save"
            name="save">
      </command>

只需将代码写入 "Add Action" 它工作正常但现在不行。

Eclipse 已经定义了 org.eclipse.ui.file.save 命令,所以您不应该尝试自己定义它。而是使用 org.eclipse.ui.handlers 扩展点来定义要在您的代码处于活动状态时使用的处理程序。

以下是 Debug 插件如何处理 'delete' 命令的示例:

<extension
     point="org.eclipse.ui.handlers">
  <handler
        class="org.eclipse.debug.internal.ui.views.launch.TerminateAndRemoveHandler"
        commandId="org.eclipse.ui.edit.delete">
     <activeWhen>
        <iterate
              ifEmpty="false"
              operator="and">
           <adapt
                 type="org.eclipse.debug.core.model.ITerminate">
           </adapt>
        </iterate>
     </activeWhen>
  </handler>
</extension>

我注意到您的常量 XConstants.SAVE_EDITOR_ID - 如果您尝试在编辑器中保存,如果它基于 EditorPart,则无需执行任何操作。

  • 这个"org.eclipse.ui.workbench_3.7.1.v20120104-1859.jar"workBench jar 必须包含存在于内部的 SaveHandler class org.eclipse.ui.internal.handlers 包裹。 下面一行必须从 plugin.xml

    中删除

这对我有用。