Procházet zdrojové kódy

Intelligent commands can now suppress normal tab completable targets, so /ctcp foo <tab> will only complete valid CTCP types, rather than completing valid CTCP types, nicknames, channel names and command names.

git-svn-id: http://svn.dmdirc.com/trunk@1585 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5
Chris Smith před 17 roky
rodič
revize
f97b39b1c5

+ 5
- 3
src/com/dmdirc/addons/nowplaying/plugin/NowPlayingCommand.java Zobrazit soubor

@@ -28,8 +28,8 @@ import com.dmdirc.addons.nowplaying.MediaSource;
28 28
 import com.dmdirc.commandparser.ChannelCommand;
29 29
 import com.dmdirc.commandparser.CommandManager;
30 30
 import com.dmdirc.commandparser.IntelligentCommand;
31
+import com.dmdirc.ui.input.AdditionalTabTargets;
31 32
 import com.dmdirc.ui.interfaces.InputWindow;
32
-import java.util.ArrayList;
33 33
 
34 34
 import java.util.List;
35 35
 
@@ -142,8 +142,10 @@ public final class NowPlayingCommand extends ChannelCommand implements Intellige
142 142
     }
143 143
     
144 144
     /** {@inheritDoc} */
145
-    public List<String> getSuggestions(int arg, List<String> previousArgs) {
146
-        final List<String> res = new ArrayList<String>();
145
+    public AdditionalTabTargets getSuggestions(int arg, List<String> previousArgs) {
146
+        final AdditionalTabTargets res = new AdditionalTabTargets();
147
+        
148
+        res.setIncludeNormal(false);
147 149
         
148 150
         if (arg == 0) {
149 151
             res.add("--sources");

+ 2
- 1
src/com/dmdirc/commandparser/IntelligentCommand.java Zobrazit soubor

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.commandparser;
24 24
 
25
+import com.dmdirc.ui.input.AdditionalTabTargets;
25 26
 import java.util.List;
26 27
 
27 28
 /**
@@ -38,6 +39,6 @@ public interface IntelligentCommand {
38 39
      * @param previousArgs The contents of the previous arguments, if any
39 40
      * @return A list of suggestions for the argument
40 41
      */
41
-    List<String> getSuggestions(int arg, List<String> previousArgs);
42
+    AdditionalTabTargets getSuggestions(int arg, List<String> previousArgs);
42 43
     
43 44
 }

+ 4
- 3
src/com/dmdirc/commandparser/commands/global/LoadPlugin.java Zobrazit soubor

@@ -26,9 +26,9 @@ import com.dmdirc.commandparser.CommandManager;
26 26
 import com.dmdirc.commandparser.GlobalCommand;
27 27
 import com.dmdirc.commandparser.IntelligentCommand;
28 28
 import com.dmdirc.plugins.PluginManager;
29
+import com.dmdirc.ui.input.AdditionalTabTargets;
29 30
 import com.dmdirc.ui.interfaces.InputWindow;
30 31
 
31
-import java.util.ArrayList;
32 32
 import java.util.Arrays;
33 33
 import java.util.List;
34 34
 
@@ -85,10 +85,11 @@ public final class LoadPlugin extends GlobalCommand implements IntelligentComman
85 85
     }
86 86
 
87 87
     /** {@inheritDoc} */
88
-    public List<String> getSuggestions(int arg, List<String> previousArgs) {
89
-        final List<String> res = new ArrayList<String>();
88
+    public AdditionalTabTargets getSuggestions(int arg, List<String> previousArgs) {
89
+        final AdditionalTabTargets res = new AdditionalTabTargets();
90 90
         
91 91
         if (arg == 0) {
92
+            res.setIncludeNormal(false);
92 93
             res.addAll(Arrays.asList(PluginManager.getPluginManager().getNames()));
93 94
         }
94 95
         

+ 5
- 3
src/com/dmdirc/commandparser/commands/global/Set.java Zobrazit soubor

@@ -26,9 +26,9 @@ import com.dmdirc.Config;
26 26
 import com.dmdirc.commandparser.CommandManager;
27 27
 import com.dmdirc.commandparser.GlobalCommand;
28 28
 import com.dmdirc.commandparser.IntelligentCommand;
29
+import com.dmdirc.ui.input.AdditionalTabTargets;
29 30
 import com.dmdirc.ui.interfaces.InputWindow;
30 31
 
31
-import java.util.ArrayList;
32 32
 import java.util.List;
33 33
 
34 34
 /**
@@ -172,13 +172,15 @@ public final class Set extends GlobalCommand implements IntelligentCommand {
172 172
     }
173 173
     
174 174
     /** {@inheritDoc} */
175
-    public List<String> getSuggestions(int arg, List<String> previousArgs) {
176
-        final List<String> res = new ArrayList<String>();
175
+    public AdditionalTabTargets getSuggestions(int arg, List<String> previousArgs) {
176
+        final AdditionalTabTargets res = new AdditionalTabTargets();
177 177
         
178 178
         if (arg == 0) {
179 179
             res.addAll(Config.getDomains());
180
+            res.setIncludeNormal(false);
180 181
         } else if (arg == 1 && previousArgs.size() >= 1) {
181 182
             res.addAll(Config.getOptions(previousArgs.get(0)));
183
+            res.setIncludeNormal(false);
182 184
         }
183 185
         
184 186
         return res;

+ 5
- 3
src/com/dmdirc/commandparser/commands/server/Ctcp.java Zobrazit soubor

@@ -27,8 +27,9 @@ import com.dmdirc.Server;
27 27
 import com.dmdirc.commandparser.CommandManager;
28 28
 import com.dmdirc.commandparser.IntelligentCommand;
29 29
 import com.dmdirc.commandparser.ServerCommand;
30
+import com.dmdirc.ui.input.AdditionalTabTargets;
30 31
 import com.dmdirc.ui.interfaces.InputWindow;
31
-import java.util.ArrayList;
32
+
32 33
 import java.util.List;
33 34
 
34 35
 /**
@@ -92,8 +93,8 @@ public final class Ctcp extends ServerCommand implements IntelligentCommand {
92 93
     }
93 94
     
94 95
     /** {@inheritDoc} */
95
-    public List<String> getSuggestions(int arg, List<String> previousArgs) {
96
-        final List<String> res = new ArrayList<String>();
96
+    public AdditionalTabTargets getSuggestions(int arg, List<String> previousArgs) {
97
+        final AdditionalTabTargets res = new AdditionalTabTargets();
97 98
         
98 99
         if (arg == 1) {
99 100
             res.add("VERSION");
@@ -104,6 +105,7 @@ public final class Ctcp extends ServerCommand implements IntelligentCommand {
104 105
             res.add("FINGER");
105 106
             res.add("SOURCE");
106 107
             res.add("TIME");
108
+            res.setIncludeNormal(false);
107 109
         }
108 110
         
109 111
         return res;

+ 59
- 0
src/com/dmdirc/ui/input/AdditionalTabTargets.java Zobrazit soubor

@@ -0,0 +1,59 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
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.ui.input;
24
+
25
+import java.util.ArrayList;
26
+
27
+/**
28
+ * The AdditionalTabTargets class is a basic wrapper around an arraylist that
29
+ * adds an additional property to determine whether or not to include normal
30
+ * tab-completable targets (such as nicknames and channels).
31
+ * 
32
+ * @author chris
33
+ */
34
+public class AdditionalTabTargets extends ArrayList<String> {
35
+    
36
+    /** Whether to include normal targets. */
37
+    private boolean includeNormal = true;
38
+
39
+    /**
40
+     * Determines if this set of tab targets precludes the inclusion of
41
+     * standard targets.
42
+     * 
43
+     * @return True if normal targets are included, false otherwise
44
+     */
45
+    public boolean shouldIncludeNormal() {
46
+        return includeNormal;
47
+    }
48
+
49
+    /**
50
+     * Sets whether or not these results preclude the inclusion of the standard
51
+     * tab-completable targets.
52
+     * 
53
+     * @param includeNormal Whether normal targets should be included or not
54
+     */
55
+    public void setIncludeNormal(final boolean includeNormal) {
56
+        this.includeNormal = includeNormal;
57
+    }    
58
+
59
+}

+ 2
- 2
src/com/dmdirc/ui/input/InputHandler.java Zobrazit soubor

@@ -321,7 +321,7 @@ public final class InputHandler implements KeyListener, ActionListener {
321 321
                 }
322 322
             }
323 323
             
324
-            final List<String> results = ((IntelligentCommand) command).getSuggestions(args, previousArgs);
324
+            final AdditionalTabTargets results = ((IntelligentCommand) command).getSuggestions(args, previousArgs);
325 325
             
326 326
             doNormalTabCompletion(text, start, end, results);
327 327
         } else {
@@ -338,7 +338,7 @@ public final class InputHandler implements KeyListener, ActionListener {
338 338
      * @param additional A list of additional strings to use
339 339
      */
340 340
     private void doNormalTabCompletion(final String text, final int start,
341
-            final int end, final List<String> additional) {
341
+            final int end, final AdditionalTabTargets additional) {
342 342
         final String word = text.substring(start, end);
343 343
         
344 344
         if (start == lastPosition && word.equals(lastWord)) {

+ 38
- 36
src/com/dmdirc/ui/input/TabCompleter.java Zobrazit soubor

@@ -46,7 +46,7 @@ public final class TabCompleter {
46 46
     
47 47
     /** Creates a new instance of TabCompleter. */
48 48
     public TabCompleter() {
49
-	//Do nothing.
49
+        //Do nothing.
50 50
     }
51 51
     
52 52
     /**
@@ -55,45 +55,47 @@ public final class TabCompleter {
55 55
      * local ones fail
56 56
      */
57 57
     public TabCompleter(final TabCompleter newParent) {
58
-	this.parent = newParent;
58
+        this.parent = newParent;
59 59
     }
60 60
     
61 61
     /**
62 62
      * Attempts to complete the partial string.
63
-     * 
63
+     *
64 64
      * @param partial The string to tab complete
65 65
      * @param additionals A list of additional strings to use
66 66
      * @return A TabCompleterResult containing any matches found
67 67
      */
68 68
     public TabCompleterResult complete(final String partial,
69
-            final List<String> additionals) {
70
-	final TabCompleterResult result = new TabCompleterResult();
69
+            final AdditionalTabTargets additionals) {
70
+        final TabCompleterResult result = new TabCompleterResult();
71 71
         
72 72
         final List<String> targets = new ArrayList<String>();
73
-        
74
-        if (additionals != null) { 
73
+                
74
+        if (additionals != null) {
75 75
             targets.addAll(additionals);
76 76
         }
77 77
         
78
-        targets.addAll(entries);
79
-	
80
-	for (String entry : targets) {
81
-	    if (Config.getOptionBool("tabcompletion", "casesensitive")) {
82
-		if (entry.startsWith(partial)) {
83
-		    result.addResult(entry);
84
-		}
85
-	    } else {
86
-		if (entry.toLowerCase(Locale.getDefault())
87
-		.startsWith(partial.toLowerCase(Locale.getDefault()))) {
88
-		    result.addResult(entry);
89
-		}
90
-	    }
91
-	}
92
-	
93
-	if (parent != null) {
94
-	    result.merge(parent.complete(partial, null));
95
-	}
96
-	return result;
78
+        if (additionals == null || additionals.shouldIncludeNormal()) {
79
+            targets.addAll(entries);
80
+        }
81
+        
82
+        for (String entry : targets) {
83
+            if (Config.getOptionBool("tabcompletion", "casesensitive")) {
84
+                if (entry.startsWith(partial)) {
85
+                    result.addResult(entry);
86
+                }
87
+            } else {
88
+                if (entry.toLowerCase(Locale.getDefault())
89
+                        .startsWith(partial.toLowerCase(Locale.getDefault()))) {
90
+                    result.addResult(entry);
91
+                }
92
+            }
93
+        }
94
+        
95
+        if (parent != null && (additionals == null || additionals.shouldIncludeNormal())) {
96
+            result.merge(parent.complete(partial, null));
97
+        }
98
+        return result;
97 99
     }
98 100
     
99 101
     /**
@@ -101,7 +103,7 @@ public final class TabCompleter {
101 103
      * @param entry The new entry to be added
102 104
      */
103 105
     public void addEntry(final String entry) {
104
-	entries.add(entry);
106
+        entries.add(entry);
105 107
     }
106 108
     
107 109
     /**
@@ -109,13 +111,13 @@ public final class TabCompleter {
109 111
      * @param newEntries Entries to be added
110 112
      */
111 113
     public void addEntries(final List<String> newEntries) {
112
-	if (newEntries == null) {
113
-	    return;
114
-	}
115
-	
116
-	for (String entry : newEntries) {
117
-	    addEntry(entry);
118
-	}
114
+        if (newEntries == null) {
115
+            return;
116
+        }
117
+        
118
+        for (String entry : newEntries) {
119
+            addEntry(entry);
120
+        }
119 121
     }
120 122
     
121 123
     /**
@@ -123,7 +125,7 @@ public final class TabCompleter {
123 125
      * @param entry The entry to be removed
124 126
      */
125 127
     public void removeEntry(final String entry) {
126
-	entries.remove(entry);
128
+        entries.remove(entry);
127 129
     }
128 130
     
129 131
     /**
@@ -131,7 +133,7 @@ public final class TabCompleter {
131 133
      * @param newEntries the new entries to use
132 134
      */
133 135
     public void replaceEntries(final List<String> newEntries) {
134
-	entries = newEntries;
136
+        entries = newEntries;
135 137
     }
136 138
     
137 139
 }

Načítá se…
Zrušit
Uložit