Ver código fonte

Allow things to stop events displaying.

pull/517/head
Chris Smith 9 anos atrás
pai
commit
cb33e97d2b

+ 2
- 0
src/com/dmdirc/events/DisplayProperty.java Ver arquivo

@@ -33,5 +33,7 @@ public final class DisplayProperty<T> {
33 33
     public static final DisplayProperty<Colour> FOREGROUND_COLOUR = new DisplayProperty<>();
34 34
     /** The background colour of text relating to the event. */
35 35
     public static final DisplayProperty<Colour> BACKGROUND_COLOUR = new DisplayProperty<>();
36
+    /** Whether to suppress display of the event. */
37
+    public static final DisplayProperty<Void> DO_NOT_DISPLAY = new DisplayProperty<>();
36 38
 
37 39
 }

+ 17
- 4
src/com/dmdirc/ui/messages/BackBuffer.java Ver arquivo

@@ -24,7 +24,9 @@ package com.dmdirc.ui.messages;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.FrameContainer;
27
+import com.dmdirc.events.DisplayProperty;
27 28
 import com.dmdirc.events.DisplayableEvent;
29
+import com.dmdirc.util.EventUtils;
28 30
 
29 31
 import net.engio.mbassy.listener.Handler;
30 32
 
@@ -72,19 +74,30 @@ public class BackBuffer {
72 74
      *
73 75
      * @param event The event to be displayed.
74 76
      */
75
-    @Handler
76
-    public void handleDisplayableEvent(final DisplayableEvent event) {
77
-        if (event.getSource().equals(owner)) {
77
+    @Handler(priority = EventUtils.PRIORITY_DISPLAYABLE_EVENT_HANDLER)
78
+    private void handleDisplayableEvent(final DisplayableEvent event) {
79
+        if (shouldDisplay(event)) {
78 80
             formatter.format(event).map(s -> s.split("\n")).ifPresent(
79 81
                     t -> {
80 82
                         for (String line : t) {
81 83
                             document.addText(event.getTimestamp(), event
82
-                                            .getDisplayProperties(), line);
84
+                                    .getDisplayProperties(), line);
83 85
                         }
84 86
                     });
85 87
         }
86 88
     }
87 89
 
90
+    /**
91
+     * Determines if the specified event should be displayed in this backbuffer.
92
+     *
93
+     * @param event The event to check
94
+     * @return True if the event should be displayed, false otherwise.
95
+     */
96
+    private boolean shouldDisplay(final DisplayableEvent event) {
97
+        return event.getSource().equals(owner)
98
+                && !event.getDisplayProperty(DisplayProperty.DO_NOT_DISPLAY).isPresent();
99
+    }
100
+
88 101
     public IRCDocument getDocument() {
89 102
         return document;
90 103
     }

Carregando…
Cancelar
Salvar