mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
shorten too long notification texts before showing a balloon (IDEA-144301)
This commit is contained in:
+22
-19
@@ -17,7 +17,9 @@ package com.intellij.notification.impl.ui;
|
||||
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationListener;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.ui.MessageType;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.ColorUtil;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.xml.util.XmlStringUtil;
|
||||
@@ -33,29 +35,35 @@ import java.awt.*;
|
||||
* @author spleaner
|
||||
*/
|
||||
public class NotificationsUtil {
|
||||
|
||||
private NotificationsUtil() {
|
||||
}
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.notification.impl.ui.NotificationsUtil");
|
||||
private static final int TITLE_LIMIT = 1000;
|
||||
private static final int CONTENT_LIMIT = 10000;
|
||||
|
||||
public static String buildHtml(@NotNull final Notification notification, @Nullable String style) {
|
||||
String result = "";
|
||||
if (style != null) {
|
||||
result += "<div style=\"" + style + "\">";
|
||||
String title = notification.getTitle();
|
||||
String content = notification.getContent();
|
||||
if (title.length() > TITLE_LIMIT || content.length() > CONTENT_LIMIT) {
|
||||
LOG.info("Too large notification " + notification + " of " + notification.getClass() +
|
||||
"\nListener=" + notification.getListener() +
|
||||
"\nTitle=" + title +
|
||||
"\nContent=" + content);
|
||||
title = StringUtil.trimLog(title, TITLE_LIMIT);
|
||||
content = StringUtil.trimLog(content, CONTENT_LIMIT);
|
||||
}
|
||||
result += "<b color=\"#"+ ColorUtil.toHex(getMessageType(notification).getTitleForeground())+"\">" + notification.getTitle() + "</b>" +
|
||||
"<p>" + notification.getContent() + "</p>";
|
||||
if (style != null) {
|
||||
result += "</div>";
|
||||
}
|
||||
return XmlStringUtil.wrapInHtml(result);
|
||||
return buildHtml(title, content, style, "#" + ColorUtil.toHex(getMessageType(notification).getTitleForeground()));
|
||||
}
|
||||
|
||||
public static String buildHtml(@NotNull final String title, @NotNull final String content, @Nullable String style) {
|
||||
return buildHtml(title, content, style, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String buildHtml(@NotNull String title, @NotNull String content, @Nullable String style, @Nullable String color) {
|
||||
String result = "";
|
||||
if (style != null) {
|
||||
result += "<div style=\"" + style + "\">";
|
||||
}
|
||||
result += "<b>" + title + "</b><p>" + content + "</p>";
|
||||
result += "<b" + (color == null ? ">" : " color=\"" + color + "\">") + title + "</b><p>" + content + "</p>";
|
||||
if (style != null) {
|
||||
result += "</div>";
|
||||
}
|
||||
@@ -81,12 +89,7 @@ public class NotificationsUtil {
|
||||
|
||||
public static Icon getIcon(@NotNull final Notification notification) {
|
||||
Icon icon = notification.getIcon();
|
||||
|
||||
if (icon == null) {
|
||||
icon = getMessageType(notification).getDefaultIcon();
|
||||
}
|
||||
|
||||
return icon;
|
||||
return icon != null ? icon : getMessageType(notification).getDefaultIcon();
|
||||
}
|
||||
|
||||
public static MessageType getMessageType(@NotNull Notification notification) {
|
||||
|
||||
Reference in New Issue
Block a user