|
@@ -22,8 +22,12 @@
|
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
|
28
|
|
|
29
|
+import com.dmdirc.interfaces.Displayable;
|
|
30
|
+import com.dmdirc.util.colours.ColourUtils;
|
27
|
31
|
import java.util.Optional;
|
28
|
32
|
|
29
|
33
|
import javax.inject.Inject;
|
|
@@ -111,13 +115,20 @@ public class EventFormatter {
|
111
|
115
|
private String getReplacement(final Object dataSource, final String tag) {
|
112
|
116
|
final String[] functionParts = tag.split("\\|");
|
113
|
117
|
final String[] dataParts = functionParts[0].split("\\.");
|
|
118
|
+ final DisplayPropertyMap displayProperties = new DisplayPropertyMap();
|
114
|
119
|
|
115
|
120
|
Object target = dataSource;
|
116
|
121
|
for (String part : dataParts) {
|
117
|
|
- final Optional<Object> result =
|
118
|
|
- propertyManager.getProperty(target, target.getClass(), part);
|
|
122
|
+ final Optional<Object> result = propertyManager.getProperty(target, target.getClass(), part);
|
119
|
123
|
if (result.isPresent()) {
|
120
|
124
|
target = result.get();
|
|
125
|
+
|
|
126
|
+ // Collate all the display properties for objects as we traverse. More specific ones will
|
|
127
|
+ // override earlier ones.
|
|
128
|
+ if (target instanceof Displayable) {
|
|
129
|
+ displayProperties.putAll(((Displayable) target).getDisplayProperties());
|
|
130
|
+ }
|
|
131
|
+
|
121
|
132
|
} else {
|
122
|
133
|
return ERROR_STRING;
|
123
|
134
|
}
|
|
@@ -128,7 +139,25 @@ public class EventFormatter {
|
128
|
139
|
value = propertyManager.applyFunction(value, functionParts[i]);
|
129
|
140
|
}
|
130
|
141
|
|
131
|
|
- return value;
|
|
142
|
+ return applyDisplayProperties(displayProperties, value);
|
|
143
|
+ }
|
|
144
|
+
|
|
145
|
+ // TODO: It should be possible for plugins etc to add new ways of applying properties.
|
|
146
|
+ private String applyDisplayProperties(final DisplayPropertyMap displayProperties, final String value) {
|
|
147
|
+ final StringBuilder res = new StringBuilder(value);
|
|
148
|
+
|
|
149
|
+ displayProperties.get(DisplayProperty.LINK_USER).ifPresent(user -> res
|
|
150
|
+ .insert(0, StyleApplier.CODE_NICKNAME)
|
|
151
|
+ .insert(0, user.getNickname())
|
|
152
|
+ .insert(0, StyleApplier.CODE_NICKNAME)
|
|
153
|
+ .append(StyleApplier.CODE_NICKNAME));
|
|
154
|
+
|
|
155
|
+ displayProperties.get(DisplayProperty.FOREGROUND_COLOUR).ifPresent(colour -> res
|
|
156
|
+ .insert(0, ColourUtils.getHex(colour))
|
|
157
|
+ .insert(0, IRCControlCodes.COLOUR_HEX)
|
|
158
|
+ .append(IRCControlCodes.COLOUR_HEX));
|
|
159
|
+
|
|
160
|
+ return res.toString();
|
132
|
161
|
}
|
133
|
162
|
|
134
|
163
|
}
|