Przeglądaj źródła

Use TabCompleter factories in a few more places.

This removes some static references and simplifies the
constructors of some of our model classes quite a bit.

Change-Id: Ic1644412a4956aa01b67e1129be47420c7a47b46
Reviewed-on: http://gerrit.dmdirc.com/2832
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8rc1
Chris Smith 10 lat temu
rodzic
commit
b3c4e3b122

+ 5
- 6
src/com/dmdirc/Channel.java Wyświetl plik

@@ -24,7 +24,6 @@ package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.actions.CoreActionType;
27
-import com.dmdirc.commandparser.CommandManager;
28 27
 import com.dmdirc.commandparser.CommandType;
29 28
 import com.dmdirc.commandparser.parsers.ChannelCommandParser;
30 29
 import com.dmdirc.interfaces.NicklistListener;
@@ -39,6 +38,7 @@ import com.dmdirc.ui.Colour;
39 38
 import com.dmdirc.ui.WindowManager;
40 39
 import com.dmdirc.ui.core.components.WindowComponent;
41 40
 import com.dmdirc.ui.input.TabCompleter;
41
+import com.dmdirc.ui.input.TabCompleterFactory;
42 42
 import com.dmdirc.ui.input.TabCompletionType;
43 43
 import com.dmdirc.ui.messages.ColourManager;
44 44
 import com.dmdirc.ui.messages.Styliser;
@@ -105,6 +105,7 @@ public class Channel extends MessageTarget implements ConfigChangeListener {
105 105
      * @param newChannelInfo The parser's channel object that corresponds to this channel
106 106
      * @param focus Whether or not to focus this channel
107 107
      * @param configMigrator The config migrator which provides the config for this channel.
108
+     * @param tabCompleterFactory The factory to use to create tab completers.
108 109
      * @param messageSinkManager The sink manager to use to despatch messages.
109 110
      * @param windowManager Window management
110 111
      */
@@ -113,6 +114,7 @@ public class Channel extends MessageTarget implements ConfigChangeListener {
113 114
             final ChannelInfo newChannelInfo,
114 115
             final boolean focus,
115 116
             final ConfigProviderMigrator configMigrator,
117
+            final TabCompleterFactory tabCompleterFactory,
116 118
             final MessageSinkManager messageSinkManager,
117 119
             final WindowManager windowManager) {
118 120
         super("channel-inactive", newChannelInfo.getName(),
@@ -138,11 +140,8 @@ public class Channel extends MessageTarget implements ConfigChangeListener {
138 140
         showModePrefix = getConfigManager().getOptionBool("channel", "showmodeprefix");
139 141
         showColours = getConfigManager().getOptionBool("ui", "shownickcoloursintext");
140 142
 
141
-        tabCompleter = new TabCompleter(getConfigManager(), server.getTabCompleter());
142
-        tabCompleter.addEntries(TabCompletionType.COMMAND,
143
-                CommandManager.getCommandManager().getCommandNames(CommandType.TYPE_CHANNEL));
144
-        tabCompleter.addEntries(TabCompletionType.COMMAND,
145
-                CommandManager.getCommandManager().getCommandNames(CommandType.TYPE_CHAT));
143
+        tabCompleter = tabCompleterFactory.getTabCompleter(server.getTabCompleter(),
144
+                getConfigManager(), CommandType.TYPE_CHANNEL, CommandType.TYPE_CHAT);
146 145
 
147 146
         windowManager.addWindow(server, this, focus);
148 147
 

+ 16
- 13
src/com/dmdirc/GlobalWindow.java Wyświetl plik

@@ -22,20 +22,18 @@
22 22
 
23 23
 package com.dmdirc;
24 24
 
25
-import com.dmdirc.actions.wrappers.AliasWrapper;
26
-import com.dmdirc.commandparser.CommandManager;
25
+import com.dmdirc.ClientModule.GlobalConfig;
27 26
 import com.dmdirc.commandparser.CommandType;
28 27
 import com.dmdirc.commandparser.parsers.CommandParser;
29 28
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
30 29
 import com.dmdirc.interfaces.CommandController;
31 30
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
32 31
 import com.dmdirc.interfaces.config.ConfigChangeListener;
33
-import com.dmdirc.interfaces.config.IdentityController;
34 32
 import com.dmdirc.messages.MessageSinkManager;
35 33
 import com.dmdirc.ui.WindowManager;
36 34
 import com.dmdirc.ui.core.components.WindowComponent;
37 35
 import com.dmdirc.ui.input.TabCompleter;
38
-import com.dmdirc.ui.input.TabCompletionType;
36
+import com.dmdirc.ui.input.TabCompleterFactory;
39 37
 
40 38
 import java.util.Arrays;
41 39
 
@@ -55,6 +53,7 @@ public class GlobalWindow extends WritableFrameContainer {
55 53
 
56 54
     /** The tab completer we use. */
57 55
     @Getter
56
+    @SuppressWarnings("PMD.UnusedPrivateField")
58 57
     private final TabCompleter tabCompleter;
59 58
 
60 59
     /**
@@ -63,23 +62,21 @@ public class GlobalWindow extends WritableFrameContainer {
63 62
      * @param config The ConfigManager to retrieve settings from.
64 63
      * @param parser The command parser to use to parse input.
65 64
      * @param windowManager The window manager.
65
+     * @param tabCompleterFactory The factory to use to create tab completers.
66 66
      * @param messageSinkManager The sink manager to use to despatch messages.
67 67
      */
68 68
     public GlobalWindow(
69 69
             final AggregateConfigProvider config,
70 70
             final CommandParser parser,
71 71
             final WindowManager windowManager,
72
+            final TabCompleterFactory tabCompleterFactory,
72 73
             final MessageSinkManager messageSinkManager) {
73 74
         super("icon", "Global", "(Global)", config, parser, messageSinkManager, windowManager,
74 75
                 Arrays.asList(
75 76
                         WindowComponent.TEXTAREA.getIdentifier(),
76 77
                         WindowComponent.INPUTFIELD.getIdentifier()));
77 78
 
78
-        tabCompleter = new TabCompleter(config);
79
-        tabCompleter.addEntries(TabCompletionType.COMMAND,
80
-                CommandManager.getCommandManager().getCommandNames(CommandType.TYPE_GLOBAL));
81
-        tabCompleter.addEntries(TabCompletionType.COMMAND,
82
-                AliasWrapper.getAliasWrapper().getAliases());
79
+        tabCompleter = tabCompleterFactory.getTabCompleter(config, CommandType.TYPE_GLOBAL);
83 80
 
84 81
         windowManager.addWindow(this);
85 82
     }
@@ -124,6 +121,8 @@ public class GlobalWindow extends WritableFrameContainer {
124 121
 
125 122
         /** The global configuration to read settings from. */
126 123
         private final AggregateConfigProvider globalConfig;
124
+        /** The factory to use to create tab completers. */
125
+        private final TabCompleterFactory tabCompleterFactory;
127 126
         /** The provider to use to retrieve a command controller. */
128 127
         private final Provider<CommandController> commandControllerProvider;
129 128
         /** The provider to use to retrieve a window manager. */
@@ -134,18 +133,21 @@ public class GlobalWindow extends WritableFrameContainer {
134 133
         /**
135 134
          * Creates a new instance of {@link GlobalWindowManager}.
136 135
          *
137
-         * @param identityController Controller to retrieve global configuration from.
136
+         * @param globalConfig Configuration provider to read settings from.
137
+         * @param tabCompleterFactory Factory to use to create tab completers.
138 138
          * @param commandControllerProvider The provider to use to retrieve a command controller.
139 139
          * @param windowManagerProvider The provider to use to retrieve a window manager.
140 140
          * @param messageSinkManagerProvider The provider to use to retrieve a sink manager.
141 141
          */
142 142
         @Inject
143 143
         public GlobalWindowManager(
144
-                final IdentityController identityController,
144
+                @GlobalConfig final AggregateConfigProvider globalConfig,
145
+                final TabCompleterFactory tabCompleterFactory,
145 146
                 final Provider<CommandController> commandControllerProvider,
146 147
                 final Provider<WindowManager> windowManagerProvider,
147 148
                 final Provider<MessageSinkManager> messageSinkManagerProvider) {
148
-            this.globalConfig = identityController.getGlobalConfiguration();
149
+            this.globalConfig = globalConfig;
150
+            this.tabCompleterFactory = tabCompleterFactory;
149 151
             this.commandControllerProvider = commandControllerProvider;
150 152
             this.windowManagerProvider = windowManagerProvider;
151 153
             this.messageSinkManagerProvider = messageSinkManagerProvider;
@@ -175,7 +177,8 @@ public class GlobalWindow extends WritableFrameContainer {
175 177
                     if (globalWindow == null) {
176 178
                         globalWindow = new GlobalWindow(globalConfig,
177 179
                                 new GlobalCommandParser(globalConfig, commandControllerProvider.get()),
178
-                                windowManagerProvider.get(), messageSinkManagerProvider.get());
180
+                                windowManagerProvider.get(), tabCompleterFactory,
181
+                                messageSinkManagerProvider.get());
179 182
                     }
180 183
                 } else {
181 184
                     if (globalWindow != null) {

+ 6
- 8
src/com/dmdirc/Query.java Wyświetl plik

@@ -24,7 +24,6 @@ package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.actions.CoreActionType;
27
-import com.dmdirc.commandparser.CommandManager;
28 27
 import com.dmdirc.commandparser.CommandType;
29 28
 import com.dmdirc.commandparser.parsers.QueryCommandParser;
30 29
 import com.dmdirc.logger.ErrorLevel;
@@ -43,7 +42,7 @@ import com.dmdirc.parser.interfaces.callbacks.QuitListener;
43 42
 import com.dmdirc.ui.WindowManager;
44 43
 import com.dmdirc.ui.core.components.WindowComponent;
45 44
 import com.dmdirc.ui.input.TabCompleter;
46
-import com.dmdirc.ui.input.TabCompletionType;
45
+import com.dmdirc.ui.input.TabCompleterFactory;
47 46
 
48 47
 import java.awt.Toolkit;
49 48
 import java.util.Arrays;
@@ -74,11 +73,13 @@ public class Query extends MessageTarget implements PrivateActionListener,
74 73
      * @param newHost host of the remove client
75 74
      * @param newServer The server object that this Query belongs to
76 75
      * @param focus Should we focus the query on open?
76
+     * @param tabCompleterFactory The factory to use to create tab completers.
77 77
      * @param messageSinkManager The sink manager to use to despatch messages.
78 78
      * @param windowManager Window management
79 79
      */
80 80
     public Query(final Server newServer, final String newHost,
81
-            final boolean focus, final MessageSinkManager messageSinkManager,
81
+            final boolean focus, final TabCompleterFactory tabCompleterFactory,
82
+            final MessageSinkManager messageSinkManager,
82 83
             final WindowManager windowManager) {
83 84
         super("query", newServer.parseHostmask(newHost)[0],
84 85
                 newServer.parseHostmask(newHost)[0],
@@ -97,11 +98,8 @@ public class Query extends MessageTarget implements PrivateActionListener,
97 98
         ActionManager.getActionManager().triggerEvent(
98 99
                 CoreActionType.QUERY_OPENED, null, this);
99 100
 
100
-        tabCompleter = new TabCompleter(getConfigManager(), server.getTabCompleter());
101
-        tabCompleter.addEntries(TabCompletionType.COMMAND,
102
-                CommandManager.getCommandManager().getCommandNames(CommandType.TYPE_QUERY));
103
-        tabCompleter.addEntries(TabCompletionType.COMMAND,
104
-                CommandManager.getCommandManager().getCommandNames(CommandType.TYPE_CHAT));
101
+        tabCompleter = tabCompleterFactory.getTabCompleter(server.getTabCompleter(),
102
+                getConfigManager(), CommandType.TYPE_QUERY, CommandType.TYPE_CHAT);
105 103
 
106 104
         if (!server.getState().isDisconnected()) {
107 105
             reregister();

+ 7
- 2
src/com/dmdirc/Server.java Wyświetl plik

@@ -157,6 +157,9 @@ public class Server extends WritableFrameContainer implements ConfigChangeListen
157 157
     /** The tabcompleter used for this server. */
158 158
     private final TabCompleter tabCompleter;
159 159
 
160
+    /** The factory to give to children to create tabcompleters. */
161
+    private final TabCompleterFactory tabCompleterFactory;
162
+
160 163
     /** Our reason for being away, if any. */
161 164
     private String awayMessage;
162 165
 
@@ -249,6 +252,7 @@ public class Server extends WritableFrameContainer implements ConfigChangeListen
249 252
         this.messageSinkManager = messageSinkManager;
250 253
         this.windowManager = windowManager;
251 254
         this.configMigrator = configMigrator;
255
+        this.tabCompleterFactory = tabCompleterFactory;
252 256
 
253 257
         setConnectionDetails(uri, profile);
254 258
 
@@ -563,7 +567,8 @@ public class Server extends WritableFrameContainer implements ConfigChangeListen
563 567
         final String lnick = converter.toLowerCase(nick);
564 568
 
565 569
         if (!queries.containsKey(lnick)) {
566
-            final Query newQuery = new Query(this, host, focus, messageSinkManager, windowManager);
570
+            final Query newQuery = new Query(this, host, focus, tabCompleterFactory,
571
+                    messageSinkManager, windowManager);
567 572
 
568 573
             tabCompleter.addEntry(TabCompletionType.QUERY_NICK, nick);
569 574
             queries.put(lnick, newQuery);
@@ -658,7 +663,7 @@ public class Server extends WritableFrameContainer implements ConfigChangeListen
658 663
             final ConfigProviderMigrator channelConfig = identityFactory.createMigratableConfig(
659 664
                     getProtocol(), getIrcd(), getNetwork(), getAddress(), chan.getName());
660 665
             final Channel newChan = new Channel(this, chan, focus, channelConfig,
661
-                    messageSinkManager, windowManager);
666
+                    tabCompleterFactory, messageSinkManager, windowManager);
662 667
 
663 668
             tabCompleter.addEntry(TabCompletionType.CHANNEL, chan.getName());
664 669
             channels.put(converter.toLowerCase(chan.getName()), newChan);

Ładowanie…
Anuluj
Zapisz