shorten too long notification texts before showing a balloon (IDEA-144301)

This commit is contained in:
peter
2015-08-25 13:11:10 +02:00
parent bf3bbf9746
commit 75f7c3e251
@@ -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) {