Przeglądaj źródła

Add back buffer entries based on events.

Any formattable DisplayableEvent received on a frame container's
event bus is now automatically added to the IRC Document.

Current problems:
  1) Every time this happens the old path still executes, so you
     end up with two lines
  2) Every event on a channel's event bus gets passed to the
     server's, so the lines appear there as well.
pull/205/head
Chris Smith 9 lat temu
rodzic
commit
e69d7aee10

+ 7
- 0
src/com/dmdirc/events/DisplayableEvent.java Wyświetl plik

@@ -61,4 +61,11 @@ public interface DisplayableEvent {
61 61
      */
62 62
     <T> Optional<T> getDisplayProperty(DisplayProperty<T> property);
63 63
 
64
+    /**
65
+     * Gets the timestamp at which the event occurred.
66
+     *
67
+     * @return The timestamp the event occurred at.
68
+     */
69
+    long getTimestamp();
70
+
64 71
 }

+ 16
- 0
src/com/dmdirc/ui/core/BackBuffer.java Wyświetl plik

@@ -25,11 +25,17 @@ package com.dmdirc.ui.core;
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.FrameContainer;
27 27
 import com.dmdirc.events.DisplayableEvent;
28
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
28 29
 import com.dmdirc.ui.messages.ColourManagerFactory;
29 30
 import com.dmdirc.ui.messages.EventFormatter;
31
+import com.dmdirc.ui.messages.Formatter;
30 32
 import com.dmdirc.ui.messages.IRCDocument;
31 33
 import com.dmdirc.ui.messages.Styliser;
32 34
 
35
+import java.util.Date;
36
+
37
+import net.engio.mbassy.listener.Handler;
38
+
33 39
 /**
34 40
  * Models the history of a window in the client.
35 41
  */
@@ -39,6 +45,7 @@ public class BackBuffer {
39 45
     private final Styliser styliser;
40 46
     private final DMDircMBassador eventBus;
41 47
     private final EventFormatter formatter;
48
+    private final AggregateConfigProvider configProvider;
42 49
 
43 50
     public BackBuffer(
44 51
             final FrameContainer owner,
@@ -52,6 +59,7 @@ public class BackBuffer {
52 59
         this.document = new IRCDocument(owner.getConfigManager(), styliser, owner.getEventBus());
53 60
         this.eventBus = owner.getEventBus();
54 61
         this.formatter = formatter;
62
+        this.configProvider = owner.getConfigManager();
55 63
     }
56 64
 
57 65
     /**
@@ -73,8 +81,16 @@ public class BackBuffer {
73 81
      *
74 82
      * @param event The event to be displayed.
75 83
      */
84
+    @Handler
76 85
     public void handleDisplayableEvent(final DisplayableEvent event) {
86
+        formatter.format(event)
87
+                .map(l -> new String[]{getTimestamp(event), l})
88
+                .ifPresent(document::addText);
89
+    }
77 90
 
91
+    private String getTimestamp(final DisplayableEvent event) {
92
+        return Formatter.formatMessage(configProvider, "timestamp",
93
+                new Date(event.getTimestamp()));
78 94
     }
79 95
 
80 96
     public IRCDocument getDocument() {

+ 0
- 1
src/com/dmdirc/ui/messages/IRCDocument.java Wyświetl plik

@@ -363,5 +363,4 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
363 363
         }
364 364
         fireRepaintNeeded();
365 365
     }
366
-
367 366
 }

Ładowanie…
Anuluj
Zapisz