Browse Source

Remove some silly AliasWrapper deps.

Don't manually iterate servers and look up the global window,
instead just use the WindowManager to find writable root windows.

This also fixes a bug whereby aliases were never removed from
the global window.

Change-Id: I8e009e03b1d48646a01b683d20712fd042628349
Reviewed-on: http://gerrit.dmdirc.com/2834
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8rc1
Chris Smith 10 years ago
parent
commit
b922ccbc12

+ 3
- 3
src/com/dmdirc/ClientModule.java View File

@@ -348,15 +348,15 @@ public class ClientModule {
348 348
      * Gets the alias actions wrapper.
349 349
      *
350 350
      * @param commandController The controller to register commands with
351
-     * @param serverManager The manager to use to iterate servers.
351
+     * @param windowManager The manager to use to iterate windows.
352 352
      * @return An alias wrapper to use in the client.
353 353
      */
354 354
     @Provides
355 355
     @Singleton
356 356
     public AliasWrapper getAliasWrapper(
357 357
             final CommandController commandController,
358
-            final ServerManager serverManager) {
359
-        final AliasWrapper wrapper = new AliasWrapper(commandController, serverManager);
358
+            final WindowManager windowManager) {
359
+        final AliasWrapper wrapper = new AliasWrapper(commandController, windowManager);
360 360
         AliasWrapper.setAliasWrapper(wrapper);
361 361
         return wrapper;
362 362
     }

+ 0
- 1
src/com/dmdirc/GlobalWindow.java View File

@@ -51,7 +51,6 @@ import lombok.Getter;
51 51
 public class GlobalWindow extends WritableFrameContainer {
52 52
 
53 53
     /** The global window that's in use, if any. */
54
-    @Getter
55 54
     private static GlobalWindow globalWindow;
56 55
 
57 56
     /** The tab completer we use. */

+ 21
- 15
src/com/dmdirc/actions/wrappers/AliasWrapper.java View File

@@ -22,9 +22,8 @@
22 22
 
23 23
 package com.dmdirc.actions.wrappers;
24 24
 
25
-import com.dmdirc.GlobalWindow;
26
-import com.dmdirc.Server;
27
-import com.dmdirc.ServerManager;
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.WritableFrameContainer;
28 27
 import com.dmdirc.actions.Action;
29 28
 import com.dmdirc.actions.ActionCondition;
30 29
 import com.dmdirc.actions.ActionGroup;
@@ -32,6 +31,7 @@ import com.dmdirc.actions.CoreActionType;
32 31
 import com.dmdirc.interfaces.CommandController;
33 32
 import com.dmdirc.logger.ErrorLevel;
34 33
 import com.dmdirc.logger.Logger;
34
+import com.dmdirc.ui.WindowManager;
35 35
 import com.dmdirc.ui.input.TabCompletionType;
36 36
 
37 37
 import java.util.ArrayList;
@@ -52,24 +52,28 @@ public class AliasWrapper extends ActionGroup {
52 52
     private final CommandController commandController;
53 53
 
54 54
     /** Server Manager. */
55
-    private final ServerManager serverManager;
55
+    private final WindowManager windowManager;
56 56
 
57 57
     /**
58 58
      * Creates a new instance of AliasWrapper.
59 59
      *
60 60
      * @param commandController Command controller to get command info from.
61
+     * @param windowManager The window manager to use to find root windows.
61 62
      */
62
-    public AliasWrapper(final CommandController commandController, final ServerManager serverManager) {
63
+    public AliasWrapper(
64
+            final CommandController commandController,
65
+            final WindowManager windowManager) {
63 66
         super("aliases");
64 67
 
65 68
         this.commandController = commandController;
66
-        this.serverManager = serverManager;
69
+        this.windowManager = windowManager;
67 70
     }
68 71
 
69 72
     /**
70 73
      * Retrieves a singleton instance of this alias wrapper.
71 74
      *
72 75
      * @return A singleton instance of AliasWrapper
76
+     * @deprecated Global state is bad.
73 77
      */
74 78
     @Deprecated
75 79
     public static AliasWrapper getAliasWrapper() {
@@ -80,6 +84,7 @@ public class AliasWrapper extends ActionGroup {
80 84
      * Sets the alias wrapper that will be used as a singleton instance.
81 85
      *
82 86
      * @param wrapper The wrapper to use as a singleton.
87
+     * @deprecated Global state is bad.
83 88
      */
84 89
     @Deprecated
85 90
     public static void setAliasWrapper(final AliasWrapper wrapper) {
@@ -106,13 +111,11 @@ public class AliasWrapper extends ActionGroup {
106 111
                 super.add(action);
107 112
                 aliases.add(commandName);
108 113
 
109
-                if (GlobalWindow.getGlobalWindow() != null) {
110
-                    GlobalWindow.getGlobalWindow().getTabCompleter()
111
-                            .addEntry(TabCompletionType.COMMAND, commandName);
112
-                }
113
-
114
-                for (Server server : serverManager.getServers()) {
115
-                    server.getTabCompleter().addEntry(TabCompletionType.COMMAND, commandName);
114
+                for (FrameContainer root : windowManager.getRootWindows()) {
115
+                    if (root instanceof WritableFrameContainer) {
116
+                        ((WritableFrameContainer) root).getTabCompleter()
117
+                                .addEntry(TabCompletionType.COMMAND, commandName);
118
+                    }
116 119
                 }
117 120
             } else {
118 121
                 Logger.userError(ErrorLevel.MEDIUM, "Invalid alias action (no name): "
@@ -134,8 +137,11 @@ public class AliasWrapper extends ActionGroup {
134 137
 
135 138
             aliases.remove(commandName);
136 139
 
137
-            for (Server server : serverManager.getServers()) {
138
-                server.getTabCompleter().removeEntry(TabCompletionType.COMMAND, commandName);
140
+            for (FrameContainer root : windowManager.getRootWindows()) {
141
+                if (root instanceof WritableFrameContainer) {
142
+                    ((WritableFrameContainer) root).getTabCompleter()
143
+                            .removeEntry(TabCompletionType.COMMAND, commandName);
144
+                }
139 145
             }
140 146
         }
141 147
     }

+ 3
- 3
test/com/dmdirc/actions/wrappers/AliasWrapperTest.java View File

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.actions.wrappers;
24 24
 
25
-import com.dmdirc.ServerManager;
26 25
 import com.dmdirc.actions.Action;
27 26
 import com.dmdirc.actions.ActionCondition;
28 27
 import com.dmdirc.actions.CoreActionComparison;
@@ -32,6 +31,7 @@ import com.dmdirc.interfaces.CommandController;
32 31
 import com.dmdirc.interfaces.actions.ActionType;
33 32
 import com.dmdirc.logger.ErrorManager;
34 33
 import com.dmdirc.logger.Logger;
34
+import com.dmdirc.ui.WindowManager;
35 35
 
36 36
 import java.util.ArrayList;
37 37
 import java.util.List;
@@ -51,7 +51,7 @@ public class AliasWrapperTest {
51 51
 
52 52
     @Mock private Action action;
53 53
     @Mock private ActionCondition condition;
54
-    @Mock private ServerManager serverManager;
54
+    @Mock private WindowManager windowManager;
55 55
     @Mock private CommandController commandController;
56 56
     private List<ActionCondition> conditions;
57 57
 
@@ -68,7 +68,7 @@ public class AliasWrapperTest {
68 68
         when(commandController.getCommandChar()).thenReturn('!');
69 69
 
70 70
         conditions = new ArrayList<>();
71
-        aliasWrapper = new AliasWrapper(commandController, serverManager);
71
+        aliasWrapper = new AliasWrapper(commandController, windowManager);
72 72
 
73 73
         when(condition.getArg()).thenReturn(1);
74 74
         when(condition.getComparison()).thenReturn(CoreActionComparison.STRING_EQUALS);

Loading…
Cancel
Save