From 75f7c3e251736e0d7cf457be45df2caf7a3daef2 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 25 Aug 2015 13:08:25 +0200 Subject: [PATCH] shorten too long notification texts before showing a balloon (IDEA-144301) --- .../impl/ui/NotificationsUtil.java | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationsUtil.java b/platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationsUtil.java index b94fb222503b..abb84610a119 100644 --- a/platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationsUtil.java +++ b/platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationsUtil.java @@ -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 += "
"; + 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 += "" + notification.getTitle() + "" + - "

" + notification.getContent() + "

"; - if (style != null) { - result += "
"; - } - 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 += "
"; } - result += "" + title + "

" + content + "

"; + result += "" : " color=\"" + color + "\">") + title + "

" + content + "

"; if (style != null) { result += "
"; } @@ -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) {