Search in sources :

Example 1 with HintListener

use of com.intellij.ui.HintListener 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)

Example 2 with HintListener

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

the class DaemonRespondToChangesTest method testLightBulbIsHiddenWhenFixRangeIsCollapsed.

public void testLightBulbIsHiddenWhenFixRangeIsCollapsed() {
    configureByText(StdFileTypes.JAVA, "class S { void foo() { boolean var; if (<selection>va<caret>r</selection>) {}} }");
    ((EditorImpl) myEditor).getScrollPane().getViewport().setSize(1000, 1000);
    final Set<LightweightHint> visibleHints = ContainerUtil.newIdentityTroveSet();
    getProject().getMessageBus().connect(getTestRootDisposable()).subscribe(EditorHintListener.TOPIC, new EditorHintListener() {

        @Override
        public void hintShown(final Project project, final LightweightHint hint, final int flags) {
            visibleHints.add(hint);
            hint.addHintListener(new HintListener() {

                @Override
                public void hintHidden(EventObject event) {
                    visibleHints.remove(hint);
                    hint.removeHintListener(this);
                }
            });
        }
    });
    highlightErrors();
    IntentionHintComponent lastHintBeforeDeletion = myDaemonCodeAnalyzer.getLastIntentionHint();
    assertNotNull(lastHintBeforeDeletion);
    delete(myEditor);
    highlightErrors();
    IntentionHintComponent lastHintAfterDeletion = myDaemonCodeAnalyzer.getLastIntentionHint();
    assertSame(lastHintBeforeDeletion, lastHintAfterDeletion);
    assertEmpty(visibleHints);
}
Also used : EditorHintListener(com.intellij.codeInsight.hint.EditorHintListener) HintListener(com.intellij.ui.HintListener) Project(com.intellij.openapi.project.Project) IntentionHintComponent(com.intellij.codeInsight.intention.impl.IntentionHintComponent) EditorHintListener(com.intellij.codeInsight.hint.EditorHintListener) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) LightweightHint(com.intellij.ui.LightweightHint) LightweightHint(com.intellij.ui.LightweightHint)

Example 3 with HintListener

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

the class TrafficTooltipRendererImpl method show.

@Override
public LightweightHint show(@NotNull Editor editor, @NotNull Point p, boolean alignToRight, @NotNull TooltipGroup group, @NotNull HintHint hintHint) {
    myTrafficLightRenderer = (TrafficLightRenderer) ((EditorMarkupModelImpl) 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) {
            //double hide?
            if (myPanel == null)
                return;
            myPanel = null;
            onHide.run();
        }
    });
    return hint;
}
Also used : HintListener(com.intellij.ui.HintListener) HintManagerImpl(com.intellij.codeInsight.hint.HintManagerImpl) LightweightHint(com.intellij.ui.LightweightHint) EditorMarkupModelImpl(com.intellij.openapi.editor.impl.EditorMarkupModelImpl) EventObject(java.util.EventObject)

Aggregations

HintListener (com.intellij.ui.HintListener)3 LightweightHint (com.intellij.ui.LightweightHint)3 EventObject (java.util.EventObject)2 EditorHintListener (com.intellij.codeInsight.hint.EditorHintListener)1 HintManagerImpl (com.intellij.codeInsight.hint.HintManagerImpl)1 IntentionHintComponent (com.intellij.codeInsight.intention.impl.IntentionHintComponent)1 DiffFragment (com.intellij.diff.fragments.DiffFragment)1 Disposable (com.intellij.openapi.Disposable)1 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)1 EditorMarkupModelImpl (com.intellij.openapi.editor.impl.EditorMarkupModelImpl)1 FileType (com.intellij.openapi.fileTypes.FileType)1 PlainTextFileType (com.intellij.openapi.fileTypes.PlainTextFileType)1 Project (com.intellij.openapi.project.Project)1 HintHint (com.intellij.ui.HintHint)1