Browse Source

Stop TabCompleter depending on CommandManager.

pull/597/head
Chris Smith 9 years ago
parent
commit
0a7fb8b874

+ 14
- 5
src/com/dmdirc/commandparser/CommandManager.java View File

163
     private void registerCommandName(final CommandInfo command,
163
     private void registerCommandName(final CommandInfo command,
164
             final boolean register) {
164
             final boolean register) {
165
         // Do tab completion
165
         // Do tab completion
166
-        final String commandName = getCommandChar() + command.getName();
166
+        final String plainCommandName = getCommandChar() + command.getName();
167
+        final String silencedCommandName = getCommandChar() + getSilenceChar() + command.getName();
167
 
168
 
168
         if (command.getType() == CommandType.TYPE_GLOBAL) {
169
         if (command.getType() == CommandType.TYPE_GLOBAL) {
169
             registerCommandName(globalWindowProvider.get().getTabCompleter(),
170
             registerCommandName(globalWindowProvider.get().getTabCompleter(),
170
-                    commandName, register);
171
+                    plainCommandName, register);
172
+            registerCommandName(globalWindowProvider.get().getTabCompleter(),
173
+                    silencedCommandName, register);
171
         }
174
         }
172
 
175
 
173
         // TODO: This logic is probably in two places. Abstract it.
176
         // TODO: This logic is probably in two places. Abstract it.
175
             if (command.getType() == CommandType.TYPE_SERVER
178
             if (command.getType() == CommandType.TYPE_SERVER
176
                     || command.getType() == CommandType.TYPE_GLOBAL) {
179
                     || command.getType() == CommandType.TYPE_GLOBAL) {
177
                 registerCommandName(server.getWindowModel().getTabCompleter(),
180
                 registerCommandName(server.getWindowModel().getTabCompleter(),
178
-                        commandName, register);
181
+                        plainCommandName, register);
182
+                registerCommandName(server.getWindowModel().getTabCompleter(),
183
+                        silencedCommandName, register);
179
             }
184
             }
180
 
185
 
181
             if (command.getType() == CommandType.TYPE_CHANNEL
186
             if (command.getType() == CommandType.TYPE_CHANNEL
182
                     || command.getType() == CommandType.TYPE_CHAT) {
187
                     || command.getType() == CommandType.TYPE_CHAT) {
183
                 for (GroupChat channel : server.getGroupChatManager().getChannels()) {
188
                 for (GroupChat channel : server.getGroupChatManager().getChannels()) {
184
                     registerCommandName(channel.getWindowModel().getTabCompleter(),
189
                     registerCommandName(channel.getWindowModel().getTabCompleter(),
185
-                            commandName, register);
190
+                            plainCommandName, register);
191
+                    registerCommandName(channel.getWindowModel().getTabCompleter(),
192
+                            silencedCommandName, register);
186
                 }
193
                 }
187
             }
194
             }
188
 
195
 
190
                     || command.getType() == CommandType.TYPE_CHAT) {
197
                     || command.getType() == CommandType.TYPE_CHAT) {
191
                 for (Query query : server.getQueries()) {
198
                 for (Query query : server.getQueries()) {
192
                     registerCommandName(query.getTabCompleter(),
199
                     registerCommandName(query.getTabCompleter(),
193
-                            commandName, register);
200
+                            plainCommandName, register);
201
+                    registerCommandName(query.getTabCompleter(),
202
+                            silencedCommandName, register);
194
                 }
203
                 }
195
             }
204
             }
196
         }
205
         }

+ 1
- 20
src/com/dmdirc/ui/input/TabCompleter.java View File

22
 
22
 
23
 package com.dmdirc.ui.input;
23
 package com.dmdirc.ui.input;
24
 
24
 
25
-import com.dmdirc.interfaces.CommandController;
26
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
25
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
27
 
26
 
28
 import com.google.common.collect.ArrayListMultimap;
27
 import com.google.common.collect.ArrayListMultimap;
42
     private final TabCompleter parent;
41
     private final TabCompleter parent;
43
     /** The config manager to use for reading settings. */
42
     /** The config manager to use for reading settings. */
44
     private final AggregateConfigProvider configManager;
43
     private final AggregateConfigProvider configManager;
45
-    /** The controller to use to retrieve command information. */
46
-    private final CommandController commandController;
47
     /** The entries in this completer. */
44
     /** The entries in this completer. */
48
     private final Multimap<TabCompletionType, String> entries = ArrayListMultimap.create();
45
     private final Multimap<TabCompletionType, String> entries = ArrayListMultimap.create();
49
 
46
 
50
     /**
47
     /**
51
      * Creates a new instance of {@link TabCompleter}.
48
      * Creates a new instance of {@link TabCompleter}.
52
      *
49
      *
53
-     * @param commandController The controller to use for command information.
54
      * @param configManager     The manager to read config settings from.
50
      * @param configManager     The manager to read config settings from.
55
      */
51
      */
56
-    public TabCompleter(
57
-            final CommandController commandController,
58
-            final AggregateConfigProvider configManager) {
52
+    public TabCompleter(final AggregateConfigProvider configManager) {
59
         this.parent = null;
53
         this.parent = null;
60
-        this.commandController = commandController;
61
         this.configManager = configManager;
54
         this.configManager = configManager;
62
     }
55
     }
63
 
56
 
64
     /**
57
     /**
65
      * Creates a new instance of {@link TabCompleter}.
58
      * Creates a new instance of {@link TabCompleter}.
66
      *
59
      *
67
-     * @param commandController The controller to use for command information.
68
      * @param configManager     The manager to read config settings from.
60
      * @param configManager     The manager to read config settings from.
69
      * @param parent            The parent tab completer to inherit completions from.
61
      * @param parent            The parent tab completer to inherit completions from.
70
      */
62
      */
71
     public TabCompleter(
63
     public TabCompleter(
72
-            final CommandController commandController,
73
             final AggregateConfigProvider configManager,
64
             final AggregateConfigProvider configManager,
74
             @Nullable final TabCompleter parent) {
65
             @Nullable final TabCompleter parent) {
75
         this.parent = parent;
66
         this.parent = parent;
76
-        this.commandController = commandController;
77
         this.configManager = configManager;
67
         this.configManager = configManager;
78
     }
68
     }
79
 
69
 
134
      */
124
      */
135
     public void addEntry(final TabCompletionType type, final String entry) {
125
     public void addEntry(final TabCompletionType type, final String entry) {
136
         entries.put(type, entry);
126
         entries.put(type, entry);
137
-
138
-        if (type == TabCompletionType.COMMAND && entry.length() > 1
139
-                && entry.charAt(0) == commandController.getCommandChar()
140
-                && entry.charAt(1) != commandController.getSilenceChar()) {
141
-            // If we're adding a command name that doesn't include the silence
142
-            // character, also add a version with the silence char
143
-            addEntry(type, entry.substring(0, 1) + commandController.getSilenceChar()
144
-                    + entry.substring(1));
145
-        }
146
     }
127
     }
147
 
128
 
148
     /**
129
     /**

+ 2
- 3
src/com/dmdirc/ui/input/TabCompleterFactory.java View File

62
     public TabCompleter getTabCompleter(
62
     public TabCompleter getTabCompleter(
63
             final AggregateConfigProvider configProvider,
63
             final AggregateConfigProvider configProvider,
64
             final CommandType... commandTypes) {
64
             final CommandType... commandTypes) {
65
-        final TabCompleter tabCompleter = new TabCompleter(commandController.get(), configProvider);
65
+        final TabCompleter tabCompleter = new TabCompleter(configProvider);
66
         addCommands(tabCompleter, commandTypes);
66
         addCommands(tabCompleter, commandTypes);
67
         return tabCompleter;
67
         return tabCompleter;
68
     }
68
     }
81
             final TabCompleter parent,
81
             final TabCompleter parent,
82
             final AggregateConfigProvider configProvider,
82
             final AggregateConfigProvider configProvider,
83
             final CommandType... commandTypes) {
83
             final CommandType... commandTypes) {
84
-        final TabCompleter tabCompleter = new TabCompleter(commandController.get(),
85
-                configProvider, parent);
84
+        final TabCompleter tabCompleter = new TabCompleter(configProvider, parent);
86
         addCommands(tabCompleter, commandTypes);
85
         addCommands(tabCompleter, commandTypes);
87
         return tabCompleter;
86
         return tabCompleter;
88
     }
87
     }

+ 1
- 4
test/com/dmdirc/harness/TestWritableFrameContainer.java View File

26
 import com.dmdirc.FrameContainer;
26
 import com.dmdirc.FrameContainer;
27
 import com.dmdirc.commandparser.CommandManager;
27
 import com.dmdirc.commandparser.CommandManager;
28
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
28
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
29
-import com.dmdirc.interfaces.CommandController;
30
 import com.dmdirc.interfaces.Connection;
29
 import com.dmdirc.interfaces.Connection;
31
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
30
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
32
 import com.dmdirc.ui.input.TabCompleter;
31
 import com.dmdirc.ui.input.TabCompleter;
36
 import java.util.Collections;
35
 import java.util.Collections;
37
 import java.util.Optional;
36
 import java.util.Optional;
38
 
37
 
39
-import static org.mockito.Mockito.mock;
40
-
41
 public class TestWritableFrameContainer extends FrameContainer {
38
 public class TestWritableFrameContainer extends FrameContainer {
42
 
39
 
43
     private final int lineLength;
40
     private final int lineLength;
48
             final DMDircMBassador eventBus,
45
             final DMDircMBassador eventBus,
49
             final BackBufferFactory backBufferFactory) {
46
             final BackBufferFactory backBufferFactory) {
50
         super(null, "raw", "Raw", "(Raw)", cm, backBufferFactory,
47
         super(null, "raw", "Raw", "(Raw)", cm, backBufferFactory,
51
-                new TabCompleter(mock(CommandController.class), cm),
48
+                new TabCompleter(cm),
52
                 messageSinkManager,
49
                 messageSinkManager,
53
                 eventBus,
50
                 eventBus,
54
                 Collections.<String>emptySet());
51
                 Collections.<String>emptySet());

Loading…
Cancel
Save