|
@@ -22,16 +22,21 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.ui.messages;
|
24
|
24
|
|
|
25
|
+import com.dmdirc.config.ConfigBinding;
|
25
|
26
|
import com.dmdirc.events.BaseChannelTextEvent;
|
26
|
27
|
import com.dmdirc.events.BaseQueryTextEvent;
|
27
|
28
|
import com.dmdirc.events.ChannelHighlightEvent;
|
28
|
29
|
import com.dmdirc.events.DisplayProperty;
|
|
30
|
+import com.dmdirc.events.DisplayableEvent;
|
29
|
31
|
import com.dmdirc.events.QueryHighlightEvent;
|
30
|
32
|
import com.dmdirc.events.ServerConnectedEvent;
|
31
|
33
|
import com.dmdirc.events.ServerNickchangeEvent;
|
32
|
34
|
import com.dmdirc.interfaces.User;
|
|
35
|
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
33
|
36
|
import com.dmdirc.util.colours.Colour;
|
34
|
37
|
|
|
38
|
+import com.google.common.base.Strings;
|
|
39
|
+
|
35
|
40
|
import java.util.ArrayList;
|
36
|
41
|
import java.util.Collection;
|
37
|
42
|
import java.util.Optional;
|
|
@@ -48,35 +53,80 @@ public class HighlightManager {
|
48
|
53
|
"(\\p{Space}|\\p{Punct}|$).*";
|
49
|
54
|
|
50
|
55
|
private final Collection<Pattern> patterns = new ArrayList<>();
|
|
56
|
+ private final AggregateConfigProvider configProvider;
|
|
57
|
+ private final ColourManager colourManager;
|
51
|
58
|
|
52
|
59
|
private Optional<Pattern> nicknamePattern = Optional.empty();
|
53
|
60
|
|
|
61
|
+ private Optional<Colour> backgroundColour = Optional.of(Colour.RED);
|
|
62
|
+ private Optional<Colour> foregroundColour = Optional.empty();
|
|
63
|
+
|
|
64
|
+ public HighlightManager(
|
|
65
|
+ final AggregateConfigProvider configProvider,
|
|
66
|
+ final ColourManager colourManager) {
|
|
67
|
+ this.configProvider = configProvider;
|
|
68
|
+ this.colourManager = colourManager;
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+ public void init() {
|
|
72
|
+ configProvider.getBinder().bind(this, HighlightManager.class);
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ public void stop() {
|
|
76
|
+ configProvider.getBinder().unbind(this);
|
|
77
|
+ }
|
|
78
|
+
|
54
|
79
|
@Handler
|
55
|
|
- public void handleChannelMessage(final BaseChannelTextEvent event) {
|
|
80
|
+ void handleChannelMessage(final BaseChannelTextEvent event) {
|
56
|
81
|
if (patterns.stream().anyMatch(p -> p.matcher(event.getMessage()).matches())) {
|
57
|
|
- event.setDisplayProperty(DisplayProperty.BACKGROUND_COLOUR, Colour.RED);
|
|
82
|
+ setColours(event);
|
58
|
83
|
event.getChannel().getEventBus().publishAsync(new ChannelHighlightEvent(event));
|
59
|
84
|
}
|
60
|
85
|
}
|
61
|
86
|
|
62
|
87
|
@Handler
|
63
|
|
- public void handleQueryMessage(final BaseQueryTextEvent event) {
|
|
88
|
+ void handleQueryMessage(final BaseQueryTextEvent event) {
|
64
|
89
|
if (patterns.stream().anyMatch(p -> p.matcher(event.getMessage()).matches())) {
|
65
|
|
- event.setDisplayProperty(DisplayProperty.BACKGROUND_COLOUR, Colour.RED);
|
|
90
|
+ setColours(event);
|
66
|
91
|
event.getQuery().getEventBus().publishAsync(new QueryHighlightEvent(event));
|
67
|
92
|
}
|
68
|
93
|
}
|
69
|
94
|
|
70
|
95
|
@Handler
|
71
|
|
- public void handleNickChange(final ServerNickchangeEvent event) {
|
|
96
|
+ void handleNickChange(final ServerNickchangeEvent event) {
|
72
|
97
|
setNickname(event.getNewNick());
|
73
|
98
|
}
|
74
|
99
|
|
75
|
100
|
@Handler
|
76
|
|
- public void handleConnected(final ServerConnectedEvent event) {
|
|
101
|
+ void handleConnected(final ServerConnectedEvent event) {
|
77
|
102
|
event.getConnection().getLocalUser().map(User::getNickname).ifPresent(this::setNickname);
|
78
|
103
|
}
|
79
|
104
|
|
|
105
|
+ @ConfigBinding(domain = "ui", key = "highlightLineForegroundColour")
|
|
106
|
+ void handleForegroundColour(final String value) {
|
|
107
|
+ if (Strings.isNullOrEmpty(value)) {
|
|
108
|
+ foregroundColour = Optional.empty();
|
|
109
|
+ } else {
|
|
110
|
+ foregroundColour = Optional.ofNullable(colourManager.getColourFromString(value, null));
|
|
111
|
+ }
|
|
112
|
+ }
|
|
113
|
+
|
|
114
|
+ @ConfigBinding(domain = "ui", key = "highlightLineBackgroundColour")
|
|
115
|
+ void handleBackgroundColour(final String value) {
|
|
116
|
+ if (Strings.isNullOrEmpty(value)) {
|
|
117
|
+ backgroundColour = Optional.empty();
|
|
118
|
+ } else {
|
|
119
|
+ backgroundColour = Optional.ofNullable(colourManager.getColourFromString(value, null));
|
|
120
|
+ }
|
|
121
|
+ }
|
|
122
|
+
|
|
123
|
+ private void setColours(final DisplayableEvent event) {
|
|
124
|
+ backgroundColour.ifPresent(
|
|
125
|
+ c -> event.setDisplayProperty(DisplayProperty.BACKGROUND_COLOUR, c));
|
|
126
|
+ foregroundColour.ifPresent(
|
|
127
|
+ c -> event.setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, c));
|
|
128
|
+ }
|
|
129
|
+
|
80
|
130
|
private void setNickname(final String newNick) {
|
81
|
131
|
nicknamePattern.ifPresent(patterns::remove);
|
82
|
132
|
nicknamePattern = Optional.of(compile(newNick));
|