Search in sources :

Example 11 with LightweightHint

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

the class FileInEditorProcessor method showHintWithoutScroll.

private static void showHintWithoutScroll(Editor editor, LightweightHint hint, int flags) {
    Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
    short constraint;
    int y;
    if (isCaretAboveTop(editor, visibleArea)) {
        y = visibleArea.y;
        constraint = HintManager.UNDER;
    } else {
        y = visibleArea.y + visibleArea.height;
        constraint = HintManager.ABOVE;
    }
    Point hintPoint = new Point(visibleArea.x + (visibleArea.width / 2), y);
    JComponent component = HintManagerImpl.getExternalComponent(editor);
    Point convertedPoint = SwingUtilities.convertPoint(editor.getContentComponent(), hintPoint, component);
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, convertedPoint, flags, 0, false, constraint);
}
Also used : LightweightHint(com.intellij.ui.LightweightHint)

Example 12 with LightweightHint

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

the class BraceHighlightingHandler method showScopeHint.

private void showScopeHint(final int lbraceStart, final int lbraceEnd) {
    LogicalPosition bracePosition = myEditor.offsetToLogicalPosition(lbraceStart);
    Point braceLocation = myEditor.logicalPositionToXY(bracePosition);
    final int y = braceLocation.y;
    myAlarm.addRequest(() -> {
        if (myProject.isDisposed())
            return;
        PsiDocumentManager.getInstance(myProject).performLaterWhenAllCommitted(() -> {
            if (!myEditor.getComponent().isShowing())
                return;
            Rectangle viewRect = myEditor.getScrollingModel().getVisibleArea();
            if (y < viewRect.y) {
                int start = lbraceStart;
                if (!(myPsiFile instanceof PsiPlainTextFile) && myPsiFile.isValid()) {
                    start = BraceMatchingUtil.getBraceMatcher(getFileTypeByOffset(lbraceStart), PsiUtilCore.getLanguageAtOffset(myPsiFile, lbraceStart)).getCodeConstructStart(myPsiFile, lbraceStart);
                }
                TextRange range = new TextRange(start, lbraceEnd);
                int line1 = myDocument.getLineNumber(range.getStartOffset());
                int line2 = myDocument.getLineNumber(range.getEndOffset());
                line1 = Math.max(line1, line2 - 5);
                range = new TextRange(myDocument.getLineStartOffset(line1), range.getEndOffset());
                LightweightHint hint = EditorFragmentComponent.showEditorFragmentHint(myEditor, range, true, true);
                myEditor.putUserData(HINT_IN_EDITOR_KEY, hint);
            }
        });
    }, 300, ModalityState.stateForComponent(myEditor.getComponent()));
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) LightweightHint(com.intellij.ui.LightweightHint) TextRange(com.intellij.openapi.util.TextRange) LightweightHint(com.intellij.ui.LightweightHint)

Example 13 with LightweightHint

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

the class IncrementalSearchHandler method invoke.

public void invoke(Project project, final Editor editor) {
    if (!ourActionsRegistered) {
        EditorActionManager actionManager = EditorActionManager.getInstance();
        TypedAction typedAction = actionManager.getTypedAction();
        typedAction.setupRawHandler(new MyTypedHandler(typedAction.getRawHandler()));
        actionManager.setActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE, new BackSpaceHandler(actionManager.getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE)));
        actionManager.setActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_UP, new UpHandler(actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_UP)));
        actionManager.setActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN, new DownHandler(actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN)));
        ourActionsRegistered = true;
    }
    FeatureUsageTracker.getInstance().triggerFeatureUsed("editing.incremental.search");
    String selection = editor.getSelectionModel().getSelectedText();
    JLabel label2 = new MyLabel(selection == null ? "" : selection);
    PerEditorSearchData data = editor.getUserData(SEARCH_DATA_IN_EDITOR_VIEW_KEY);
    if (data == null) {
        data = new PerEditorSearchData();
    } else {
        if (data.hint != null) {
            if (data.lastSearch != null) {
                PerHintSearchData hintData = data.hint.getUserData(SEARCH_DATA_IN_HINT_KEY);
                //The user has not started typing
                if ("".equals(hintData.label.getText())) {
                    label2 = new MyLabel(data.lastSearch);
                }
            }
            data.hint.hide();
        }
    }
    JLabel label1 = new MyLabel(" " + CodeInsightBundle.message("incremental.search.tooltip.prefix"));
    label1.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
    JPanel panel = new MyPanel(label1);
    panel.add(label1, BorderLayout.WEST);
    panel.add(label2, BorderLayout.CENTER);
    panel.setBorder(BorderFactory.createLineBorder(Color.black));
    final DocumentListener[] documentListener = new DocumentListener[1];
    final CaretListener[] caretListener = new CaretListener[1];
    final Document document = editor.getDocument();
    final LightweightHint hint = new LightweightHint(panel) {

        @Override
        public void hide() {
            PerHintSearchData data = getUserData(SEARCH_DATA_IN_HINT_KEY);
            LOG.assertTrue(data != null);
            String prefix = data.label.getText();
            super.hide();
            if (data.segmentHighlighter != null) {
                data.segmentHighlighter.dispose();
            }
            PerEditorSearchData editorData = editor.getUserData(SEARCH_DATA_IN_EDITOR_VIEW_KEY);
            editorData.hint = null;
            editorData.lastSearch = prefix;
            if (documentListener[0] != null) {
                document.removeDocumentListener(documentListener[0]);
                documentListener[0] = null;
            }
            if (caretListener[0] != null) {
                CaretListener listener = caretListener[0];
                editor.getCaretModel().removeCaretListener(listener);
            }
        }
    };
    documentListener[0] = new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            if (!hint.isVisible())
                return;
            hint.hide();
        }
    };
    document.addDocumentListener(documentListener[0]);
    caretListener[0] = new CaretAdapter() {

        @Override
        public void caretPositionChanged(CaretEvent e) {
            PerHintSearchData data = hint.getUserData(SEARCH_DATA_IN_HINT_KEY);
            if (data != null && data.ignoreCaretMove)
                return;
            if (!hint.isVisible())
                return;
            hint.hide();
        }
    };
    CaretListener listener = caretListener[0];
    editor.getCaretModel().addCaretListener(listener);
    final JComponent component = editor.getComponent();
    int x = SwingUtilities.convertPoint(component, 0, 0, component).x;
    int y = -hint.getComponent().getPreferredSize().height;
    Point p = SwingUtilities.convertPoint(component, x, y, component.getRootPane().getLayeredPane());
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, p, HintManagerImpl.HIDE_BY_ESCAPE | HintManagerImpl.HIDE_BY_TEXT_CHANGE, 0, false, new HintHint(editor, p).setAwtTooltip(false));
    PerHintSearchData hintData = new PerHintSearchData(project, label2);
    hintData.searchStart = editor.getCaretModel().getOffset();
    hint.putUserData(SEARCH_DATA_IN_HINT_KEY, hintData);
    data.hint = hint;
    editor.putUserData(SEARCH_DATA_IN_EDITOR_VIEW_KEY, data);
    if (hintData.label.getText().length() > 0) {
        updatePosition(editor, hintData, true, false);
    }
}
Also used : Document(com.intellij.openapi.editor.Document) LightweightHint(com.intellij.ui.LightweightHint) TypedAction(com.intellij.openapi.editor.actionSystem.TypedAction) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) EditorActionManager(com.intellij.openapi.editor.actionSystem.EditorActionManager) HintHint(com.intellij.ui.HintHint)

Example 14 with LightweightHint

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

the class SelectOccurrencesActionHandler method showHint.

protected static void showHint(final Editor editor) {
    String message = FindBundle.message("select.next.occurence.not.found.message");
    final LightweightHint hint = new LightweightHint(HintUtil.createInformationLabel(message));
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, HintManager.UNDER, HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false);
}
Also used : LightweightHint(com.intellij.ui.LightweightHint)

Example 15 with LightweightHint

use of com.intellij.ui.LightweightHint in project flutter-intellij by flutter.

the class FlutterReloadManager method showEditorHint.

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();
}
Also used : LightweightHint(com.intellij.ui.LightweightHint) AtomicReference(java.util.concurrent.atomic.AtomicReference)

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