Ver código fonte

Switch some more output to events.

pull/463/head
Chris Smith 9 anos atrás
pai
commit
ce25b15a62

+ 2
- 0
res/com/dmdirc/ui/messages/format.yml Ver arquivo

@@ -111,6 +111,8 @@ QuerySelfMessageEvent:
111 111
 CommandErrorEvent:
112 112
   format: "{{message}}"
113 113
   colour: 7
114
+CommandOutputEvent:
115
+  format: "{{message}}"
114 116
 
115 117
 ################## TODO ############################################################################
116 118
 #  channelUserAway=14-- %1$s%2$s is now away.

+ 3
- 1
src/com/dmdirc/Channel.java Ver arquivo

@@ -29,6 +29,7 @@ import com.dmdirc.events.ChannelClosedEvent;
29 29
 import com.dmdirc.events.ChannelSelfActionEvent;
30 30
 import com.dmdirc.events.ChannelSelfJoinEvent;
31 31
 import com.dmdirc.events.ChannelSelfMessageEvent;
32
+import com.dmdirc.events.CommandErrorEvent;
32 33
 import com.dmdirc.events.DisplayProperty;
33 34
 import com.dmdirc.events.NickListClientAddedEvent;
34 35
 import com.dmdirc.events.NickListClientRemovedEvent;
@@ -195,7 +196,8 @@ public class Channel extends FrameContainer implements GroupChat {
195 196
 
196 197
         if (connection.getParser().get().getMaxLength("PRIVMSG", getChannelInfo().getName())
197 198
                 <= action.length()) {
198
-            addLine("actionTooLong", action.length());
199
+            getEventBus().publishAsync(new CommandErrorEvent(this,
200
+                    "Warning: action too long to be sent"));
199 201
         } else {
200 202
             final GroupChatUser me = getUser(connection.getLocalUser().get()).get();
201 203
             getEventBus().publishAsync(new ChannelSelfActionEvent(this, me, action));

+ 3
- 1
src/com/dmdirc/Query.java Ver arquivo

@@ -25,6 +25,7 @@ package com.dmdirc;
25 25
 import com.dmdirc.commandparser.CommandType;
26 26
 import com.dmdirc.commandparser.parsers.QueryCommandParser;
27 27
 import com.dmdirc.events.AppErrorEvent;
28
+import com.dmdirc.events.CommandErrorEvent;
28 29
 import com.dmdirc.events.QueryActionEvent;
29 30
 import com.dmdirc.events.QueryClosedEvent;
30 31
 import com.dmdirc.events.QueryMessageEvent;
@@ -154,7 +155,8 @@ public class Query extends FrameContainer implements PrivateActionListener,
154 155
             getEventBus().publishAsync(
155 156
                     new QuerySelfActionEvent(this, connection.getLocalUser().get(), action));
156 157
         } else {
157
-            addLine("actionTooLong", action.length());
158
+            getEventBus().publishAsync(
159
+                    new CommandErrorEvent(this, "Warning: action too long to be sent"));
158 160
         }
159 161
     }
160 162
 

+ 6
- 3
src/com/dmdirc/commandparser/commands/global/Echo.java Ver arquivo

@@ -34,6 +34,7 @@ import com.dmdirc.commandparser.commands.context.CommandContext;
34 34
 import com.dmdirc.commandparser.commands.flags.CommandFlag;
35 35
 import com.dmdirc.commandparser.commands.flags.CommandFlagHandler;
36 36
 import com.dmdirc.commandparser.commands.flags.CommandFlagResult;
37
+import com.dmdirc.events.CommandOutputEvent;
37 38
 import com.dmdirc.interfaces.CommandController;
38 39
 import com.dmdirc.interfaces.Connection;
39 40
 import com.dmdirc.ui.WindowManager;
@@ -119,10 +120,12 @@ public class Echo extends Command implements IntelligentCommand {
119 120
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
120 121
                         "Unable to find target window");
121 122
             } else if (!args.isSilent()) {
122
-                frame.addLine(FORMAT_OUTPUT, time, results.getArgumentsAsString());
123
+                frame.getEventBus().publishAsync(new CommandOutputEvent(frame, time.getTime(),
124
+                        results.getArgumentsAsString()));
123 125
             }
124
-        } else if (origin != null && !args.isSilent()) {
125
-            origin.addLine(FORMAT_OUTPUT, time, results.getArgumentsAsString());
126
+        } else if (!args.isSilent()) {
127
+            origin.getEventBus().publishAsync(new CommandOutputEvent(origin, time.getTime(),
128
+                    results.getArgumentsAsString()));
126 129
         }
127 130
     }
128 131
 

+ 4
- 2
src/com/dmdirc/commandparser/commands/global/NewServer.java Ver arquivo

@@ -31,6 +31,7 @@ import com.dmdirc.commandparser.commands.Command;
31 31
 import com.dmdirc.commandparser.commands.IntelligentCommand;
32 32
 import com.dmdirc.commandparser.commands.context.CommandContext;
33 33
 import com.dmdirc.config.profiles.ProfileManager;
34
+import com.dmdirc.events.CommandErrorEvent;
34 35
 import com.dmdirc.interfaces.CommandController;
35 36
 import com.dmdirc.interfaces.Connection;
36 37
 import com.dmdirc.interfaces.ConnectionFactory;
@@ -94,8 +95,9 @@ public class NewServer extends Command implements IntelligentCommand {
94 95
                     profileManager.getDefault());
95 96
             server.connect();
96 97
         } catch (InvalidURIException ex) {
97
-            origin.addLine(FORMAT_ERROR, "Invalid URI: " + ex.getMessage()
98
-                    + (ex.getCause() == null ? "" : ": " + ex.getCause().getMessage()));
98
+            origin.getEventBus().publishAsync(new CommandErrorEvent(origin,
99
+                    "Invalid URI: " + ex.getMessage() +
100
+                            (ex.getCause() == null ? "" : ": " + ex.getCause().getMessage())));
99 101
         }
100 102
     }
101 103
 

+ 4
- 2
src/com/dmdirc/commandparser/commands/server/ChangeServer.java Ver arquivo

@@ -30,6 +30,7 @@ import com.dmdirc.commandparser.CommandType;
30 30
 import com.dmdirc.commandparser.commands.Command;
31 31
 import com.dmdirc.commandparser.commands.context.CommandContext;
32 32
 import com.dmdirc.commandparser.commands.context.ServerCommandContext;
33
+import com.dmdirc.events.CommandErrorEvent;
33 34
 import com.dmdirc.interfaces.CommandController;
34 35
 import com.dmdirc.interfaces.Connection;
35 36
 import com.dmdirc.util.InvalidURIException;
@@ -78,8 +79,9 @@ public class ChangeServer extends Command {
78 79
             final URI address = uriParser.parseFromText(args.getArgumentsAsString());
79 80
             connection.connect(address, connection.getProfile());
80 81
         } catch (InvalidURIException ex) {
81
-            origin.addLine(FORMAT_ERROR, "Invalid URI: " + ex.getMessage()
82
-                    + (ex.getCause() == null ? "" : ": " + ex.getCause().getMessage()));
82
+            origin.getEventBus().publishAsync(
83
+                    new CommandErrorEvent(origin, "Invalid URI: " + ex.getMessage() +
84
+                            (ex.getCause() == null ? "" : ": " + ex.getCause().getMessage())));
83 85
         }
84 86
     }
85 87
 

+ 3
- 1
src/com/dmdirc/commandparser/parsers/CommandParser.java Ver arquivo

@@ -33,6 +33,7 @@ import com.dmdirc.commandparser.commands.CommandOptions;
33 33
 import com.dmdirc.commandparser.commands.ExternalCommand;
34 34
 import com.dmdirc.commandparser.commands.PreviousCommand;
35 35
 import com.dmdirc.commandparser.commands.context.CommandContext;
36
+import com.dmdirc.events.CommandErrorEvent;
36 37
 import com.dmdirc.events.UnknownCommandEvent;
37 38
 import com.dmdirc.interfaces.CommandController;
38 39
 import com.dmdirc.interfaces.Connection;
@@ -199,7 +200,8 @@ public abstract class CommandParser implements Serializable {
199 200
         if (someValid) {
200 201
             for (String channelName : parts) {
201 202
                 if (!server.getGroupChatManager().isValidChannelName(channelName)) {
202
-                    origin.addLine("commandError", "Invalid channel name: " + channelName);
203
+                    origin.getEventBus().publishAsync(new CommandErrorEvent(origin,
204
+                            "Invalid channel name: " + channelName));
203 205
                     continue;
204 206
                 }
205 207
 

+ 3
- 1
src/com/dmdirc/commandparser/parsers/ServerCommandParser.java Ver arquivo

@@ -31,6 +31,7 @@ import com.dmdirc.commandparser.CommandType;
31 31
 import com.dmdirc.commandparser.commands.Command;
32 32
 import com.dmdirc.commandparser.commands.context.CommandContext;
33 33
 import com.dmdirc.commandparser.commands.context.ServerCommandContext;
34
+import com.dmdirc.events.CommandErrorEvent;
34 35
 import com.dmdirc.interfaces.CommandController;
35 36
 import com.dmdirc.interfaces.Connection;
36 37
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
@@ -100,7 +101,8 @@ public class ServerCommandParser extends GlobalCommandParser {
100 101
                     && server.getState() != ServerState.CONNECTING)
101 102
                     || !server.getParser().isPresent())) {
102 103
                 if (!args.isSilent()) {
103
-                    origin.addLine("commandError", "You must be connected to use this command");
104
+                    origin.getEventBus().publishAsync(new CommandErrorEvent(origin,
105
+                            "You must be connected to use this command"));
104 106
                 }
105 107
             } else {
106 108
                 command.execute(origin, args, context);

+ 49
- 0
src/com/dmdirc/events/CommandOutputEvent.java Ver arquivo

@@ -0,0 +1,49 @@
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 outputs some generic text to the user.
29
+ */
30
+public class CommandOutputEvent extends BaseDisplayableEvent {
31
+
32
+    private final String message;
33
+
34
+    public CommandOutputEvent(final FrameContainer source, final long timestamp,
35
+            final String message) {
36
+        super(timestamp, source);
37
+        this.message = message;
38
+    }
39
+
40
+    public CommandOutputEvent(final FrameContainer source, final String message) {
41
+        super(source);
42
+        this.message = message;
43
+    }
44
+
45
+    public String getMessage() {
46
+        return message;
47
+    }
48
+
49
+}

Carregando…
Cancelar
Salvar