Browse Source

Add a CommandErrorEvent and format.

pull/408/head
Chris Smith 9 years ago
parent
commit
451a7f3b60

+ 6
- 1
res/com/dmdirc/ui/messages/format.yml View File

@@ -106,6 +106,12 @@ QueryMessageEvent:
106 106
 QuerySelfMessageEvent:
107 107
   format: "<{{user.nickname}}> {{message}}"
108 108
 
109
+################## Miscellaneous events ############################################################
110
+
111
+CommandErrorEvent:
112
+  format: "{{message}}"
113
+  colour: 7
114
+
109 115
 ################## TODO ############################################################################
110 116
 #  channelUserAway=14-- %1$s%2$s is now away.
111 117
 #  channelUserBack=14-- %1$s%2$s is now back.
@@ -149,7 +155,6 @@ QuerySelfMessageEvent:
149 155
 #  rawIn=<< %1$s
150 156
 #  rawOut=>> %1$s
151 157
 #  commandOutput=%1$s
152
-#  commandError=7%1$s
153 158
 #  actionTooLong=Warning: action too long to be sent
154 159
 #  tabCompletion=14Multiple possibilities: %1$s
155 160
 #  serverError=4ERROR: %1$s

+ 3
- 1
src/com/dmdirc/GlobalWindow.java View File

@@ -25,6 +25,7 @@ package com.dmdirc;
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26 26
 import com.dmdirc.commandparser.CommandType;
27 27
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
28
+import com.dmdirc.events.CommandErrorEvent;
28 29
 import com.dmdirc.interfaces.Connection;
29 30
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
30 31
 import com.dmdirc.interfaces.config.ConfigChangeListener;
@@ -71,7 +72,8 @@ public class GlobalWindow extends FrameContainer {
71 72
 
72 73
     @Override
73 74
     public void sendLine(final String line) {
74
-        addLine("commandError", "You may only enter commands in the global window.");
75
+        getEventBus().publishAsync(
76
+                new CommandErrorEvent(this, "You may only enter commands in the global window."));
75 77
     }
76 78
 
77 79
     @Override

+ 5
- 3
src/com/dmdirc/commandparser/parsers/GlobalCommandParser.java View File

@@ -30,6 +30,7 @@ import com.dmdirc.commandparser.CommandInfo;
30 30
 import com.dmdirc.commandparser.CommandType;
31 31
 import com.dmdirc.commandparser.commands.Command;
32 32
 import com.dmdirc.commandparser.commands.context.CommandContext;
33
+import com.dmdirc.events.CommandErrorEvent;
33 34
 import com.dmdirc.events.UserErrorEvent;
34 35
 import com.dmdirc.interfaces.CommandController;
35 36
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
@@ -106,10 +107,11 @@ public class GlobalCommandParser extends CommandParser {
106 107
     protected void handleNonCommand(final FrameContainer origin, final String line) {
107 108
         if (origin == null) {
108 109
             eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM,
109
-                    new IllegalArgumentException("Invalid Global Command: " +  line),
110
-                    "Invalid Global Command: " +  line, ""));
110
+                    new IllegalArgumentException("Invalid Global Command: " + line),
111
+                    "Invalid Global Command: " + line, ""));
111 112
         } else {
112
-            origin.addLine("commandError", "Invalid global command: " + line);
113
+            origin.getEventBus().publishAsync(
114
+                    new CommandErrorEvent(origin, "Invalid global command: " + line));
113 115
         }
114 116
     }
115 117
 

+ 81
- 0
src/com/dmdirc/events/BaseDisplayableEvent.java View File

@@ -0,0 +1,81 @@
1
+/*
2
+ * Copyright (c) 2006-2015 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
+import com.dmdirc.FrameContainer;
26
+
27
+import java.util.Optional;
28
+import java.util.concurrent.atomic.AtomicReference;
29
+
30
+/**
31
+ * Base class for miscallenous displayable events.
32
+ */
33
+public abstract class BaseDisplayableEvent extends DMDircEvent implements DisplayableEvent {
34
+
35
+    /** The display format to use for this event. */
36
+    private final AtomicReference<String> displayFormatRef = new AtomicReference<>("");
37
+    /** The properties associated with this event. */
38
+    private final DisplayPropertyMap properties = new DisplayPropertyMap();
39
+    /** The frame container that caused this event. */
40
+    private final FrameContainer source;
41
+
42
+    public BaseDisplayableEvent(final long timestamp, final FrameContainer source) {
43
+        super(timestamp);
44
+        this.source = source;
45
+    }
46
+
47
+    public BaseDisplayableEvent(final FrameContainer source) {
48
+        this.source = source;
49
+    }
50
+
51
+    @Override
52
+    public String getDisplayFormat() {
53
+        return displayFormatRef.get();
54
+    }
55
+
56
+    @Override
57
+    public void setDisplayFormat(final String format) {
58
+        displayFormatRef.set(format);
59
+    }
60
+
61
+    @Override
62
+    public <T> void setDisplayProperty(final DisplayProperty<T> property, final T value) {
63
+        properties.put(property, value);
64
+    }
65
+
66
+    @Override
67
+    public <T> Optional<T> getDisplayProperty(final DisplayProperty<T> property) {
68
+        return properties.get(property);
69
+    }
70
+
71
+    @Override
72
+    public DisplayPropertyMap getDisplayProperties() {
73
+        return properties;
74
+    }
75
+
76
+    @Override
77
+    public FrameContainer getSource() {
78
+        return source;
79
+    }
80
+
81
+}

+ 43
- 0
src/com/dmdirc/events/CommandErrorEvent.java View File

@@ -0,0 +1,43 @@
1
+/*
2
+ * Copyright (c) 2006-2015 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
+import com.dmdirc.FrameContainer;
26
+
27
+/**
28
+ * Event raised when a command encounters an error and needs to provide feedback to the user.
29
+ */
30
+public class CommandErrorEvent extends BaseDisplayableEvent {
31
+
32
+    private final String message;
33
+
34
+    public CommandErrorEvent(final FrameContainer source, final String message) {
35
+        super(source);
36
+        this.message = message;
37
+    }
38
+
39
+    public String getMessage() {
40
+        return message;
41
+    }
42
+
43
+}

Loading…
Cancel
Save