align multiline event log entries to date

This commit is contained in:
peter
2012-02-20 18:45:54 +01:00
parent b178b95992
commit 935e96cfc8
5 changed files with 19 additions and 17 deletions
@@ -121,7 +121,7 @@ public class EventLog implements Notifications {
return getLogModel(project).getStatusMessage();
}
public static LogEntry formatForLog(@NotNull final Notification notification) {
public static LogEntry formatForLog(@NotNull final Notification notification, String indent) {
DocumentImpl logDoc = new DocumentImpl(true);
AtomicBoolean showMore = new AtomicBoolean(false);
Map<RangeMarker, HyperlinkInfo> links = new LinkedHashMap<RangeMarker, HyperlinkInfo>();
@@ -141,7 +141,7 @@ public class EventLog implements Notifications {
String status = getStatusText(logDoc, showMore, lineSeparators, hasHtml);
indentNewLines(logDoc, lineSeparators, afterTitle, hasHtml);
indentNewLines(logDoc, lineSeparators, afterTitle, hasHtml, indent);
ArrayList<Pair<TextRange, HyperlinkInfo>> list = new ArrayList<Pair<TextRange, HyperlinkInfo>>();
for (RangeMarker marker : links.keySet()) {
@@ -165,7 +165,7 @@ public class EventLog implements Notifications {
return new LogEntry(logDoc.getText(), status, list);
}
private static void indentNewLines(DocumentImpl logDoc, List<RangeMarker> lineSeparators, RangeMarker afterTitle, boolean hasHtml) {
private static void indentNewLines(DocumentImpl logDoc, List<RangeMarker> lineSeparators, RangeMarker afterTitle, boolean hasHtml, String indent) {
if (!hasHtml) {
int i = -1;
while (true) {
@@ -187,8 +187,8 @@ public class EventLog implements Notifications {
continue;
}
logDoc.replaceString(start, separator.getEndOffset(), "\n\t");
nextLineStart = start + 2;
logDoc.replaceString(start, separator.getEndOffset(), "\n" + indent);
nextLineStart = start + 1 + indent.length();
while (nextLineStart < logDoc.getTextLength() && Character.isWhitespace(logDoc.getCharsSequence().charAt(nextLineStart))) {
logDoc.deleteString(nextLineStart, nextLineStart + 1);
}
@@ -38,6 +38,7 @@ import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.NotNullLazyValue;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.EditorPopupHandler;
import com.intellij.util.text.DateFormatUtil;
@@ -137,10 +138,11 @@ class EventLogConsole {
if (notificationTime == null) {
return;
}
append(document, DateFormatUtil.formatTimeWithSeconds(notificationTime) + " ");
EventLog.LogEntry pair = EventLog.formatForLog(notification);
String date = DateFormatUtil.formatTimeWithSeconds(notificationTime) + " ";
append(document, date);
EventLog.LogEntry pair = EventLog.formatForLog(notification, StringUtil.repeatSymbol(' ', date.length()));
final NotificationType type = notification.getType();
TextAttributesKey key = type == NotificationType.ERROR
@@ -61,7 +61,7 @@ public class NotificationTestAction extends AnAction implements DumbAware {
};
final Notification notification = new Notification(TEST_GROUP_ID, "This is a test notification", //"a",
"You can close this very very very very long notification by clicking <a href=\"close\">this link</a>. Long long long long. It should be long. Very long. Too long. And even longer.",
"You can<br> close this very<p> very very very long notification by clicking <a href=\"close\">this link</a>. Long long long long. It should be long. Very long. Too long. And even longer.",
type, listener);
messageBus.syncPublisher(Notifications.TOPIC).notify(notification);
@@ -161,7 +161,7 @@ class StatusPanel extends JPanel {
@Override
public void run() {
assert statusMessage != null;
String text = EventLog.formatForLog(statusMessage.first).status;
String text = EventLog.formatForLog(statusMessage.first, "").status;
if (myDirty || System.currentTimeMillis() - statusMessage.second >= DateFormatUtil.MINUTE) {
myTimeStart = text.length() + 1;
text += " (" + StringUtil.decapitalize(DateFormatUtil.formatPrettyDateTime(statusMessage.second)) + ")";
@@ -30,17 +30,17 @@ class EventLogTest extends LightPlatformTestCase {
}
public void testHtmlEntities() {
def entry = EventLog.formatForLog(new Notification("xxx", "Title", "Hello&nbsp;world&laquo;&raquo;", NotificationType.ERROR))
def entry = format("Title", "Hello&nbsp;world&laquo;&raquo;")
assert entry.message == 'Title: Hello world<<>>'
}
public void testParseMultilineText() {
def entry = EventLog.formatForLog(new Notification("xxx", "Title", "<html><body> " +
def entry = format("Title", "<html><body> " +
"<font size=\"3\">first line<br>" +
"second line<br>" +
"third<br>" +
"<a href=\"create\">Action</a><br>" +
"</body></html>", NotificationType.ERROR))
"</body></html>")
assert entry.status == 'Title: first line second line third // Action'
assert entry.message == '''Title
\tfirst line
@@ -52,13 +52,13 @@ class EventLogTest extends LightPlatformTestCase {
}
public void testInParagraph() {
def entry = EventLog.formatForLog(new Notification("xxx", "Title", "<p>message</p>", NotificationType.ERROR))
def entry = format("Title", "<p>message</p>")
assert entry.message == 'Title: message'
assert entry.status == 'Title: message'
}
public void testJavaSeparators() {
def entry = EventLog.formatForLog(new Notification("xxx", "Title", "fst\nsnd", NotificationType.ERROR))
def entry = format("Title", "fst\nsnd")
assert entry.message == '''Title
\tfst
\tsnd'''
@@ -71,7 +71,7 @@ class EventLogTest extends LightPlatformTestCase {
}
public void testMalformedLink() throws Exception {
def entry = EventLog.formatForLog(new Notification("xxx", '<a href="a">link<a/>', "content", NotificationType.ERROR))
def entry = format('<a href="a">link<a/>', "content")
assert entry.message == 'link: content (show balloon)'
}
@@ -96,7 +96,7 @@ class EventLogTest extends LightPlatformTestCase {
}
EventLog.LogEntry format(String title, String content) {
EventLog.formatForLog(new Notification("xxx", title, content, NotificationType.ERROR))
EventLog.formatForLog(new Notification("xxx", title, content, NotificationType.ERROR), '\t')
}
public void testManyNewlines() throws Exception {