覆盖标记点击操作

时间:2018-10-26 13:25:24

标签: eclipse eclipse-plugin eclipse-rcp eclipse-pde

我想在用户单击编辑器左垂直标尺上的标记时添加自定义动作

enter image description here

我设法通过在plugin.xml中添加以下代码来运行自定义操作:

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

我想调用IQuickFixProcessor的自定义实现,但是实现的方法getCorrections需要IInvocationContextIProblemLocation[]。 我如何获得这些信息?

我想到的一个非常糟糕的方法是模拟Ctrl+1快捷键的按下,但是如果尖晶石与所单击的标记不在同一行,它将为该尖晶石显示快速修复:

public class MarkerClickAction implements IEditorActionDelegate {

    @Override
    public void run(IAction action) {
        Robot robot = null;
        try {
            robot = new Robot();
        } catch (AWTException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_1);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.keyRelease(KeyEvent.VK_1);
    }

    @Override
    public void selectionChanged(IAction action, ISelection selection) {
        // TODO Auto-generated method stub

    }

    @Override
    public void setActiveEditor(IAction action, IEditorPart targetEditor) {
        // TODO Auto-generated method stub

    }

}

如果无法调用Ctrl + 1快捷方式后面的方法,该如何将小刀放置在标记的行上?

0 个答案:

没有答案