Override marker click action

泪湿孤枕 提交于 2019-12-24 01:01:41

问题


I want to add a custom action when the user clicks on a marker from the left vertical ruler of the editor

I managed to run a custom action by adding in the plugin.xml the following code:

<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>

I want to call a custom implementation of the IQuickFixProcessor, but the implemented method getCorrections requires an IInvocationContext and IProblemLocation[]. How can I get those informations?

A really bad implentation which I thought of was to simulate the Ctrl+1 shortcut press, but if the carret is not positioned on the same line with the clicked marker, it will show quick fixes for the one from the carret:

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

    }

}

If it's not possible to call the methods behind the Ctrl + 1 shortcut, how can I position the carret to the marker's line?

来源:https://stackoverflow.com/questions/53009796/override-marker-click-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!