Search in sources :

Example 36 with LightweightHint

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

the class FindManagerImpl method highlightNextHighlighter.

private static boolean highlightNextHighlighter(RangeHighlighter[] highlighters, Editor editor, int offset, boolean isForward, boolean secondPass) {
    RangeHighlighter highlighterToSelect = null;
    Object wasNotFound = editor.getUserData(HIGHLIGHTER_WAS_NOT_FOUND_KEY);
    for (RangeHighlighter highlighter : highlighters) {
        int start = highlighter.getStartOffset();
        int end = highlighter.getEndOffset();
        if (highlighter.isValid() && start < end) {
            if (isForward && (start > offset || start == offset && secondPass)) {
                if (highlighterToSelect == null || highlighterToSelect.getStartOffset() > start)
                    highlighterToSelect = highlighter;
            }
            if (!isForward && (end < offset || end == offset && secondPass)) {
                if (highlighterToSelect == null || highlighterToSelect.getEndOffset() < end)
                    highlighterToSelect = highlighter;
            }
        }
    }
    if (highlighterToSelect != null) {
        expandFoldRegionsIfNecessary(editor, highlighterToSelect.getStartOffset(), highlighterToSelect.getEndOffset());
        editor.getSelectionModel().setSelection(highlighterToSelect.getStartOffset(), highlighterToSelect.getEndOffset());
        editor.getCaretModel().moveToOffset(highlighterToSelect.getStartOffset());
        ScrollType scrollType;
        if (secondPass) {
            scrollType = isForward ? ScrollType.CENTER_UP : ScrollType.CENTER_DOWN;
        } else {
            scrollType = isForward ? ScrollType.CENTER_DOWN : ScrollType.CENTER_UP;
        }
        editor.getScrollingModel().scrollToCaret(scrollType);
        editor.putUserData(HIGHLIGHTER_WAS_NOT_FOUND_KEY, null);
        return true;
    }
    if (wasNotFound == null) {
        editor.putUserData(HIGHLIGHTER_WAS_NOT_FOUND_KEY, Boolean.TRUE);
        String message = FindBundle.message("find.highlight.no.more.highlights.found");
        if (isForward) {
            AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_NEXT);
            String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
            if (shortcutsText.isEmpty()) {
                message = FindBundle.message("find.search.again.from.top.action.message", message);
            } else {
                message = FindBundle.message("find.search.again.from.top.hotkey.message", message, shortcutsText);
            }
        } else {
            AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_PREVIOUS);
            String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
            if (shortcutsText.isEmpty()) {
                message = FindBundle.message("find.search.again.from.bottom.action.message", message);
            } else {
                message = FindBundle.message("find.search.again.from.bottom.hotkey.message", message, shortcutsText);
            }
        }
        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);
        return true;
    }
    if (!secondPass) {
        offset = isForward ? 0 : editor.getDocument().getTextLength();
        return highlightNextHighlighter(highlighters, editor, offset, isForward, true);
    }
    return false;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) LightweightHint(com.intellij.ui.LightweightHint) AnAction(com.intellij.openapi.actionSystem.AnAction) LightweightHint(com.intellij.ui.LightweightHint)

Example 37 with LightweightHint

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

the class ShowContainerInfoHandler method invoke.

@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
    PsiElement container = null;
    WeakReference<LightweightHint> ref = editor.getUserData(MY_LAST_HINT_KEY);
    LightweightHint hint = SoftReference.dereference(ref);
    if (hint != null && hint.isVisible()) {
        hint.hide();
        container = hint.getUserData(CONTAINER_KEY);
        if (container != null && !container.isValid()) {
            container = null;
        }
    }
    StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(file);
    if (builder instanceof TreeBasedStructureViewBuilder) {
        StructureViewModel model = ((TreeBasedStructureViewBuilder) builder).createStructureViewModel(editor);
        boolean goOneLevelUp = true;
        try {
            if (container == null) {
                goOneLevelUp = false;
                Object element = model.getCurrentEditorElement();
                if (element instanceof PsiElement) {
                    container = (PsiElement) element;
                }
            }
        } finally {
            model.dispose();
        }
        while (true) {
            if (container == null || container instanceof PsiFile) {
                return;
            }
            if (goOneLevelUp) {
                goOneLevelUp = false;
            } else {
                if (!isDeclarationVisible(container, editor)) {
                    break;
                }
            }
            container = container.getParent();
            while (container != null && DeclarationRangeUtil.getPossibleDeclarationAtRange(container) == null) {
                container = container.getParent();
                if (container instanceof PsiFile)
                    return;
            }
        }
    }
    if (container == null) {
        return;
    }
    final TextRange range = DeclarationRangeUtil.getPossibleDeclarationAtRange(container);
    if (range == null) {
        return;
    }
    final PsiElement _container = container;
    ApplicationManager.getApplication().invokeLater(() -> {
        LightweightHint hint1 = EditorFragmentComponent.showEditorFragmentHint(editor, range, true, true);
        if (hint1 != null) {
            hint1.putUserData(CONTAINER_KEY, _container);
            editor.putUserData(MY_LAST_HINT_KEY, new WeakReference<>(hint1));
        }
    });
}
Also used : LanguageStructureViewBuilder(com.intellij.lang.LanguageStructureViewBuilder) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) LightweightHint(com.intellij.ui.LightweightHint) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement)

Example 38 with LightweightHint

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

the class BraceHighlightingHandler method clearBraceHighlighters.

void clearBraceHighlighters() {
    List<RangeHighlighter> highlighters = getHighlightersList();
    for (final RangeHighlighter highlighter : highlighters) {
        highlighter.dispose();
    }
    highlighters.clear();
    LightweightHint hint = myEditor.getUserData(HINT_IN_EDITOR_KEY);
    if (hint != null) {
        hint.hide();
        myEditor.putUserData(HINT_IN_EDITOR_KEY, null);
    }
}
Also used : LightweightHint(com.intellij.ui.LightweightHint)

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