com.intellij.codeInsight.hint.HintManager Java Examples

The following examples show how to use com.intellij.codeInsight.hint.HintManager. 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: TrafficTooltipRendererImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public LightweightHint show(@Nonnull Editor editor, @Nonnull Point p, boolean alignToRight, @Nonnull TooltipGroup group, @Nonnull HintHint hintHint) {
  myTrafficLightRenderer = (TrafficLightRenderer)((EditorMarkupModel)editor.getMarkupModel()).getErrorStripeRenderer();
  myPanel = new TrafficProgressPanel(myTrafficLightRenderer, editor, hintHint);
  repaintTooltipWindow();
  LineTooltipRenderer.correctLocation(editor, myPanel, p, alignToRight, true, myPanel.getMinWidth());
  LightweightHint hint = new LightweightHint(myPanel);

  HintManagerImpl hintManager = (HintManagerImpl)HintManager.getInstance();
  hintManager.showEditorHint(hint, editor, p,
                             HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_OTHER_HINT |
                             HintManager.HIDE_BY_SCROLLING, 0, false, hintHint);
  hint.addHintListener(new HintListener() {
    @Override
    public void hintHidden(EventObject event) {
      if (myPanel == null) return; //double hide?
      myPanel = null;
      onHide.run();
    }
  });
  return hint;
}
 
Example #2
Source File: FlutterReloadManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private LightweightHint showEditorHint(@NotNull Editor editor, String message, boolean isError) {
  final AtomicReference<LightweightHint> ref = new AtomicReference<>();

  ApplicationManager.getApplication().invokeAndWait(() -> {
    final JComponent component = isError
                                 ? HintUtil.createErrorLabel(message)
                                 : HintUtil.createInformationLabel(message);
    final LightweightHint hint = new LightweightHint(component);
    ref.set(hint);
    HintManagerImpl.getInstanceImpl().showEditorHint(
      hint, editor, HintManager.UNDER,
      HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING | HintManager.HIDE_BY_OTHER_HINT,
      isError ? 0 : 3000, false);
  });

  return ref.get();
}
 
Example #3
Source File: FindUsagesAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
static void chooseAmbiguousTargetAndPerform(@Nonnull final Project project, final Editor editor, @Nonnull PsiElementProcessor<PsiElement> processor) {
  if (editor == null) {
    Messages.showMessageDialog(project, FindBundle.message("find.no.usages.at.cursor.error"), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
  }
  else {
    int offset = editor.getCaretModel().getOffset();
    boolean chosen = GotoDeclarationAction.chooseAmbiguousTarget(editor, offset, processor, FindBundle.message("find.usages.ambiguous.title"), null);
    if (!chosen) {
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          if (editor.isDisposed() || !editor.getComponent().isShowing()) return;
          HintManager.getInstance().showErrorHint(editor, FindBundle.message("find.no.usages.at.cursor.error"));
        }
      }, project.getDisposed());
    }
  }
}
 
Example #4
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showHint(@Nullable final Editor editor,
                      @Nonnull String hint,
                      @Nonnull FindUsagesHandler handler,
                      @Nonnull final RelativePoint popupPosition,
                      int maxUsages,
                      @Nonnull FindUsagesOptions options,
                      boolean isWarning) {
  Runnable runnable = () -> {
    if (!handler.getPsiElement().isValid()) return;

    JComponent label = createHintComponent(hint, handler, popupPosition, editor, ShowUsagesAction::hideHints, maxUsages, options, isWarning);
    if (editor == null || editor.isDisposed() || !editor.getComponent().isShowing()) {
      HintManager.getInstance()
              .showHint(label, popupPosition, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0);
    }
    else {
      HintManager.getInstance().showInformationHint(editor, label);
    }
  };
  if (editor == null) {
    runnable.run();
  }
  else {
    DesktopAsyncEditorLoader.performWhenLoaded(editor, runnable);
  }
}
 
Example #5
Source File: CommonRefactoringUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void showErrorHint(@Nonnull Project project,
                                 @Nullable Editor editor,
                                 @Nonnull @Nls String message,
                                 @Nonnull @Nls String title,
                                 @javax.annotation.Nullable String helpId) {
  if (ApplicationManager.getApplication().isUnitTestMode()) throw new RefactoringErrorHintException(message);

  ApplicationManager.getApplication().invokeLater(() -> {
    if (editor == null || editor.getComponent().getRootPane() == null) {
      showErrorMessage(title, message, helpId, project);
    }
    else {
      HintManager.getInstance().showErrorHint(editor, message);
    }
  });
}
 
Example #6
Source File: ElmImportQuickFix.java    From elm-plugin with MIT License 6 votes vote down vote up
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    List<String> refComponents = Arrays.asList(referenceNameToFix.split(Pattern.quote(".")));

    List<ElmImportCandidate> candidates = findCandidates(project, refComponents);
    if (candidates.isEmpty()) {
        HintManager.getInstance().showErrorHint(editor, "No module exporting '" + referenceNameToFix + "' found");
    } else if (candidates.size() == 1) {
        ElmImportCandidate candidate = candidates.get(0);
        fixWithCandidate(project, (ElmFile) file, refComponents, candidate);
    } else {
        List<ElmImportCandidate> sortedCandidates = new ArrayList<>(candidates);
        sortedCandidates.sort((a,b) -> a.moduleName.compareTo(b.moduleName));
        promptToSelectCandidate(project, (ElmFile) file, refComponents, sortedCandidates);
    }
}
 
Example #7
Source File: EditorPerfDecorations.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void showPerfViewMessage() {
  final FlutterPerformanceView flutterPerfView = ServiceManager.getService(getApp().getProject(), FlutterPerformanceView.class);
  flutterPerfView.showForAppRebuildCounts(getApp());
  String message = "<html><body>" +
                   getTooltipHtmlFragment() +
                   "</body></html>";
  final Iterable<SummaryStats> current = perfModelForFile.getStats().getRangeStats(range);
  if (current.iterator().hasNext()) {
    final SummaryStats first = current.iterator().next();
    final XSourcePosition position = first.getLocation().getXSourcePosition();
    if (position != null) {
      AsyncUtils.invokeLater(() -> {
        position.createNavigatable(getApp().getProject()).navigate(true);
        HintManager.getInstance().showInformationHint(perfModelForFile.getTextEditor().getEditor(), message);
      });
    }
  }
}
 
Example #8
Source File: FlutterReloadManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private LightweightHint showEditorHint(@NotNull Editor editor, String message, boolean isError) {
  final AtomicReference<LightweightHint> ref = new AtomicReference<>();

  ApplicationManager.getApplication().invokeAndWait(() -> {
    final JComponent component = isError
                                 ? HintUtil.createErrorLabel(message)
                                 : HintUtil.createInformationLabel(message);
    final LightweightHint hint = new LightweightHint(component);
    ref.set(hint);
    HintManagerImpl.getInstanceImpl().showEditorHint(
      hint, editor, HintManager.UNDER,
      HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING | HintManager.HIDE_BY_OTHER_HINT,
      isError ? 0 : 3000, false);
  });

  return ref.get();
}
 
Example #9
Source File: EditorPerfDecorations.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void showPerfViewMessage() {
  final FlutterPerformanceView flutterPerfView = ServiceManager.getService(getApp().getProject(), FlutterPerformanceView.class);
  flutterPerfView.showForAppRebuildCounts(getApp());
  String message = "<html><body>" +
                   getTooltipHtmlFragment() +
                   "</body></html>";
  final Iterable<SummaryStats> current = perfModelForFile.getStats().getRangeStats(range);
  if (current.iterator().hasNext()) {
    final SummaryStats first = current.iterator().next();
    final XSourcePosition position = first.getLocation().getXSourcePosition();
    if (position != null) {
      AsyncUtils.invokeLater(() -> {
        position.createNavigatable(getApp().getProject()).navigate(true);
        HintManager.getInstance().showInformationHint(perfModelForFile.getTextEditor().getEditor(), message);
      });
    }
  }
}
 
Example #10
Source File: SetValueInplaceEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void doOKAction() {
  if (myModifier == null) return;

  DebuggerUIUtil.setTreeNodeValue(myValueNode, getExpression().getExpression(), errorMessage -> {
    Editor editor = getEditor();
    if (editor != null) {
      HintManager.getInstance().showErrorHint(editor, errorMessage);
    }
    else {
      Messages.showErrorDialog(myTree, errorMessage);
    }
  });

  super.doOKAction();
}
 
Example #11
Source File: HighlightUsagesHandlerBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void performHighlighting() {
  boolean clearHighlights = HighlightUsagesHandler.isClearHighlights(myEditor);
  EditorColorsManager manager = EditorColorsManager.getInstance();
  TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
  TextAttributes writeAttributes = manager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
  HighlightUsagesHandler.highlightRanges(HighlightManager.getInstance(myEditor.getProject()),
                                         myEditor, attributes, clearHighlights, myReadUsages);
  HighlightUsagesHandler.highlightRanges(HighlightManager.getInstance(myEditor.getProject()),
                                         myEditor, writeAttributes, clearHighlights, myWriteUsages);
  if (!clearHighlights) {
    WindowManager.getInstance().getStatusBar(myEditor.getProject()).setInfo(myStatusText);

    HighlightHandlerBase.setupFindModel(myEditor.getProject()); // enable f3 navigation
  }
  if (myHintText != null) {
    HintManager.getInstance().showInformationHint(myEditor, myHintText);
  }
}
 
Example #12
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 6 votes vote down vote up
static void chooseAmbiguousTargetAndPerform(@NotNull final Project project,
    final Editor editor,
    @NotNull PsiElementProcessor<PsiElement> processor) {
  if (editor == null) {
    Messages.showMessageDialog(project, FindBundle.message("find.no.usages.at.cursor.error"),
        CommonBundle.getErrorTitle(), Messages.getErrorIcon());
  }
  else {
    int offset = editor.getCaretModel().getOffset();
    boolean chosen = GotoDeclarationAction.chooseAmbiguousTarget(editor, offset, processor,
        FindBundle.message("find.usages.ambiguous.title", "crap"), null);
    if (!chosen) {
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          if (editor.isDisposed() || !editor.getComponent().isShowing()) return;
          HintManager.getInstance().showErrorHint(editor, FindBundle.message("find.no.usages.at.cursor.error"));
        }
      }, project.getDisposed());
    }
  }
}
 
Example #13
Source File: CleanupInspectionIntention.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void invoke(@Nonnull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {

  final List<ProblemDescriptor> descriptions =
          ProgressManager.getInstance().runProcess(() -> {
            InspectionManager inspectionManager = InspectionManager.getInstance(project);
            return InspectionEngine.runInspectionOnFile(file, myToolWrapper, inspectionManager.createNewGlobalContext(false));
          }, new EmptyProgressIndicator());

  if (!descriptions.isEmpty() && !FileModificationService.getInstance().preparePsiElementForWrite(file)) return;

  final AbstractPerformFixesTask fixesTask = applyFixes(project, "Apply Fixes", descriptions, myQuickfixClass);

  if (!fixesTask.isApplicableFixFound()) {
    HintManager.getInstance().showErrorHint(editor, "Unfortunately '" + myText + "' is currently not available for batch mode\n User interaction is required for each problem found");
  }
}
 
Example #14
Source File: DoctrineRepositoryClassConstantIntention.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) throws IncorrectOperationException {
    PsiElement parent = psiElement.getParent();
    if(!(parent instanceof StringLiteralExpression)) {
        return;
    }

    try {
        PhpClass phpClass = EntityHelper.resolveShortcutName(project, ((StringLiteralExpression) parent).getContents());
        if(phpClass == null) {
            throw new Exception("Can not resolve model class");
        }
        PhpElementsUtil.replaceElementWithClassConstant(phpClass, parent);
    } catch (Exception e) {
        HintManager.getInstance().showErrorHint(editor, e.getMessage());
    }
}
 
Example #15
Source File: ConvertIndentsActionBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredWriteAction
@Override
public void executeWriteAction(final Editor editor, @Nullable Caret caret, DataContext dataContext) {
  final SelectionModel selectionModel = editor.getSelectionModel();
  int changedLines = 0;
  if (selectionModel.hasSelection()) {
    changedLines = performAction(editor, new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()));
  }
  else {
    changedLines += performAction(editor, new TextRange(0, editor.getDocument().getTextLength()));
  }
  if (changedLines == 0) {
    HintManager.getInstance().showInformationHint(editor, "All lines already have requested indentation");
  }
  else {
    HintManager.getInstance().showInformationHint(editor, "Changed indentation in " + changedLines + (changedLines == 1 ? " line" : " lines"));
  }
}
 
Example #16
Source File: InputPanel.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void highlightAndOfferHint(Editor editor, int offset,
                                  Interval sourceInterval,
                                  JBColor color,
                                  EffectType effectType, String hintText) {
	CaretModel caretModel = editor.getCaretModel();
	final TextAttributes attr = new TextAttributes();
	attr.setForegroundColor(color);
	attr.setEffectColor(color);
	attr.setEffectType(effectType);
	MarkupModel markupModel = editor.getMarkupModel();
	markupModel.addRangeHighlighter(
		sourceInterval.a,
		sourceInterval.b,
		InputPanel.TOKEN_INFO_LAYER, // layer
		attr,
		HighlighterTargetArea.EXACT_RANGE
	                               );

	if ( hintText.contains("<") ) {
		hintText = hintText.replaceAll("<", "&lt;");
	}

	// HINT
	caretModel.moveToOffset(offset); // info tooltip only shows at cursor :(
	HintManager.getInstance().showInformationHint(editor, hintText);
}
 
Example #17
Source File: Selection.java    From emacsIDEAs with Apache License 2.0 6 votes vote down vote up
public static TextRange getTextRangeBy(Editor editor, CommandContext cmdCtx) {
    char key = cmdCtx.getLastCmdKey();
    Selector selector = SelectorFactory.createSelectorBy(key, editor);

    if (selector == null) {
        HintManager.getInstance().showInformationHint(editor, SelectorFactory.HELP_MSG);
        return null;
    }

    TextRange tr = selector.getRange(cmdCtx);
    if (tr == null) {
        HintManager.getInstance().showInformationHint(editor, "404");
    }

    return tr;
}
 
Example #18
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 6 votes vote down vote up
static void chooseAmbiguousTargetAndPerform(@NotNull final Project project, final Editor editor,
    @NotNull PsiElementProcessor<PsiElement> processor) {
  if (editor == null) {
    Messages.showMessageDialog(project, FindBundle.message("find.no.usages.at.cursor.error"),
        CommonBundle.getErrorTitle(), Messages.getErrorIcon());
  } else {
    int offset = editor.getCaretModel().getOffset();
    boolean chosen = GotoDeclarationAction.chooseAmbiguousTarget(editor, offset, processor,
        FindBundle.message("find.usages.ambiguous.title", "crap"), null);
    if (!chosen) {
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          if (editor.isDisposed() || !editor.getComponent().isShowing()) return;
          HintManager.getInstance()
              .showErrorHint(editor, FindBundle.message("find.no.usages.at.cursor.error"));
        }
      }, project.getDisposed());
    }
  }
}
 
Example #19
Source File: CodeInsightUtilBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean prepareFileForWrite(@Nullable final PsiFile psiFile) {
  if (psiFile == null) return false;
  final VirtualFile file = psiFile.getVirtualFile();
  final Project project = psiFile.getProject();

  if (ReadonlyStatusHandler.ensureFilesWritable(project, file)) {
    return true;
  }
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, file), true);
      if (editor != null && editor.getComponent().isDisplayable()) {
        HintManager.getInstance().showErrorHint(editor, CodeInsightBundle.message("error.hint.file.is.readonly", file.getPresentableUrl()));
      }
    }
  }, project.getDisposed());

  return false;
}
 
Example #20
Source File: CommentByBlockCommentHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showMessageIfNeeded() {
  if (myWarning != null) {
    myEditor.getScrollingModel().disableAnimation();
    myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
    myEditor.getScrollingModel().enableAnimation();

    LogicalPosition hintPosition = myCaret.getLogicalPosition();
    if (myWarningLocation != null) {
      LogicalPosition targetPosition = myEditor.offsetToLogicalPosition(myWarningLocation.getStartOffset());
      Point targetPoint = myEditor.logicalPositionToXY(targetPosition);
      if (myEditor.getScrollingModel().getVisibleArea().contains(targetPoint)) {
        hintPosition = targetPosition;
      }
    }
    LightweightHint hint = new LightweightHint(HintUtil.createInformationLabel(myWarning));
    Point p = HintManagerImpl.getHintPosition(hint, myEditor, hintPosition, HintManager.ABOVE);
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, myEditor, p, 0, 0, false);
  }
}
 
Example #21
Source File: PhpBundleFileFactory.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
public static PsiElement invokeCreateCompilerPass(@NotNull PhpClass bundleClass, @Nullable Editor editor) {
    String className = Messages.showInputDialog("Class name for CompilerPass (no namespace needed): ", "New File", Symfony2Icons.SYMFONY);
    if(StringUtils.isBlank(className)) {
        return null;
    }

    if(!PhpNameUtil.isValidClassName(className)) {
        Messages.showMessageDialog(bundleClass.getProject(), "Invalid class name", "Error", Symfony2Icons.SYMFONY);
    }

    try {
        return PhpBundleFileFactory.createCompilerPass(bundleClass, className);
    } catch (Exception e) {
        if(editor != null) {
            HintManager.getInstance().showErrorHint(editor, "Error:" + e.getMessage());
        } else {
            JOptionPane.showMessageDialog(null, "Error:" + e.getMessage());
        }
    }

    return null;
}
 
Example #22
Source File: IntentionListStep.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void applyAction(@Nonnull IntentionActionWithTextCaching cachedAction) {
  myFinalRunnable = () -> {
    HintManager.getInstance().hideAllHints();
    if (myProject.isDisposed()) return;
    if (myEditor != null && (myEditor.isDisposed() || (!myEditor.getComponent().isShowing() && !ApplicationManager.getApplication().isUnitTestMode()))) return;

    if (DumbService.isDumb(myProject) && !DumbService.isDumbAware(cachedAction)) {
      DumbService.getInstance(myProject).showDumbModeNotification(cachedAction.getText() + " is not available during indexing");
      return;
    }

    PsiDocumentManager.getInstance(myProject).commitAllDocuments();

    PsiFile file = myEditor != null ? PsiUtilBase.getPsiFileInEditor(myEditor, myProject) : myFile;
    if (file == null) {
      return;
    }

    ShowIntentionActionsHandler.chooseActionAndInvoke(file, myEditor, cachedAction.getAction(), cachedAction.getText(), myProject);
  };
}
 
Example #23
Source File: YamlSuggestIntentionAction.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void insert(@NotNull String selected) {
    String text = this.psiElement.getText();

    int i = getServiceChar(text);
    if(i < 0) {
        HintManager.getInstance().showErrorHint(editor, "No valid char in text range");
        return;
    }

    String afterAtText = text.substring(i);

    // strip ending quotes
    int length = StringUtils.stripEnd(afterAtText, "'\"").length();

    int startOffset = this.psiElement.getTextRange().getStartOffset();
    int afterAt = startOffset + i + 1;

    editor.getDocument().deleteString(afterAt, afterAt + length - 1);
    editor.getDocument().insertString(afterAt, selected);
}
 
Example #24
Source File: YamlSuggestIntentionAction.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @Nullable Editor editor, @NotNull PsiElement psiElement, @NotNull PsiElement psiElement1) {
    if(editor == null) {
        return;
    }

    Collection<PhpClass> anyByFQN = PhpIndex.getInstance(project).getAnyByFQN(this.expectedClass);
    if(anyByFQN.size() == 0) {
        return;
    }

    Collection<ContainerService> suggestions = ServiceUtil.getServiceSuggestionForPhpClass(anyByFQN.iterator().next(), ContainerCollectionResolver.getServices(project));
    if(suggestions.size() == 0) {
        HintManager.getInstance().showErrorHint(editor, "No suggestion found");
        return;
    }

    ServiceSuggestDialog.create(
        editor,
        ContainerUtil.map(suggestions, ContainerService::getName),
        new MyInsertCallback(editor, psiElement)
    );
}
 
Example #25
Source File: FormTypeConstantMigrationAction.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile psiFile) {
    PhpClass phpClass = PhpCodeEditUtil.findClassAtCaret(editor, psiFile);
    if(phpClass == null) {
        HintManager.getInstance().showErrorHint(editor, "No class context found");
        return;
    }

    final Collection<StringLiteralExpression> formTypes = new ArrayList<>();
    phpClass.acceptChildren(new FormTypeStringElementVisitor(formTypes));

    if(formTypes.size() == 0) {
        HintManager.getInstance().showErrorHint(editor, "Nothing to do for me");
        return;
    }

    for (StringLiteralExpression formType : formTypes) {
        try {
            FormUtil.replaceFormStringAliasWithClassConstant(formType);
        } catch (Exception ignored) {
        }
    }

}
 
Example #26
Source File: SelectionBasedPsiElementInternalAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void performOnElement(@Nonnull final Editor editor, @Nonnull T first) {
  final TextRange textRange = first.getTextRange();
  editor.getSelectionModel().setSelection(textRange.getStartOffset(), textRange.getEndOffset());
  final String informationHint = getInformationHint(first);
  if (informationHint != null) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        HintManager.getInstance().showInformationHint(editor, informationHint);
      }
    });
  }
  else {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        HintManager.getInstance().showErrorHint(editor, getErrorHint());
      }
    });
  }
}
 
Example #27
Source File: IntentionsUIImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(@Nonnull CachedIntentions cachedIntentions, boolean actionsChanged) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  Editor editor = cachedIntentions.getEditor();
  if (editor == null) return;
  if (!ApplicationManager.getApplication().isUnitTestMode() && !editor.getContentComponent().hasFocus()) return;
  if (!actionsChanged) return;

  //IntentionHintComponent hint = myLastIntentionHint;
  //if (hint != null && hint.getPopupUpdateResult(actionsChanged) == IntentionHintComponent.PopupUpdateResult.CHANGED_INVISIBLE) {
  //  hint.recreate();
  //  return;
  //}

  Project project = cachedIntentions.getProject();
  LogicalPosition caretPos = editor.getCaretModel().getLogicalPosition();
  Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
  Point xy = editor.logicalPositionToXY(caretPos);

  hide();
  if (!HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(false) &&
      visibleArea.contains(xy) &&
      editor.getSettings().isShowIntentionBulb() &&
      editor.getCaretModel().getCaretCount() == 1 &&
      cachedIntentions.showBulb()) {
    myLastIntentionHint = IntentionHintComponent.showIntentionHint(project, cachedIntentions.getFile(), editor, false, cachedIntentions);
  }
}
 
Example #28
Source File: CtrlMouseHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void disposeHighlighter() {
  HighlightersSet highlighter = myHighlighter;
  if (highlighter != null) {
    myHighlighter = null;
    highlighter.uninstall();
    HintManager.getInstance().hideAllHints();
  }
}
 
Example #29
Source File: CtrlMouseHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void showHint(@Nonnull LightweightHint hint, @Nonnull Editor editor) {
  if (ApplicationManager.getApplication().isUnitTestMode() || editor.isDisposed()) return;
  final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
  short constraint = HintManager.ABOVE;
  LogicalPosition position = editor.offsetToLogicalPosition(getOffset(editor));
  Point p = HintManagerImpl.getHintPosition(hint, editor, position, constraint);
  if (p.y - hint.getComponent().getPreferredSize().height < 0) {
    constraint = HintManager.UNDER;
    p = HintManagerImpl.getHintPosition(hint, editor, position, constraint);
  }
  hintManager.showEditorHint(hint, editor, p, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false,
                             HintManagerImpl.createHintHint(editor, p, hint, constraint).setContentActive(false));
}
 
Example #30
Source File: GotoDeclarationAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void chooseAmbiguousTarget(final Editor editor, int offset, PsiElement[] elements, @Nullable PsiElementListCellRenderer<PsiElement> render) {
  PsiElementProcessor<PsiElement> navigateProcessor = new PsiElementProcessor<PsiElement>() {
    @Override
    public boolean execute(@Nonnull final PsiElement element) {
      gotoTargetElement(element);
      return true;
    }
  };
  boolean found = chooseAmbiguousTarget(editor, offset, navigateProcessor, CodeInsightBundle.message("declaration.navigation.title"), elements, render);
  if (!found) {
    HintManager.getInstance().showErrorHint(editor, "Cannot find declaration to go to");
  }
}