display unread important notifications in bold, highlight them on gutter and stripe bar

This commit is contained in:
peter
2011-06-16 19:32:54 +02:00
parent 75a47caeb9
commit c7f3caf2a9
4 changed files with 82 additions and 7 deletions
@@ -682,7 +682,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
}
protected EditorEx createRealEditor() {
final EditorEx editor = ConsoleViewUtil.setupConsoleEditor(myProject, true);
final EditorEx editor = ConsoleViewUtil.setupConsoleEditor(myProject, true, false);
editor.getDocument().addDocumentListener(new DocumentListener() {
public void beforeDocumentChange(DocumentEvent event) {
@@ -33,13 +33,13 @@ import java.awt.*;
* @author peter
*/
public class ConsoleViewUtil {
public static EditorEx setupConsoleEditor(Project project, final boolean foldingOutlineShown) {
public static EditorEx setupConsoleEditor(Project project, final boolean foldingOutlineShown, final boolean lineMarkerAreaShown) {
EditorEx editor = (EditorEx) EditorFactory
.getInstance().createViewer(((EditorFactoryImpl)EditorFactory.getInstance()).createDocument(true), project);
editor.setSoftWrapAppliancePlace(SoftWrapAppliancePlaces.CONSOLE);
final EditorSettings editorSettings = editor.getSettings();
editorSettings.setLineMarkerAreaShown(false);
editorSettings.setLineMarkerAreaShown(lineMarkerAreaShown);
editorSettings.setIndentGuidesShown(false);
editorSettings.setLineNumbersShown(false);
editorSettings.setFoldingOutlineShown(foldingOutlineShown);
@@ -28,12 +28,13 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.editor.event.EditorMouseEvent;
import com.intellij.openapi.editor.markup.HighlighterLayer;
import com.intellij.openapi.editor.markup.HighlighterTargetArea;
import com.intellij.openapi.editor.ex.EditorMarkupModel;
import com.intellij.openapi.editor.markup.*;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.Balloon;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.Pair;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.EditorPopupHandler;
@@ -54,7 +55,7 @@ class EventLogConsole {
EventLogConsole(@NotNull Project project, LogModel model) {
myProjectModel = model;
myLogEditor = ConsoleViewUtil.setupConsoleEditor(project, false);
myLogEditor = ConsoleViewUtil.setupConsoleEditor(project, false, true);
Disposer.register(project, new Disposable() {
@Override
public void dispose() {
@@ -62,6 +63,9 @@ class EventLogConsole {
}
});
((EditorMarkupModel) myLogEditor.getMarkupModel()).setErrorStripeVisible(true);
myLogEditor.addEditorMouseListener(new EditorPopupHandler() {
public void invokePopup(final EditorMouseEvent event) {
final ActionManager actionManager = ActionManager.getInstance();
@@ -120,7 +124,8 @@ class EventLogConsole {
: ConsoleViewContentType.WARNING_OUTPUT;
int msgStart = document.getTextLength();
append(document, pair.first);
String message = pair.first;
append(document, message);
myLogEditor.getMarkupModel()
.addRangeHighlighter(msgStart, document.getTextLength(), HighlighterLayer.CARET_ROW + 1, contentType.getAttributes(),
HighlighterTargetArea.EXACT_RANGE);
@@ -158,6 +163,66 @@ class EventLogConsole {
myLogEditor.getCaretModel().moveToOffset(document.getTextLength());
myLogEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
}
if (notification.isImportant()) {
highlightNotification(notification, message, document.getLineCount() - 2);
}
}
private void highlightNotification(final Notification notification,
String message, final int line) {
TextAttributes attr = new TextAttributes(null, null, null, null, Font.BOLD);
final RangeHighlighter lineHighlighter = myLogEditor.getMarkupModel().addLineHighlighter(line, HighlighterLayer.CARET_ROW + 1, attr);
Color color = notification.getType() == NotificationType.ERROR
? Color.red
: notification.getType() == NotificationType.WARNING ? Color.yellow : Color.green;
lineHighlighter.setErrorStripeMarkColor(color);
lineHighlighter.setErrorStripeTooltip(message);
lineHighlighter.setGutterIconRenderer(new GutterIconRenderer() {
@NotNull
@Override
public Icon getIcon() {
return IconLoader.getIcon("/general/reset.png");
}
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
@Override
public boolean equals(Object obj) {
return this == obj;
}
@Override
public int hashCode() {
return 0;
}
@Override
public String getTooltipText() {
return "Mark as read";
}
@Override
public boolean isNavigateAction() {
return true;
}
@Override
public AnAction getClickAction() {
return new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
myProjectModel.removeNotification(notification);
}
};
}
});
myProjectModel.removeHandlers.put(notification, new Runnable() {
@Override
public void run() {
myLogEditor.getMarkupModel().removeHighlighter(lineHighlighter);
}
});
}
public Editor getConsoleEditor() {
@@ -21,11 +21,13 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashMap;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* @author peter
@@ -34,6 +36,7 @@ public class LogModel {
private final List<Notification> myNotifications = new ArrayList<Notification>();
private Notification myStatusMessage;
private final Project myProject;
final Map<Notification, Runnable> removeHandlers = new THashMap<Notification, Runnable>();
LogModel(@Nullable Project project) {
myProject = project;
@@ -88,6 +91,12 @@ public class LogModel {
synchronized (myNotifications) {
myNotifications.remove(notification);
}
Runnable handler = removeHandlers.remove(notification);
if (handler != null) {
handler.run();
}
if (notification == getStatusMessage() && notification.isImportant()) {
ArrayList<Notification> notifications = getNotifications();
Collections.reverse(notifications);
@@ -99,4 +108,5 @@ public class LogModel {
}));
}
}
}