Sfoglia il codice sorgente

Use CommandArguments in intelligent tab completion code.

This enables completion on silenced commands (/.)
Fixes issue 2729

Change-Id: Idf0cf6c70fb40b33d1b965973fd37e34ecce722e
Reviewed-on: http://gerrit.dmdirc.com/210
Reviewed-by: Gregory Holmes <greboid@dmdirc.com>
Tested-by: Gregory Holmes <greboid@dmdirc.com>
tags/0.6.3b1
Chris Smith 14 anni fa
parent
commit
a9cc3716b0

+ 23
- 0
src/com/dmdirc/commandparser/CommandArguments.java Vedi File

@@ -26,6 +26,7 @@ import com.dmdirc.Precondition;
26 26
 import com.dmdirc.logger.Logger;
27 27
 
28 28
 import java.util.Arrays;
29
+import java.util.Collection;
29 30
 import java.util.regex.Matcher;
30 31
 import java.util.regex.Pattern;
31 32
 
@@ -55,6 +56,28 @@ public class CommandArguments {
55 56
         this.line = line;
56 57
     }
57 58
 
59
+    /**
60
+     * Creates a new command arguments parser for the specified words.
61
+     *
62
+     * @param words The words which form the line ot be parsed
63
+     * @since 0.6.3
64
+     */
65
+    public CommandArguments(final Collection<String> words) {
66
+        this.words = words.toArray(new String[words.size()]);
67
+
68
+        final StringBuilder builder = new StringBuilder();
69
+
70
+        for (String word : words) {
71
+            if (builder.length() > 0) {
72
+                builder.append(' ');
73
+            }
74
+
75
+            builder.append(word);
76
+        }
77
+
78
+        this.line = builder.toString();
79
+    }
80
+
58 81
     /**
59 82
      * Retrieves the raw line that was input, including any command character(s)
60 83
      * and names.

+ 11
- 8
src/com/dmdirc/ui/input/TabCompleter.java Vedi File

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.ui.input;
24 24
 
25
+import com.dmdirc.commandparser.CommandArguments;
25 26
 import com.dmdirc.commandparser.CommandInfo;
26 27
 import com.dmdirc.commandparser.CommandManager;
27 28
 import com.dmdirc.commandparser.commands.ChannelCommand;
@@ -224,7 +225,8 @@ public final class TabCompleter implements Serializable {
224 225
             targets.include(TabCompletionType.COMMAND);
225 226
             return targets;
226 227
         } else {
227
-            return getIntelligentResults(previousArgs.subList(offset, previousArgs.size()));
228
+            return getIntelligentResults(
229
+                    new CommandArguments(previousArgs.subList(offset, previousArgs.size())));
228 230
         }        
229 231
     }
230 232
     
@@ -232,23 +234,24 @@ public final class TabCompleter implements Serializable {
232 234
      * Retrieves the intelligent results for the command and its arguments
233 235
      * formed from args.
234 236
      * 
235
-     * @param args A list of "words" in the input
237
+     * @param args The input arguments
236 238
      * @return Additional tab targets for the text, or null if none are available
237 239
      */
238
-    private static AdditionalTabTargets getIntelligentResults(final List<String> args) {
239
-        if (args.isEmpty() || args.get(0).charAt(0) != CommandManager.getCommandChar()) {
240
+    private static AdditionalTabTargets getIntelligentResults(final CommandArguments args) {
241
+        if (!args.isCommand()) {
240 242
             return null;
241 243
         }
242 244
         
243
-        final String signature = args.get(0).substring(1);
244
-        final Map.Entry<CommandInfo, Command> command = CommandManager.getCommand(signature);
245
+        final Map.Entry<CommandInfo, Command> command
246
+                = CommandManager.getCommand(args.getCommandName());
245 247
 
246 248
         AdditionalTabTargets targets = null;
247 249
 
248 250
         if (command != null) {
249 251
             if (command.getValue() instanceof IntelligentCommand) {
250 252
                 targets = ((IntelligentCommand) command.getValue())
251
-                        .getSuggestions(args.size() - 1, args.subList(1, args.size()));
253
+                        .getSuggestions(args.getArguments().length,
254
+                        Arrays.asList(args.getArgumentsAsString()));
252 255
             }
253 256
 
254 257
             if (command.getValue() instanceof ChannelCommand) {
@@ -270,6 +273,6 @@ public final class TabCompleter implements Serializable {
270 273
      * @return Additional tab targets for the text, or null if none are available
271 274
      */
272 275
     public static AdditionalTabTargets getIntelligentResults(final String text) {
273
-        return getIntelligentResults(Arrays.asList(text.split(" ")));
276
+        return getIntelligentResults(new CommandArguments(text));
274 277
     }
275 278
 }

Loading…
Annulla
Salva