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