use of com.intellij.ui.HintHint 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.HintHint in project intellij-community by JetBrains.
the class EmmetPreviewHint method showHint.
public void showHint() {
myParentEditor.putUserData(KEY, this);
Pair<Point, Short> position = guessPosition();
JRootPane pane = myParentEditor.getComponent().getRootPane();
JComponent layeredPane = pane != null ? pane.getLayeredPane() : myParentEditor.getComponent();
HintHint hintHint = new HintHint(layeredPane, position.first).setAwtTooltip(true).setContentActive(true).setExplicitClose(true).setShowImmediately(true).setPreferredPosition(position.second == HintManager.ABOVE ? Balloon.Position.above : Balloon.Position.below).setTextBg(myParentEditor.getColorsScheme().getDefaultBackground()).setBorderInsets(JBUI.insets(1));
int hintFlags = HintManager.HIDE_BY_OTHER_HINT | HintManager.HIDE_BY_ESCAPE | HintManager.UPDATE_BY_SCROLLING;
HintManagerImpl.getInstanceImpl().showEditorHint(this, myParentEditor, position.first, hintFlags, 0, false, hintHint);
}
use of com.intellij.ui.HintHint in project intellij-community by JetBrains.
the class IntentionDescriptionPanel method toHTML.
// TODO 134099: see SingleInspectionProfilePanel#setHTML
private String toHTML(String text) {
final HintHint hintHint = new HintHint(myDescriptionBrowser, new Point(0, 0));
hintHint.setFont(UIUtil.getLabelFont());
return HintUtil.prepareHintText(text, hintHint);
}
use of com.intellij.ui.HintHint in project intellij-community by JetBrains.
the class ParameterInfoController method showHint.
public void showHint(boolean requestFocus) {
Pair<Point, Short> pos = myProvider.getBestPointPosition(myHint, myComponent.getParameterOwner(), myLbraceMarker.getStartOffset(), true, HintManager.UNDER);
HintHint hintHint = HintManagerImpl.createHintHint(myEditor, pos.getFirst(), myHint, pos.getSecond());
hintHint.setExplicitClose(true);
hintHint.setRequestFocus(requestFocus);
Editor editorToShow = myEditor instanceof EditorWindow ? ((EditorWindow) myEditor).getDelegate() : myEditor;
// is case of injection we need to calculate position for EditorWindow
// also we need to show the hint in the main editor because of intention bulb
HintManagerImpl.getInstanceImpl().showEditorHint(myHint, editorToShow, pos.getFirst(), HintManager.HIDE_BY_ESCAPE | HintManager.UPDATE_BY_SCROLLING, 0, false, hintHint);
updateComponent();
}
use of com.intellij.ui.HintHint in project intellij-community by JetBrains.
the class IncrementalSearchHandler method invoke.
public void invoke(Project project, final Editor editor) {
if (!ourActionsRegistered) {
EditorActionManager actionManager = EditorActionManager.getInstance();
TypedAction typedAction = actionManager.getTypedAction();
typedAction.setupRawHandler(new MyTypedHandler(typedAction.getRawHandler()));
actionManager.setActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE, new BackSpaceHandler(actionManager.getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE)));
actionManager.setActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_UP, new UpHandler(actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_UP)));
actionManager.setActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN, new DownHandler(actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN)));
ourActionsRegistered = true;
}
FeatureUsageTracker.getInstance().triggerFeatureUsed("editing.incremental.search");
String selection = editor.getSelectionModel().getSelectedText();
JLabel label2 = new MyLabel(selection == null ? "" : selection);
PerEditorSearchData data = editor.getUserData(SEARCH_DATA_IN_EDITOR_VIEW_KEY);
if (data == null) {
data = new PerEditorSearchData();
} else {
if (data.hint != null) {
if (data.lastSearch != null) {
PerHintSearchData hintData = data.hint.getUserData(SEARCH_DATA_IN_HINT_KEY);
//The user has not started typing
if ("".equals(hintData.label.getText())) {
label2 = new MyLabel(data.lastSearch);
}
}
data.hint.hide();
}
}
JLabel label1 = new MyLabel(" " + CodeInsightBundle.message("incremental.search.tooltip.prefix"));
label1.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
JPanel panel = new MyPanel(label1);
panel.add(label1, BorderLayout.WEST);
panel.add(label2, BorderLayout.CENTER);
panel.setBorder(BorderFactory.createLineBorder(Color.black));
final DocumentListener[] documentListener = new DocumentListener[1];
final CaretListener[] caretListener = new CaretListener[1];
final Document document = editor.getDocument();
final LightweightHint hint = new LightweightHint(panel) {
@Override
public void hide() {
PerHintSearchData data = getUserData(SEARCH_DATA_IN_HINT_KEY);
LOG.assertTrue(data != null);
String prefix = data.label.getText();
super.hide();
if (data.segmentHighlighter != null) {
data.segmentHighlighter.dispose();
}
PerEditorSearchData editorData = editor.getUserData(SEARCH_DATA_IN_EDITOR_VIEW_KEY);
editorData.hint = null;
editorData.lastSearch = prefix;
if (documentListener[0] != null) {
document.removeDocumentListener(documentListener[0]);
documentListener[0] = null;
}
if (caretListener[0] != null) {
CaretListener listener = caretListener[0];
editor.getCaretModel().removeCaretListener(listener);
}
}
};
documentListener[0] = new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
if (!hint.isVisible())
return;
hint.hide();
}
};
document.addDocumentListener(documentListener[0]);
caretListener[0] = new CaretAdapter() {
@Override
public void caretPositionChanged(CaretEvent e) {
PerHintSearchData data = hint.getUserData(SEARCH_DATA_IN_HINT_KEY);
if (data != null && data.ignoreCaretMove)
return;
if (!hint.isVisible())
return;
hint.hide();
}
};
CaretListener listener = caretListener[0];
editor.getCaretModel().addCaretListener(listener);
final JComponent component = editor.getComponent();
int x = SwingUtilities.convertPoint(component, 0, 0, component).x;
int y = -hint.getComponent().getPreferredSize().height;
Point p = SwingUtilities.convertPoint(component, x, y, component.getRootPane().getLayeredPane());
HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, p, HintManagerImpl.HIDE_BY_ESCAPE | HintManagerImpl.HIDE_BY_TEXT_CHANGE, 0, false, new HintHint(editor, p).setAwtTooltip(false));
PerHintSearchData hintData = new PerHintSearchData(project, label2);
hintData.searchStart = editor.getCaretModel().getOffset();
hint.putUserData(SEARCH_DATA_IN_HINT_KEY, hintData);
data.hint = hint;
editor.putUserData(SEARCH_DATA_IN_EDITOR_VIEW_KEY, data);
if (hintData.label.getText().length() > 0) {
updatePosition(editor, hintData, true, false);
}
}
Aggregations