Explorar el Código

Switch some more output to events.

pull/463/head
Chris Smith hace 9 años
padre
commit
ce25b15a62

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

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

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

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

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

25
 import com.dmdirc.commandparser.CommandType;
25
 import com.dmdirc.commandparser.CommandType;
26
 import com.dmdirc.commandparser.parsers.QueryCommandParser;
26
 import com.dmdirc.commandparser.parsers.QueryCommandParser;
27
 import com.dmdirc.events.AppErrorEvent;
27
 import com.dmdirc.events.AppErrorEvent;
28
+import com.dmdirc.events.CommandErrorEvent;
28
 import com.dmdirc.events.QueryActionEvent;
29
 import com.dmdirc.events.QueryActionEvent;
29
 import com.dmdirc.events.QueryClosedEvent;
30
 import com.dmdirc.events.QueryClosedEvent;
30
 import com.dmdirc.events.QueryMessageEvent;
31
 import com.dmdirc.events.QueryMessageEvent;
154
             getEventBus().publishAsync(
155
             getEventBus().publishAsync(
155
                     new QuerySelfActionEvent(this, connection.getLocalUser().get(), action));
156
                     new QuerySelfActionEvent(this, connection.getLocalUser().get(), action));
156
         } else {
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 fichero

34
 import com.dmdirc.commandparser.commands.flags.CommandFlag;
34
 import com.dmdirc.commandparser.commands.flags.CommandFlag;
35
 import com.dmdirc.commandparser.commands.flags.CommandFlagHandler;
35
 import com.dmdirc.commandparser.commands.flags.CommandFlagHandler;
36
 import com.dmdirc.commandparser.commands.flags.CommandFlagResult;
36
 import com.dmdirc.commandparser.commands.flags.CommandFlagResult;
37
+import com.dmdirc.events.CommandOutputEvent;
37
 import com.dmdirc.interfaces.CommandController;
38
 import com.dmdirc.interfaces.CommandController;
38
 import com.dmdirc.interfaces.Connection;
39
 import com.dmdirc.interfaces.Connection;
39
 import com.dmdirc.ui.WindowManager;
40
 import com.dmdirc.ui.WindowManager;
119
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
120
                 sendLine(origin, args.isSilent(), FORMAT_ERROR,
120
                         "Unable to find target window");
121
                         "Unable to find target window");
121
             } else if (!args.isSilent()) {
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 fichero

31
 import com.dmdirc.commandparser.commands.IntelligentCommand;
31
 import com.dmdirc.commandparser.commands.IntelligentCommand;
32
 import com.dmdirc.commandparser.commands.context.CommandContext;
32
 import com.dmdirc.commandparser.commands.context.CommandContext;
33
 import com.dmdirc.config.profiles.ProfileManager;
33
 import com.dmdirc.config.profiles.ProfileManager;
34
+import com.dmdirc.events.CommandErrorEvent;
34
 import com.dmdirc.interfaces.CommandController;
35
 import com.dmdirc.interfaces.CommandController;
35
 import com.dmdirc.interfaces.Connection;
36
 import com.dmdirc.interfaces.Connection;
36
 import com.dmdirc.interfaces.ConnectionFactory;
37
 import com.dmdirc.interfaces.ConnectionFactory;
94
                     profileManager.getDefault());
95
                     profileManager.getDefault());
95
             server.connect();
96
             server.connect();
96
         } catch (InvalidURIException ex) {
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 fichero

30
 import com.dmdirc.commandparser.commands.Command;
30
 import com.dmdirc.commandparser.commands.Command;
31
 import com.dmdirc.commandparser.commands.context.CommandContext;
31
 import com.dmdirc.commandparser.commands.context.CommandContext;
32
 import com.dmdirc.commandparser.commands.context.ServerCommandContext;
32
 import com.dmdirc.commandparser.commands.context.ServerCommandContext;
33
+import com.dmdirc.events.CommandErrorEvent;
33
 import com.dmdirc.interfaces.CommandController;
34
 import com.dmdirc.interfaces.CommandController;
34
 import com.dmdirc.interfaces.Connection;
35
 import com.dmdirc.interfaces.Connection;
35
 import com.dmdirc.util.InvalidURIException;
36
 import com.dmdirc.util.InvalidURIException;
78
             final URI address = uriParser.parseFromText(args.getArgumentsAsString());
79
             final URI address = uriParser.parseFromText(args.getArgumentsAsString());
79
             connection.connect(address, connection.getProfile());
80
             connection.connect(address, connection.getProfile());
80
         } catch (InvalidURIException ex) {
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 fichero

33
 import com.dmdirc.commandparser.commands.ExternalCommand;
33
 import com.dmdirc.commandparser.commands.ExternalCommand;
34
 import com.dmdirc.commandparser.commands.PreviousCommand;
34
 import com.dmdirc.commandparser.commands.PreviousCommand;
35
 import com.dmdirc.commandparser.commands.context.CommandContext;
35
 import com.dmdirc.commandparser.commands.context.CommandContext;
36
+import com.dmdirc.events.CommandErrorEvent;
36
 import com.dmdirc.events.UnknownCommandEvent;
37
 import com.dmdirc.events.UnknownCommandEvent;
37
 import com.dmdirc.interfaces.CommandController;
38
 import com.dmdirc.interfaces.CommandController;
38
 import com.dmdirc.interfaces.Connection;
39
 import com.dmdirc.interfaces.Connection;
199
         if (someValid) {
200
         if (someValid) {
200
             for (String channelName : parts) {
201
             for (String channelName : parts) {
201
                 if (!server.getGroupChatManager().isValidChannelName(channelName)) {
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
                     continue;
205
                     continue;
204
                 }
206
                 }
205
 
207
 

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

31
 import com.dmdirc.commandparser.commands.Command;
31
 import com.dmdirc.commandparser.commands.Command;
32
 import com.dmdirc.commandparser.commands.context.CommandContext;
32
 import com.dmdirc.commandparser.commands.context.CommandContext;
33
 import com.dmdirc.commandparser.commands.context.ServerCommandContext;
33
 import com.dmdirc.commandparser.commands.context.ServerCommandContext;
34
+import com.dmdirc.events.CommandErrorEvent;
34
 import com.dmdirc.interfaces.CommandController;
35
 import com.dmdirc.interfaces.CommandController;
35
 import com.dmdirc.interfaces.Connection;
36
 import com.dmdirc.interfaces.Connection;
36
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
37
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
100
                     && server.getState() != ServerState.CONNECTING)
101
                     && server.getState() != ServerState.CONNECTING)
101
                     || !server.getParser().isPresent())) {
102
                     || !server.getParser().isPresent())) {
102
                 if (!args.isSilent()) {
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
             } else {
107
             } else {
106
                 command.execute(origin, args, context);
108
                 command.execute(origin, args, context);

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

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
+}

Loading…
Cancelar
Guardar