Ejemplo n.º 1
0
    void execute(BrowseMode browseMode) {
      myBrowseMode = browseMode;

      Document document = myEditor.getDocument();
      final PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
      if (file == null) return;
      PsiDocumentManager.getInstance(myProject).commitAllDocuments();

      if (EditorUtil.inVirtualSpace(myEditor, myPosition)) {
        return;
      }

      final int offset = myEditor.logicalPositionToOffset(myPosition);

      int selStart = myEditor.getSelectionModel().getSelectionStart();
      int selEnd = myEditor.getSelectionModel().getSelectionEnd();

      if (offset >= selStart && offset < selEnd) return;

      ProgressIndicatorUtils.scheduleWithWriteActionPriority(
          myProgress,
          new ReadTask() {
            @Override
            public void computeInReadAction(@NotNull ProgressIndicator indicator) {
              doExecute(file, offset);
            }

            @Override
            public void onCanceled(@NotNull ProgressIndicator indicator) {}
          });
    }
Ejemplo n.º 2
0
    public void execute(BrowseMode browseMode) {
      myBrowseMode = browseMode;

      Document document = myEditor.getDocument();
      final PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
      if (file == null) return;
      PsiDocumentManager.getInstance(myProject).commitAllDocuments();

      if (TargetElementUtilBase.inVirtualSpace(myEditor, myPosition)) {
        return;
      }

      final int offset = myEditor.logicalPositionToOffset(myPosition);

      int selStart = myEditor.getSelectionModel().getSelectionStart();
      int selEnd = myEditor.getSelectionModel().getSelectionEnd();

      if (offset >= selStart && offset < selEnd) return;

      ApplicationManager.getApplication()
          .executeOnPooledThread(
              new Runnable() {
                public void run() {
                  final ProgressIndicator progressIndicator = new ProgressIndicatorBase();
                  final ApplicationAdapter listener =
                      new ApplicationAdapter() {
                        @Override
                        public void beforeWriteActionStart(Object action) {
                          progressIndicator.cancel();
                        }
                      };
                  final Application application = ApplicationManager.getApplication();
                  try {
                    application.addApplicationListener(listener);
                    ProgressManager.getInstance()
                        .runProcess(
                            new Runnable() {
                              @Override
                              public void run() {
                                // This read action can possibe last for a long time, we want it to
                                // stop immediately on the first write access.
                                // For this purpose we launch it under empty progress and invoke
                                // progressIndicator#cancel on write access to avoid possible write
                                // lock delays.
                                application.runReadAction(
                                    new Runnable() {
                                      public void run() {
                                        doExecute(file, offset);
                                      }
                                    });
                              }
                            },
                            progressIndicator);
                  } finally {
                    application.removeApplicationListener(listener);
                  }
                }
              });
    }
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);
        }
Ejemplo n.º 4
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);
        }