mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[10.0.2] HintManager.showErrorHint accepts html
This commit is contained in:
@@ -513,10 +513,7 @@ public class CtrlMouseHandler extends AbstractProjectComponent {
|
||||
|
||||
if (text == null) return;
|
||||
|
||||
JLabel label = HintUtil.createInformationLabel(text);
|
||||
label.setUI(new MultiLineLabelUI());
|
||||
Font FONT = UIUtil.getLabelFont();
|
||||
label.setFont(FONT);
|
||||
JComponent label = HintUtil.createInformationLabel(text);
|
||||
final LightweightHint hint = new LightweightHint(label);
|
||||
final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
|
||||
label.addMouseMotionListener(new MouseMotionAdapter() {
|
||||
|
||||
@@ -254,7 +254,7 @@ public class ShowUsagesAction extends AnAction {
|
||||
private JComponent createHintComponent(String text, final FindUsagesHandler handler, final RelativePoint popupPosition, final Editor editor,
|
||||
final Runnable cancelAction,
|
||||
int maxUsages) {
|
||||
JLabel label = HintUtil.createInformationLabel(text);
|
||||
JComponent label = HintUtil.createInformationLabel(text);
|
||||
InplaceButton button = createSettingsButton(handler, popupPosition, editor, maxUsages, cancelAction);
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
button.setBackground(label.getBackground());
|
||||
|
||||
@@ -575,14 +575,14 @@ public class HintManagerImpl extends HintManager implements Disposable {
|
||||
}
|
||||
|
||||
public void showErrorHint(@NotNull Editor editor, @NotNull String text) {
|
||||
JLabel label = HintUtil.createErrorLabel(text);
|
||||
JComponent label = HintUtil.createErrorLabel(text);
|
||||
LightweightHint hint = new LightweightHint(label);
|
||||
Point p = getHintPosition(hint, editor, ABOVE);
|
||||
showEditorHint(hint, editor, p, HIDE_BY_ANY_KEY | HIDE_BY_TEXT_CHANGE | HIDE_BY_SCROLLING, 0, false);
|
||||
}
|
||||
|
||||
public void showInformationHint(@NotNull Editor editor, @NotNull String text) {
|
||||
JLabel label = HintUtil.createInformationLabel(text);
|
||||
JComponent label = HintUtil.createInformationLabel(text);
|
||||
showInformationHint(editor, label);
|
||||
}
|
||||
|
||||
@@ -598,7 +598,7 @@ public class HintManagerImpl extends HintManager implements Disposable {
|
||||
}
|
||||
|
||||
public void showErrorHint(@NotNull Editor editor, @NotNull String hintText, int offset1, int offset2, short constraint, int flags, int timeout) {
|
||||
JLabel label = HintUtil.createErrorLabel(hintText);
|
||||
JComponent label = HintUtil.createErrorLabel(hintText);
|
||||
LightweightHint hint = new LightweightHint(label);
|
||||
final LogicalPosition pos1 = editor.offsetToLogicalPosition(offset1);
|
||||
final LogicalPosition pos2 = editor.offsetToLogicalPosition(offset2);
|
||||
@@ -614,7 +614,7 @@ public class HintManagerImpl extends HintManager implements Disposable {
|
||||
int offset2,
|
||||
@NotNull QuestionAction action) {
|
||||
|
||||
JLabel label = HintUtil.createQuestionLabel(hintText);
|
||||
JComponent label = HintUtil.createQuestionLabel(hintText);
|
||||
LightweightHint hint = new LightweightHint(label);
|
||||
showQuestionHint(editor, offset1, offset2, hint, action, ABOVE);
|
||||
}
|
||||
|
||||
@@ -15,10 +15,13 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.hint;
|
||||
|
||||
import com.intellij.ide.IdeTooltipManager;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.ui.ColoredSideBorder;
|
||||
import com.intellij.ui.HintHint;
|
||||
import com.intellij.ui.SimpleColoredComponent;
|
||||
import com.intellij.ui.SimpleColoredText;
|
||||
import com.intellij.ui.components.panels.NonOpaquePanel;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -41,15 +44,20 @@ public class HintUtil {
|
||||
private HintUtil() {
|
||||
}
|
||||
|
||||
public static JLabel createInformationLabel(String text) {
|
||||
JLabel label = new HintLabel();
|
||||
label.setText(text);
|
||||
public static JComponent createInformationLabel(String text) {
|
||||
HintHint hintHint = new HintHint().setTextBg(INFORMATION_COLOR).setTextFg(Color.black).setFont(getBoldFont()).setAwtTooltip(true);
|
||||
|
||||
HintLabel label = new HintLabel();
|
||||
label.setText(text, hintHint);
|
||||
label.setIcon(INFORMATION_ICON);
|
||||
label.setBorder(createHintBorder());
|
||||
label.setForeground(Color.black);
|
||||
label.setFont(getBoldFont());
|
||||
label.setBackground(INFORMATION_COLOR);
|
||||
label.setOpaque(true);
|
||||
|
||||
if (!hintHint.isAwtTooltip()) {
|
||||
label.setBorder(createHintBorder());
|
||||
label.setForeground(Color.black);
|
||||
label.setFont(getBoldFont());
|
||||
label.setBackground(INFORMATION_COLOR);
|
||||
label.setOpaque(true);
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
@@ -65,16 +73,20 @@ public class HintUtil {
|
||||
return createInformationLabel(text, INFORMATION_ICON);
|
||||
}
|
||||
|
||||
public static JLabel createQuestionLabel(String text) {
|
||||
JLabel label = new HintLabel();
|
||||
label.setText(text);
|
||||
public static JComponent createQuestionLabel(String text) {
|
||||
HintHint hintHint = new HintHint().setTextBg(QUESTION_COLOR).setTextFg(Color.black).setFont(getBoldFont()).setAwtTooltip(true);
|
||||
|
||||
HintLabel label = new HintLabel();
|
||||
label.setText(text, hintHint);
|
||||
label.setIcon(QUESTION_ICON);
|
||||
// label.setBorder(BorderFactory.createLineBorder(Color.black));
|
||||
label.setBorder(createHintBorder());
|
||||
label.setForeground(Color.black);
|
||||
label.setFont(getBoldFont());
|
||||
label.setBackground(QUESTION_COLOR);
|
||||
label.setOpaque(true);
|
||||
|
||||
if (!hintHint.isAwtTooltip()) {
|
||||
label.setBorder(createHintBorder());
|
||||
label.setForeground(Color.black);
|
||||
label.setFont(getBoldFont());
|
||||
label.setBackground(QUESTION_COLOR);
|
||||
label.setOpaque(true);
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
@@ -87,26 +99,27 @@ public class HintUtil {
|
||||
highlighted.setFont(getBoldFont());
|
||||
text.appendToComponent(highlighted);
|
||||
|
||||
Box box = Box.createHorizontalBox();
|
||||
box.setBorder(new ColoredSideBorder(Color.white, Color.white, Color.gray, Color.gray, 1));
|
||||
box.setForeground(Color.black);
|
||||
box.setBackground(INFORMATION_COLOR);
|
||||
box.add(highlighted);
|
||||
box.setOpaque(true);
|
||||
return box;
|
||||
HintLabel label = new HintLabel();
|
||||
label.setText(highlighted);
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
public static JLabel createErrorLabel(String text) {
|
||||
JLabel label = new HintLabel();
|
||||
label.setText(text.replaceAll("\n"," "));
|
||||
public static JComponent createErrorLabel(String text) {
|
||||
HintHint hintHint = new HintHint().setTextBg(ERROR_COLOR).setTextFg(Color.black).setFont(getBoldFont()).setAwtTooltip(true);
|
||||
HintLabel label = new HintLabel();
|
||||
label.setText(text, hintHint);
|
||||
label.setIcon(ERROR_ICON);
|
||||
// label.setBorder(BorderFactory.createLineBorder(Color.black));
|
||||
label.setBorder(createHintBorder()
|
||||
);
|
||||
label.setForeground(Color.black);
|
||||
label.setFont(getBoldFont());
|
||||
label.setBackground(ERROR_COLOR);
|
||||
label.setOpaque(true);
|
||||
|
||||
if (!hintHint.isAwtTooltip()) {
|
||||
label.setBorder(createHintBorder()
|
||||
);
|
||||
label.setForeground(Color.black);
|
||||
label.setFont(getBoldFont());
|
||||
label.setBackground(ERROR_COLOR);
|
||||
label.setOpaque(true);
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
@@ -128,27 +141,75 @@ public class HintUtil {
|
||||
return label;
|
||||
}
|
||||
|
||||
private static class HintLabel extends JLabel {
|
||||
public void setText(String s) {
|
||||
if (s == null) {
|
||||
super.setText(null);
|
||||
}
|
||||
else {
|
||||
final int length = s.length();
|
||||
private static class HintLabel extends JPanel {
|
||||
|
||||
final String alignedText;
|
||||
if (length < 100 && !s.contains("\n")) {
|
||||
alignedText = s;
|
||||
} else {
|
||||
alignedText = s.replaceAll("(\n)|(\r\n)", " \n ");
|
||||
}
|
||||
super.setText(" " + alignedText + " ");
|
||||
private JEditorPane myPane;
|
||||
private SimpleColoredComponent myColored;
|
||||
private JLabel myIcon;
|
||||
|
||||
private HintLabel() {
|
||||
setLayout(new BorderLayout());
|
||||
}
|
||||
|
||||
|
||||
public void setText(SimpleColoredComponent colored) {
|
||||
clearText();
|
||||
|
||||
myColored = colored;
|
||||
add(myColored, BorderLayout.CENTER);
|
||||
|
||||
setOpaque(true);
|
||||
setBackground(colored.getBackground());
|
||||
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setText(String s, HintHint hintHint) {
|
||||
clearText();
|
||||
|
||||
if (s != null) {
|
||||
myPane = IdeTooltipManager.initPane(s, hintHint, null);
|
||||
add(myPane, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
setOpaque(true);
|
||||
setBackground(hintHint.getTextBackground());
|
||||
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
private void clearText() {
|
||||
if (myPane != null) {
|
||||
remove(myPane);
|
||||
myPane = null;
|
||||
}
|
||||
|
||||
if (myColored != null) {
|
||||
remove(myColored);
|
||||
myColored = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setIcon(Icon icon) {
|
||||
if (myIcon != null) {
|
||||
remove(myIcon);
|
||||
}
|
||||
|
||||
myIcon = new JLabel(icon, JLabel.CENTER);
|
||||
myIcon.setVerticalAlignment(JLabel.TOP);
|
||||
|
||||
add(myIcon, BorderLayout.WEST);
|
||||
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Hint: '" + getText() + "'";
|
||||
return "Hint: text='" + (myPane != null ? myPane.getText() : "") + "'";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -489,7 +489,7 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener
|
||||
}
|
||||
|
||||
if (hintHint.isAwtTooltip()) {
|
||||
Dimension size = layeredPane.getSize();
|
||||
Dimension size = layeredPane != null ? layeredPane.getSize() : new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
int fitWidth = (int)(size.width * 0.8);
|
||||
Dimension prefSizeOriginal = pane.getPreferredSize();
|
||||
if (prefSizeOriginal.width > fitWidth) {
|
||||
|
||||
+1
-1
@@ -410,7 +410,7 @@ public abstract class FileTextFieldImpl implements FileLookup, Disposable, FileT
|
||||
|
||||
if (!isExplicit) return;
|
||||
|
||||
final JLabel message = HintUtil.createErrorLabel(IdeBundle.message("file.chooser.completion.no.suggestions"));
|
||||
final JComponent message = HintUtil.createErrorLabel(IdeBundle.message("file.chooser.completion.no.suggestions"));
|
||||
final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(message, message);
|
||||
builder.setRequestFocus(false).setResizable(false).setAlpha(0.1f).setFocusOwners(new Component[] {myPathTextField});
|
||||
myNoSuggestionsPopup = builder.createPopup();
|
||||
|
||||
+5
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.openapi.wm.impl.status;
|
||||
|
||||
import com.intellij.codeInsight.hint.HintManager;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
@@ -39,6 +40,10 @@ public class AddTestProcessAction extends AnAction implements DumbAware {
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
HintManager.getInstance().showErrorHint(PlatformDataKeys.EDITOR.getData(e.getDataContext()), "<html>Fuck<br>Fuck again</html>");
|
||||
if (true) return;
|
||||
|
||||
|
||||
final Project p = PlatformDataKeys.PROJECT.getData(e.getDataContext());
|
||||
if (p != null) {
|
||||
ToolWindowManager.getInstance(p)
|
||||
|
||||
@@ -48,6 +48,9 @@ public class HintHint {
|
||||
private int myPositionChangeX;
|
||||
private int myPositionChangeY;
|
||||
|
||||
public HintHint() {
|
||||
}
|
||||
|
||||
public HintHint(MouseEvent e) {
|
||||
this(e.getComponent(), e.getPoint());
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@ public class AndroidUtils {
|
||||
|
||||
public static void navigateTo(@NotNull PsiElement[] targets, @Nullable RelativePoint pointToShowPopup) {
|
||||
if (targets.length == 0) {
|
||||
final JLabel renderer = HintUtil.createErrorLabel("Empty text");
|
||||
final JComponent renderer = HintUtil.createErrorLabel("Empty text");
|
||||
final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(renderer, renderer).createPopup();
|
||||
if (pointToShowPopup != null) {
|
||||
popup.show(pointToShowPopup);
|
||||
|
||||
@@ -288,7 +288,7 @@ public abstract class SearchSupport<T extends Task> {
|
||||
|
||||
private void showNoSuggestions() {
|
||||
hideCurrentPopup();
|
||||
final JLabel message = HintUtil.createErrorLabel(IdeBundle.message("file.chooser.completion.no.suggestions"));
|
||||
final JComponent message = HintUtil.createErrorLabel(IdeBundle.message("file.chooser.completion.no.suggestions"));
|
||||
final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(message, message);
|
||||
builder.setRequestFocus(false).setResizable(false).setAlpha(0.1f).
|
||||
setFocusOwners(new Component[] {myTextField});
|
||||
|
||||
+1
-1
@@ -104,7 +104,7 @@ public abstract class NavigationGutterIconRenderer extends GutterIconRenderer im
|
||||
final List<PsiElement> list = getTargetElements();
|
||||
if (list.isEmpty()) {
|
||||
if (myEmptyText != null) {
|
||||
final JLabel renderer = HintUtil.createErrorLabel(myEmptyText);
|
||||
final JComponent renderer = HintUtil.createErrorLabel(myEmptyText);
|
||||
final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(renderer, renderer).createPopup();
|
||||
if (event != null) {
|
||||
popup.show(new RelativePoint(event));
|
||||
|
||||
Reference in New Issue
Block a user