Search in sources :

Example 21 with LightweightHint

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

the class CompletionProgressIndicator method showErrorHint.

private static LightweightHint showErrorHint(Project project, Editor editor, String text) {
    final LightweightHint[] result = { null };
    final EditorHintListener listener = (project1, hint, flags) -> result[0] = hint;
    final MessageBusConnection connection = project.getMessageBus().connect();
    connection.subscribe(EditorHintListener.TOPIC, listener);
    assert text != null;
    HintManager.getInstance().showErrorHint(editor, StringUtil.escapeXml(text), HintManager.UNDER);
    connection.disconnect();
    return result[0];
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) MessageType(com.intellij.openapi.ui.MessageType) Document(com.intellij.openapi.editor.Document) IdeActions(com.intellij.openapi.actionSystem.IdeActions) AutoPopupController(com.intellij.codeInsight.AutoPopupController) PerformanceWatcher(com.intellij.diagnostic.PerformanceWatcher) Semaphore(com.intellij.util.concurrency.Semaphore) Disposer(com.intellij.openapi.util.Disposer) FeatureUsageTracker(com.intellij.featureStatistics.FeatureUsageTracker) EditorHintListener(com.intellij.codeInsight.hint.EditorHintListener) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Logger(com.intellij.openapi.diagnostic.Logger) ReferenceRange(com.intellij.psi.ReferenceRange) Extensions(com.intellij.openapi.extensions.Extensions) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) DocumentWindow(com.intellij.injected.editor.DocumentWindow) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings) PsiReference(com.intellij.psi.PsiReference) Set(java.util.Set) com.intellij.codeInsight.lookup(com.intellij.codeInsight.lookup) TextRange(com.intellij.openapi.util.TextRange) KeyEvent(java.awt.event.KeyEvent) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Registry(com.intellij.openapi.util.registry.Registry) Queue(java.util.Queue) NotNull(org.jetbrains.annotations.NotNull) LightweightHint(com.intellij.ui.LightweightHint) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) ContainerUtil(com.intellij.util.containers.ContainerUtil) KeyAdapter(java.awt.event.KeyAdapter) Caret(com.intellij.openapi.editor.Caret) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) CompletionSorterImpl(com.intellij.codeInsight.completion.impl.CompletionSorterImpl) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ProgressWrapper(com.intellij.openapi.progress.util.ProgressWrapper) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) JobScheduler(com.intellij.concurrency.JobScheduler) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) CompletionAutoPopupHandler(com.intellij.codeInsight.editorActions.CompletionAutoPopupHandler) StringUtil(com.intellij.openapi.util.text.StringUtil) CompletionServiceImpl(com.intellij.codeInsight.completion.impl.CompletionServiceImpl) Editor(com.intellij.openapi.editor.Editor) GuiUtils(com.intellij.ui.GuiUtils) EditorWindow(com.intellij.injected.editor.EditorWindow) Disposable(com.intellij.openapi.Disposable) ElementPattern(com.intellij.patterns.ElementPattern) MergingUpdateQueue(com.intellij.util.ui.update.MergingUpdateQueue) TestOnly(org.jetbrains.annotations.TestOnly) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) CommandProcessor(com.intellij.openapi.command.CommandProcessor) Update(com.intellij.util.ui.update.Update) Result(com.intellij.openapi.application.Result) Pair(com.intellij.openapi.util.Pair) TargetElementUtil(com.intellij.codeInsight.TargetElementUtil) ObjectUtils(com.intellij.util.ObjectUtils) HintManager(com.intellij.codeInsight.hint.HintManager) javax.swing(javax.swing) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) EditorHintListener(com.intellij.codeInsight.hint.EditorHintListener) LightweightHint(com.intellij.ui.LightweightHint)

Example 22 with LightweightHint

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

the class CompletionProgressIndicator method handleEmptyLookup.

protected void handleEmptyLookup(final boolean awaitSecondInvocation) {
    if (isAutopopupCompletion() && ApplicationManager.getApplication().isUnitTestMode()) {
        return;
    }
    LOG.assertTrue(!isAutopopupCompletion());
    if (ApplicationManager.getApplication().isUnitTestMode() || !myHandler.invokedExplicitly) {
        CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
        return;
    }
    for (final CompletionContributor contributor : CompletionContributor.forParameters(getParameters())) {
        final String text = contributor.handleEmptyLookup(getParameters(), getEditor());
        if (StringUtil.isNotEmpty(text)) {
            LightweightHint hint = showErrorHint(getProject(), getEditor(), text);
            CompletionServiceImpl.setCompletionPhase(awaitSecondInvocation ? new CompletionPhase.NoSuggestionsHint(hint, this) : CompletionPhase.NoCompletion);
            return;
        }
    }
    CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
}
Also used : LightweightHint(com.intellij.ui.LightweightHint)

Example 23 with LightweightHint

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

the class FileInEditorProcessor method showHint.

public static void showHint(@NotNull Editor editor, @NotNull String info, @Nullable HyperlinkListener hyperlinkListener) {
    JComponent component = HintUtil.createInformationLabel(info, hyperlinkListener, null, null);
    LightweightHint hint = new LightweightHint(component);
    int flags = HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING;
    if (isCaretVisible(editor)) {
        HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, HintManager.UNDER, flags, 0, false);
    } else {
        showHintWithoutScroll(editor, hint, flags);
    }
}
Also used : LightweightHint(com.intellij.ui.LightweightHint) LightweightHint(com.intellij.ui.LightweightHint)

Example 24 with LightweightHint

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

the class FindUtil method processNotFound.

public static void processNotFound(final Editor editor, String stringToFind, FindModel model, Project project) {
    String message = FindBundle.message("find.search.string.not.found.message", stringToFind);
    short position = HintManager.UNDER;
    if (model.isGlobal()) {
        final FindModel newModel = model.clone();
        FindManager findManager = FindManager.getInstance(project);
        Document document = editor.getDocument();
        FindResult result = findManager.findString(document.getCharsSequence(), newModel.isForward() ? 0 : document.getTextLength(), model, getVirtualFile(editor));
        if (!result.isStringFound()) {
            result = null;
        }
        FindModel modelForNextSearch = findManager.getFindNextModel(editor);
        if (modelForNextSearch == null) {
            modelForNextSearch = findManager.getFindInFileModel();
        }
        if (result != null) {
            if (newModel.isForward()) {
                AnAction action = ActionManager.getInstance().getAction(modelForNextSearch.isForward() ? IdeActions.ACTION_FIND_NEXT : IdeActions.ACTION_FIND_PREVIOUS);
                String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
                if (!shortcutsText.isEmpty()) {
                    message = FindBundle.message("find.search.again.from.top.hotkey.message", message, shortcutsText);
                } else {
                    message = FindBundle.message("find.search.again.from.top.action.message", message);
                }
                editor.putUserData(KEY, Direction.DOWN);
            } else {
                AnAction action = ActionManager.getInstance().getAction(modelForNextSearch.isForward() ? IdeActions.ACTION_FIND_PREVIOUS : IdeActions.ACTION_FIND_NEXT);
                String shortcutsText = KeymapUtil.getFirstKeyboardShortcutText(action);
                if (!shortcutsText.isEmpty()) {
                    message = FindBundle.message("find.search.again.from.bottom.hotkey.message", message, shortcutsText);
                } else {
                    message = FindBundle.message("find.search.again.from.bottom.action.message", message);
                }
                editor.putUserData(KEY, Direction.UP);
                position = HintManager.ABOVE;
            }
        }
        CaretListener listener = new CaretAdapter() {

            @Override
            public void caretPositionChanged(CaretEvent e) {
                editor.putUserData(KEY, null);
                editor.getCaretModel().removeCaretListener(this);
            }
        };
        editor.getCaretModel().addCaretListener(listener);
    }
    JComponent component = HintUtil.createInformationLabel(JDOMUtil.escapeText(message, false, false));
    final LightweightHint hint = new LightweightHint(component);
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, position, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false);
}
Also used : CaretEvent(com.intellij.openapi.editor.event.CaretEvent) CaretListener(com.intellij.openapi.editor.event.CaretListener) LightweightHint(com.intellij.ui.LightweightHint) CaretAdapter(com.intellij.openapi.editor.event.CaretAdapter)

Example 25 with LightweightHint

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

the class LineStatusMarkerPopup method showHintAt.

public void showHintAt(@Nullable Point mousePosition) {
    if (!myTracker.isValid())
        return;
    final Disposable disposable = Disposer.newDisposable();
    FileType fileType = getFileType();
    List<DiffFragment> wordDiff = computeWordDiff();
    installMasterEditorHighlighters(wordDiff, disposable);
    JComponent editorComponent = createEditorComponent(fileType, wordDiff);
    ActionToolbar toolbar = buildToolbar(mousePosition, disposable);
    // we need valid ActionToolbar.getPreferredSize() to calc size of popup
    toolbar.updateActionsImmediately();
    toolbar.setReservePlaceAutoPopupIcon(false);
    PopupPanel popupPanel = new PopupPanel(myEditor, toolbar, editorComponent);
    LightweightHint hint = new LightweightHint(popupPanel);
    HintListener closeListener = new HintListener() {

        public void hintHidden(final EventObject event) {
            Disposer.dispose(disposable);
        }
    };
    hint.addHintListener(closeListener);
    int line = myEditor.getCaretModel().getLogicalPosition().line;
    Point point = HintManagerImpl.getHintPosition(hint, myEditor, new LogicalPosition(line, 0), HintManager.UNDER);
    if (mousePosition != null) {
        // show right after the nearest line
        int lineHeight = myEditor.getLineHeight();
        int delta = (point.y - mousePosition.y) % lineHeight;
        if (delta < 0)
            delta += lineHeight;
        point.y = mousePosition.y + delta;
    }
    // align main editor with the one in popup
    point.x -= popupPanel.getEditorTextOffset();
    int flags = HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING;
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, myEditor, point, flags, -1, false, new HintHint(myEditor, point));
    if (!hint.isVisible()) {
        closeListener.hintHidden(null);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) LightweightHint(com.intellij.ui.LightweightHint) EventObject(java.util.EventObject) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) HintListener(com.intellij.ui.HintListener) HintHint(com.intellij.ui.HintHint) DiffFragment(com.intellij.diff.fragments.DiffFragment) PlainTextFileType(com.intellij.openapi.fileTypes.PlainTextFileType) FileType(com.intellij.openapi.fileTypes.FileType)

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