Search in sources :

Example 1 with EditorMouseEventArea

use of com.intellij.openapi.editor.event.EditorMouseEventArea in project intellij-community by JetBrains.

the class OpenInEditorWithMouseAction method update.

@Override
public void update(@NotNull AnActionEvent e) {
    InputEvent inputEvent = e.getInputEvent();
    if (!(inputEvent instanceof MouseEvent)) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    if (e.getProject() == null) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    if (e.getData(OpenInEditorAction.KEY) == null) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    Component component = inputEvent.getComponent();
    if (component == null) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    Point point = ((MouseEvent) inputEvent).getPoint();
    Component componentAt = SwingUtilities.getDeepestComponentAt(component, point.x, point.y);
    if (!(componentAt instanceof EditorGutterComponentEx)) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    Editor editor = getEditor(componentAt);
    if (editor == null) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    MouseEvent convertedEvent = SwingUtilities.convertMouseEvent(inputEvent.getComponent(), (MouseEvent) inputEvent, componentAt);
    EditorMouseEventArea area = editor.getMouseEventArea(convertedEvent);
    if (area != EditorMouseEventArea.LINE_NUMBERS_AREA) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    e.getPresentation().setEnabledAndVisible(true);
}
Also used : EditorGutterComponentEx(com.intellij.openapi.editor.ex.EditorGutterComponentEx) MouseEvent(java.awt.event.MouseEvent) InputEvent(java.awt.event.InputEvent) EditorMouseEventArea(com.intellij.openapi.editor.event.EditorMouseEventArea) Editor(com.intellij.openapi.editor.Editor)

Aggregations

Editor (com.intellij.openapi.editor.Editor)1 EditorMouseEventArea (com.intellij.openapi.editor.event.EditorMouseEventArea)1 EditorGutterComponentEx (com.intellij.openapi.editor.ex.EditorGutterComponentEx)1 InputEvent (java.awt.event.InputEvent)1 MouseEvent (java.awt.event.MouseEvent)1