com.intellij.openapi.editor.event.EditorMouseEventArea Java Examples

The following examples show how to use com.intellij.openapi.editor.event.EditorMouseEventArea. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void fireEventToTextAnnotationListeners(final MouseEvent e) {
  if (myEditor.getMouseEventArea(e) == EditorMouseEventArea.ANNOTATIONS_AREA) {
    final Point clickPoint = e.getPoint();

    final TextAnnotationGutterProvider provider = getProviderAtPoint(clickPoint);

    if (provider == null) {
      return;
    }

    EditorGutterAction action = myProviderToListener.get(provider);
    if (action != null) {
      int line = getLineNumAtPoint(clickPoint);

      if (line >= 0 && line < myEditor.getDocument().getLineCount() && UIUtil.isActionClick(e, MouseEvent.MOUSE_RELEASED)) {
        action.doAction(line);
      }
    }
  }
}
 
Example #2
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
EditorMouseEventArea getEditorMouseAreaByOffset(int offset) {
  if (isLineNumbersShown() && offset < getLineNumberAreaOffset() + getLineNumberAreaWidth()) {
    return EditorMouseEventArea.LINE_NUMBERS_AREA;
  }

  if (isAnnotationsShown() && offset < getAnnotationsAreaOffset() + getAnnotationsAreaWidth()) {
    return EditorMouseEventArea.ANNOTATIONS_AREA;
  }

  if (isLineMarkersShown() && offset < getFoldingAreaOffset()) {
    return EditorMouseEventArea.LINE_MARKERS_AREA;
  }

  if (isFoldingOutlineShown() && offset < getFoldingAreaOffset() + getFoldingAreaWidth()) {
    return EditorMouseEventArea.FOLDING_OUTLINE_AREA;
  }

  return null;
}
 
Example #3
Source File: CommentsDiffTool.java    From review-board-idea-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void show(DiffRequest request) {
    final FrameWrapper frameWrapper = new FrameWrapper(request.getProject(), request.getGroupKey());
    final DiffPanelImpl diffPanel = createDiffPanelImpl(request, frameWrapper.getFrame(), frameWrapper);
    final Editor editor = diffPanel.getEditor2();
    updateHighLights(editor);

    editor.addEditorMouseListener(new EditorMouseAdapter() {
        @Override
        public void mouseClicked(EditorMouseEvent e) {
            if (e.getArea() != null && e.getArea().equals(EditorMouseEventArea.LINE_MARKERS_AREA)) {
                final Point locationOnScreen = e.getMouseEvent().getLocationOnScreen();
                final int lineNumber = EditorUtil.yPositionToLogicalLine(editor, e.getMouseEvent()) + 1;
                showCommentsView(locationOnScreen, lineNumber, editor, e);
            }
        }
    });

    DiffUtil.initDiffFrame(request.getProject(), frameWrapper, diffPanel, diffPanel.getComponent());
    frameWrapper.setTitle(request.getWindowTitle());
    frameWrapper.setPreferredFocusedComponent(diffPanel.getComponent());
    frameWrapper.show();
}
 
Example #4
Source File: PreviewEditorMouseListener.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private int getEditorCharOffsetAndRemoveTokenHighlighters(EditorMouseEvent e) {
		if ( e.getArea()!=EditorMouseEventArea.EDITING_AREA ) {
			return -1;
		}

		MouseEvent mouseEvent=e.getMouseEvent();
		Editor editor=e.getEditor();
		int offset = MyActionUtils.getMouseOffset(mouseEvent, editor);
//		System.out.println("offset="+offset);

		if ( offset >= editor.getDocument().getTextLength() ) {
			return -1;
		}

		// Mouse has moved so make sure we don't show any token information tooltips
		InputPanel.clearTokenInfoHighlighters(e.getEditor());
		return offset;
	}
 
Example #5
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void processClose(final MouseEvent e) {
  final IdeEventQueue queue = IdeEventQueue.getInstance();

  // See IDEA-59553 for rationale on why this feature is disabled
  //if (isLineNumbersShown()) {
  //  if (e.getX() >= getLineNumberAreaOffset() && getLineNumberAreaOffset() + getLineNumberAreaWidth() >= e.getX()) {
  //    queue.blockNextEvents(e);
  //    myEditor.getSettings().setLineNumbersShown(false);
  //    e.consume();
  //    return;
  //  }
  //}

  if (getGutterRenderer(e) != null) return;

  if (myEditor.getMouseEventArea(e) == EditorMouseEventArea.ANNOTATIONS_AREA) {
    queue.blockNextEvents(e);
    closeAllAnnotations();
    e.consume();
  }
}
 
Example #6
Source File: FoldingPopupManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void mouseMoved(@Nonnull EditorMouseEvent e) {
  myAlarm.cancelAllRequests();
  Editor editor = e.getEditor();
  if (editor.getUserData(DISABLED) != null) return;
  if (e.getArea() == EditorMouseEventArea.EDITING_AREA) {
    MouseEvent mouseEvent = e.getMouseEvent();
    Point point = mouseEvent.getPoint();
    FoldRegion fold = ((EditorEx)editor).getFoldingModel().getFoldingPlaceholderAt(point);
    TooltipController controller = TooltipController.getInstance();
    if (fold != null && !fold.shouldNeverExpand()) {
      myAlarm.addRequest(() -> {
        if (editor.getUserData(DISABLED) != null || !editor.getComponent().isShowing() || !fold.isValid() || fold.isExpanded()) return;
        DocumentFragment range = createDocumentFragment(fold);
        Point p = SwingUtilities.convertPoint((Component)mouseEvent.getSource(), point, editor.getComponent().getRootPane().getLayeredPane());
        controller.showTooltip(editor, p, new DocumentFragmentTooltipRenderer(range), false, FOLDING_TOOLTIP_GROUP);
      }, TOOLTIP_DELAY_MS);
    }
    else {
      controller.cancelTooltip(FOLDING_TOOLTIP_GROUP, mouseEvent, true);
    }
  }
}
 
Example #7
Source File: PasteFromX11Action.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  Presentation presentation = e.getPresentation();
  Editor editor = e.getData(CommonDataKeys.EDITOR);
  if (editor == null || !SystemInfo.isXWindow) {
    presentation.setEnabled(false);
  }
  else {
    boolean rightPlace = true;
    final InputEvent inputEvent = e.getInputEvent();
    if (inputEvent instanceof MouseEvent) {
      rightPlace = false;
      final MouseEvent me = (MouseEvent)inputEvent;
      if (editor.getMouseEventArea(me) == EditorMouseEventArea.EDITING_AREA) {
        final Component component = SwingUtilities.getDeepestComponentAt(me.getComponent(), me.getX(), me.getY());
        rightPlace = !(component instanceof JScrollBar);
      }
    }
    presentation.setEnabled(rightPlace);
  }
}
 
Example #8
Source File: EditorPerfDecorations.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void mouseExited(EditorMouseEvent e) {
  final EditorMouseEventArea area = e.getArea();
  setHoverState(false);
  // TODO(jacobr): hovers over a tooltip triggered by a gutter icon should
  // be considered a hover of the gutter but this logic does not handle that
  // case correctly.
}
 
Example #9
Source File: ValueLookupManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void mouseMoved(EditorMouseEvent e) {
  if (e.isConsumed()) {
    return;
  }

  Editor editor = e.getEditor();
  if (editor.getProject() != null && editor.getProject() != myProject) {
    return;
  }

  ValueHintType type = AbstractValueHint.getHintType(e);
  if (e.getArea() != EditorMouseEventArea.EDITING_AREA ||
      DISABLE_VALUE_LOOKUP.get(editor) == Boolean.TRUE ||
      type == null) {
    myAlarm.cancelAllRequests();
    return;
  }

  Point point = e.getMouseEvent().getPoint();
  if (myRequest != null && !myRequest.isKeepHint(editor, point)) {
    hideHint();
  }

  for (DebuggerSupport support : mySupports) {
    QuickEvaluateHandler handler = support.getQuickEvaluateHandler();
    if (handler.isEnabled(myProject)) {
      requestHint(handler, editor, point, type);
      break;
    }
  }
}
 
Example #10
Source File: EditorActionUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void showEditorPopup(final EditorMouseEvent event, @Nonnull final ActionGroup group) {
  if (!event.isConsumed() && event.getArea() == EditorMouseEventArea.EDITING_AREA) {
    ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.EDITOR_POPUP, group);
    MouseEvent e = event.getMouseEvent();
    final Component c = e.getComponent();
    if (c != null && c.isShowing()) {
      popupMenu.getComponent().show(c, e.getX(), e.getY());
    }
    e.consume();
  }
}
 
Example #11
Source File: EditorPerfDecorations.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void mouseExited(EditorMouseEvent e) {
  final EditorMouseEventArea area = e.getArea();
  setHoverState(false);
  // TODO(jacobr): hovers over a tooltip triggered by a gutter icon should
  // be considered a hover of the gutter but this logic does not handle that
  // case correctly.
}
 
Example #12
Source File: EditorPerfDecorations.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void mouseEntered(EditorMouseEvent e) {
  final EditorMouseEventArea area = e.getArea();
  if (!hoveredOverLineMarkerArea &&
      area == EditorMouseEventArea.LINE_MARKERS_AREA ||
      area == EditorMouseEventArea.FOLDING_OUTLINE_AREA ||
      area == EditorMouseEventArea.LINE_NUMBERS_AREA) {
    // Hover is over the gutter area.
    setHoverState(true);
  }
}
 
Example #13
Source File: EditorPerfDecorations.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void mouseEntered(EditorMouseEvent e) {
  final EditorMouseEventArea area = e.getArea();
  if (!hoveredOverLineMarkerArea &&
      area == EditorMouseEventArea.LINE_MARKERS_AREA ||
      area == EditorMouseEventArea.FOLDING_OUTLINE_AREA ||
      area == EditorMouseEventArea.LINE_NUMBERS_AREA) {
    // Hover is over the gutter area.
    setHoverState(true);
  }
}
 
Example #14
Source File: TextComponentEditorImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public EditorMouseEventArea getMouseEventArea(@Nonnull final MouseEvent e) {
  throw new UnsupportedOperationException("Not implemented");
}
 
Example #15
Source File: DiffSideView.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean isInMyArea(EditorMouseEvent e) {
  return e.getArea() == EditorMouseEventArea.LINE_NUMBERS_AREA;
}
 
Example #16
Source File: OpenInEditorWithMouseAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void update(@Nonnull 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);
}
 
Example #17
Source File: EditorPopupHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void handle(EditorMouseEvent e) {
  if (e.getMouseEvent().isPopupTrigger() && e.getArea() == EditorMouseEventArea.EDITING_AREA) {
    invokePopup(e);
    e.consume();
  }
}
 
Example #18
Source File: LazyEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public EditorMouseEventArea getMouseEventArea(@Nonnull final MouseEvent e) {
  return getEditor().getMouseEventArea(e);
}
 
Example #19
Source File: EditorWindowImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public EditorMouseEventArea getMouseEventArea(@Nonnull final MouseEvent e) {
  return myDelegate.getMouseEventArea(e);
}
 
Example #20
Source File: Editor.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the editor area (text, gutter, folding outline and so on) in which the specified
 * mouse event occurred.
 *
 * @param e the mouse event for which the area is requested.
 * @return the editor area, or null if the event occurred over an unknown area.
 */
@Nullable
default EditorMouseEventArea getMouseEventArea(@Nonnull MouseEvent e) {
  throw new UnsupportedOperationException("Unsupported platform");
}