Bladeren bron

Always specify an origin when parsing commands.

Where commands are executed globally, pass in a GlobalWindow.

Make the GlobalWindow a singleton that persists, and is simply
added/removed from the WindowManager when the user wants to
show/hide it.

Change-Id: Iac94848487442509bdbf8ec98f67983e313ed743
Reviewed-on: http://gerrit.dmdirc.com/3451
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
pull/1/head
Chris Smith 10 jaren geleden
bovenliggende
commit
09cb002be2

+ 4
- 3
src/com/dmdirc/FrameContainer.java Bestand weergeven

@@ -362,11 +362,12 @@ public abstract class FrameContainer {
362 362
     }
363 363
 
364 364
     /**
365
-     * Closes this container (and it's associated frame).
365
+     * Closes this container (and its associated frame).
366 366
      */
367 367
     public void close() {
368 368
         for (FrameCloseListener listener : listeners.get(FrameCloseListener.class)) {
369 369
             listener.windowClosing(this);
370
+            listeners.remove(FrameCloseListener.class, listener);
370 371
         }
371 372
     }
372 373
 
@@ -530,9 +531,9 @@ public abstract class FrameContainer {
530 531
     }
531 532
 
532 533
     /**
533
-     * Adds a close listener for this frame container.
534
+     * Adds a close listener for this frame container. Close listeners will only be called once,
535
+     * even if the container is closed, re-added, and closed again.
534 536
      *
535
-     * @since 0.6.5
536 537
      * @param listener The listener to be added
537 538
      */
538 539
     public void addCloseListener(final FrameCloseListener listener) {

+ 28
- 53
src/com/dmdirc/GlobalWindow.java Bestand weergeven

@@ -24,7 +24,6 @@ package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26 26
 import com.dmdirc.commandparser.CommandType;
27
-import com.dmdirc.commandparser.parsers.CommandParser;
28 27
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
29 28
 import com.dmdirc.interfaces.Connection;
30 29
 import com.dmdirc.interfaces.FrameCloseListener;
@@ -47,6 +46,7 @@ import javax.inject.Singleton;
47 46
 /**
48 47
  * A window which can be used to execute global commands.
49 48
  */
49
+@Singleton
50 50
 public class GlobalWindow extends FrameContainer {
51 51
 
52 52
     /**
@@ -59,9 +59,10 @@ public class GlobalWindow extends FrameContainer {
59 59
      * @param urlBuilder          The URL builder to use when finding icons.
60 60
      * @param eventBus            The bus to despatch events on.
61 61
      */
62
+    @Inject
62 63
     public GlobalWindow(
63
-            final AggregateConfigProvider config,
64
-            final CommandParser parser,
64
+            @GlobalConfig final AggregateConfigProvider config,
65
+            final GlobalCommandParser parser,
65 66
             final TabCompleterFactory tabCompleterFactory,
66 67
             final MessageSinkManager messageSinkManager,
67 68
             final URLBuilder urlBuilder,
@@ -93,51 +94,28 @@ public class GlobalWindow extends FrameContainer {
93 94
     @Singleton
94 95
     public static class GlobalWindowManager implements ConfigChangeListener {
95 96
 
97
+        /** Provider to use to obtain global window instances. */
98
+        private final Provider<GlobalWindow> globalWindowProvider;
96 99
         /** The global configuration to read settings from. */
97 100
         private final AggregateConfigProvider globalConfig;
98
-        /** The factory to use to create tab completers. */
99
-        private final TabCompleterFactory tabCompleterFactory;
100 101
         /** The provider to use to retrieve a window manager. */
101 102
         private final Provider<WindowManager> windowManagerProvider;
102
-        /** The provider to use to retrieve message sink managers. */
103
-        private final Provider<MessageSinkManager> messageSinkManagerProvider;
104
-        /** The provider to use to retrieve a global command parser. */
105
-        private final Provider<GlobalCommandParser> globalCommandParserProvider;
106
-        /** The URL builder to use when finding icons. */
107
-        private final URLBuilder urlBuilder;
108
-        /** The bus to despatch events on. */
109
-        private final EventBus eventBus;
110
-        /** The global window that's in use, if any. */
111
-        private GlobalWindow globalWindow;
112 103
 
113 104
         /**
114 105
          * Creates a new instance of {@link GlobalWindowManager}.
115 106
          *
116
-         * @param globalConfig                Configuration provider to read settings from.
117
-         * @param tabCompleterFactory         Factory to use to create tab completers.
118
-         * @param windowManagerProvider       The provider to use to retrieve a window manager.
119
-         * @param messageSinkManagerProvider  The provider to use to retrieve a sink manager.
120
-         * @param globalCommandParserProvider The provider to use to retrieve a global command
121
-         *                                    parser.
122
-         * @param urlBuilder                  The URL builder to use when finding icons.
123
-         * @param eventBus                    The bus to despatch events on.
107
+         * @param globalWindowProvider  The provider to use to obtain global windows.
108
+         * @param globalConfig          Configuration provider to read settings from.
109
+         * @param windowManagerProvider The provider to use to retrieve a window manager.
124 110
          */
125 111
         @Inject
126 112
         public GlobalWindowManager(
113
+                final Provider<GlobalWindow> globalWindowProvider,
127 114
                 @GlobalConfig final AggregateConfigProvider globalConfig,
128
-                final TabCompleterFactory tabCompleterFactory,
129
-                final Provider<WindowManager> windowManagerProvider,
130
-                final Provider<MessageSinkManager> messageSinkManagerProvider,
131
-                final Provider<GlobalCommandParser> globalCommandParserProvider,
132
-                final URLBuilder urlBuilder,
133
-                final EventBus eventBus) {
115
+                final Provider<WindowManager> windowManagerProvider) {
116
+            this.globalWindowProvider = globalWindowProvider;
134 117
             this.globalConfig = globalConfig;
135
-            this.tabCompleterFactory = tabCompleterFactory;
136 118
             this.windowManagerProvider = windowManagerProvider;
137
-            this.messageSinkManagerProvider = messageSinkManagerProvider;
138
-            this.globalCommandParserProvider = globalCommandParserProvider;
139
-            this.urlBuilder = urlBuilder;
140
-            this.eventBus = eventBus;
141 119
         }
142 120
 
143 121
         @Override
@@ -158,22 +136,19 @@ public class GlobalWindow extends FrameContainer {
158 136
          * setting.
159 137
          */
160 138
         protected void updateWindowState() {
161
-            synchronized (GlobalWindow.class) {
162
-                if (globalConfig.getOptionBool("general", "showglobalwindow")) {
163
-                    if (globalWindow == null) {
164
-                        globalWindow = new GlobalWindow(globalConfig,
165
-                                globalCommandParserProvider.get(),
166
-                                tabCompleterFactory,
167
-                                messageSinkManagerProvider.get(),
168
-                                urlBuilder,
169
-                                eventBus);
170
-                        addCloseListener(globalWindow);
171
-                        windowManagerProvider.get().addWindow(globalWindow);
172
-                    }
173
-                } else {
174
-                    if (globalWindow != null) {
175
-                        globalWindow.close();
176
-                    }
139
+            final WindowManager windowManager = windowManagerProvider.get();
140
+            final GlobalWindow globalWindow = globalWindowProvider.get();
141
+            final boolean globalWindowExists = windowManager.getRootWindows()
142
+                    .contains(globalWindow);
143
+
144
+            if (globalConfig.getOptionBool("general", "showglobalwindow")) {
145
+                if (!globalWindowExists) {
146
+                    addCloseListener(globalWindow);
147
+                    windowManager.addWindow(globalWindow);
148
+                }
149
+            } else {
150
+                if (globalWindowExists) {
151
+                    globalWindow.close();
177 152
                 }
178 153
             }
179 154
         }
@@ -181,14 +156,14 @@ public class GlobalWindow extends FrameContainer {
181 156
         /**
182 157
          * Adds a {@link FrameCloseListener} to the specified window to update the global window
183 158
          * state if the user closes it from the UI.
159
+         *
160
+         * @param window The window to add a listener to.
184 161
          */
185 162
         private void addCloseListener(final GlobalWindow window) {
186 163
             window.addCloseListener(new FrameCloseListener() {
187 164
                 @Override
188 165
                 public void windowClosing(final FrameContainer container) {
189
-                    synchronized (GlobalWindow.class) {
190
-                        globalWindow = null;
191
-                    }
166
+                    container.removeCloseListener(this);
192 167
                 }
193 168
             });
194 169
         }

+ 8
- 3
src/com/dmdirc/actions/Action.java Bestand weergeven

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.actions;
24 24
 
25
+import com.dmdirc.GlobalWindow;
25 26
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
26 27
 import com.dmdirc.config.prefs.PreferencesSetting;
27 28
 import com.dmdirc.config.prefs.PreferencesType;
@@ -82,6 +83,7 @@ public class Action extends ActionModel implements ConfigChangeListener {
82 83
      * a valid action already saved to disk.
83 84
      *
84 85
      * @param globalCommandParserProvider Provider of global command parsers for triggering actions.
86
+     * @param globalWindowProvider        Provider of global windows for triggering actions.
85 87
      * @param substitutorFactory          Factory to use to create action substitutors.
86 88
      * @param actionController            The controller that owns this action.
87 89
      * @param identityController          The controller to use to retrieve and update settings.
@@ -91,13 +93,14 @@ public class Action extends ActionModel implements ConfigChangeListener {
91 93
      */
92 94
     public Action(
93 95
             final Provider<GlobalCommandParser> globalCommandParserProvider,
96
+            final Provider<GlobalWindow> globalWindowProvider,
94 97
             final ActionSubstitutorFactory substitutorFactory,
95 98
             final ActionController actionController,
96 99
             final IdentityController identityController,
97 100
             final String actionsDirectory,
98 101
             final String group,
99 102
             final String name) {
100
-        super(globalCommandParserProvider, substitutorFactory, group, name);
103
+        super(globalCommandParserProvider, globalWindowProvider, substitutorFactory, group, name);
101 104
 
102 105
         this.actionController = actionController;
103 106
         this.identityController = identityController;
@@ -124,6 +127,7 @@ public class Action extends ActionModel implements ConfigChangeListener {
124 127
      * Creates a new instance of Action with the specified properties and saves it to disk.
125 128
      *
126 129
      * @param globalCommandParserProvider Provider of global command parsers for triggering actions.
130
+     * @param globalWindowProvider        Provider of global windows for triggering actions.
127 131
      * @param substitutorFactory          Factory to use to create action substitutors.
128 132
      * @param actionController            The controller that owns this action.
129 133
      * @param identityController          The controller to use to retrieve and update settings.
@@ -138,6 +142,7 @@ public class Action extends ActionModel implements ConfigChangeListener {
138 142
      */
139 143
     public Action(
140 144
             final Provider<GlobalCommandParser> globalCommandParserProvider,
145
+            final Provider<GlobalWindow> globalWindowProvider,
141 146
             final ActionSubstitutorFactory substitutorFactory,
142 147
             final ActionController actionController,
143 148
             final IdentityController identityController,
@@ -149,8 +154,8 @@ public class Action extends ActionModel implements ConfigChangeListener {
149 154
             final List<ActionCondition> conditions,
150 155
             final ConditionTree conditionTree,
151 156
             final String newFormat) {
152
-        super(globalCommandParserProvider, substitutorFactory, group, name, triggers, response,
153
-                conditions, conditionTree, newFormat);
157
+        super(globalCommandParserProvider, globalWindowProvider, substitutorFactory, group, name,
158
+                triggers, response, conditions, conditionTree, newFormat);
154 159
 
155 160
         this.actionController = actionController;
156 161
         this.identityController = identityController;

+ 29
- 5
src/com/dmdirc/actions/ActionFactory.java Bestand weergeven

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.actions;
24 24
 
25
+import com.dmdirc.GlobalWindow;
25 26
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
26 27
 import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
27 28
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
@@ -47,6 +48,8 @@ public class ActionFactory {
47 48
     private final Provider<ActionController> actionController;
48 49
     /** The controller to use to retrieve and update settings. */
49 50
     private final Provider<IdentityController> identityController;
51
+    /** The global window to use for actions without windows. */
52
+    private final Provider<GlobalWindow> globalWindowProvider;
50 53
     /** The factory to use to create substitutors. */
51 54
     private final ActionSubstitutorFactory substitutorFactory;
52 55
     /** The base directory to store actions in. */
@@ -59,6 +62,7 @@ public class ActionFactory {
59 62
      * @param identityController          The controller to use to retrieve and update settings.
60 63
      * @param globalCommandParserProvider The global command parser to use for actions without
61 64
      *                                    windows.
65
+     * @param globalWindowProvider        The global window to use for actions without windows.
62 66
      * @param substitutorFactory          The factory to use to create substitutors.
63 67
      * @param actionsDirectory            The base directory to store actions in.
64 68
      */
@@ -67,11 +71,13 @@ public class ActionFactory {
67 71
             final Provider<ActionController> actionController,
68 72
             final Provider<IdentityController> identityController,
69 73
             final Provider<GlobalCommandParser> globalCommandParserProvider,
74
+            final Provider<GlobalWindow> globalWindowProvider,
70 75
             final ActionSubstitutorFactory substitutorFactory,
71 76
             @Directory(DirectoryType.ACTIONS) final String actionsDirectory) {
72 77
         this.actionController = actionController;
73 78
         this.identityController = identityController;
74 79
         this.globalCommandParserProvider = globalCommandParserProvider;
80
+        this.globalWindowProvider = globalWindowProvider;
75 81
         this.substitutorFactory = substitutorFactory;
76 82
         this.actionsDirectory = actionsDirectory;
77 83
     }
@@ -86,8 +92,15 @@ public class ActionFactory {
86 92
      * @return A relevant action.
87 93
      */
88 94
     public Action getAction(final String group, final String name) {
89
-        return new Action(globalCommandParserProvider, substitutorFactory, actionController.get(),
90
-                identityController.get(), actionsDirectory, group, name);
95
+        return new Action(
96
+                globalCommandParserProvider,
97
+                globalWindowProvider,
98
+                substitutorFactory,
99
+                actionController.get(),
100
+                identityController.get(),
101
+                actionsDirectory,
102
+                group,
103
+                name);
91 104
     }
92 105
 
93 106
     /**
@@ -107,9 +120,20 @@ public class ActionFactory {
107 120
             final ActionType[] triggers, final String[] response,
108 121
             final List<ActionCondition> conditions,
109 122
             final ConditionTree conditionTree, final String newFormat) {
110
-        return new Action(globalCommandParserProvider, substitutorFactory, actionController.get(),
111
-                identityController.get(), actionsDirectory, group,
112
-                name, triggers, response, conditions, conditionTree, newFormat);
123
+        return new Action(
124
+                globalCommandParserProvider,
125
+                globalWindowProvider,
126
+                substitutorFactory,
127
+                actionController.get(),
128
+                identityController.get(),
129
+                actionsDirectory,
130
+                group,
131
+                name,
132
+                triggers,
133
+                response,
134
+                conditions,
135
+                conditionTree,
136
+                newFormat);
113 137
     }
114 138
 
115 139
 }

+ 15
- 12
src/com/dmdirc/actions/ActionModel.java Bestand weergeven

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.actions;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
+import com.dmdirc.GlobalWindow;
26 27
 import com.dmdirc.Precondition;
27 28
 import com.dmdirc.ServerManager;
28 29
 import com.dmdirc.commandparser.parsers.CommandParser;
@@ -41,8 +42,12 @@ import javax.inject.Provider;
41 42
  */
42 43
 public class ActionModel {
43 44
 
45
+    // TODO: Sort out the mess of protected fields here.
46
+
44 47
     /** Provider of global command parsers, for use when triggering window-less actions. */
45 48
     private final Provider<GlobalCommandParser> globalCommandParserProvider;
49
+    /** Provider of global windows for global actions. */
50
+    private final Provider<GlobalWindow> globalWindowProvider;
46 51
     /** Factory to use to creator substitutors. */
47 52
     private final ActionSubstitutorFactory substitutorFactory;
48 53
     /** The group this action belongs to. */
@@ -75,17 +80,20 @@ public class ActionModel {
75 80
     /**
76 81
      * Creates a new instance of ActionModel with the specified properties.
77 82
      *
78
-     * @param globalCommandParserProvider Provider of global command parsers for triggering actions.
83
+     * @param globalCommandParserProvider Provider of global command parsers for global actions.
84
+     * @param globalWindowProvider        Provider of global windows for global actions.
79 85
      * @param substitutorFactory          Factory to use to create action substitutors.
80 86
      * @param group                       The group the action belongs to
81 87
      * @param name                        The name of the action
82 88
      */
83 89
     public ActionModel(
84 90
             final Provider<GlobalCommandParser> globalCommandParserProvider,
91
+            final Provider<GlobalWindow> globalWindowProvider,
85 92
             final ActionSubstitutorFactory substitutorFactory,
86 93
             final String group,
87 94
             final String name) {
88 95
         this.globalCommandParserProvider = globalCommandParserProvider;
96
+        this.globalWindowProvider = globalWindowProvider;
89 97
         this.substitutorFactory = substitutorFactory;
90 98
         this.group = group;
91 99
         this.name = name;
@@ -95,6 +103,7 @@ public class ActionModel {
95 103
      * Creates a new instance of ActionModel with the specified properties.
96 104
      *
97 105
      * @param globalCommandParserProvider Provider of global command parsers for triggering actions.
106
+     * @param globalWindowProvider        Provider of global windows for global actions.
98 107
      * @param substitutorFactory          Factory to use to create action substitutors.
99 108
      * @param group                       The group the action belongs to
100 109
      * @param name                        The name of the action
@@ -106,12 +115,13 @@ public class ActionModel {
106 115
      */
107 116
     public ActionModel(
108 117
             final Provider<GlobalCommandParser> globalCommandParserProvider,
118
+            final Provider<GlobalWindow> globalWindowProvider,
109 119
             final ActionSubstitutorFactory substitutorFactory,
110 120
             final String group, final String name,
111 121
             final ActionType[] triggers, final String[] response,
112 122
             final List<ActionCondition> conditions,
113 123
             final ConditionTree conditionTree, final String newFormat) {
114
-        this(globalCommandParserProvider, substitutorFactory, group, name);
124
+        this(globalCommandParserProvider, globalWindowProvider, substitutorFactory, group, name);
115 125
         this.triggers = triggers.clone();
116 126
         this.response = response.clone();
117 127
         this.conditions = conditions;
@@ -149,22 +159,15 @@ public class ActionModel {
149 159
             return false;
150 160
         }
151 161
 
152
-        FrameContainer container = null;
153
-        CommandParser cp;
154
-
162
+        final FrameContainer container;
155 163
         if (arguments.length > 0 && arguments[0] instanceof FrameContainer
156 164
                 && ((FrameContainer) arguments[0]).isWritable()) {
157 165
             container = (FrameContainer) arguments[0];
158
-        } else if (serverManager.numServers() > 0) {
159
-            container = serverManager.getServers().get(0);
160
-        }
161
-
162
-        if (container == null) {
163
-            cp = globalCommandParserProvider.get();
164 166
         } else {
165
-            cp = container.getCommandParser();
167
+            container = globalWindowProvider.get();
166 168
         }
167 169
 
170
+        final CommandParser cp = container.getCommandParser();
168 171
         for (String command : response) {
169 172
             cp.parseCommand(container, sub.doSubstitution(command, arguments));
170 173
         }

+ 8
- 2
src/com/dmdirc/commandparser/commands/global/Ifplugin.java Bestand weergeven

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.commandparser.commands.global;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
+import com.dmdirc.GlobalWindow;
26 27
 import com.dmdirc.commandparser.BaseCommandInfo;
27 28
 import com.dmdirc.commandparser.CommandArguments;
28 29
 import com.dmdirc.commandparser.CommandInfo;
@@ -55,6 +56,8 @@ public class Ifplugin extends Command implements IntelligentCommand {
55 56
     private final PluginManager pluginManager;
56 57
     /** Provider of global command parsers. */
57 58
     private final Provider<GlobalCommandParser> globalCommandParserProvider;
59
+    /** Proivder of global windows. */
60
+    private final Provider<GlobalWindow> globalWindowProvider;
58 61
 
59 62
     /**
60 63
      * Creates a new instance of the {@link Ifplugin} command.
@@ -62,15 +65,18 @@ public class Ifplugin extends Command implements IntelligentCommand {
62 65
      * @param controller                  The controller to use for command information.
63 66
      * @param pluginManager               The plugin manager to use to query plugins.
64 67
      * @param globalCommandParserProvider Provider to use to retrieve a global command parser.
68
+     * @param globalWindowProvider        Provider to use to retrieve a global window.
65 69
      */
66 70
     @Inject
67 71
     public Ifplugin(
68 72
             final CommandController controller,
69 73
             final PluginManager pluginManager,
70
-            final Provider<GlobalCommandParser> globalCommandParserProvider) {
74
+            final Provider<GlobalCommandParser> globalCommandParserProvider,
75
+            final Provider<GlobalWindow> globalWindowProvider) {
71 76
         super(controller);
72 77
         this.pluginManager = pluginManager;
73 78
         this.globalCommandParserProvider = globalCommandParserProvider;
79
+        this.globalWindowProvider = globalWindowProvider;
74 80
     }
75 81
 
76 82
     @Override
@@ -96,7 +102,7 @@ public class Ifplugin extends Command implements IntelligentCommand {
96 102
         if (result != negative) {
97 103
             if (origin == null || !origin.isWritable()) {
98 104
                 globalCommandParserProvider.get()
99
-                        .parseCommand(null, args.getArgumentsAsString(1));
105
+                        .parseCommand(globalWindowProvider.get(), args.getArgumentsAsString(1));
100 106
             } else {
101 107
                 origin.getCommandParser().parseCommand(origin, args.getArgumentsAsString(1));
102 108
             }

+ 11
- 6
src/com/dmdirc/commandparser/parsers/CommandParser.java Bestand weergeven

@@ -44,6 +44,10 @@ import java.io.Serializable;
44 44
 import java.util.HashMap;
45 45
 import java.util.Map;
46 46
 
47
+import javax.annotation.Nonnull;
48
+
49
+import static com.google.common.base.Preconditions.checkNotNull;
50
+
47 51
 /**
48 52
  * Represents a generic command parser. A command parser takes a line of input from the user,
49 53
  * determines if it is an attempt at executing a command (based on the character at the start of the
@@ -135,10 +139,11 @@ public abstract class CommandParser implements Serializable {
135 139
      *
136 140
      * @since 0.6.4
137 141
      */
138
-    public final void parseCommand(final FrameContainer origin,
139
-            final String line, final boolean parseChannel) {
140
-        final CommandArguments args = new CommandArguments(commandManager, line);
142
+    public final void parseCommand(@Nonnull final FrameContainer origin, final String line,
143
+            final boolean parseChannel) {
144
+        checkNotNull(origin);
141 145
 
146
+        final CommandArguments args = new CommandArguments(commandManager, line);
142 147
         if (args.isCommand()) {
143 148
             if (handleChannelCommand(origin, args, parseChannel)) {
144 149
                 return;
@@ -170,13 +175,13 @@ public abstract class CommandParser implements Serializable {
170 175
      *
171 176
      * @return True iff the command was handled, false otherwise
172 177
      */
173
-    protected boolean handleChannelCommand(final FrameContainer origin,
178
+    protected boolean handleChannelCommand(@Nonnull final FrameContainer origin,
174 179
             final CommandArguments args, final boolean parseChannel) {
175 180
         final boolean silent = args.isSilent();
176 181
         final String command = args.getCommandName();
177 182
         final String[] cargs = args.getArguments();
178 183
 
179
-        if (cargs.length == 0 || !parseChannel || origin == null
184
+        if (cargs.length == 0 || !parseChannel
180 185
                 || origin.getConnection() == null
181 186
                 || !commandManager.isChannelCommand(command)) {
182 187
             return false;
@@ -265,7 +270,7 @@ public abstract class CommandParser implements Serializable {
265 270
      *
266 271
      * @since 0.6.4
267 272
      */
268
-    public void parseCommand(final FrameContainer origin, final String line) {
273
+    public void parseCommand(@Nonnull final FrameContainer origin, final String line) {
269 274
         parseCommand(origin, line, true);
270 275
     }
271 276
 

+ 22
- 9
test/com/dmdirc/actions/ActionModelTest.java Bestand weergeven

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.actions;
24 24
 
25
+import com.dmdirc.GlobalWindow;
25 26
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
26 27
 import com.dmdirc.interfaces.ActionController;
27 28
 import com.dmdirc.interfaces.CommandController;
@@ -39,12 +40,16 @@ import org.junit.runner.RunWith;
39 40
 import org.mockito.Mock;
40 41
 import org.mockito.runners.MockitoJUnitRunner;
41 42
 
42
-import static org.junit.Assert.*;
43
+import static org.junit.Assert.assertEquals;
44
+import static org.junit.Assert.assertFalse;
45
+import static org.junit.Assert.assertNull;
46
+import static org.junit.Assert.assertTrue;
43 47
 
44 48
 @RunWith(MockitoJUnitRunner.class)
45 49
 public class ActionModelTest {
46 50
 
47 51
     @Mock private Provider<GlobalCommandParser> gcpProvider;
52
+    @Mock private Provider<GlobalWindow> gwProvider;
48 53
     @Mock private ActionSubstitutorFactory substitutorFactory;
49 54
     @Mock private ActionController actionController;
50 55
     @Mock private CommandController commandController;
@@ -52,7 +57,8 @@ public class ActionModelTest {
52 57
 
53 58
     @Test
54 59
     public void testConditions() {
55
-        final ActionModel model = new ActionModel(gcpProvider, substitutorFactory, "group", "name");
60
+        final ActionModel model = new ActionModel(gcpProvider, gwProvider, substitutorFactory,
61
+                "group", "name");
56 62
 
57 63
         assertTrue("ActionModel must start with no conditions",
58 64
                 model.getConditions().isEmpty());
@@ -67,7 +73,8 @@ public class ActionModelTest {
67 73
 
68 74
     @Test
69 75
     public void testTriggers() {
70
-        final ActionModel model = new ActionModel(gcpProvider, substitutorFactory, "group", "name");
76
+        final ActionModel model = new ActionModel(gcpProvider, gwProvider, substitutorFactory,
77
+                "group", "name");
71 78
 
72 79
         assertNull("ActionModel must start with null triggers",
73 80
                 model.getTriggers());
@@ -82,7 +89,8 @@ public class ActionModelTest {
82 89
 
83 90
     @Test
84 91
     public void testNewFormat() {
85
-        final ActionModel model = new ActionModel(gcpProvider, substitutorFactory, "group", "name");
92
+        final ActionModel model = new ActionModel(gcpProvider, gwProvider, substitutorFactory,
93
+                "group", "name");
86 94
 
87 95
         assertNull("ActionModel must start with null format",
88 96
                 model.getNewFormat());
@@ -100,7 +108,8 @@ public class ActionModelTest {
100 108
 
101 109
     @Test
102 110
     public void testResponse() {
103
-        final ActionModel model = new ActionModel(gcpProvider, substitutorFactory, "group", "name");
111
+        final ActionModel model = new ActionModel(gcpProvider, gwProvider, substitutorFactory,
112
+                "group", "name");
104 113
 
105 114
         assertNull("ActionModel must start with null response",
106 115
                 model.getResponse());
@@ -115,7 +124,8 @@ public class ActionModelTest {
115 124
 
116 125
     @Test
117 126
     public void testGroup() {
118
-        final ActionModel model = new ActionModel(gcpProvider, substitutorFactory, "group", "name");
127
+        final ActionModel model = new ActionModel(gcpProvider, gwProvider, substitutorFactory,
128
+                "group", "name");
119 129
 
120 130
         assertEquals("ActionModel constructor must set group",
121 131
                 "group", model.getGroup());
@@ -128,7 +138,8 @@ public class ActionModelTest {
128 138
 
129 139
     @Test
130 140
     public void testName() {
131
-        final ActionModel model = new ActionModel(gcpProvider, substitutorFactory, "group", "name");
141
+        final ActionModel model = new ActionModel(gcpProvider, gwProvider, substitutorFactory,
142
+                "group", "name");
132 143
 
133 144
         assertEquals("ActionModel constructor must set name",
134 145
                 "name", model.getName());
@@ -141,7 +152,8 @@ public class ActionModelTest {
141 152
 
142 153
     @Test
143 154
     public void testTest() {
144
-        final ActionModel model = new ActionModel(gcpProvider, substitutorFactory, "group", "name",
155
+        final ActionModel model = new ActionModel(gcpProvider, gwProvider, substitutorFactory,
156
+                "group", "name",
145 157
                 new ActionType[]{CoreActionType.CHANNEL_ACTION},
146 158
                 new String[0], Arrays.asList(new ActionCondition[]{
147 159
                     new ActionCondition(2, CoreActionComponent.STRING_STRING,
@@ -162,7 +174,8 @@ public class ActionModelTest {
162 174
 
163 175
     @Test
164 176
     public void testTestNoCondTree() {
165
-        final ActionModel model = new ActionModel(gcpProvider, substitutorFactory, "group", "name",
177
+        final ActionModel model = new ActionModel(gcpProvider, gwProvider, substitutorFactory,
178
+                "group", "name",
166 179
                 new ActionType[]{CoreActionType.CHANNEL_ACTION},
167 180
                 new String[0], Arrays.asList(new ActionCondition[]{
168 181
                     new ActionCondition(2, CoreActionComponent.STRING_STRING,

+ 9
- 7
test/com/dmdirc/actions/ActionTest.java Bestand weergeven

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.actions;
24 24
 
25
+import com.dmdirc.GlobalWindow;
25 26
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
26 27
 import com.dmdirc.config.prefs.PreferencesSetting;
27 28
 import com.dmdirc.config.prefs.PreferencesType;
@@ -68,6 +69,7 @@ public class ActionTest {
68 69
     @Rule public final TemporaryFolder folder = new TemporaryFolder();
69 70
 
70 71
     @Mock private Provider<GlobalCommandParser> gcpProvider;
72
+    @Mock private Provider<GlobalWindow> gwProvider;
71 73
     @Mock private ActionSubstitutorFactory substitutorFactory;
72 74
     @Mock private ActionController actionController;
73 75
     @Mock private ActionGroup actionGroup;
@@ -103,8 +105,8 @@ public class ActionTest {
103 105
 
104 106
     @Test
105 107
     public void testSave() {
106
-        new Action(gcpProvider, substitutorFactory, actionController, identityController,
107
-                getTempDirectory(), "unit-test", "test1", new ActionType[0],
108
+        new Action(gcpProvider, gwProvider, substitutorFactory, actionController,
109
+                identityController, getTempDirectory(), "unit-test", "test1", new ActionType[0],
108 110
                 new String[0], new ArrayList<ActionCondition>(),
109 111
                 ConditionTree.createConjunction(0), null);
110 112
         assertTrue("Action constructor must create new file",
@@ -114,7 +116,7 @@ public class ActionTest {
114 116
 
115 117
     @Test
116 118
     public void testSetGroup() {
117
-        Action action = new Action(gcpProvider, substitutorFactory, actionController,
119
+        Action action = new Action(gcpProvider, gwProvider, substitutorFactory, actionController,
118 120
                 identityController, getTempDirectory(),
119 121
                 "unit-test", "test1", new ActionType[0],
120 122
                 new String[0], new ArrayList<ActionCondition>(),
@@ -131,7 +133,7 @@ public class ActionTest {
131 133
 
132 134
     @Test
133 135
     public void testSetName() {
134
-        Action action = new Action(gcpProvider, substitutorFactory, actionController,
136
+        Action action = new Action(gcpProvider, gwProvider, substitutorFactory, actionController,
135 137
                 identityController, getTempDirectory(),
136 138
                 "unit-test", "test1", new ActionType[0],
137 139
                 new String[0], new ArrayList<ActionCondition>(),
@@ -148,7 +150,7 @@ public class ActionTest {
148 150
 
149 151
     @Test
150 152
     public void testDelete() {
151
-        Action action = new Action(gcpProvider, substitutorFactory, actionController,
153
+        Action action = new Action(gcpProvider, gwProvider, substitutorFactory, actionController,
152 154
                 identityController, getTempDirectory(),
153 155
                 "unit-test", "test1", new ActionType[0],
154 156
                 new String[0], new ArrayList<ActionCondition>(),
@@ -162,7 +164,7 @@ public class ActionTest {
162 164
 
163 165
     @Test
164 166
     public void testRead() throws IOException, InvalidConfigFileException {
165
-        Action action = new Action(gcpProvider, substitutorFactory, actionController,
167
+        Action action = new Action(gcpProvider, gwProvider, substitutorFactory, actionController,
166 168
                 identityController, getTempDirectory(),
167 169
                 "unit-test", "doesn't_exist");
168 170
         action.config = new ConfigFile(getClass().getResourceAsStream("action1"));
@@ -181,7 +183,7 @@ public class ActionTest {
181 183
 
182 184
     @Test
183 185
     public void testMultipleGroups() throws IOException, InvalidConfigFileException {
184
-        Action action = new Action(gcpProvider, substitutorFactory, actionController,
186
+        Action action = new Action(gcpProvider, gwProvider, substitutorFactory, actionController,
185 187
                 identityController, getTempDirectory(),
186 188
                 "unit-test", "doesn't_exist");
187 189
         action.config = new ConfigFile(getClass().getResourceAsStream("action_multisettings"));

+ 8
- 2
test/com/dmdirc/commandparser/commands/global/IfpluginTest.java Bestand weergeven

@@ -22,6 +22,7 @@
22 22
 package com.dmdirc.commandparser.commands.global;
23 23
 
24 24
 import com.dmdirc.FrameContainer;
25
+import com.dmdirc.GlobalWindow;
25 26
 import com.dmdirc.commandparser.CommandArguments;
26 27
 import com.dmdirc.commandparser.commands.context.CommandContext;
27 28
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
@@ -29,17 +30,22 @@ import com.dmdirc.interfaces.CommandController;
29 30
 import com.dmdirc.plugins.PluginManager;
30 31
 
31 32
 import javax.inject.Provider;
33
+
32 34
 import org.junit.Before;
33 35
 import org.junit.Test;
34 36
 import org.junit.runner.RunWith;
35 37
 import org.mockito.Mock;
36 38
 import org.mockito.runners.MockitoJUnitRunner;
37 39
 
38
-import static org.mockito.Mockito.*;
40
+import static org.mockito.Matchers.anyChar;
41
+import static org.mockito.Matchers.anyString;
42
+import static org.mockito.Matchers.eq;
43
+import static org.mockito.Mockito.verify;
39 44
 
40 45
 @RunWith(MockitoJUnitRunner.class)
41 46
 public class IfpluginTest {
42 47
 
48
+    @Mock private Provider<GlobalWindow> gwProvider;
43 49
     @Mock private Provider<GlobalCommandParser> gcpProvider;
44 50
     @Mock private CommandController controller;
45 51
     @Mock private PluginManager pluginManager;
@@ -48,7 +54,7 @@ public class IfpluginTest {
48 54
 
49 55
     @Before
50 56
     public void setUp() {
51
-        command = new Ifplugin(controller, pluginManager, gcpProvider);
57
+        command = new Ifplugin(controller, pluginManager, gcpProvider, gwProvider);
52 58
     }
53 59
 
54 60
     @Test

+ 11
- 11
test/com/dmdirc/commandparser/parsers/CommandParserTest.java Bestand weergeven

@@ -88,7 +88,7 @@ public class CommandParserTest {
88 88
 
89 89
     @Test
90 90
     public void testParseCommandWithArguments() {
91
-        commandParser.parseCommand(null, "/command this is a test");
91
+        commandParser.parseCommand(container, "/command this is a test");
92 92
 
93 93
         assertNull(commandParser.nonCommandLine);
94 94
         assertNull(commandParser.invalidCommand);
@@ -99,7 +99,7 @@ public class CommandParserTest {
99 99
 
100 100
     @Test
101 101
     public void testParseCommandWithoutArguments() {
102
-        commandParser.parseCommand(null, "/command");
102
+        commandParser.parseCommand(container, "/command");
103 103
 
104 104
         assertNull(commandParser.nonCommandLine);
105 105
         assertNull(commandParser.invalidCommand);
@@ -110,7 +110,7 @@ public class CommandParserTest {
110 110
 
111 111
     @Test
112 112
     public void testParseSilentCommandWithoutArguments() {
113
-        commandParser.parseCommand(null, "/.command");
113
+        commandParser.parseCommand(container, "/.command");
114 114
 
115 115
         assertNull(commandParser.nonCommandLine);
116 116
         assertNull(commandParser.invalidCommand);
@@ -121,7 +121,7 @@ public class CommandParserTest {
121 121
 
122 122
     @Test
123 123
     public void testParseSilentCommandWithArguments() {
124
-        commandParser.parseCommand(null, "/.command this is a test");
124
+        commandParser.parseCommand(container, "/.command this is a test");
125 125
 
126 126
         assertNull(commandParser.nonCommandLine);
127 127
         assertNull(commandParser.invalidCommand);
@@ -132,7 +132,7 @@ public class CommandParserTest {
132 132
 
133 133
     @Test
134 134
     public void testParseUnknownCommand() {
135
-        commandParser.parseCommand(null, "/foobar moo bar");
135
+        commandParser.parseCommand(container, "/foobar moo bar");
136 136
 
137 137
         assertNull(commandParser.nonCommandLine);
138 138
         assertEquals("foobar", commandParser.invalidCommand);
@@ -142,7 +142,7 @@ public class CommandParserTest {
142 142
 
143 143
     @Test
144 144
     public void testParseEmptyCommand() {
145
-        commandParser.parseCommand(null, "/ moo bar");
145
+        commandParser.parseCommand(container, "/ moo bar");
146 146
 
147 147
         assertNull(commandParser.nonCommandLine);
148 148
         assertEquals("", commandParser.invalidCommand);
@@ -152,7 +152,7 @@ public class CommandParserTest {
152 152
 
153 153
     @Test
154 154
     public void testParseEmptySilenceCommand() {
155
-        commandParser.parseCommand(null, "/. moo bar");
155
+        commandParser.parseCommand(container, "/. moo bar");
156 156
 
157 157
         assertNull(commandParser.nonCommandLine);
158 158
         assertEquals("", commandParser.invalidCommand);
@@ -162,7 +162,7 @@ public class CommandParserTest {
162 162
 
163 163
     @Test
164 164
     public void testParseNonCommand() {
165
-        commandParser.parseCommand(null, "Foobar baz");
165
+        commandParser.parseCommand(container, "Foobar baz");
166 166
 
167 167
         assertEquals("Foobar baz", commandParser.nonCommandLine);
168 168
         assertNull(commandParser.invalidCommand);
@@ -172,12 +172,12 @@ public class CommandParserTest {
172 172
 
173 173
     @Test
174 174
     public void testGetCommandTime() {
175
-        commandParser.parseCommand(null, "/command this is a test");
175
+        commandParser.parseCommand(container, "/command this is a test");
176 176
 
177 177
         final long time1 = commandParser.getCommandTime("command this is a test");
178 178
         assertTrue(time1 > 0);
179 179
 
180
-        commandParser.parseCommand(null, "/command this is a test");
180
+        commandParser.parseCommand(container, "/command this is a test");
181 181
         final long time2 = commandParser.getCommandTime("command this is a test");
182 182
         assertTrue(time2 > 0);
183 183
         assertTrue(time2 >= time1);
@@ -236,7 +236,7 @@ public class CommandParserTest {
236 236
     @Test
237 237
     public void testParseUnregisterCommand() {
238 238
         commandParser.unregisterCommand(commandInfo);
239
-        commandParser.parseCommand(null, "/command test 123");
239
+        commandParser.parseCommand(container, "/command test 123");
240 240
 
241 241
         assertNull(commandParser.nonCommandLine);
242 242
         assertEquals("command", commandParser.invalidCommand);

Laden…
Annuleren
Opslaan