Explorar el Código

Change all command output/error to use events.

pull/442/head
Chris Smith hace 8 años
padre
commit
c6376f4cc2

+ 2
- 2
audio/src/com/dmdirc/addons/audio/AudioCommand.java Ver fichero

64
             if (AudioPlayer.isValid(file)) {
64
             if (AudioPlayer.isValid(file)) {
65
                 new AudioPlayer(file).play();
65
                 new AudioPlayer(file).play();
66
             } else {
66
             } else {
67
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "Invalid file type");
67
+                showError(origin, args.isSilent(), "Invalid file type");
68
             }
68
             }
69
         } else {
69
         } else {
70
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "File does not exist");
70
+            showError(origin, args.isSilent(), "File does not exist");
71
         }
71
         }
72
     }
72
     }
73
 
73
 

+ 4
- 8
calc/src/com/dmdirc/addons/calc/CalcCommand.java Ver fichero

64
             int offset = 0;
64
             int offset = 0;
65
             boolean showexpr = false;
65
             boolean showexpr = false;
66
 
66
 
67
-            if (args.getArguments().length > 0 && args.getArguments()[0]
68
-                    .equals("--showexpr")) {
67
+            if (args.getArguments().length > 0 && "--showexpr".equals(args.getArguments()[0])) {
69
                 showexpr = true;
68
                 showexpr = true;
70
                 offset++;
69
                 offset++;
71
             }
70
             }
75
             final Parser parser = new Parser(lexer);
74
             final Parser parser = new Parser(lexer);
76
             final Evaluator evaluator = new Evaluator(parser.parse());
75
             final Evaluator evaluator = new Evaluator(parser.parse());
77
             final Number result = evaluator.evaluate();
76
             final Number result = evaluator.evaluate();
78
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
79
-                    (showexpr ? input + " = " : "") + result);
77
+            showOutput(origin, args.isSilent(), (showexpr ? input + " = " : "") + result);
80
         } catch (ParseException ex) {
78
         } catch (ParseException ex) {
81
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
82
-                    "Unable to parse expression: " + ex.getMessage());
79
+            showError(origin, args.isSilent(), "Unable to parse expression: " + ex.getMessage());
83
         } catch (ArithmeticException ex) {
80
         } catch (ArithmeticException ex) {
84
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
85
-                    "Unable to calculate expression: " + ex.getMessage());
81
+            showError(origin, args.isSilent(), "Unable to calculate expression: " + ex.getMessage());
86
         }
82
         }
87
     }
83
     }
88
 
84
 

+ 73
- 79
conditional_execute/src/com/dmdirc/addons/conditional_execute/ConditionalExecuteCommand.java Ver fichero

72
             final String arg = arguments[i].toLowerCase();
72
             final String arg = arguments[i].toLowerCase();
73
             final String nextArg = i + 1 < arguments.length ? arguments[i + 1] : "";
73
             final String nextArg = i + 1 < arguments.length ? arguments[i + 1] : "";
74
 
74
 
75
-            if (arg.equalsIgnoreCase("--help")) {
76
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Usage:");
77
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
78
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, cmdname + " <args>");
79
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, cmdname
75
+            if ("--help".equalsIgnoreCase(arg)) {
76
+                showOutput(origin, args.isSilent(), "Usage:");
77
+                showOutput(origin, args.isSilent(), "");
78
+                showOutput(origin, args.isSilent(), cmdname + " <args>");
79
+                showOutput(origin, args.isSilent(), cmdname
80
                         + " --namespace <name> <namespace commands>");
80
                         + " --namespace <name> <namespace commands>");
81
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, cmdname
81
+                showOutput(origin, args.isSilent(), cmdname
82
                         + " --namespace <name> [--inverse] </commandToRun <command args>>");
82
                         + " --namespace <name> [--inverse] </commandToRun <command args>>");
83
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
84
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
83
+                showOutput(origin, args.isSilent(), "");
84
+                showOutput(origin, args.isSilent(),
85
                         "Commands can only be specified if no other non-namespace args are given.");
85
                         "Commands can only be specified if no other non-namespace args are given.");
86
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
87
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
86
+                showOutput(origin, args.isSilent(), "");
87
+                showOutput(origin, args.isSilent(),
88
                         "When trying to run a command, the namespace will be checked to see if the command can be run.");
88
                         "When trying to run a command, the namespace will be checked to see if the command can be run.");
89
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
89
+                showOutput(origin, args.isSilent(),
90
                         "The checks performed are as follows:");
90
                         "The checks performed are as follows:");
91
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
91
+                showOutput(origin, args.isSilent(),
92
                         "   1) Does the namespace exist? if not, run the command and create the namespace.");
92
                         "   1) Does the namespace exist? if not, run the command and create the namespace.");
93
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
93
+                showOutput(origin, args.isSilent(),
94
                         "   2) Is the namespace inhibited? - Do not run the command.");
94
                         "   2) Is the namespace inhibited? - Do not run the command.");
95
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
95
+                showOutput(origin, args.isSilent(),
96
                         "   3) Is the namespace in forced mode? - Run the command.");
96
                         "   3) Is the namespace in forced mode? - Run the command.");
97
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
97
+                showOutput(origin, args.isSilent(),
98
                         "   4) If --inverse is specified, are we under the limit time? Run the command");
98
                         "   4) If --inverse is specified, are we under the limit time? Run the command");
99
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
99
+                showOutput(origin, args.isSilent(),
100
                         "   5) If --inverse is not specified, are we over the limit time? Run the command");
100
                         "   5) If --inverse is not specified, are we over the limit time? Run the command");
101
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "   6) Do not run the command.");
102
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
103
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "General Arguments.");
104
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
101
+                showOutput(origin, args.isSilent(), "   6) Do not run the command.");
102
+                showOutput(origin, args.isSilent(), "");
103
+                showOutput(origin, args.isSilent(), "General Arguments.");
104
+                showOutput(origin, args.isSilent(),
105
                         "  --list                   - List all current namespaces and their status");
105
                         "  --list                   - List all current namespaces and their status");
106
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
106
+                showOutput(origin, args.isSilent(),
107
                         "  --help                   - Print this help.");
107
                         "  --help                   - Print this help.");
108
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
108
+                showOutput(origin, args.isSilent(),
109
                         "  --reset                  - Remove all namespaces.");
109
                         "  --reset                  - Remove all namespaces.");
110
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
111
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Useful things:");
112
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
110
+                showOutput(origin, args.isSilent(), "");
111
+                showOutput(origin, args.isSilent(), "Useful things:");
112
+                showOutput(origin, args.isSilent(),
113
                         "  --namespace <name>       - Namespace to modify. If the namespace does not exist, it will be created. Namespaces are not remembered across sessions.");
113
                         "  --namespace <name>       - Namespace to modify. If the namespace does not exist, it will be created. Namespaces are not remembered across sessions.");
114
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
115
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Arguments related to a namespace:");
116
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
114
+                showOutput(origin, args.isSilent(), "");
115
+                showOutput(origin, args.isSilent(), "Arguments related to a namespace:");
116
+                showOutput(origin, args.isSilent(),
117
                         "  --settime <time>         - Set the limit time on this namespace. Time can be either a time in seconds, 'now' for now, or 'nowifless' to set to now only if it is currently less.");
117
                         "  --settime <time>         - Set the limit time on this namespace. Time can be either a time in seconds, 'now' for now, or 'nowifless' to set to now only if it is currently less.");
118
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
118
+                showOutput(origin, args.isSilent(),
119
                         "  --delay <seconds>        - Increase the 'limit' time on this namespace by <seconds> seconds");
119
                         "  --delay <seconds>        - Increase the 'limit' time on this namespace by <seconds> seconds");
120
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
120
+                showOutput(origin, args.isSilent(),
121
                         "  --inhibit                - Prevent any attempts at running commands in this namespace from executing");
121
                         "  --inhibit                - Prevent any attempts at running commands in this namespace from executing");
122
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
122
+                showOutput(origin, args.isSilent(),
123
                         "  --force                  - Any future attempts at running commands in this namespace will always execute");
123
                         "  --force                  - Any future attempts at running commands in this namespace will always execute");
124
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
124
+                showOutput(origin, args.isSilent(),
125
                         "  --allow                  - Disable '--force' or '--inhibit' and resume normal operation.");
125
                         "  --allow                  - Disable '--force' or '--inhibit' and resume normal operation.");
126
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
126
+                showOutput(origin, args.isSilent(),
127
                         "  --remove                 - Remove this namespace.");
127
                         "  --remove                 - Remove this namespace.");
128
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
128
+                showOutput(origin, args.isSilent(),
129
                         "  --status                 - Show the status of this namespace.");
129
                         "  --status                 - Show the status of this namespace.");
130
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
131
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Arguments when running a command:");
132
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
130
+                showOutput(origin, args.isSilent(), "");
131
+                showOutput(origin, args.isSilent(), "Arguments when running a command:");
132
+                showOutput(origin, args.isSilent(),
133
                         "  --inverse              - Inverse the match against the 'limit' time.");
133
                         "  --inverse              - Inverse the match against the 'limit' time.");
134
                 return;
134
                 return;
135
-            } else if (arg.equalsIgnoreCase("--list")) {
135
+            } else if ("--list".equalsIgnoreCase(arg)) {
136
                 if (namespaces.isEmpty()) {
136
                 if (namespaces.isEmpty()) {
137
-                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
137
+                    showOutput(origin, args.isSilent(),
138
                             "There are currently no known namespaces.");
138
                             "There are currently no known namespaces.");
139
                 } else {
139
                 } else {
140
-                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Current namespaces: ");
140
+                    showOutput(origin, args.isSilent(), "Current namespaces: ");
141
                     for (final Map.Entry<String, ConditionalExecuteNamespace> e : namespaces.
141
                     for (final Map.Entry<String, ConditionalExecuteNamespace> e : namespaces.
142
                             entrySet()) {
142
                             entrySet()) {
143
-                        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "    " + e.getValue().
144
-                                toString());
143
+                        showOutput(origin, args.isSilent(),"    " + e.getValue());
145
                     }
144
                     }
146
                 }
145
                 }
147
                 return;
146
                 return;
148
-            } else if (arg.equalsIgnoreCase("--reset")) {
147
+            } else if ("--reset".equalsIgnoreCase(arg)) {
149
                 namespaces.clear();
148
                 namespaces.clear();
150
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "All namespaces removed.");
149
+                showOutput(origin, args.isSilent(), "All namespaces removed.");
151
                 return;
150
                 return;
152
             } else if (namespace == null) {
151
             } else if (namespace == null) {
153
-                if (arg.equalsIgnoreCase("--namespace")) {
152
+                if ("--namespace".equalsIgnoreCase(arg)) {
154
                     if (nextArg.isEmpty()) {
153
                     if (nextArg.isEmpty()) {
155
-                        sendLine(origin, args.isSilent(), FORMAT_ERROR,
156
-                                "Error: You must specify a namespace.");
154
+                        showError(origin, args.isSilent(), "Error: You must specify a namespace.");
157
                         return;
155
                         return;
158
                     } else {
156
                     } else {
159
                         if (!namespaces.containsKey(nextArg.toLowerCase())) {
157
                         if (!namespaces.containsKey(nextArg.toLowerCase())) {
166
                         i++;
164
                         i++;
167
                     }
165
                     }
168
                 } else {
166
                 } else {
169
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR,
167
+                    showError(origin, args.isSilent(),
170
                             "Error: You must specify a namespace first.");
168
                             "Error: You must specify a namespace first.");
171
                     return;
169
                     return;
172
                 }
170
                 }
173
-            } else if (arg.equalsIgnoreCase("--inhibit")) {
171
+            } else if ("--inhibit".equalsIgnoreCase(arg)) {
174
                 namespace.inhibit();
172
                 namespace.inhibit();
175
                 manipulated = true;
173
                 manipulated = true;
176
-            } else if (arg.equalsIgnoreCase("--force")) {
174
+            } else if ("--force".equalsIgnoreCase(arg)) {
177
                 namespace.force();
175
                 namespace.force();
178
                 manipulated = true;
176
                 manipulated = true;
179
-            } else if (arg.equalsIgnoreCase("--allow")) {
177
+            } else if ("--allow".equalsIgnoreCase(arg)) {
180
                 namespace.reset();
178
                 namespace.reset();
181
                 manipulated = true;
179
                 manipulated = true;
182
-            } else if (arg.equalsIgnoreCase("--settime")) {
180
+            } else if ("--settime".equalsIgnoreCase(arg)) {
183
                 if (nextArg.isEmpty()) {
181
                 if (nextArg.isEmpty()) {
184
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR,
185
-                            "Error: You must provide a time to use.");
182
+                    showError(origin, args.isSilent(), "Error: You must provide a time to use.");
186
                     return;
183
                     return;
187
-                } else if (nextArg.equalsIgnoreCase("now")) {
184
+                } else if ("now".equalsIgnoreCase(nextArg)) {
188
                     namespace.setLimit(System.currentTimeMillis());
185
                     namespace.setLimit(System.currentTimeMillis());
189
                     i++;
186
                     i++;
190
                     manipulated = true;
187
                     manipulated = true;
191
-                } else if (nextArg.equalsIgnoreCase("nowifless")) {
188
+                } else if ("nowifless".equalsIgnoreCase(nextArg)) {
192
                     if (namespace.getLimitTime() < System.currentTimeMillis()) {
189
                     if (namespace.getLimitTime() < System.currentTimeMillis()) {
193
                         namespace.setLimit(System.currentTimeMillis());
190
                         namespace.setLimit(System.currentTimeMillis());
194
                     }
191
                     }
200
                         i++;
197
                         i++;
201
                         manipulated = true;
198
                         manipulated = true;
202
                     } catch (final NumberFormatException nfe) {
199
                     } catch (final NumberFormatException nfe) {
203
-                        sendLine(origin, args.isSilent(), FORMAT_ERROR, "Error: Invalid time: "
204
-                                + nextArg);
200
+                        showError(origin, args.isSilent(), "Error: Invalid time: " + nextArg);
205
                         return;
201
                         return;
206
                     }
202
                     }
207
                 }
203
                 }
208
-            } else if (arg.equalsIgnoreCase("--delay")) {
204
+            } else if ("--delay".equalsIgnoreCase(arg)) {
209
                 if (nextArg.isEmpty()) {
205
                 if (nextArg.isEmpty()) {
210
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR,
211
-                            "Error: You must provide a delay to use.");
206
+                    showError(origin, args.isSilent(),  "Error: You must provide a delay to use.");
212
                     return;
207
                     return;
213
                 } else {
208
                 } else {
214
                     try {
209
                     try {
216
                         i++;
211
                         i++;
217
                         manipulated = true;
212
                         manipulated = true;
218
                     } catch (final NumberFormatException nfe) {
213
                     } catch (final NumberFormatException nfe) {
219
-                        sendLine(origin, args.isSilent(), FORMAT_ERROR, "Error: Invalid delay: "
220
-                                + nextArg);
214
+                        showError(origin, args.isSilent(), "Error: Invalid delay: " + nextArg);
221
                         return;
215
                         return;
222
                     }
216
                     }
223
                 }
217
                 }
224
-            } else if (arg.equalsIgnoreCase("--remove")) {
218
+            } else if ("--remove".equalsIgnoreCase(arg)) {
225
                 namespaces.remove(namespace.getName());
219
                 namespaces.remove(namespace.getName());
226
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Removed namespace '" + namespace.
227
-                        getName() + "'");
220
+                showOutput(origin, args.isSilent(),
221
+                        "Removed namespace '" + namespace.getName() + '\'');
228
                 return;
222
                 return;
229
-            } else if (arg.equalsIgnoreCase("--status")) {
223
+            } else if ("--status".equalsIgnoreCase(arg)) {
230
                 // Show the current status, in case some manipulations occurred prior to this.
224
                 // Show the current status, in case some manipulations occurred prior to this.
231
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, namespaces.get(namespace.getName()));
225
+                showOutput(origin, args.isSilent(), namespaces.get(namespace.getName()).toString());
232
                 return;
226
                 return;
233
-            } else if (arg.equalsIgnoreCase("--inverse")) {
227
+            } else if ("--inverse".equalsIgnoreCase(arg)) {
234
                 inverse = true;
228
                 inverse = true;
235
             } else if (manipulated) {
229
             } else if (manipulated) {
236
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
230
+                showError(origin, args.isSilent(),
237
                         "You can't run commands and manipulate the namespace at the same time, ignored.");
231
                         "You can't run commands and manipulate the namespace at the same time, ignored.");
238
             } else {
232
             } else {
239
                 // Command to run!
233
                 // Command to run!
246
 
240
 
247
         // If we get here, we either manipulated something, or should show the usage text.
241
         // If we get here, we either manipulated something, or should show the usage text.
248
         if (manipulated) {
242
         if (manipulated) {
249
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Namespace updated.");
250
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, namespace.toString());
243
+            showOutput(origin, args.isSilent(), "Namespace updated.");
244
+            showOutput(origin, args.isSilent(), namespace.toString());
251
             namespaces.put(namespace.getName(), namespace);
245
             namespaces.put(namespace.getName(), namespace);
252
         } else {
246
         } else {
253
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Usage:");
254
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "");
255
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, cmdname + " <args>");
256
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, cmdname
247
+            showError(origin, args.isSilent(), "Usage:");
248
+            showError(origin, args.isSilent(), "");
249
+            showError(origin, args.isSilent(), cmdname + " <args>");
250
+            showError(origin, args.isSilent(), cmdname
257
                     + " --namespace <name> <namespace commands>");
251
                     + " --namespace <name> <namespace commands>");
258
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, cmdname
252
+            showError(origin, args.isSilent(), cmdname
259
                     + " --namespace <name> [--inverse] </commandToRun <command args>>");
253
                     + " --namespace <name> [--inverse] </commandToRun <command args>>");
260
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "");
261
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "For more information, see " + cmdname
254
+            showError(origin, args.isSilent(), "");
255
+            showError(origin, args.isSilent(), "For more information, see " + cmdname
262
                     + " --help");
256
                     + " --help");
263
         }
257
         }
264
     }
258
     }

+ 11
- 3
conditional_execute/test/com/dmdirc/addons/conditional_execute/ConditionalExecuteCommandTest.java Ver fichero

22
 
22
 
23
 package com.dmdirc.addons.conditional_execute;
23
 package com.dmdirc.addons.conditional_execute;
24
 
24
 
25
+import com.dmdirc.DMDircMBassador;
25
 import com.dmdirc.commandparser.CommandArguments;
26
 import com.dmdirc.commandparser.CommandArguments;
26
 import com.dmdirc.commandparser.commands.context.CommandContext;
27
 import com.dmdirc.commandparser.commands.context.CommandContext;
27
 import com.dmdirc.commandparser.parsers.CommandParser;
28
 import com.dmdirc.commandparser.parsers.CommandParser;
29
+import com.dmdirc.events.CommandErrorEvent;
28
 import com.dmdirc.interfaces.CommandController;
30
 import com.dmdirc.interfaces.CommandController;
29
 import com.dmdirc.interfaces.WindowModel;
31
 import com.dmdirc.interfaces.WindowModel;
30
 
32
 
31
 import org.junit.Before;
33
 import org.junit.Before;
32
 import org.junit.Test;
34
 import org.junit.Test;
33
 import org.junit.runner.RunWith;
35
 import org.junit.runner.RunWith;
36
+import org.mockito.ArgumentCaptor;
37
+import org.mockito.Captor;
34
 import org.mockito.Mock;
38
 import org.mockito.Mock;
35
 import org.mockito.runners.MockitoJUnitRunner;
39
 import org.mockito.runners.MockitoJUnitRunner;
36
 
40
 
41
+import static org.junit.Assert.assertTrue;
37
 import static org.mockito.Matchers.anyString;
42
 import static org.mockito.Matchers.anyString;
38
-import static org.mockito.Matchers.contains;
39
 import static org.mockito.Matchers.eq;
43
 import static org.mockito.Matchers.eq;
40
 import static org.mockito.Matchers.same;
44
 import static org.mockito.Matchers.same;
41
 import static org.mockito.Mockito.never;
45
 import static org.mockito.Mockito.never;
49
     @Mock private CommandParser commandParser;
53
     @Mock private CommandParser commandParser;
50
     @Mock private WindowModel container;
54
     @Mock private WindowModel container;
51
     @Mock private CommandContext context;
55
     @Mock private CommandContext context;
56
+    @Mock private DMDircMBassador eventbus;
57
+    @Captor private ArgumentCaptor<CommandErrorEvent> errorEventCaptor;
52
     private ConditionalExecuteCommand command;
58
     private ConditionalExecuteCommand command;
53
 
59
 
54
     @Before
60
     @Before
57
         when(commandController.getSilenceChar()).thenReturn('/');
63
         when(commandController.getSilenceChar()).thenReturn('/');
58
         when(container.getCommandParser()).thenReturn(commandParser);
64
         when(container.getCommandParser()).thenReturn(commandParser);
59
         when(container.isWritable()).thenReturn(true);
65
         when(container.isWritable()).thenReturn(true);
66
+        when(container.getEventBus()).thenReturn(eventbus);
60
 
67
 
61
         command = new ConditionalExecuteCommand(commandController);
68
         command = new ConditionalExecuteCommand(commandController);
62
     }
69
     }
166
         verify(commandParser, never()).parseCommand(same(container), anyString());
173
         verify(commandParser, never()).parseCommand(same(container), anyString());
167
     }
174
     }
168
 
175
 
169
-    private void verifyErrorOutput(final String substring) {
170
-        verify(container).addLine(eq("commandError"), contains(substring));
176
+    private void verifyErrorOutput(final CharSequence substring) {
177
+        verify(eventbus).publishAsync(errorEventCaptor.capture());
178
+        assertTrue(errorEventCaptor.getValue().getMessage().contains(substring));
171
     }
179
     }
172
 
180
 
173
 }
181
 }

+ 2
- 4
dcc/src/com/dmdirc/addons/dcc/DCCCommand.java Ver fichero

138
                 sendFile(target, origin, connection, true,
138
                 sendFile(target, origin, connection, true,
139
                         args.getArgumentsAsString(2));
139
                         args.getArgumentsAsString(2));
140
             } else {
140
             } else {
141
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
142
-                        "Unknown DCC Type: '" + type + "'");
141
+                showError(origin, args.isSilent(), "Unknown DCC Type: '" + type + '\'');
143
             }
142
             }
144
         } else {
143
         } else {
145
             showUsage(origin, true, INFO.getName(), INFO.getHelp());
144
             showUsage(origin, true, INFO.getName(), INFO.getHelp());
229
             eventBus.publish(new DccSendRequestEvent(connection, target, selectedFile.
228
             eventBus.publish(new DccSendRequestEvent(connection, target, selectedFile.
230
                     getAbsolutePath()));
229
                     getAbsolutePath()));
231
 
230
 
232
-            sendLine(origin, isSilent, FORMAT_OUTPUT,
233
-                    "Starting DCC Send with: " + target);
231
+            showOutput(origin, isSilent, "Starting DCC Send with: " + target);
234
 
232
 
235
             send.setFileName(selectedFile.getAbsolutePath());
233
             send.setFileName(selectedFile.getAbsolutePath());
236
             send.setFileSize(selectedFile.length());
234
             send.setFileSize(selectedFile.length());

+ 1
- 1
dcop/src/com/dmdirc/addons/dcop/DcopCommand.java Ver fichero

73
 
73
 
74
         final List<String> res = executor.getDcopResult(arguments[0], arguments[1], arguments[2]);
74
         final List<String> res = executor.getDcopResult(arguments[0], arguments[1], arguments[2]);
75
         for (String line : res) {
75
         for (String line : res) {
76
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, line);
76
+            showOutput(origin, args.isSilent(), line);
77
         }
77
         }
78
     }
78
     }
79
 
79
 

+ 1
- 0
debug/src/com/dmdirc/addons/debug/Debug.java Ver fichero

109
      * @param type     The type of message to send
109
      * @param type     The type of message to send
110
      * @param args     The arguments of the message
110
      * @param args     The arguments of the message
111
      */
111
      */
112
+    @Deprecated
112
     public void proxySendLine(final WindowModel target,
113
     public void proxySendLine(final WindowModel target,
113
             final boolean isSilent, final String type, final Object... args) {
114
             final boolean isSilent, final String type, final Object... args) {
114
         sendLine(target, isSilent, type, args);
115
         sendLine(target, isSilent, type, args);

+ 3
- 3
dns/src/com/dmdirc/addons/dns/DNSCommand.java Ver fichero

71
             return;
71
             return;
72
         }
72
         }
73
 
73
 
74
-        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Resolving: " + args.getArguments()[0]);
74
+        showOutput(origin, args.isSilent(), "Resolving: " + args.getArguments()[0]);
75
         new Timer("DNS Command Timer").schedule(new TimerTask() {
75
         new Timer("DNS Command Timer").schedule(new TimerTask() {
76
 
76
 
77
             @Override
77
             @Override
85
             final String arg) {
85
             final String arg) {
86
         try {
86
         try {
87
             final InetAddress address = InetAddresses.forString(arg);
87
             final InetAddress address = InetAddresses.forString(arg);
88
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolved: "
88
+            showOutput(origin, isSilent, "Resolved: "
89
                     + arg + ": " + address.getCanonicalHostName());
89
                     + arg + ": " + address.getCanonicalHostName());
90
         } catch (IllegalArgumentException ex) {
90
         } catch (IllegalArgumentException ex) {
91
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolved: "
91
+            showOutput(origin, isSilent, "Resolved: "
92
                     + arg + ": " + getIPs(arg));
92
                     + arg + ": " + getIPs(arg));
93
         }
93
         }
94
     }
94
     }

+ 4
- 4
exec/src/com/dmdirc/addons/exec/ExecCommand.java Ver fichero

72
             // This checks the command to execute has correct quotes
72
             // This checks the command to execute has correct quotes
73
             // (if necessary). Without this /exec "command arg1 arg2 would error.
73
             // (if necessary). Without this /exec "command arg1 arg2 would error.
74
             if (commandArray.length == 0) {
74
             if (commandArray.length == 0) {
75
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
75
+                showError(origin, args.isSilent(),
76
                         "Could not execute: Invalid file name provided");
76
                         "Could not execute: Invalid file name provided");
77
             } else if (!new File(commandArray[0]).exists()) {
77
             } else if (!new File(commandArray[0]).exists()) {
78
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
78
+                showError(origin, args.isSilent(),
79
                         "Could not execute: " + commandArray[0] + " does not exist.");
79
                         "Could not execute: " + commandArray[0] + " does not exist.");
80
             } else {
80
             } else {
81
                 final Process p = Runtime.getRuntime().exec(commandArray);
81
                 final Process p = Runtime.getRuntime().exec(commandArray);
88
                     final List<String> errorOutput = CharStreams.readLines(
88
                     final List<String> errorOutput = CharStreams.readLines(
89
                             new InputStreamReader(p.getErrorStream()));
89
                             new InputStreamReader(p.getErrorStream()));
90
                     for (String line : execOutput) {
90
                     for (String line : execOutput) {
91
-                        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, line);
91
+                        showOutput(origin, args.isSilent(), line);
92
                     }
92
                     }
93
                     for (String line : errorOutput) {
93
                     for (String line : errorOutput) {
94
-                        sendLine(origin, args.isSilent(), FORMAT_ERROR, line);
94
+                        showError(origin, args.isSilent(), line);
95
                     }
95
                     }
96
                 }
96
                 }
97
             }
97
             }

+ 7
- 8
logging/src/com/dmdirc/addons/logging/LoggingCommand.java Ver fichero

67
         if (args.getArguments().length > 0) {
67
         if (args.getArguments().length > 0) {
68
             if ("history".equalsIgnoreCase(args.getArguments()[0])) {
68
             if ("history".equalsIgnoreCase(args.getArguments()[0])) {
69
                 if (!manager.showHistory(origin)) {
69
                 if (!manager.showHistory(origin)) {
70
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR,
71
-                            "Unable to open history for this window.");
70
+                    showError(origin, args.isSilent(), "Unable to open history for this window.");
72
                 }
71
                 }
73
             } else if ("help".equalsIgnoreCase(args.getArguments()[0])) {
72
             } else if ("help".equalsIgnoreCase(args.getArguments()[0])) {
74
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, LOGGING
73
+                showOutput(origin, args.isSilent(), LOGGING
75
                         + " history          - Open the history of this window, if available.");
74
                         + " history          - Open the history of this window, if available.");
76
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, LOGGING
75
+                showOutput(origin, args.isSilent(), LOGGING
77
                         + " help             - Show this help.");
76
                         + " help             - Show this help.");
78
             } else {
77
             } else {
79
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unknown command '" + args.
80
-                        getArguments()[0] + "'. Use " + LOGGING + " help for a list of commands.");
78
+                showError(origin, args.isSilent(), "Unknown command '"
79
+                        + args.getArguments()[0] + "'. Use " + LOGGING
80
+                        + " help for a list of commands.");
81
             }
81
             }
82
         } else {
82
         } else {
83
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Use " + LOGGING
84
-                    + " help for a list of commands.");
83
+            showError(origin, args.isSilent(), "Use " + LOGGING + " help for a list of commands.");
85
         }
84
         }
86
     }
85
     }
87
 
86
 

+ 2
- 3
nma/src/com/dmdirc/addons/nma/NotifyMyAndroidCommand.java Ver fichero

85
         new Thread(() -> {
85
         new Thread(() -> {
86
             try {
86
             try {
87
                 client.notify(parts[0], parts[1]);
87
                 client.notify(parts[0], parts[1]);
88
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Notification sent");
88
+                showOutput(origin, args.isSilent(), "Notification sent");
89
             } catch (IOException ex) {
89
             } catch (IOException ex) {
90
                 LOG.info("Exception when trying to notify NMA", ex);
90
                 LOG.info("Exception when trying to notify NMA", ex);
91
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unable to send: " + ex.
92
-                        getMessage());
91
+                showError(origin, args.isSilent(), "Unable to send: " + ex.getMessage());
93
             }
92
             }
94
         }, "NMA Thread").start();
93
         }, "NMA Thread").start();
95
     }
94
     }

+ 5
- 8
notifications/src/com/dmdirc/addons/notifications/NotificationCommand.java Ver fichero

79
                 final NotificationHandler handler = manager.getHandler(sourceName);
79
                 final NotificationHandler handler = manager.getHandler(sourceName);
80
 
80
 
81
                 if (handler == null) {
81
                 if (handler == null) {
82
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR,
83
-                            "Method not found.");
82
+                    showError(origin, args.isSilent(), "Method not found.");
84
                 } else {
83
                 } else {
85
                     handler.showNotification("DMDirc", args.getArgumentsAsString(2));
84
                     handler.showNotification("DMDirc", args.getArgumentsAsString(2));
86
                 }
85
                 }
87
             } else {
86
             } else {
88
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
87
+                showError(origin, args.isSilent(),
89
                         "You must specify a method when using --method.");
88
                         "You must specify a method when using --method.");
90
             }
89
             }
91
         } else if (manager.hasActiveHandler()) {
90
         } else if (manager.hasActiveHandler()) {
92
             manager.getPreferredHandler().showNotification("DMDirc", args.getArgumentsAsString(0));
91
             manager.getPreferredHandler().showNotification("DMDirc", args.getArgumentsAsString(0));
93
         } else {
92
         } else {
94
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
95
-                    "No active notification methods available.");
93
+            showError(origin, args.isSilent(), "No active notification methods available.");
96
         }
94
         }
97
     }
95
     }
98
 
96
 
107
         final Collection<String> handlers = manager.getHandlerNames();
105
         final Collection<String> handlers = manager.getHandlerNames();
108
 
106
 
109
         if (handlers.isEmpty()) {
107
         if (handlers.isEmpty()) {
110
-            sendLine(origin, isSilent, FORMAT_ERROR, "No notification "
111
-                    + "methods available.");
108
+            showError(origin, isSilent, "No notification methods available.");
112
         } else {
109
         } else {
113
             final String[] headers = {"Method"};
110
             final String[] headers = {"Method"};
114
             final String[][] data = new String[handlers.size()][1];
111
             final String[][] data = new String[handlers.size()][1];
118
                 i++;
115
                 i++;
119
             }
116
             }
120
 
117
 
121
-            sendLine(origin, isSilent, FORMAT_OUTPUT, doTable(headers, data));
118
+            showOutput(origin, isSilent, doTable(headers, data));
122
         }
119
         }
123
     }
120
     }
124
 
121
 

+ 6
- 7
nowplaying/src/com/dmdirc/addons/nowplaying/NowPlayingCommand.java Ver fichero

101
                 final MediaSource source = manager.getSource(sourceName);
101
                 final MediaSource source = manager.getSource(sourceName);
102
 
102
 
103
                 if (source == null) {
103
                 if (source == null) {
104
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR, "Source not found.");
104
+                    showError(origin, args.isSilent(), "Source not found.");
105
                 } else {
105
                 } else {
106
                     if (source.getState() == MediaSourceState.CLOSED) {
106
                     if (source.getState() == MediaSourceState.CLOSED) {
107
-                        sendLine(origin, args.isSilent(), FORMAT_ERROR, "Source is not running.");
107
+                        showError(origin, args.isSilent(), "Source is not running.");
108
                     } else {
108
                     } else {
109
                         target.getWindowModel().getCommandParser().parseCommand(origin,
109
                         target.getWindowModel().getCommandParser().parseCommand(origin,
110
                                 getInformation(source, args.getArgumentsAsString(2)));
110
                                 getInformation(source, args.getArgumentsAsString(2)));
111
                     }
111
                     }
112
                 }
112
                 }
113
             } else {
113
             } else {
114
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
114
+                showError(origin, args.isSilent(),
115
                         "You must specify a source when using --source.");
115
                         "You must specify a source when using --source.");
116
             }
116
             }
117
         } else {
117
         } else {
120
                         getInformation(manager.getBestSource(), args.
120
                         getInformation(manager.getBestSource(), args.
121
                                 getArgumentsAsString(0)));
121
                                 getArgumentsAsString(0)));
122
             } else {
122
             } else {
123
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
124
-                        "No running media sources available.");
123
+                showError(origin, args.isSilent(), "No running media sources available.");
125
             }
124
             }
126
         }
125
         }
127
     }
126
     }
138
         final List<MediaSource> sources = manager.getSources();
137
         final List<MediaSource> sources = manager.getSources();
139
 
138
 
140
         if (sources.isEmpty()) {
139
         if (sources.isEmpty()) {
141
-            sendLine(origin, isSilent, FORMAT_ERROR, "No media sources available.");
140
+            showError(origin, isSilent, "No media sources available.");
142
         } else {
141
         } else {
143
             final String[] headers = {"Source", "Status", "Information"};
142
             final String[] headers = {"Source", "Status", "Information"};
144
             final String[][] data = new String[sources.size()][3];
143
             final String[][] data = new String[sources.size()][3];
158
                 i++;
157
                 i++;
159
             }
158
             }
160
 
159
 
161
-            sendLine(origin, isSilent, FORMAT_OUTPUT, doTable(headers, data));
160
+            showOutput(origin, isSilent, doTable(headers, data));
162
         }
161
         }
163
     }
162
     }
164
 
163
 

+ 5
- 6
osd/src/com/dmdirc/addons/osd/OsdCommand.java Ver fichero

86
         } else if (args.getArguments().length > 0
86
         } else if (args.getArguments().length > 0
87
                 && "--timeout".equalsIgnoreCase(args.getArguments()[0])) {
87
                 && "--timeout".equalsIgnoreCase(args.getArguments()[0])) {
88
             if (args.getArguments().length < 2) {
88
             if (args.getArguments().length < 2) {
89
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "You "
90
-                        + "must specify a valid number for the OSD timeout.");
89
+                showError(origin, args.isSilent(),
90
+                        "You must specify a valid number for the OSD timeout.");
91
                 return;
91
                 return;
92
             }
92
             }
93
 
93
 
95
                 showOSD(Integer.parseInt(args.getArguments()[1]), null,
95
                 showOSD(Integer.parseInt(args.getArguments()[1]), null,
96
                         args.getArgumentsAsString(2));
96
                         args.getArgumentsAsString(2));
97
             } catch (NumberFormatException ex) {
97
             } catch (NumberFormatException ex) {
98
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "You "
99
-                        + "must specify a valid number for the OSD timeout.");
98
+                showError(origin, args.isSilent(),
99
+                        "You must specify a valid number for the OSD timeout.");
100
             }
100
             }
101
         } else {
101
         } else {
102
             showOSD(-1, null, args.getArgumentsAsString());
102
             showOSD(-1, null, args.getArgumentsAsString());
111
         if (arg == 0) {
111
         if (arg == 0) {
112
             res.add("--close");
112
             res.add("--close");
113
             res.add("--timeout");
113
             res.add("--timeout");
114
-        } else if (arg > 0 && context.getPreviousArgs().get(0)
115
-                .equals("--close")) {
114
+        } else if (arg > 0 && "--close".equals(context.getPreviousArgs().get(0))) {
116
             res.excludeAll();
115
             res.excludeAll();
117
         }
116
         }
118
 
117
 

+ 3
- 3
parserdebug/src/com/dmdirc/addons/parserdebug/ParserDebugCommand.java Ver fichero

82
         final Optional<Parser> parser = connection.getParser();
82
         final Optional<Parser> parser = connection.getParser();
83
 
83
 
84
         if (!parser.isPresent()) {
84
         if (!parser.isPresent()) {
85
-            sendLine(origin, isSilent, FORMAT_ERROR, "Unable to get a parser for this window.");
85
+            showError(origin, isSilent, "Unable to get a parser for this window.");
86
             return;
86
             return;
87
         }
87
         }
88
         if (parserDebugManager.containsParser(parser.get())) {
88
         if (parserDebugManager.containsParser(parser.get())) {
89
             parserDebugManager.removeParser(parser.get(), false);
89
             parserDebugManager.removeParser(parser.get(), false);
90
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "Removed callback");
90
+            showOutput(origin, isSilent, "Removed callback");
91
         } else {
91
         } else {
92
             parserDebugManager.addParser(parser.get(), connection);
92
             parserDebugManager.addParser(parser.get(), connection);
93
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "Added callback");
93
+            showOutput(origin, isSilent, "Added callback");
94
         }
94
         }
95
     }
95
     }
96
 
96
 

+ 28
- 32
scriptplugin/src/com/dmdirc/addons/scriptplugin/ScriptCommand.java Ver fichero

99
 
99
 
100
         if (sargs.length > 0 && ("rehash".equalsIgnoreCase(sargs[0]) ||
100
         if (sargs.length > 0 && ("rehash".equalsIgnoreCase(sargs[0]) ||
101
                 "reload".equalsIgnoreCase(sargs[0]))) {
101
                 "reload".equalsIgnoreCase(sargs[0]))) {
102
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Reloading scripts");
102
+            showOutput(origin, args.isSilent(), "Reloading scripts");
103
             scriptManager.rehash();
103
             scriptManager.rehash();
104
         } else if (sargs.length > 0 && "load".equalsIgnoreCase(sargs[0])) {
104
         } else if (sargs.length > 0 && "load".equalsIgnoreCase(sargs[0])) {
105
             if (sargs.length > 1) {
105
             if (sargs.length > 1) {
106
                 final String filename = args.getArgumentsAsString(1);
106
                 final String filename = args.getArgumentsAsString(1);
107
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Loading: " + filename + " ["
107
+                showOutput(origin, args.isSilent(), "Loading: " + filename + " ["
108
                         + scriptManager.loadScript(scriptDirectory + filename) + ']');
108
                         + scriptManager.loadScript(scriptDirectory + filename) + ']');
109
             } else {
109
             } else {
110
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "You must specify a script to load");
110
+                showError(origin, args.isSilent(), "You must specify a script to load");
111
             }
111
             }
112
         } else if (sargs.length > 0 && "unload".equalsIgnoreCase(sargs[0])) {
112
         } else if (sargs.length > 0 && "unload".equalsIgnoreCase(sargs[0])) {
113
             if (sargs.length > 1) {
113
             if (sargs.length > 1) {
114
                 final String filename = args.getArgumentsAsString(1);
114
                 final String filename = args.getArgumentsAsString(1);
115
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Unloading: " + filename + " ["
115
+                showOutput(origin, args.isSilent(), "Unloading: " + filename + " ["
116
                         + scriptManager.loadScript(scriptDirectory + filename) + ']');
116
                         + scriptManager.loadScript(scriptDirectory + filename) + ']');
117
             } else {
117
             } else {
118
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
119
-                        "You must specify a script to unload");
118
+                showError(origin, args.isSilent(), "You must specify a script to unload");
120
             }
119
             }
121
         } else if (sargs.length > 0 && "eval".equalsIgnoreCase(sargs[0])) {
120
         } else if (sargs.length > 0 && "eval".equalsIgnoreCase(sargs[0])) {
122
             if (sargs.length > 1) {
121
             if (sargs.length > 1) {
123
                 final String script = args.getArgumentsAsString(1);
122
                 final String script = args.getArgumentsAsString(1);
124
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Evaluating: " + script);
123
+                showOutput(origin, args.isSilent(), "Evaluating: " + script);
125
                 try {
124
                 try {
126
                     final ScriptEngineWrapper wrapper;
125
                     final ScriptEngineWrapper wrapper;
127
                     if (globalConfig.hasOptionString(domain, "eval.baseFile")) {
126
                     if (globalConfig.hasOptionString(domain, "eval.baseFile")) {
138
                     wrapper.getScriptEngine().put("cmd_origin", origin);
137
                     wrapper.getScriptEngine().put("cmd_origin", origin);
139
                     wrapper.getScriptEngine().put("cmd_isSilent", args.isSilent());
138
                     wrapper.getScriptEngine().put("cmd_isSilent", args.isSilent());
140
                     wrapper.getScriptEngine().put("cmd_args", sargs);
139
                     wrapper.getScriptEngine().put("cmd_args", sargs);
141
-                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Result: " + wrapper.
142
-                            getScriptEngine().eval(script));
140
+                    showOutput(origin, args.isSilent(), "Result: "
141
+                            + wrapper.getScriptEngine().eval(script));
143
                 } catch (ScriptException e) {
142
                 } catch (ScriptException e) {
144
-                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Exception: " + e + " -> " + e.
145
-                            getMessage());
143
+                    showOutput(origin, args.isSilent(), "Exception: " + e + " -> "
144
+                            + e.getMessage());
146
 
145
 
147
                     if (globalConfig.getOptionBool(domain, "eval.showStackTrace")) {
146
                     if (globalConfig.getOptionBool(domain, "eval.showStackTrace")) {
148
                         final String[] stacktrace = getTrace(e);
147
                         final String[] stacktrace = getTrace(e);
149
                         for (String line : stacktrace) {
148
                         for (String line : stacktrace) {
150
-                            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Stack trace: " + line);
149
+                            showOutput(origin, args.isSilent(), "Stack trace: " + line);
151
                         }
150
                         }
152
                     }
151
                     }
153
 
152
 
154
                 }
153
                 }
155
             } else {
154
             } else {
156
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
157
-                        "You must specify some script to eval.");
155
+                showError(origin, args.isSilent(), "You must specify some script to eval.");
158
             }
156
             }
159
         } else if (sargs.length > 0 && "savetobasefile".equalsIgnoreCase(sargs[0])) {
157
         } else if (sargs.length > 0 && "savetobasefile".equalsIgnoreCase(sargs[0])) {
160
             if (sargs.length > 2) {
158
             if (sargs.length > 2) {
161
                 final String[] bits = sargs[1].split("/");
159
                 final String[] bits = sargs[1].split("/");
162
                 final String functionName = bits[0];
160
                 final String functionName = bits[0];
163
                 final String script = args.getArgumentsAsString(2);
161
                 final String script = args.getArgumentsAsString(2);
164
-                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Saving as '" + functionName
162
+                showOutput(origin, args.isSilent(), "Saving as '" + functionName
165
                         + "': " + script);
163
                         + "': " + script);
166
                 if (globalConfig.hasOptionString(domain, "eval.baseFile")) {
164
                 if (globalConfig.hasOptionString(domain, "eval.baseFile")) {
167
                     try {
165
                     try {
181
                             writer.flush();
179
                             writer.flush();
182
                         }
180
                         }
183
                     } catch (IOException ioe) {
181
                     } catch (IOException ioe) {
184
-                        sendLine(origin, args.isSilent(), FORMAT_ERROR, "IOException: " + ioe.
185
-                                getMessage());
182
+                        showError(origin, args.isSilent(), "IOException: " + ioe.getMessage());
186
                     }
183
                     }
187
                 } else {
184
                 } else {
188
-                    sendLine(origin, args.isSilent(), FORMAT_ERROR,
185
+                    showError(origin, args.isSilent(),
189
                             "No baseFile specified, please /set " + domain
186
                             "No baseFile specified, please /set " + domain
190
                             + " eval.baseFile filename (stored in scripts dir of profile)");
187
                             + " eval.baseFile filename (stored in scripts dir of profile)");
191
                 }
188
                 }
192
             } else if (sargs.length > 1) {
189
             } else if (sargs.length > 1) {
193
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
194
-                        "You must specify some script to save.");
190
+                showError(origin, args.isSilent(), "You must specify some script to save.");
195
             } else {
191
             } else {
196
-                sendLine(origin, args.isSilent(), FORMAT_ERROR,
192
+                showError(origin, args.isSilent(),
197
                         "You must specify a function name and some script to save.");
193
                         "You must specify a function name and some script to save.");
198
             }
194
             }
199
         } else if (sargs.length > 0 && "help".equalsIgnoreCase(sargs[0])) {
195
         } else if (sargs.length > 0 && "help".equalsIgnoreCase(sargs[0])) {
200
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
196
+            showOutput(origin, args.isSilent(),
201
                     "This command allows you to interact with the script plugin");
197
                     "This command allows you to interact with the script plugin");
202
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "-------------------");
203
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
198
+            showOutput(origin, args.isSilent(), "-------------------");
199
+            showOutput(origin, args.isSilent(),
204
                     "reload/rehash                  - Reload all loaded scripts");
200
                     "reload/rehash                  - Reload all loaded scripts");
205
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
201
+            showOutput(origin, args.isSilent(),
206
                     "load <script>                  - load scripts/<script> (file name relative to scripts dir)");
202
                     "load <script>                  - load scripts/<script> (file name relative to scripts dir)");
207
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
203
+            showOutput(origin, args.isSilent(),
208
                     "unload <script>                - unload <script> (full file name)");
204
                     "unload <script>                - unload <script> (full file name)");
209
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
205
+            showOutput(origin, args.isSilent(),
210
                     "eval <script>                  - evaluate the code <script> and return the result");
206
                     "eval <script>                  - evaluate the code <script> and return the result");
211
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
207
+            showOutput(origin, args.isSilent(),
212
                     "savetobasefile <name> <script> - save the code <script> to the eval basefile ("
208
                     "savetobasefile <name> <script> - save the code <script> to the eval basefile ("
213
                     + domain + ".eval.basefile)");
209
                     + domain + ".eval.basefile)");
214
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
210
+            showOutput(origin, args.isSilent(),
215
                     "                                 as the function <name> (name/foo/bar will save it as 'name' with foo and");
211
                     "                                 as the function <name> (name/foo/bar will save it as 'name' with foo and");
216
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
212
+            showOutput(origin, args.isSilent(),
217
                     "                                 bar as arguments.");
213
                     "                                 bar as arguments.");
218
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "-------------------");
214
+            showOutput(origin, args.isSilent(), "-------------------");
219
         } else {
215
         } else {
220
-            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unknown subcommand.");
216
+            showError(origin, args.isSilent(), "Unknown subcommand.");
221
         }
217
         }
222
     }
218
     }
223
 
219
 

+ 1
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/commands/PopInCommand.java Ver fichero

70
         UIUtilities.invokeLater(() -> {
70
         UIUtilities.invokeLater(() -> {
71
             final TextFrame swingWindow = windowFactory.getSwingWindow(origin);
71
             final TextFrame swingWindow = windowFactory.getSwingWindow(origin);
72
             if (swingWindow == null) {
72
             if (swingWindow == null) {
73
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "There is"
74
-                        + " currently no window to pop in.");
73
+                showError(origin, args.isSilent(), "There is currently no window to pop in.");
75
             } else {
74
             } else {
76
                 swingWindow.setPopout(false);
75
                 swingWindow.setPopout(false);
77
             }
76
             }

+ 1
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/commands/PopOutCommand.java Ver fichero

70
         UIUtilities.invokeLater(() -> {
70
         UIUtilities.invokeLater(() -> {
71
             final TextFrame swingWindow = windowFactory.getSwingWindow(origin);
71
             final TextFrame swingWindow = windowFactory.getSwingWindow(origin);
72
             if (swingWindow == null) {
72
             if (swingWindow == null) {
73
-                sendLine(origin, args.isSilent(), FORMAT_ERROR, "There is"
74
-                        + " currently no window to pop out.");
73
+                showError(origin, args.isSilent(), "There is currently no window to pop out.");
75
             } else {
74
             } else {
76
                 swingWindow.setPopout(true);
75
                 swingWindow.setPopout(true);
77
             }
76
             }

Loading…
Cancelar
Guardar