Browse Source

Use events for some more plugin outputs.

This slightly changes how the logging plugin history window
works - instead of parsing dates and using DMDirc timestamps,
it just shows the logged timestamp like the backbuffer does.

As history tends to span several days this seems more useful.

Issue DMDirc/DMDirc#426
pull/450/head
Chris Smith 8 years ago
parent
commit
a685d38706

+ 2
- 9
logging/src/com/dmdirc/addons/logging/HistoryWindow.java View File

@@ -34,10 +34,7 @@ import com.google.common.annotations.VisibleForTesting;
34 34
 
35 35
 import java.io.IOException;
36 36
 import java.nio.file.Path;
37
-import java.text.ParsePosition;
38
-import java.text.SimpleDateFormat;
39 37
 import java.util.Collections;
40
-import java.util.Date;
41 38
 import java.util.List;
42 39
 import java.util.Optional;
43 40
 
@@ -84,12 +81,8 @@ public class HistoryWindow extends FrameContainer {
84 81
         try (final ReverseFileReader reader = new ReverseFileReader(logFile)) {
85 82
             final List<String> lines = reader.getLines(Math.min(limit, numLines));
86 83
             Collections.reverse(lines);
87
-            lines.forEach(l -> {
88
-                final ParsePosition pos = new ParsePosition(0);
89
-                final Date date = new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]").parse(l, pos);
90
-                final String text = l.substring(pos.getIndex()+1);
91
-                addLine(text, date);
92
-            });
84
+            lines.forEach(l ->
85
+                    getEventBus().publishAsync(new HistoricalLineRestoredEvent(this, l)));
93 86
         } catch (IOException | SecurityException ex) {
94 87
             LOG.warn(USER_ERROR, "Unable to read log file.", ex);
95 88
         }

+ 4
- 3
parserdebug/src/com/dmdirc/addons/parserdebug/DebugWindow.java View File

@@ -24,13 +24,13 @@ package com.dmdirc.addons.parserdebug;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.FrameContainer;
27
+import com.dmdirc.events.CommandOutputEvent;
27 28
 import com.dmdirc.interfaces.Connection;
28 29
 import com.dmdirc.parser.interfaces.Parser;
29 30
 import com.dmdirc.ui.core.components.WindowComponent;
30 31
 import com.dmdirc.ui.messages.BackBufferFactory;
31 32
 
32 33
 import java.util.Arrays;
33
-import java.util.Date;
34 34
 import java.util.Optional;
35 35
 
36 36
 /**
@@ -74,8 +74,9 @@ public class DebugWindow extends FrameContainer {
74 74
      * Set the parser to null to stop us holding onto parsers when the server connection is closed.
75 75
      */
76 76
     public void unsetParser() {
77
-        addLine("======================", new Date());
78
-        addLine("Unset parser: " + parser, new Date());
77
+        getEventBus().publishAsync(new CommandOutputEvent(this,
78
+                "======================\n" +
79
+                "Unset parser: " + parser));
79 80
         parser = null;
80 81
     }
81 82
 

+ 11
- 8
parserdebug/src/com/dmdirc/addons/parserdebug/ParserDebugManager.java View File

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.addons.parserdebug;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26
+import com.dmdirc.events.CommandOutputEvent;
26 27
 import com.dmdirc.events.ServerDisconnectedEvent;
27 28
 import com.dmdirc.interfaces.Connection;
28 29
 import com.dmdirc.parser.events.DebugInfoEvent;
@@ -30,7 +31,6 @@ import com.dmdirc.parser.interfaces.Parser;
30 31
 import com.dmdirc.ui.WindowManager;
31 32
 import com.dmdirc.ui.messages.BackBufferFactory;
32 33
 
33
-import java.util.Date;
34 34
 import java.util.HashMap;
35 35
 import java.util.Map;
36 36
 
@@ -96,9 +96,10 @@ public class ParserDebugManager {
96 96
                 connection, eventBus, backBufferFactory);
97 97
         windowManager.addWindow(connection.getWindowModel(), window);
98 98
         registeredParsers.put(parser, window);
99
-        window.addLine("======================", new Date());
100
-        window.addLine("Started Monitoring: " + parser, new Date());
101
-        window.addLine("======================", new Date());
99
+        window.getEventBus().publishAsync(new CommandOutputEvent(window,
100
+                "======================\n" +
101
+                "Started Monitoring: " + parser + '\n' +
102
+                "======================"));
102 103
     }
103 104
 
104 105
     /**
@@ -110,9 +111,10 @@ public class ParserDebugManager {
110 111
     public void removeParser(final Parser parser, final boolean close) {
111 112
         parser.getCallbackManager().unsubscribe(this);
112 113
         final DebugWindow window = registeredParsers.get(parser);
113
-        window.addLine("======================", new Date());
114
-        window.addLine("No Longer Monitoring: " + parser + " (User Requested)", new Date());
115
-        window.addLine("======================", new Date());
114
+        window.getEventBus().publishAsync(new CommandOutputEvent(window,
115
+                "======================\n" +
116
+                "No Longer Monitoring: " + parser + " (User Requested)\n" +
117
+                "======================"));
116 118
         if (close) {
117 119
             window.close();
118 120
         }
@@ -142,7 +144,8 @@ public class ParserDebugManager {
142 144
     public void onDebugInfo(final DebugInfoEvent event) {
143 145
         final DebugWindow window = registeredParsers.get(event.getParser());
144 146
         if (window != null) {
145
-            window.addLine(String.format("[%d] %s%n", event.getLevel(), event.getData()), new Date());
147
+            window.getEventBus().publishAsync(new CommandOutputEvent(window,
148
+                    String.format("[%d] %s%n", event.getLevel(), event.getData())));
146 149
         }
147 150
     }
148 151
 

Loading…
Cancel
Save