Search in sources :

Example 1 with LightweightHint

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

the class AbstractQuickFixManager method showHint.

private void showHint() {
    if (!myComponent.isShowing() || !IJSwingUtilities.hasFocus(myComponent)) {
        hideHint();
        return;
    }
    // 1. Hide previous hint (if any)
    hideHint();
    // 2. Found error (if any)
    List<ErrorInfo> infos = getErrorInfos();
    if (!ErrorInfo.haveFixes(infos)) {
        hideHint();
        return;
    }
    boolean error = false;
    for (ErrorInfo errorInfo : infos) {
        if (errorInfo.getLevel() == HighlightDisplayLevel.ERROR) {
            error = true;
            break;
        }
    }
    // 3. Determine position where this hint should be shown
    Rectangle bounds = getErrorBounds();
    if (bounds == null) {
        return;
    }
    // 4. Show light bulb to fix this error
    myHint = new LightweightHint(new InspectionHint(error ? AllIcons.Actions.QuickfixBulb : AllIcons.Actions.IntentionBulb));
    myLastHintBounds = bounds;
    myHint.show(myComponent, bounds.x - AllIcons.Actions.IntentionBulb.getIconWidth() - 4, bounds.y, myComponent, new HintHint(myComponent, bounds.getLocation()));
}
Also used : HintHint(com.intellij.ui.HintHint) ErrorInfo(com.intellij.designer.model.ErrorInfo) LightweightHint(com.intellij.ui.LightweightHint)

Example 2 with LightweightHint

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

the class EditorFragmentComponent method showEditorFragmentHintAt.

/**
   * @param y <code>y</code> coordinate in layered pane coordinate system.
   */
@Nullable
public static LightweightHint showEditorFragmentHintAt(Editor editor, TextRange range, int y, boolean showUpward, boolean showFolding, boolean hideByAnyKey, boolean hideByScrolling, boolean useCaretRowBackground) {
    if (ApplicationManager.getApplication().isUnitTestMode())
        return null;
    Document document = editor.getDocument();
    int startOffset = range.getStartOffset();
    int startLine = document.getLineNumber(startOffset);
    CharSequence text = document.getCharsSequence();
    // There is a possible case that we have a situation like below:
    //    line 1
    //    line 2 <fragment start>
    //    line 3<fragment end>
    // We don't want to include 'line 2' to the target fragment then.
    boolean incrementLine = false;
    for (int offset = startOffset, max = Math.min(range.getEndOffset(), text.length()); offset < max; offset++) {
        char c = text.charAt(offset);
        incrementLine = StringUtil.isWhiteSpace(c);
        if (!incrementLine || c == '\n') {
            break;
        }
    }
    if (incrementLine) {
        startLine++;
    }
    int endLine = Math.min(document.getLineNumber(range.getEndOffset()) + 1, document.getLineCount() - 1);
    if (startLine >= endLine)
        return null;
    EditorFragmentComponent fragmentComponent = createEditorFragmentComponent(editor, startLine, endLine, showFolding, true, useCaretRowBackground);
    if (showUpward) {
        y -= fragmentComponent.getPreferredSize().height;
        y = Math.max(0, y);
    }
    final JComponent c = editor.getComponent();
    //IDEA-68016
    int x = SwingUtilities.convertPoint(c, new Point(JBUI.scale(-3), 0), UIUtil.getRootPane(c)).x;
    Point p = new Point(x, y);
    LightweightHint hint = new MyComponentHint(fragmentComponent);
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, p, (hideByAnyKey ? HintManager.HIDE_BY_ANY_KEY : 0) | (hideByScrolling ? HintManager.HIDE_BY_SCROLLING : 0) | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_MOUSEOVER, 0, false, new HintHint(editor, p));
    return hint;
}
Also used : HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) Document(com.intellij.openapi.editor.Document) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with LightweightHint

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

the class EditorFragmentComponent method showEditorFragmentHint.

@Nullable
public static LightweightHint showEditorFragmentHint(Editor editor, TextRange range, boolean showFolding, boolean hideByAnyKey) {
    if (!(editor instanceof EditorEx))
        return null;
    JRootPane rootPane = editor.getComponent().getRootPane();
    if (rootPane == null)
        return null;
    JLayeredPane layeredPane = rootPane.getLayeredPane();
    int lineHeight = editor.getLineHeight();
    int overhang = editor.getScrollingModel().getVisibleArea().y - editor.logicalPositionToXY(editor.offsetToLogicalPosition(range.getEndOffset())).y;
    int yRelative = overhang > 0 && overhang < lineHeight ? lineHeight - overhang + JBUI.scale(LINE_BORDER_THICKNESS + EMPTY_BORDER_THICKNESS) : 0;
    Point point = SwingUtilities.convertPoint(((EditorEx) editor).getScrollPane().getViewport(), -2, yRelative, layeredPane);
    return showEditorFragmentHintAt(editor, range, point.y, true, showFolding, hideByAnyKey, true, false);
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with LightweightHint

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

the class CoverageLineMarkerRenderer method showHint.

private void showHint(final Editor editor, final Point point, final int lineNumber) {
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(createActionsToolbar(editor, lineNumber), BorderLayout.NORTH);
    final LineData lineData = getLineData(lineNumber);
    final EditorImpl uEditor;
    if (lineData != null && lineData.getStatus() != LineCoverage.NONE && !mySubCoverageActive) {
        final EditorFactory factory = EditorFactory.getInstance();
        final Document doc = factory.createDocument(getReport(editor, lineNumber));
        doc.setReadOnly(true);
        uEditor = (EditorImpl) factory.createEditor(doc, editor.getProject());
        panel.add(EditorFragmentComponent.createEditorFragmentComponent(uEditor, 0, doc.getLineCount(), false, false), BorderLayout.CENTER);
    } else {
        uEditor = null;
    }
    final LightweightHint hint = new LightweightHint(panel) {

        @Override
        public void hide() {
            if (uEditor != null)
                EditorFactory.getInstance().releaseEditor(uEditor);
            super.hide();
        }
    };
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point, HintManagerImpl.HIDE_BY_ANY_KEY | HintManagerImpl.HIDE_BY_TEXT_CHANGE | HintManagerImpl.HIDE_BY_OTHER_HINT | HintManagerImpl.HIDE_BY_SCROLLING, -1, false, new HintHint(editor, point));
}
Also used : LineData(com.intellij.rt.coverage.data.LineData) EditorFactory(com.intellij.openapi.editor.EditorFactory) HintHint(com.intellij.ui.HintHint) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) LightweightHint(com.intellij.ui.LightweightHint) Document(com.intellij.openapi.editor.Document)

Example 5 with LightweightHint

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

the class SelectUnselectOccurrenceActionsTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    EditorHintListener listener = new EditorHintListener() {

        @Override
        public void hintShown(Project project, LightweightHint hint, int flags) {
            hintCount++;
        }
    };
    ApplicationManager.getApplication().getMessageBus().connect(myFixture.getTestRootDisposable()).subscribe(EditorHintListener.TOPIC, listener);
}
Also used : Project(com.intellij.openapi.project.Project) EditorHintListener(com.intellij.codeInsight.hint.EditorHintListener) 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