从 editorAction 迁移到 org.eclipse.ui.menus

Migrating from editorAction to org.eclipse.ui.menus

对于我拥有的 previous question,我找到了一个解决方案,该解决方案利用了一些已弃用的 API。

所以当用户点击标记时 运行 一些东西,我将其添加到我的 plugin.xml:

<extension point="org.eclipse.ui.editorActions">
    <editorContribution targetID="org.eclipse.cdt.ui.editor.CEditor"
        id="org.eclipse.ui.texteditor.ruler.actions">
         <action
               actionID="RulerClick"
               class="com.example.MarkerClickAction"
               id="com.example.MarkerClickAction"
               label="%Dummy.label">
         </action>
    </editorContribution>
</extension>

我试图将 editorActions 翻译成 org.eclipse.ui.menus,到目前为止我想出了这个:

<extension
      point="org.eclipse.ui.menus">
   <menuContribution
         allPopups="false"
         locationURI="org.eclipse.cdt.ui.editor.CEditor">
      <command
            commandId="com.example.MarkerClickAction"
            description="Opens Quick Fix when the user clicks a marker"
            id="org.eclipse.ui.texteditor.ruler.actions"
            name="Marker Click Action">
      </command>
   </menuContribution>
</extension>
<extension
    point="org.eclipse.ui.handlers">
    <handler
        class="com.example.MarkerClickAction"
        commandId="com.example.MarkerAction">
    </handler>
</extension>  

我不知道如何映射的唯一一件事是 <action> 中的 actionID="RulerClick" 字段。
我应该在哪里配置该信息?

您还需要一个 org.eclipse.ui.commands 扩展点来定义命令 ID。

没有从处理程序到旧操作的简单映射。

处理程序通常会扩展 org.eclipse.core.commands.AbstractHandler

org.eclipse.ui.handlers.HandlerUtil class 为处理程序提供了许多辅助方法来执行诸如获取活动编辑器之类的操作。

请注意,虽然 org.eclipse.ui.editorActions 被标记为已弃用,但由于现有代码使用它的太多,因此它不太可能被删除。