public void invoke(
      @NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) {
    PsiDocumentManager.getInstance(project).commitAllDocuments();

    final LookupEx lookup = LookupManagerImpl.getActiveLookup(editor);
    if (lookup != null) {
      lookup.showElementActions();
      return;
    }

    if (HintManagerImpl.getInstanceImpl().performCurrentQuestionAction()) return;

    // intentions check isWritable before modification: if (!file.isWritable()) return;
    if (file instanceof PsiCodeFragment) return;

    TemplateState state = TemplateManagerImpl.getTemplateState(editor);
    if (state != null && !state.isFinished()) {
      return;
    }

    final DaemonCodeAnalyzerImpl codeAnalyzer =
        (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(project);
    codeAnalyzer.autoImportReferenceAtCursor(editor, file); // let autoimport complete

    ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo();
    ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1);

    if (!intentions.isEmpty()) {
      IntentionHintComponent.showIntentionHint(project, file, editor, intentions, true);
    }
  }
 private static void showEditorHint(String message, final Editor editor) {
   JComponent component = HintUtil.createInformationLabel(message);
   final LightweightHint hint = new LightweightHint(component);
   HintManagerImpl.getInstanceImpl()
       .showEditorHint(
           hint,
           editor,
           HintManager.UNDER,
           HintManager.HIDE_BY_ANY_KEY
               | HintManager.HIDE_BY_TEXT_CHANGE
               | HintManager.HIDE_BY_SCROLLING,
           0,
           false);
 }
Exemplo n.º 3
0
 public void showHint(LightweightHint hint) {
   final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
   Point p = HintManagerImpl.getHintPosition(hint, myEditor, myPosition, HintManager.ABOVE);
   hintManager.showEditorHint(
       hint,
       myEditor,
       p,
       HintManager.HIDE_BY_ANY_KEY
           | HintManager.HIDE_BY_TEXT_CHANGE
           | HintManager.HIDE_BY_SCROLLING,
       0,
       false,
       HintManagerImpl.createHintHint(myEditor, p, hint, HintManager.ABOVE)
           .setContentActive(false));
 }
Exemplo n.º 4
0
  public boolean showLookup() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    checkValid();
    LOG.assertTrue(!myShown);
    myShown = true;
    myStampShown = System.currentTimeMillis();

    if (ApplicationManager.getApplication().isUnitTestMode()) return true;

    if (!myEditor.getContentComponent().isShowing()) {
      hide();
      return false;
    }

    myAdComponent.showRandomText();

    myUi = new LookupUi(this, myAdComponent, myList, myProject);
    myUi.setCalculating(myCalculating);
    Point p = myUi.calculatePosition().getLocation();
    try {
      HintManagerImpl.getInstanceImpl()
          .showEditorHint(
              this,
              myEditor,
              p,
              HintManager.HIDE_BY_ESCAPE | HintManager.UPDATE_BY_SCROLLING,
              0,
              false,
              HintManagerImpl.createHintHint(myEditor, p, this, HintManager.UNDER)
                  .setAwtTooltip(false));
    } catch (Exception e) {
      LOG.error(e);
    }

    if (!isVisible() || !myList.isShowing()) {
      hide();
      return false;
    }

    DaemonCodeAnalyzer.getInstance(myProject).disableUpdateByTimer(this);

    return true;
  }
Exemplo n.º 5
0
    private void showHint(Info info) {
      if (myDisposed) return;
      Component internalComponent = myEditor.getContentComponent();
      if (myHighlighter != null) {
        if (!info.isSimilarTo(myHighlighter.getStoredInfo())) {
          disposeHighlighter();
        } else {
          // highlighter already set
          internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          return;
        }
      }

      if (info.isValid(myEditor.getDocument())) {
        myHighlighter = installHighlighterSet(info, myEditor);

        String text = info.getInfo();

        if (text == null) return;

        JComponent label = HintUtil.createInformationLabel(text);
        final LightweightHint hint = new LightweightHint(label);
        final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
        Point p = HintManagerImpl.getHintPosition(hint, myEditor, myPosition, HintManager.ABOVE);
        hintManager.showEditorHint(
            hint,
            myEditor,
            p,
            HintManager.HIDE_BY_ANY_KEY
                | HintManager.HIDE_BY_TEXT_CHANGE
                | HintManager.HIDE_BY_SCROLLING,
            0,
            false,
            HintManagerImpl.createHintHint(myEditor, p, hint, HintManager.ABOVE)
                .setContentActive(false));
      }
    }