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()));
}
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;
}
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);
}
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));
}
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);
}
Aggregations