@Override
 public void invokePopup(final EditorMouseEvent event) {
   if (!event.isConsumed() && event.getArea() == EditorMouseEventArea.EDITING_AREA) {
     ActionGroup group =
         (ActionGroup)
             CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_EDITOR_POPUP);
     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();
   }
 }
Ejemplo n.º 2
0
        @Override
        public void mouseMoved(final EditorMouseEvent e) {
          if (e.isConsumed() || !myProject.isInitialized() || myProject.isDisposed()) {
            return;
          }
          MouseEvent mouseEvent = e.getMouseEvent();

          if (isMouseOverTooltip(mouseEvent.getLocationOnScreen())
              || ScreenUtil.isMovementTowards(
                  myPrevMouseLocation, mouseEvent.getLocationOnScreen(), getHintBounds())) {
            myPrevMouseLocation = mouseEvent.getLocationOnScreen();
            return;
          }
          myPrevMouseLocation = mouseEvent.getLocationOnScreen();

          Editor editor = e.getEditor();
          if (editor.getProject() != null && editor.getProject() != myProject) return;
          PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
          PsiFile psiFile = documentManager.getPsiFile(editor.getDocument());
          Point point = new Point(mouseEvent.getPoint());
          if (documentManager.isCommitted(editor.getDocument())) {
            // when document is committed, try to check injected stuff - it's fast
            int offset = editor.logicalPositionToOffset(editor.xyToLogicalPosition(point));
            editor =
                InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, psiFile, offset);
          }

          LogicalPosition pos = editor.xyToLogicalPosition(point);
          int offset = editor.logicalPositionToOffset(pos);
          int selStart = editor.getSelectionModel().getSelectionStart();
          int selEnd = editor.getSelectionModel().getSelectionEnd();

          myStoredModifiers = mouseEvent.getModifiers();
          BrowseMode browseMode = getBrowseMode(myStoredModifiers);

          cancelPreviousTooltip();

          if (browseMode == BrowseMode.None || offset >= selStart && offset < selEnd) {
            disposeHighlighter();
            return;
          }

          myTooltipProvider = new TooltipProvider(editor, pos);
          myTooltipProvider.execute(browseMode);
        }
Ejemplo n.º 3
0
        public void mouseMoved(final EditorMouseEvent e) {
          if (e.isConsumed() || !myProject.isInitialized()) {
            return;
          }
          MouseEvent mouseEvent = e.getMouseEvent();

          Editor editor = e.getEditor();
          if (editor.getProject() != null && editor.getProject() != myProject) return;
          PsiFile psiFile =
              PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument());
          Point point = new Point(mouseEvent.getPoint());
          if (!PsiDocumentManager.getInstance(myProject).isUncommited(editor.getDocument())) {
            // when document is committed, try to check injected stuff - it's fast
            editor =
                InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(
                    editor,
                    psiFile,
                    editor.logicalPositionToOffset(editor.xyToLogicalPosition(point)));
          }

          LogicalPosition pos = editor.xyToLogicalPosition(point);
          int offset = editor.logicalPositionToOffset(pos);
          int selStart = editor.getSelectionModel().getSelectionStart();
          int selEnd = editor.getSelectionModel().getSelectionEnd();

          myStoredModifiers = mouseEvent.getModifiers();
          BrowseMode browseMode = getBrowseMode(myStoredModifiers);

          if (myTooltipProvider != null) {
            myTooltipProvider.dispose();
          }

          if (browseMode == BrowseMode.None || offset >= selStart && offset < selEnd) {
            disposeHighlighter();
            myTooltipProvider = null;
            return;
          }

          myTooltipProvider = new TooltipProvider(editor, pos);
          myTooltipProvider.execute(browseMode);
        }
    @Override
    public void mouseClicked(final EditorMouseEvent e) {
      final Editor editor = e.getEditor();
      final MouseEvent mouseEvent = e.getMouseEvent();
      if (mouseEvent.isPopupTrigger()
          || mouseEvent.isMetaDown()
          || mouseEvent.isControlDown()
          || mouseEvent.getButton() != MouseEvent.BUTTON1
          || MarkupEditorFilterFactory.createIsDiffFilter().avaliableIn(editor)
          || e.getArea() != EditorMouseEventArea.LINE_MARKERS_AREA
          || ConsoleViewUtil.isConsoleViewEditor(editor)
          || !isFromMyProject(editor)) {
        return;
      }

      PsiDocumentManager.getInstance(myProject)
          .commitAndRunReadAction(
              new Runnable() {
                @Override
                public void run() {
                  final int line = EditorUtil.yPositionToLogicalLine(editor, mouseEvent);
                  final Document document = editor.getDocument();
                  final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
                  if (line >= 0 && line < document.getLineCount() && file != null) {
                    ApplicationManager.getApplication()
                        .invokeLater(
                            new Runnable() {
                              @Override
                              public void run() {
                                if (!myProject.isDisposed()
                                    && myProject.isInitialized()
                                    && file.isValid()) {
                                  ActionManagerEx.getInstanceEx()
                                      .fireBeforeActionPerformed(
                                          "ToggleLineBreakpoint", e.getMouseEvent());

                                  XLineBreakpoint breakpoint =
                                      XBreakpointUtil.toggleLineBreakpoint(
                                          myProject,
                                          file,
                                          editor,
                                          line,
                                          mouseEvent.isAltDown(),
                                          false);
                                  if (!mouseEvent.isAltDown()
                                      && mouseEvent.isShiftDown()
                                      && breakpoint != null) {
                                    breakpoint.setSuspendPolicy(SuspendPolicy.NONE);
                                    String selection = editor.getSelectionModel().getSelectedText();
                                    if (selection != null) {
                                      breakpoint.setLogExpression(selection);
                                    } else {
                                      breakpoint.setLogMessage(true);
                                    }
                                    // edit breakpoint
                                    DebuggerUIUtil.showXBreakpointEditorBalloon(
                                        myProject,
                                        mouseEvent.getPoint(),
                                        ((EditorEx) editor).getGutterComponentEx(),
                                        false,
                                        breakpoint);
                                  }
                                }
                              }
                            });
                  }
                }
              });
    }