Przeglądaj źródła

Fix deprecated methods in CommandFlagHandler.

pull/614/head
Chris Smith 8 lat temu
rodzic
commit
e060357fb2

+ 11
- 11
src/com/dmdirc/commandparser/commands/flags/CommandFlagHandler.java Wyświetl plik

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.commandparser.commands.flags;
24 24
 
25 25
 import com.dmdirc.commandparser.CommandArguments;
26
+import com.dmdirc.events.CommandErrorEvent;
26 27
 import com.dmdirc.interfaces.WindowModel;
27 28
 
28 29
 import java.util.ArrayList;
@@ -131,13 +132,13 @@ public class CommandFlagHandler {
131 132
                     }
132 133
                 } else if (disabledBy.containsKey(name)) {
133 134
                     // Disabled by another flag
134
-                    sendLine(origin, arguments.isSilent(), "commandError",
135
+                    sendError(origin, arguments.isSilent(),
135 136
                             "Cannot use flag --" + name
136 137
                             + " in conjunction with --" + disabledBy.get(name).getName());
137 138
                     return null;
138 139
                 } else {
139 140
                     // Disabled because not yet enabled
140
-                    sendLine(origin, arguments.isSilent(), "commandError",
141
+                    sendError(origin, arguments.isSilent(),
141 142
                             "Cannot use flag --" + name
142 143
                             + " without " + getEnablers(flag));
143 144
                     return null;
@@ -181,8 +182,8 @@ public class CommandFlagHandler {
181 182
         final int lastArg = argCount + offset - 1;
182 183
 
183 184
         if (arguments.getArguments().length <= lastArg) {
184
-            sendLine(origin, arguments.isSilent(),
185
-                    "commandError", "Flag --" + flag.getName() + " expects "
185
+            sendError(origin, arguments.isSilent(),
186
+                    "Flag --" + flag.getName() + " expects "
186 187
                     + argCount + " argument"
187 188
                     + (argCount == 1 ? "" : "s"));
188 189
             return -1;
@@ -244,17 +245,16 @@ public class CommandFlagHandler {
244 245
     }
245 246
 
246 247
     /**
247
-     * Convenience method to send a line to the specified frame container.
248
+     * Convenience method to send a command error event.
248 249
      *
249
-     * @param origin      The container to send the line to
250
+     * @param origin      The container to send the event to
250 251
      * @param isSilent    Whether the command is silenced or not
251
-     * @param messageType The type of the line to be sent
252
-     * @param args        The arguments for the specified messageType
252
+     * @param message     The error message
253 253
      */
254
-    protected static void sendLine(final WindowModel origin, final boolean isSilent,
255
-            final String messageType, final Object... args) {
254
+    private static void sendError(final WindowModel origin, final boolean isSilent,
255
+            final String message) {
256 256
         if (origin != null && !isSilent) {
257
-            origin.addLine(messageType, args);
257
+            origin.getEventBus().publishAsync(new CommandErrorEvent(origin, message));
258 258
         }
259 259
     }
260 260
 

+ 3
- 0
test/com/dmdirc/commandparser/commands/flags/CommandFlagHandlerTest.java Wyświetl plik

@@ -21,6 +21,7 @@
21 21
  */
22 22
 package com.dmdirc.commandparser.commands.flags;
23 23
 
24
+import com.dmdirc.DMDircMBassador;
24 25
 import com.dmdirc.commandparser.CommandArguments;
25 26
 import com.dmdirc.interfaces.CommandController;
26 27
 import com.dmdirc.interfaces.WindowModel;
@@ -72,9 +73,11 @@ public class CommandFlagHandlerTest {
72 73
     @Test
73 74
     public void testParse() {
74 75
         final WindowModel container = mock(WindowModel.class);
76
+        final DMDircMBassador eventBus = mock(DMDircMBassador.class);
75 77
         final CommandController controller = mock(CommandController.class);
76 78
         when(controller.getCommandChar()).thenReturn('/');
77 79
         when(controller.getSilenceChar()).thenReturn('.');
80
+        when(container.getEventBus()).thenReturn(eventBus);
78 81
 
79 82
         final Map<CommandFlag, Integer> results = handler.parse(container,
80 83
                 new CommandArguments(controller, input));

Ładowanie…
Anuluj
Zapisz