Ver código fonte

Make HighlightManager raise events.

When a highlight is found, fire a {Channel,Query}HighlightEvent
pointing to the original event that caused the highlight.
pull/277/head
Chris Smith 9 anos atrás
pai
commit
1b56af02ee

+ 41
- 0
src/com/dmdirc/events/ChannelHighlightEvent.java Ver arquivo

@@ -0,0 +1,41 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.events;
24
+
25
+/**
26
+ * Event raised when a highlight is detected in a channel.
27
+ */
28
+public class ChannelHighlightEvent extends ChannelEvent {
29
+
30
+    private final ChannelEvent cause;
31
+
32
+    public ChannelHighlightEvent(final ChannelEvent cause) {
33
+        super(cause.getTimestamp(), cause.getChannel());
34
+        this.cause = cause;
35
+    }
36
+
37
+    public ChannelEvent getCause() {
38
+        return cause;
39
+    }
40
+
41
+}

+ 41
- 0
src/com/dmdirc/events/QueryHighlightEvent.java Ver arquivo

@@ -0,0 +1,41 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.events;
24
+
25
+/**
26
+ * Event raised when a highlight is detected in a query.
27
+ */
28
+public class QueryHighlightEvent extends QueryEvent {
29
+
30
+    private final QueryEvent cause;
31
+
32
+    public QueryHighlightEvent(final QueryEvent cause) {
33
+        super(cause.getTimestamp(), cause.getQuery());
34
+        this.cause = cause;
35
+    }
36
+
37
+    public QueryEvent getCause() {
38
+        return cause;
39
+    }
40
+
41
+}

+ 5
- 0
src/com/dmdirc/ui/messages/HighlightManager.java Ver arquivo

@@ -24,7 +24,9 @@ package com.dmdirc.ui.messages;
24 24
 
25 25
 import com.dmdirc.events.BaseChannelTextEvent;
26 26
 import com.dmdirc.events.BaseQueryTextEvent;
27
+import com.dmdirc.events.ChannelHighlightEvent;
27 28
 import com.dmdirc.events.DisplayProperty;
29
+import com.dmdirc.events.QueryHighlightEvent;
28 30
 import com.dmdirc.events.ServerConnectedEvent;
29 31
 import com.dmdirc.events.ServerNickchangeEvent;
30 32
 import com.dmdirc.parser.interfaces.LocalClientInfo;
@@ -47,12 +49,14 @@ public class HighlightManager {
47 49
             "(\\p{Space}|\\p{Punct}|$).*";
48 50
 
49 51
     private final Collection<Pattern> patterns = new ArrayList<>();
52
+
50 53
     private Optional<Pattern> nicknamePattern = Optional.empty();
51 54
 
52 55
     @Handler
53 56
     public void handleChannelMessage(final BaseChannelTextEvent event) {
54 57
         if (patterns.stream().anyMatch(p -> p.matcher(event.getMessage()).matches())) {
55 58
             event.setDisplayProperty(DisplayProperty.BACKGROUND_COLOUR, Colour.RED);
59
+            event.getChannel().getEventBus().publishAsync(new ChannelHighlightEvent(event));
56 60
         }
57 61
     }
58 62
 
@@ -60,6 +64,7 @@ public class HighlightManager {
60 64
     public void handleQueryMessage(final BaseQueryTextEvent event) {
61 65
         if (patterns.stream().anyMatch(p -> p.matcher(event.getMessage()).matches())) {
62 66
             event.setDisplayProperty(DisplayProperty.BACKGROUND_COLOUR, Colour.RED);
67
+            event.getQuery().getEventBus().publishAsync(new QueryHighlightEvent(event));
63 68
         }
64 69
     }
65 70
 

Carregando…
Cancelar
Salvar