Przeglądaj źródła

Only validate/wrap commands that exist locally.

Stop the InputHandler running off to the global command manager for
commands - instead get them from the command parser it's associated
with.

Fixes #47
pull/571/head
Chris Smith 9 lat temu
rodzic
commit
7edabe683d

+ 12
- 0
src/com/dmdirc/commandparser/parsers/CommandParser.java Wyświetl plik

@@ -48,6 +48,7 @@ import java.util.Map;
48 48
 import java.util.Optional;
49 49
 
50 50
 import javax.annotation.Nonnull;
51
+import javax.annotation.Nullable;
51 52
 
52 53
 import static com.google.common.base.Preconditions.checkNotNull;
53 54
 
@@ -281,6 +282,17 @@ public abstract class CommandParser implements Serializable {
281 282
         handleNonCommand(origin, line);
282 283
     }
283 284
 
285
+    /**
286
+     * Gets the command with the given name that was previously registered with this parser.
287
+     *
288
+     * @param commandName The name of the command to retrieve.
289
+     * @return The command info pair, or {@code null} if the command does not exist.
290
+     */
291
+    @Nullable
292
+    public CommandInfoPair getCommand(final String commandName) {
293
+        return commands.get(commandName);
294
+    }
295
+
284 296
     /**
285 297
      * Gets the context that the command will execute with.
286 298
      *

+ 6
- 9
src/com/dmdirc/ui/input/InputHandler.java Wyświetl plik

@@ -25,8 +25,7 @@ package com.dmdirc.ui.input;
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.FrameContainer;
27 27
 import com.dmdirc.commandparser.CommandArguments;
28
-import com.dmdirc.commandparser.CommandInfo;
29
-import com.dmdirc.commandparser.commands.Command;
28
+import com.dmdirc.commandparser.CommandInfoPair;
30 29
 import com.dmdirc.commandparser.commands.ValidatingCommand;
31 30
 import com.dmdirc.commandparser.commands.WrappableCommand;
32 31
 import com.dmdirc.commandparser.parsers.CommandParser;
@@ -52,7 +51,6 @@ import java.awt.Toolkit;
52 51
 import java.awt.event.KeyEvent;
53 52
 import java.util.ArrayList;
54 53
 import java.util.List;
55
-import java.util.Map;
56 54
 import java.util.concurrent.Executors;
57 55
 import java.util.concurrent.ScheduledExecutorService;
58 56
 import java.util.concurrent.ScheduledFuture;
@@ -281,11 +279,10 @@ public abstract class InputHandler implements ConfigChangeListener {
281 279
         final CommandArguments args = new CommandArguments(commandController, text);
282 280
 
283 281
         if (args.isCommand()) {
284
-            final Map.Entry<CommandInfo, Command> command = commandController
285
-                    .getCommand(args.getCommandName());
282
+            final CommandInfoPair command = commandParser.getCommand(args.getCommandName());
286 283
 
287
-            if (command != null && command.getValue() instanceof ValidatingCommand) {
288
-                final ValidationResponse vr = ((ValidatingCommand) command.getValue())
284
+            if (command != null && command.getCommand() instanceof ValidatingCommand) {
285
+                final ValidationResponse vr = ((ValidatingCommand) command.getCommand())
289 286
                         .validateArguments(parentWindow, args);
290 287
 
291 288
                 if (vr.isFailure()) {
@@ -295,8 +292,8 @@ public abstract class InputHandler implements ConfigChangeListener {
295 292
                 }
296 293
             }
297 294
 
298
-            if (command != null && command.getValue() instanceof WrappableCommand) {
299
-                final int count = ((WrappableCommand) command.getValue())
295
+            if (command != null && command.getCommand() instanceof WrappableCommand) {
296
+                final int count = ((WrappableCommand) command.getCommand())
300 297
                         .getLineCount(parentWindow, args);
301 298
                 fireLineWrap(count);
302 299
             }

Ładowanie…
Anuluj
Zapisz