Search in sources :

Example 16 with LightweightHint

use of com.intellij.ui.LightweightHint in project intellij-plugins by JetBrains.

the class AbstractDartFileProcessingAction method showHintLater.

public static void showHintLater(@NotNull final Editor editor, @NotNull final String text, final boolean error) {
    ApplicationManager.getApplication().invokeLater(() -> {
        final JComponent component = error ? HintUtil.createErrorLabel(text) : HintUtil.createInformationLabel(text);
        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);
    }, ModalityState.NON_MODAL, o -> editor.isDisposed() || !editor.getComponent().isShowing());
}
Also used : LightweightHint(com.intellij.ui.LightweightHint)

Example 17 with LightweightHint

use of com.intellij.ui.LightweightHint in project intellij-community by JetBrains.

the class TooltipController method showTooltipByMouseMove.

public void showTooltipByMouseMove(@NotNull final Editor editor, @NotNull final RelativePoint point, final TooltipRenderer tooltipObject, final boolean alignToRight, @NotNull final TooltipGroup group, @NotNull HintHint hintHint) {
    LightweightHint currentTooltip = myCurrentTooltip;
    if (currentTooltip == null || !currentTooltip.isVisible()) {
        if (currentTooltip != null) {
            if (!IdeTooltipManager.getInstance().isQueuedToShow(currentTooltip.getCurrentIdeTooltip())) {
                myCurrentTooltipObject = null;
            }
        } else {
            myCurrentTooltipObject = null;
        }
    }
    if (Comparing.equal(tooltipObject, myCurrentTooltipObject)) {
        IdeTooltipManager.getInstance().cancelAutoHide();
        return;
    }
    hideCurrentTooltip();
    if (tooltipObject != null) {
        final Point p = point.getPointOn(editor.getComponent().getRootPane().getLayeredPane()).getPoint();
        if (!hintHint.isAwtTooltip()) {
            p.x += alignToRight ? -10 : 10;
        }
        Project project = editor.getProject();
        if (project != null && !project.isOpen())
            return;
        if (editor.getContentComponent().isShowing()) {
            showTooltip(editor, p, tooltipObject, alignToRight, group, hintHint);
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) LightweightHint(com.intellij.ui.LightweightHint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 18 with LightweightHint

use of com.intellij.ui.LightweightHint in project intellij-community by JetBrains.

the class TooltipController method hideCurrentTooltip.

private void hideCurrentTooltip() {
    if (myCurrentTooltip != null) {
        LightweightHint currentTooltip = myCurrentTooltip;
        myCurrentTooltip = null;
        currentTooltip.hide();
        myCurrentTooltipGroup = null;
        IdeTooltipManager.getInstance().hide(null);
    }
}
Also used : LightweightHint(com.intellij.ui.LightweightHint)

Example 19 with LightweightHint

use of com.intellij.ui.LightweightHint in project intellij-community by JetBrains.

the class DocumentFragmentTooltipRenderer method show.

@Override
public LightweightHint show(@NotNull final Editor editor, @NotNull Point p, boolean alignToRight, @NotNull TooltipGroup group, @NotNull HintHint intInfo) {
    LightweightHint hint;
    final JComponent editorComponent = editor.getComponent();
    TextRange range = myDocumentFragment.getTextRange();
    int startOffset = range.getStartOffset();
    int endOffset = range.getEndOffset();
    Document doc = myDocumentFragment.getDocument();
    int endLine = doc.getLineNumber(endOffset);
    int startLine = doc.getLineNumber(startOffset);
    JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
    // There is a possible case that collapsed folding region is soft wrapped, hence, we need to anchor
    // not logical but visual line start.
    VisualPosition visual = editor.offsetToVisualPosition(startOffset);
    p = editor.visualPositionToXY(visual);
    p = SwingUtilities.convertPoint(((EditorEx) editor).getGutterComponentEx(), p, layeredPane);
    p.x -= 3;
    p.y += editor.getLineHeight();
    Point screenPoint = new Point(p);
    SwingUtilities.convertPointToScreen(screenPoint, layeredPane);
    int maxLineCount = (ScreenUtil.getScreenRectangle(screenPoint).height - screenPoint.y) / editor.getLineHeight();
    if (endLine - startLine > maxLineCount) {
        endOffset = doc.getLineEndOffset(Math.max(0, Math.min(startLine + maxLineCount, doc.getLineCount() - 1)));
    }
    if (endOffset < startOffset)
        return null;
    FoldingModelEx foldingModel = (FoldingModelEx) editor.getFoldingModel();
    foldingModel.setFoldingEnabled(false);
    TextRange textRange = new TextRange(startOffset, endOffset);
    hint = EditorFragmentComponent.showEditorFragmentHintAt(editor, textRange, p.y, false, false, true, true, true);
    foldingModel.setFoldingEnabled(true);
    return hint;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) LightweightHint(com.intellij.ui.LightweightHint) TextRange(com.intellij.openapi.util.TextRange) FoldingModelEx(com.intellij.openapi.editor.ex.FoldingModelEx) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint)

Example 20 with LightweightHint

use of com.intellij.ui.LightweightHint in project intellij-community by JetBrains.

the class DiffRequestProcessor method notifyMessage.

private void notifyMessage(@NotNull AnActionEvent e, boolean next) {
    Editor editor = e.getData(DiffDataKeys.CURRENT_EDITOR);
    // TODO: provide "change" word in chain UserData - for tests/etc
    String message = DiffUtil.createNotificationText(next ? "Press again to go to the next file" : "Press again to go to the previous file", "You can disable this feature in " + DiffUtil.getSettingsConfigurablePath());
    final LightweightHint hint = new LightweightHint(HintUtil.createInformationLabel(message));
    Point point = new Point(myContentPanel.getWidth() / 2, next ? myContentPanel.getHeight() - JBUI.scale(40) : JBUI.scale(40));
    if (editor == null) {
        final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
        final HintHint hintHint = createNotifyHint(myContentPanel, point, next);
        hint.show(myContentPanel, point.x, point.y, owner instanceof JComponent ? (JComponent) owner : null, hintHint);
    } else {
        int x = SwingUtilities.convertPoint(myContentPanel, point, editor.getComponent()).x;
        JComponent header = editor.getHeaderComponent();
        int shift = editor.getScrollingModel().getVerticalScrollOffset() - (header != null ? header.getHeight() : 0);
        LogicalPosition position;
        LineRange changeRange = e.getData(DiffDataKeys.CURRENT_CHANGE_RANGE);
        if (changeRange == null) {
            position = new LogicalPosition(editor.getCaretModel().getLogicalPosition().line + (next ? 1 : 0), 0);
        } else {
            position = new LogicalPosition(next ? changeRange.end : changeRange.start, 0);
        }
        int y = editor.logicalPositionToXY(position).y - shift;
        Point editorPoint = new Point(x, y);
        final HintHint hintHint = createNotifyHint(editor.getComponent(), editorPoint, !next);
        HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, editorPoint, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false, hintHint);
    }
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) Editor(com.intellij.openapi.editor.Editor) LineRange(com.intellij.diff.util.LineRange) LightweightHint(com.intellij.ui.LightweightHint) HintHint(com.intellij.ui.HintHint)

Aggregations

LightweightHint (com.intellij.ui.LightweightHint)38 HintHint (com.intellij.ui.HintHint)11 Document (com.intellij.openapi.editor.Document)5 Project (com.intellij.openapi.project.Project)5 TextRange (com.intellij.openapi.util.TextRange)4 Nullable (org.jetbrains.annotations.Nullable)4 EditorHintListener (com.intellij.codeInsight.hint.EditorHintListener)3 Editor (com.intellij.openapi.editor.Editor)3 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)3 PsiFile (com.intellij.psi.PsiFile)3 HintListener (com.intellij.ui.HintListener)3 HintManager (com.intellij.codeInsight.hint.HintManager)2 IntentionHintComponent (com.intellij.codeInsight.intention.impl.IntentionHintComponent)2 Disposable (com.intellij.openapi.Disposable)2 AnAction (com.intellij.openapi.actionSystem.AnAction)2 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)2 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)2 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)2 PsiElement (com.intellij.psi.PsiElement)2 EventObject (java.util.EventObject)2