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

The following examples show how to use com.intellij.openapi.editor.event.EditorMouseEvent. 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: EditorEventManager.java    From lsp4intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Called when the mouse is clicked
 * At the moment, is used by CTRL+click to see references / goto definition
 *
 * @param e The mouse event
 */
public void mouseClicked(EditorMouseEvent e) {
    if (e.getEditor() != editor) {
        LOG.error("Wrong editor for EditorEventManager");
        return;
    }

    if (getIsCtrlDown()) {
        // If CTRL/CMD key is pressed, triggers goto definition/references and hover.
        try {
            trySourceNavigationAndHover(e);
        } catch (Exception err) {
            LOG.warn("Error occurred when trying source navigation", err);
        }
    }
}
 
Example #2
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 #3
Source File: PreviewEditorMouseListener.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void mouseMoved(EditorMouseEvent e){
	int offset = getEditorCharOffsetAndRemoveTokenHighlighters(e);
	if ( offset<0 ) return;

	Editor editor=e.getEditor();
	if ( inputPanel.previewState==null ) {
		return;
	}

	MouseEvent mouseEvent=e.getMouseEvent();
	InputPanel.clearTokenInfoHighlighters(e.getEditor());
	if ( mouseEvent.isControlDown() && inputPanel.previewState.parsingResult!=null ) {
		inputPanel.showTokenInfoUponCtrlKey(editor, inputPanel.previewState, offset);
	}
	else if ( mouseEvent.isAltDown() && inputPanel.previewState.parsingResult!=null ) {
		inputPanel.showParseRegion(e, editor, inputPanel.previewState, offset);
	}
	else { // just moving around, show any errors or hints
		InputPanel.showTooltips(e, editor, inputPanel.previewState, offset);
	}
}
 
Example #4
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 #5
Source File: EditorEventManager.java    From lsp4intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the logical position given a mouse event
 *
 * @param e The event
 * @return The position (or null if out of bounds)
 */
private LogicalPosition getPos(EditorMouseEvent e) {
    Point mousePos = e.getMouseEvent().getPoint();
    LogicalPosition editorPos = editor.xyToLogicalPosition(mousePos);
    Document doc = e.getEditor().getDocument();
    int maxLines = doc.getLineCount();
    if (editorPos.line >= maxLines) {
        return null;
    } else {
        int minY = doc.getLineStartOffset(editorPos.line) - (editorPos.line > 0 ?
                doc.getLineEndOffset(editorPos.line - 1) : 0);
        int maxY = doc.getLineEndOffset(editorPos.line) - (editorPos.line > 0 ?
                doc.getLineEndOffset(editorPos.line - 1) : 0);
        return (editorPos.column > minY && editorPos.column < maxY) ? editorPos : null;
    }
}
 
Example #6
Source File: ConsoleViewImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private EditorEx createConsoleEditor() {
  return ReadAction.compute(() -> {
    EditorEx editor = doCreateConsoleEditor();
    LOG.assertTrue(UndoUtil.isUndoDisabledFor(editor.getDocument()));
    editor.installPopupHandler(new ContextMenuPopupHandler() {
      @Override
      public ActionGroup getActionGroup(@Nonnull EditorMouseEvent event) {
        return getPopupGroup(event.getMouseEvent());
      }
    });

    int bufferSize = ConsoleBuffer.useCycleBuffer() ? ConsoleBuffer.getCycleBufferSize() : 0;
    editor.getDocument().setCyclicBufferSize(bufferSize);

    editor.putUserData(CONSOLE_VIEW_IN_EDITOR_VIEW, this);

    editor.getSettings().setAllowSingleLogicalLineFolding(true); // We want to fold long soft-wrapped command lines

    return editor;
  });
}
 
Example #7
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 #8
Source File: EventLogConsole.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void addConfigureNotificationAction(@Nonnull EditorEx editor, @Nonnull EditorMouseEvent event, @Nonnull final DefaultActionGroup actions) {
  LogicalPosition position = editor.xyToLogicalPosition(event.getMouseEvent().getPoint());
  if (EditorUtil.inVirtualSpace(editor, position)) {
    return;
  }
  int offset = editor.logicalPositionToOffset(position);
  editor.getMarkupModel().processRangeHighlightersOverlappingWith(offset, offset, new Processor<RangeHighlighterEx>() {
    @Override
    public boolean process(RangeHighlighterEx rangeHighlighter) {
      String groupId = GROUP_ID.get(rangeHighlighter);
      if (groupId != null) {
        addConfigureNotificationAction(actions, groupId);
        return false;
      }
      return true;
    }
  });
}
 
Example #9
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 #10
Source File: AbstractValueHint.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static ValueHintType getHintType(final EditorMouseEvent e) {
  int modifiers = e.getMouseEvent().getModifiers();
  if (modifiers == 0) {
    return ValueHintType.MOUSE_OVER_HINT;
  }
  else if (isAltMask(modifiers)) {
    return ValueHintType.MOUSE_ALT_OVER_HINT;
  }
  return null;
}
 
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 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 #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 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 #14
Source File: CustomEditorMouseListener.java    From jetbrains-wakatime with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void mousePressed(EditorMouseEvent editorMouseEvent) {
    FileDocumentManager instance = FileDocumentManager.getInstance();
    VirtualFile file = instance.getFile(editorMouseEvent.getEditor().getDocument());
    Project project = editorMouseEvent.getEditor().getProject();
    WakaTime.appendHeartbeat(file, project, false);
}
 
Example #15
Source File: PreviewEditorMouseListener.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void mouseClicked(EditorMouseEvent e) {
	final int offset = getEditorCharOffsetAndRemoveTokenHighlighters(e);
	if ( offset<0 ) return;

	final Editor editor=e.getEditor();
	if ( inputPanel.previewState==null ) {
		return;
	}

	if ( e.getMouseEvent().getButton()==MouseEvent.BUTTON3 ) { // right click
		rightClick(e, inputPanel.previewState, editor, offset);
		return;
	}

	MouseEvent mouseEvent=e.getMouseEvent();
	if ( mouseEvent.isControlDown() ) {
		inputPanel.setCursorToGrammarElement(e.getEditor().getProject(), inputPanel.previewState, offset);
		inputPanel.setCursorToHierarchyViewElement(offset);
	}
	else if ( mouseEvent.isAltDown() ) {
		inputPanel.setCursorToGrammarRule(e.getEditor().getProject(), inputPanel.previewState, offset);
	}
	else {
		inputPanel.setCursorToHierarchyViewElement(offset);
	}
	InputPanel.clearDecisionEventHighlighters(editor);
}
 
Example #16
Source File: ImageOrColorPreviewManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseMoved(@Nonnull EditorMouseEvent event) {
  Editor editor = event.getEditor();
  if (editor.isOneLineMode()) {
    return;
  }

  alarm.cancelAllRequests();
  Point point = event.getMouseEvent().getPoint();
  if (myElements == null && event.getMouseEvent().isShiftDown()) {
    alarm.addRequest(new PreviewRequest(point, editor, false), 100);
  }
  else {
    Collection<PsiElement> elements = myElements;
    if (!getPsiElementsAt(point, editor).equals(elements)) {
      myElements = null;
      for (ElementPreviewProvider provider : Extensions.getExtensions(ElementPreviewProvider.EP_NAME)) {
        try {
          if (elements != null) {
            for (PsiElement element : elements) {
              provider.hide(element, editor);
            }
          } else {
            provider.hide(null, editor);
          }
        }
        catch (Exception e) {
          LOG.error(e);
        }
      }
    }
  }
}
 
Example #17
Source File: GTMEditorMouseListener.java    From gtm-jetbrains-plugin with MIT License 5 votes vote down vote up
@Override
public void mousePressed(EditorMouseEvent editorMouseEvent) {
    final FileDocumentManager instance = FileDocumentManager.getInstance();
    final VirtualFile file = instance.getFile(editorMouseEvent.getEditor().getDocument());
    if (file != null) {
        GTMRecord.record(file.getPath(), editorMouseEvent.getEditor().getProject());
    }
}
 
Example #18
Source File: ANTLRv4PluginController.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void mouseEnteredGrammarEditorEvent(VirtualFile vfile, EditorMouseEvent e) {
	if ( previewPanel!=null ) {
		ProfilerPanel profilerPanel = previewPanel.getProfilerPanel();
		if ( profilerPanel!=null ) {
			profilerPanel.mouseEnteredGrammarEditorEvent(vfile, e);
		}
	}
}
 
Example #19
Source File: ANTLRv4PluginController.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void mouseClicked(EditorMouseEvent e) {
	Document doc = e.getEditor().getDocument();
	VirtualFile vfile = FileDocumentManager.getInstance().getFile(doc);
	if ( vfile!=null && vfile.getName().endsWith(".g4") ) {
		mouseEnteredGrammarEditorEvent(vfile, e);
	}
}
 
Example #20
Source File: DiffSideView.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void mouseReleased(EditorMouseEvent e) {
  if (!isEventHandled(e.getMouseEvent()) || !isInMyArea(e)) {
    return;
  }
  OpenFileDescriptor descriptor = getOpenFileDescriptor(e);
  if (descriptor == null) {
    return;
  }
  myContainer.showSource(descriptor);
}
 
Example #21
Source File: DiffSideView.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void mouseMoved(EditorMouseEvent e) {
  Editor editor = e.getEditor();
  if (editor.getProject() != null && editor.getProject() != myProject && myProject != null/*???*/) return;
  if (!isInMyArea(e)) return;
  Cursor cursor = getOpenFileDescriptor(e) != null ? HAND__CURSOR : Cursor.getDefaultCursor();
  e.getMouseEvent().getComponent().setCursor(cursor);
  myEditor.getContentComponent().setCursor(cursor);
}
 
Example #22
Source File: MergeSearchHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Change findChangeAt(EditorMouseEvent e, MergePanel2 mergePanel, int index) {
  if (mergePanel.getMergeList() == null) return null;
  Editor editor = e.getEditor();
  LOG.assertTrue(editor == mergePanel.getEditor(index));
  LogicalPosition logicalPosition = editor.xyToLogicalPosition(e.getMouseEvent().getPoint());
  int offset = editor.logicalPositionToOffset(logicalPosition);
  return forMergeList(mergePanel.getMergeList(), index).findChangeAt(offset);
}
 
Example #23
Source File: EditorActionUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link EditorEx#setContextMenuGroupId(String)} or
 * {@link EditorEx#installPopupHandler(com.intellij.openapi.editor.ex.EditorPopupHandler)} instead. To be removed in version 2020.2.
 */
@Deprecated
//@ApiStatus.ScheduledForRemoval(inVersion = "2020.2")
public static EditorPopupHandler createEditorPopupHandler(@Nonnull final ActionGroup group) {
  return new EditorPopupHandler () {
    @Override
    public void invokePopup(final EditorMouseEvent event) {
      showEditorPopup(event, group);
    }
  };
}
 
Example #24
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 #25
Source File: EventLogConsole.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static DefaultActionGroup createPopupActions(ActionManager actionManager, ClearLogAction action, EditorEx editor, EditorMouseEvent event) {
  AnAction[] children = ((ActionGroup)actionManager.getAction(IdeActions.GROUP_CONSOLE_EDITOR_POPUP)).getChildren(null);
  DefaultActionGroup group = new DefaultActionGroup();
  addConfigureNotificationAction(editor, event, group);
  group.addAll(children);
  group.addSeparator();
  group.add(action);
  return group;
}
 
Example #26
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 #27
Source File: EditorMouseListenerImpl.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseClicked(EditorMouseEvent editorMouseEvent) {
    if (checkEnabled()) {
        manager.mouseClicked(editorMouseEvent);
    }

}
 
Example #28
Source File: ContextMenuPopupHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public abstract ActionGroup getActionGroup(@Nonnull EditorMouseEvent event);
 
Example #29
Source File: ImageOrColorPreviewManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void mouseDragged(EditorMouseEvent e) {
  // nothing
}
 
Example #30
Source File: FoldingPopupManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void mousePressed(@Nonnull EditorMouseEvent e) {
}