Просмотр исходного кода

Add display property to suppress timestamps.

Formats defined in YAML can specify 'timestamps: false' to hide
the default timestamp for lines associated with that event.

Closes #633
pull/635/head
Chris Smith 8 лет назад
Родитель
Сommit
dc0f607943

+ 2
- 0
src/com/dmdirc/events/DisplayProperty.java Просмотреть файл

@@ -36,6 +36,8 @@ public interface DisplayProperty<T> {
36 36
     DisplayProperty<Colour> BACKGROUND_COLOUR = new DisplayPropertyImpl<>();
37 37
     /** Whether to suppress display of the event. */
38 38
     DisplayProperty<Boolean> DO_NOT_DISPLAY = new DisplayPropertyImpl<>();
39
+    /** Whether to suppress timestamps for the event. */
40
+    DisplayProperty<Boolean> NO_TIMESTAMPS = new DisplayPropertyImpl<>();
39 41
 
40 42
     final class DisplayPropertyImpl<T> implements DisplayProperty<T> {}
41 43
 

+ 19
- 0
src/com/dmdirc/events/DisplayPropertyMap.java Просмотреть файл

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.events;
24 24
 
25
+import java.util.Collections;
25 26
 import java.util.Map;
26 27
 import java.util.Optional;
27 28
 import java.util.concurrent.ConcurrentHashMap;
@@ -58,6 +59,15 @@ public class DisplayPropertyMap {
58 59
         properties.put(property, value);
59 60
     }
60 61
 
62
+    /**
63
+     * Adds all properties from the other map to this one.
64
+     *
65
+     * @param other The map to add properties from.
66
+     */
67
+    public void putAll(final DisplayPropertyMap other) {
68
+        properties.putAll(other.getProperties());
69
+    }
70
+
61 71
     /**
62 72
      * Removes a value for the specified property.
63 73
      *
@@ -68,6 +78,15 @@ public class DisplayPropertyMap {
68 78
         properties.remove(property);
69 79
     }
70 80
 
81
+    /**
82
+     * Returns a readonly copy of this map's properties
83
+     *
84
+     * @return This map's properties.
85
+     */
86
+    Map<DisplayProperty<?>, Object> getProperties() {
87
+        return Collections.unmodifiableMap(properties);
88
+    }
89
+
71 90
     private static class ReadOnlyDisplayPropertyMap extends DisplayPropertyMap {
72 91
         @Override
73 92
         public <T> void put(final DisplayProperty<T> property, final T value) {

+ 5
- 6
src/com/dmdirc/ui/messages/EventFormat.java Просмотреть файл

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.ui.messages;
24 24
 
25
-import com.dmdirc.util.colours.Colour;
25
+import com.dmdirc.events.DisplayPropertyMap;
26 26
 
27 27
 import com.google.auto.value.AutoValue;
28 28
 
@@ -42,18 +42,17 @@ public abstract class EventFormat {
42 42
     public abstract Optional<String> getAfterTemplate();
43 43
     /** The property that should be iterated over, if the event contains multiple lines. */
44 44
     public abstract Optional<String> getIterateProperty();
45
-
46
-    // TODO: This should probably be a generic set of properties.
47
-    public abstract Optional<Colour> getDefaultForegroundColour();
45
+    /** Display properties to use. */
46
+    public abstract DisplayPropertyMap getDisplayProperties();
48 47
 
49 48
     public static EventFormat create(
50 49
             final String template,
51 50
             final Optional<String> beforeTemplate,
52 51
             final Optional<String> afterTemplate,
53 52
             final Optional<String> iterateProperty,
54
-            final Optional<Colour> defaultForegroundColour) {
53
+            final DisplayPropertyMap displayProperties) {
55 54
         return new AutoValue_EventFormat(template, beforeTemplate, afterTemplate, iterateProperty,
56
-                defaultForegroundColour);
55
+                displayProperties);
57 56
     }
58 57
 
59 58
 }

+ 2
- 7
src/com/dmdirc/ui/messages/EventFormatter.java Просмотреть файл

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.ui.messages;
24 24
 
25
-import com.dmdirc.events.DisplayProperty;
26 25
 import com.dmdirc.events.DisplayableEvent;
27 26
 
28 27
 import java.util.Optional;
@@ -59,12 +58,8 @@ public class EventFormatter {
59 58
 
60 59
     public Optional<String> format(final DisplayableEvent event) {
61 60
         final Optional<EventFormat> format = formatProvider.getFormat(event.getClass());
62
-
63
-        if (!event.hasDisplayProperty(DisplayProperty.FOREGROUND_COLOUR)) {
64
-            format.flatMap(EventFormat::getDefaultForegroundColour)
65
-                    .ifPresent(c -> event.setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, c));
66
-        }
67
-
61
+        format.map(EventFormat::getDisplayProperties)
62
+                .ifPresent(event.getDisplayProperties()::putAll);
68 63
         return format.map(f -> format(f, event));
69 64
     }
70 65
 

+ 5
- 1
src/com/dmdirc/ui/messages/Line.java Просмотреть файл

@@ -66,7 +66,11 @@ public class Line {
66 66
      * @return Lines parts
67 67
      */
68 68
     public String[] getLineParts() {
69
-        return new String[] { timestamp, text };
69
+        if (displayProperties.get(DisplayProperty.NO_TIMESTAMPS).orElse(false)) {
70
+            return new String[] { text };
71
+        } else {
72
+            return new String[] { timestamp, text };
73
+        }
70 74
     }
71 75
 
72 76
     /**

+ 18
- 6
src/com/dmdirc/ui/messages/YamlEventFormatProvider.java Просмотреть файл

@@ -22,8 +22,9 @@
22 22
 
23 23
 package com.dmdirc.ui.messages;
24 24
 
25
+import com.dmdirc.events.DisplayProperty;
26
+import com.dmdirc.events.DisplayPropertyMap;
25 27
 import com.dmdirc.events.DisplayableEvent;
26
-import com.dmdirc.util.colours.Colour;
27 28
 
28 29
 import java.io.IOException;
29 30
 import java.io.InputStream;
@@ -102,12 +103,23 @@ public class YamlEventFormatProvider implements EventFormatProvider {
102 103
         final Optional<String> iterateProperty = info.containsKey("iterate")
103 104
                 ? Optional.of(info.get("iterate").toString())
104 105
                 : Optional.empty();
105
-        final Optional<Colour> foregroundColour = info.containsKey("colour")
106
-                ? Optional.of(colourManager.getColourFromIrcCode(
107
-                        Integer.parseInt(info.get("colour").toString())))
108
-                : Optional.empty();
109 106
         return EventFormat.create(
110
-                template, beforeTemplate, afterTemplate, iterateProperty, foregroundColour);
107
+                template, beforeTemplate, afterTemplate, iterateProperty,
108
+                getDisplayProperties(info));
109
+    }
110
+
111
+    private DisplayPropertyMap getDisplayProperties(final Map<Object, Object> info) {
112
+        final DisplayPropertyMap map = new DisplayPropertyMap();
113
+        if (info.containsKey("colour")) {
114
+            map.put(DisplayProperty.FOREGROUND_COLOUR,
115
+                    colourManager.getColourFromIrcCode(
116
+                            Integer.parseInt(info.get("colour").toString())));
117
+        }
118
+        if (info.containsKey("timestamp")) {
119
+            map.put(DisplayProperty.NO_TIMESTAMPS,
120
+                    !info.get("timestamp").toString().toLowerCase().matches("y|yes|true|1|on"));
121
+        }
122
+        return map;
111 123
     }
112 124
 
113 125
     @Override

+ 5
- 4
test/com/dmdirc/ui/messages/EventFormatterTest.java Просмотреть файл

@@ -24,6 +24,7 @@ package com.dmdirc.ui.messages;
24 24
 
25 25
 import com.dmdirc.Channel;
26 26
 import com.dmdirc.events.ChannelMessageEvent;
27
+import com.dmdirc.events.DisplayPropertyMap;
27 28
 
28 29
 import java.util.Optional;
29 30
 
@@ -61,7 +62,7 @@ public class EventFormatterTest {
61 62
                                 Optional.empty(),
62 63
                                 Optional.empty(),
63 64
                                 Optional.empty(),
64
-                                Optional.empty())));
65
+                                new DisplayPropertyMap())));
65 66
         when(propertyManager.getProperty(messageEvent, ChannelMessageEvent.class, "channel"))
66 67
                 .thenReturn(Optional.of("MONKEY"));
67 68
 
@@ -79,7 +80,7 @@ public class EventFormatterTest {
79 80
                                 Optional.of("Before!"),
80 81
                                 Optional.of("After!"),
81 82
                                 Optional.empty(),
82
-                                Optional.empty())));
83
+                                new DisplayPropertyMap())));
83 84
         when(propertyManager.getProperty(messageEvent, ChannelMessageEvent.class, "channel"))
84 85
                 .thenReturn(Optional.of("MONKEY"));
85 86
 
@@ -99,7 +100,7 @@ public class EventFormatterTest {
99 100
                                 Optional.empty(),
100 101
                                 Optional.empty(),
101 102
                                 Optional.empty(),
102
-                                Optional.empty())));
103
+                                new DisplayPropertyMap())));
103 104
         when(propertyManager.getProperty(messageEvent, ChannelMessageEvent.class, "channel"))
104 105
                 .thenReturn(Optional.of("MONKEY"));
105 106
         when(propertyManager.applyFunction("MONKEY", "lowercase")).thenReturn("monkey");
@@ -118,7 +119,7 @@ public class EventFormatterTest {
118 119
                                 Optional.empty(),
119 120
                                 Optional.empty(),
120 121
                                 Optional.empty(),
121
-                                Optional.empty())));
122
+                                new DisplayPropertyMap())));
122 123
         when(propertyManager.getProperty(messageEvent, ChannelMessageEvent.class, "message"))
123 124
                 .thenReturn(Optional.of("{{channel}}"));
124 125
 

Загрузка…
Отмена
Сохранить