Sfoglia il codice sorgente

Merge pull request #446 from csmith/master

Make logging plugin use new events.
pull/447/head
Greg Holmes 8 anni fa
parent
commit
2d7886b161

+ 4
- 0
logging/res/META-INF/format.yml Vedi File

@@ -0,0 +1,4 @@
1
+---
2
+HistoricalLineRestoredEvent:
3
+  format: "{{line}}"
4
+  timestamp: no

+ 50
- 0
logging/src/com/dmdirc/addons/logging/HistoricalLineRestoredEvent.java Vedi File

@@ -0,0 +1,50 @@
1
+/*
2
+ * Copyright (c) 2006-2015 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.logging;
24
+
25
+import com.dmdirc.events.BaseDisplayableEvent;
26
+import com.dmdirc.interfaces.WindowModel;
27
+
28
+/**
29
+ * Event raised when a line from the log is restored into a window.
30
+ */
31
+public class HistoricalLineRestoredEvent extends BaseDisplayableEvent {
32
+
33
+    private final String line;
34
+
35
+    public HistoricalLineRestoredEvent(final long timestamp, final WindowModel source,
36
+            final String line) {
37
+        super(timestamp, source);
38
+        this.line = line;
39
+    }
40
+
41
+    public HistoricalLineRestoredEvent(final WindowModel source, final String line) {
42
+        super(source);
43
+        this.line = line;
44
+    }
45
+
46
+    public String getLine() {
47
+        return line;
48
+    }
49
+
50
+}

+ 11
- 10
logging/src/com/dmdirc/addons/logging/LoggingManager.java Vedi File

@@ -205,12 +205,12 @@ public class LoggingManager implements ConfigChangeListener {
205 205
 
206 206
         synchronized (openFiles) {
207 207
             final Collection<String> old = new ArrayList<>(openFiles.size());
208
-            for (Map.Entry<String, OpenFile> entry : openFiles.entrySet()) {
209
-                if (entry.getValue().lastUsedTime < oldestTime) {
210
-                    StreamUtils.close(entry.getValue().writer);
211
-                    old.add(entry.getKey());
212
-                }
213
-            }
208
+            openFiles.entrySet().stream()
209
+                    .filter(entry -> entry.getValue().lastUsedTime < oldestTime)
210
+                    .forEach(entry -> {
211
+                        StreamUtils.close(entry.getValue().writer);
212
+                        old.add(entry.getKey());
213
+                    });
214 214
 
215 215
             openFiles.keySet().removeAll(old);
216 216
         }
@@ -410,18 +410,19 @@ public class LoggingManager implements ConfigChangeListener {
410 410
 
411 411
         final Path testFile = Paths.get(filename);
412 412
         if (Files.exists(testFile)) {
413
-            try {
414
-                final ReverseFileReader file = new ReverseFileReader(testFile);
413
+            try (final ReverseFileReader file = new ReverseFileReader(testFile)) {
415 414
                 // Because the file includes a newline char at the end, an empty line
416 415
                 // is returned by getLines. To counter this, we call getLines(1) and do
417 416
                 // nothing with the output.
418 417
                 file.getLines(1);
419 418
                 final Stack<String> lines = file.getLines(backbufferLines);
420 419
                 while (!lines.empty()) {
421
-                    frame.addLine(getColouredString(colour, lines.pop()));
420
+                    frame.getEventBus().publishAsync(new HistoricalLineRestoredEvent(frame,
421
+                            getColouredString(colour, lines.pop())));
422 422
                 }
423 423
                 file.close();
424
-                frame.addLine(getColouredString(colour, "--- End of backbuffer\n"));
424
+                frame.getEventBus().publishAsync(new HistoricalLineRestoredEvent(frame,
425
+                        getColouredString(colour, "--- End of backbuffer\n")));
425 426
             } catch (IOException | SecurityException e) {
426 427
                 LOG.info(USER_ERROR, "Unable to show backbuffer (Filename: {}): {}", filename,
427 428
                         e.getMessage(), e);

Loading…
Annulla
Salva