Browse Source

Remove input methods from WindowModel.

Migrate all users to using the InputModel.
pull/457/head
Chris Smith 8 years ago
parent
commit
e579fda440

+ 5
- 2
conditional_execute/src/com/dmdirc/addons/conditional_execute/ConditionalExecuteCommand.java View File

@@ -28,6 +28,7 @@ import com.dmdirc.commandparser.CommandType;
28 28
 import com.dmdirc.commandparser.commands.Command;
29 29
 import com.dmdirc.commandparser.commands.context.CommandContext;
30 30
 import com.dmdirc.interfaces.CommandController;
31
+import com.dmdirc.interfaces.InputModel;
31 32
 import com.dmdirc.interfaces.WindowModel;
32 33
 
33 34
 import java.util.HashMap;
@@ -231,8 +232,10 @@ public class ConditionalExecuteCommand extends Command {
231 232
                         "You can't run commands and manipulate the namespace at the same time, ignored.");
232 233
             } else {
233 234
                 // Command to run!
234
-                if (namespace.canRun(inverse) && origin.isWritable()) {
235
-                    origin.getCommandParser().parseCommand(origin, args.getArgumentsAsString(i));
235
+                if (namespace.canRun(inverse)) {
236
+                    final String command = args.getArgumentsAsString(i);
237
+                    origin.getInputModel().map(InputModel::getCommandParser)
238
+                            .ifPresent(cp -> cp.parseCommand(origin, command));
236 239
                 }
237 240
                 return;
238 241
             }

+ 6
- 2
conditional_execute/test/com/dmdirc/addons/conditional_execute/ConditionalExecuteCommandTest.java View File

@@ -28,8 +28,11 @@ import com.dmdirc.commandparser.commands.context.CommandContext;
28 28
 import com.dmdirc.commandparser.parsers.CommandParser;
29 29
 import com.dmdirc.events.CommandErrorEvent;
30 30
 import com.dmdirc.interfaces.CommandController;
31
+import com.dmdirc.interfaces.InputModel;
31 32
 import com.dmdirc.interfaces.WindowModel;
32 33
 
34
+import java.util.Optional;
35
+
33 36
 import org.junit.Before;
34 37
 import org.junit.Test;
35 38
 import org.junit.runner.RunWith;
@@ -52,6 +55,7 @@ public class ConditionalExecuteCommandTest {
52 55
     @Mock private CommandController commandController;
53 56
     @Mock private CommandParser commandParser;
54 57
     @Mock private WindowModel container;
58
+    @Mock private InputModel inputModel;
55 59
     @Mock private CommandContext context;
56 60
     @Mock private DMDircMBassador eventbus;
57 61
     @Captor private ArgumentCaptor<CommandErrorEvent> errorEventCaptor;
@@ -61,8 +65,8 @@ public class ConditionalExecuteCommandTest {
61 65
     public void setup() {
62 66
         when(commandController.getCommandChar()).thenReturn('/');
63 67
         when(commandController.getSilenceChar()).thenReturn('/');
64
-        when(container.getCommandParser()).thenReturn(commandParser);
65
-        when(container.isWritable()).thenReturn(true);
68
+        when(container.getInputModel()).thenReturn(Optional.of(inputModel));
69
+        when(inputModel.getCommandParser()).thenReturn(commandParser);
66 70
         when(container.getEventBus()).thenReturn(eventbus);
67 71
 
68 72
         command = new ConditionalExecuteCommand(commandController);

+ 1
- 1
dcc/src/com/dmdirc/addons/dcc/DCCCommandParser.java View File

@@ -59,7 +59,7 @@ public class DCCCommandParser extends GlobalCommandParser {
59 59
      */
60 60
     @Override
61 61
     protected void handleNonCommand(final WindowModel origin, final String line) {
62
-        origin.sendLine(line);
62
+        origin.getInputModel().ifPresent(im -> im.sendLine(line));
63 63
     }
64 64
 
65 65
 }

+ 2
- 1
debug/src/com/dmdirc/addons/debug/RawWindow.java View File

@@ -52,7 +52,8 @@ public class RawWindow extends FrameContainer {
52 52
         super("raw", "Raw", "(Raw log)",
53 53
                 connection.getWindowModel().getConfigManager(),
54 54
                 backBufferFactory,
55
-                tabCompleterFactory.getTabCompleter(connection.getWindowModel().getTabCompleter(),
55
+                tabCompleterFactory.getTabCompleter(
56
+                        connection.getWindowModel().getInputModel().get().getTabCompleter(),
56 57
                         connection.getWindowModel().getConfigManager(),
57 58
                         CommandType.TYPE_QUERY, CommandType.TYPE_CHAT),
58 59
                 connection.getWindowModel().getEventBus(),

+ 8
- 2
debug/src/com/dmdirc/addons/debug/commands/Time.java View File

@@ -27,10 +27,14 @@ import com.dmdirc.addons.debug.DebugCommand;
27 27
 import com.dmdirc.commandparser.CommandArguments;
28 28
 import com.dmdirc.commandparser.commands.IntelligentCommand;
29 29
 import com.dmdirc.commandparser.commands.context.CommandContext;
30
+import com.dmdirc.commandparser.parsers.CommandParser;
31
+import com.dmdirc.interfaces.InputModel;
30 32
 import com.dmdirc.interfaces.WindowModel;
31 33
 import com.dmdirc.ui.input.AdditionalTabTargets;
32 34
 import com.dmdirc.ui.input.TabCompletionType;
33 35
 
36
+import java.util.Optional;
37
+
34 38
 import javax.annotation.Nonnull;
35 39
 import javax.inject.Inject;
36 40
 import javax.inject.Provider;
@@ -79,9 +83,11 @@ public class Time extends DebugCommand implements IntelligentCommand {
79 83
             return;
80 84
         }
81 85
 
82
-        if (origin.isWritable()) {
86
+        final Optional<CommandParser> parser =
87
+                origin.getInputModel().map(InputModel::getCommandParser);
88
+        if (parser.isPresent()) {
83 89
             final long start = System.currentTimeMillis();
84
-            origin.getCommandParser().parseCommand(origin, args.getArgumentsAsString(0));
90
+            parser.get().parseCommand(origin, args.getArgumentsAsString(0));
85 91
             final long end = System.currentTimeMillis();
86 92
             showOutput(origin, args.isSilent(),
87 93
                     "Command executed in " + (end - start) + " milliseconds.");

+ 8
- 5
nowplaying/src/com/dmdirc/addons/nowplaying/NowPlayingCommand.java View File

@@ -33,6 +33,7 @@ import com.dmdirc.commandparser.commands.context.ChatCommandContext;
33 33
 import com.dmdirc.commandparser.commands.context.CommandContext;
34 34
 import com.dmdirc.interfaces.Chat;
35 35
 import com.dmdirc.interfaces.CommandController;
36
+import com.dmdirc.interfaces.InputModel;
36 37
 import com.dmdirc.interfaces.WindowModel;
37 38
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
38 39
 import com.dmdirc.plugins.PluginDomain;
@@ -106,8 +107,9 @@ public class NowPlayingCommand extends Command implements IntelligentCommand {
106 107
                     if (source.getState() == MediaSourceState.CLOSED) {
107 108
                         showError(origin, args.isSilent(), "Source is not running.");
108 109
                     } else {
109
-                        target.getWindowModel().getCommandParser().parseCommand(origin,
110
-                                getInformation(source, args.getArgumentsAsString(2)));
110
+                        target.getWindowModel().getInputModel().map(InputModel::getCommandParser)
111
+                                .ifPresent(cp -> cp.parseCommand(origin,
112
+                                        getInformation(source, args.getArgumentsAsString(2))));
111 113
                     }
112 114
                 }
113 115
             } else {
@@ -116,9 +118,10 @@ public class NowPlayingCommand extends Command implements IntelligentCommand {
116 118
             }
117 119
         } else {
118 120
             if (manager.hasRunningSource()) {
119
-                target.getWindowModel().getCommandParser().parseCommand(origin,
120
-                        getInformation(manager.getBestSource(), args.
121
-                                getArgumentsAsString(0)));
121
+                target.getWindowModel().getInputModel().map(InputModel::getCommandParser)
122
+                        .ifPresent(cp -> cp.parseCommand(origin,
123
+                                getInformation(manager.getBestSource(),
124
+                                        args.getArgumentsAsString(0))));
122 125
             } else {
123 126
                 showError(origin, args.isSilent(), "No running media sources available.");
124 127
             }

+ 5
- 4
redirect/src/com/dmdirc/addons/redirect/FakeWriteableFrameContainer.java View File

@@ -48,20 +48,21 @@ public class FakeWriteableFrameContainer extends FrameContainer {
48 48
             final BackBufferFactory backBufferFactory) {
49 49
         super(target.getIcon(), target.getName(), target.getTitle(),
50 50
                 target.getConfigManager(), backBufferFactory,
51
-                target.getTabCompleter(), eventBus, Collections.<String>emptyList());
51
+                target.getInputModel().get().getTabCompleter(), eventBus,
52
+                Collections.<String>emptyList());
52 53
         this.target = target;
53 54
         initBackBuffer();
54
-        setCommandParser(target.getCommandParser());
55
+        setCommandParser(target.getInputModel().get().getCommandParser());
55 56
     }
56 57
 
57 58
     @Override
58 59
     public void sendLine(final String line) {
59
-        target.sendLine(line);
60
+        target.getInputModel().ifPresent(im -> im.sendLine(line));
60 61
     }
61 62
 
62 63
     @Override
63 64
     public int getMaxLineLength() {
64
-        return target.getMaxLineLength();
65
+        return target.getInputModel().get().getMaxLineLength();
65 66
     }
66 67
 
67 68
     @Override

+ 6
- 4
redirect/src/com/dmdirc/addons/redirect/RedirectCommand.java View File

@@ -32,6 +32,7 @@ import com.dmdirc.commandparser.commands.context.ChatCommandContext;
32 32
 import com.dmdirc.commandparser.commands.context.CommandContext;
33 33
 import com.dmdirc.interfaces.Chat;
34 34
 import com.dmdirc.interfaces.CommandController;
35
+import com.dmdirc.interfaces.InputModel;
35 36
 import com.dmdirc.interfaces.WindowModel;
36 37
 import com.dmdirc.ui.input.AdditionalTabTargets;
37 38
 import com.dmdirc.ui.input.TabCompleterUtils;
@@ -76,10 +77,11 @@ public class RedirectCommand extends Command implements IntelligentCommand {
76 77
     public void execute(@Nonnull final WindowModel origin,
77 78
             final CommandArguments args, final CommandContext context) {
78 79
         final Chat target = ((ChatCommandContext) context).getChat();
79
-        target.getWindowModel().getCommandParser().parseCommand(
80
-                new FakeWriteableFrameContainer(target.getWindowModel(),
81
-                        eventBus, backBufferFactory),
82
-                args.getArgumentsAsString());
80
+        target.getWindowModel().getInputModel().map(InputModel::getCommandParser).
81
+                ifPresent(cp -> cp.parseCommand(
82
+                        new FakeWriteableFrameContainer(target.getWindowModel(),
83
+                                eventBus, backBufferFactory),
84
+                        args.getArgumentsAsString()));
83 85
     }
84 86
 
85 87
     @Override

+ 1
- 1
time/src/com/dmdirc/addons/time/TimedCommand.java View File

@@ -101,7 +101,7 @@ public class TimedCommand extends TimerTask {
101 101
         if (timer == null) {
102 102
             return;
103 103
         }
104
-        origin.getCommandParser().parseCommand(origin, command);
104
+        origin.getInputModel().get().getCommandParser().parseCommand(origin, command);
105 105
 
106 106
         if (--repetitions <= 0) {
107 107
             manager.removeTimer(timerKey);

+ 5
- 1
time/test/com/dmdirc/addons/time/TimedCommandTest.java View File

@@ -23,8 +23,10 @@
23 23
 package com.dmdirc.addons.time;
24 24
 
25 25
 import com.dmdirc.commandparser.parsers.CommandParser;
26
+import com.dmdirc.interfaces.InputModel;
26 27
 import com.dmdirc.interfaces.WindowModel;
27 28
 
29
+import java.util.Optional;
28 30
 import java.util.Timer;
29 31
 
30 32
 import org.junit.Before;
@@ -45,6 +47,7 @@ public class TimedCommandTest {
45 47
 
46 48
     @Mock private TimerManager timerManager;
47 49
     @Mock private WindowModel origin;
50
+    @Mock private InputModel inputModel;
48 51
     @Mock private CommandParser commandParser;
49 52
     @Mock private TimerFactory timerFactory;
50 53
     @Mock private Timer timer;
@@ -54,7 +57,8 @@ public class TimedCommandTest {
54 57
     @Before
55 58
     public void setUp() throws Exception {
56 59
         when(timerFactory.getTimer(anyString())).thenReturn(timer);
57
-        when(origin.getCommandParser()).thenReturn(commandParser);
60
+        when(origin.getInputModel()).thenReturn(Optional.of(inputModel));
61
+        when(inputModel.getCommandParser()).thenReturn(commandParser);
58 62
         instance = new TimedCommand(timerManager, 1, 2, 3, "command", origin);
59 63
     }
60 64
 

+ 3
- 3
ui_swing/src/com/dmdirc/addons/ui_swing/components/TopicBar.java View File

@@ -122,7 +122,6 @@ public class TopicBar extends JComponent implements ActionListener, ConfigChange
122 122
      * @param channel           The channel that this topic bar is for.
123 123
      * @param window            The window this topic bar is for.
124 124
      * @param iconManager       The icon manager to use for this bar's icons.
125
-     * @param eventBus          The event bus to post errors to
126 125
      */
127 126
     public TopicBar(
128 127
             final Window parentWindow,
@@ -159,10 +158,11 @@ public class TopicBar extends JComponent implements ActionListener, ConfigChange
159 158
 
160 159
         final SwingInputHandler handler = new SwingInputHandler(
161 160
                 serviceManager, topicText, commandController,
162
-                channel.getWindowModel().getCommandParser(), channel.getWindowModel(),
161
+                channel.getWindowModel().getInputModel().get().getCommandParser(),
162
+                channel.getWindowModel(),
163 163
                 tabCompleterUtils, channel.getEventBus());
164 164
         handler.setTypes(true, false, true, false);
165
-        handler.setTabCompleter(channel.getWindowModel().getTabCompleter());
165
+        handler.setTabCompleter(channel.getWindowModel().getInputModel().get().getTabCompleter());
166 166
 
167 167
         final JScrollPane sp = new JScrollPane(topicText);
168 168
         sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

+ 4
- 3
ui_swing/src/com/dmdirc/addons/ui_swing/components/frames/InputTextFrame.java View File

@@ -96,7 +96,7 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow, M
96 96
             final Provider<SwingInputField> inputFieldProvider,
97 97
             final InputTextFramePasteActionFactory inputTextFramePasteActionFactory,
98 98
             final WindowModel owner) {
99
-        super(owner, owner.getCommandParser(), deps);
99
+        super(owner, owner.getInputModel().get().getCommandParser(), deps);
100 100
 
101 101
         serviceManager = deps.serviceManager;
102 102
         commandController = deps.commandController;
@@ -135,9 +135,10 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow, M
135 135
             final TabCompleterUtils tabCompleterUtils) {
136 136
         inputField = inputFieldProvider.get();
137 137
         inputHandler = new SwingInputHandler(serviceManager, inputField, commandController,
138
-                getContainer().getCommandParser(), getContainer(), tabCompleterUtils, eventBus);
138
+                getContainer().getInputModel().get().getCommandParser(), getContainer(),
139
+                tabCompleterUtils, eventBus);
139 140
         inputHandler.addValidationListener(inputField);
140
-        inputHandler.setTabCompleter(frameParent.getTabCompleter());
141
+        inputHandler.setTabCompleter(frameParent.getInputModel().get().getTabCompleter());
141 142
 
142 143
         initPopupMenu();
143 144
         nickPopup = new JPopupMenu();

+ 4
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/components/frames/InputTextFramePasteAction.java View File

@@ -137,13 +137,15 @@ public final class InputTextFramePasteAction extends AbstractAction {
137 137
             final Integer pasteTrigger = container.getConfigManager().
138 138
                     getOptionInt("ui", "pasteProtectionLimit", false);
139 139
             //check whether the number of lines is over the limit
140
-            if (pasteTrigger != null && container.getNumLines(text) > pasteTrigger) {
140
+            if (pasteTrigger != null && container.getInputModel().get().getNumLines(text) >
141
+                    pasteTrigger) {
141 142
                 //show the multi line paste dialog
142 143
                 pasteDialogFactory.getPasteDialog(inputFrame, text, window).displayOrRequestFocus();
143 144
             } else {
144 145
                 //send the lines
145 146
                 for (final String clipboardLine : clipboardLines) {
146
-                    inputFrame.getContainer().sendLine(clipboardLine);
147
+                    inputFrame.getContainer().getInputModel()
148
+                            .ifPresent(im -> im.sendLine(clipboardLine));
147 149
                 }
148 150
             }
149 151
         } else {

+ 3
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicDisplayPane.java View File

@@ -125,10 +125,11 @@ public class TopicDisplayPane extends JPanel implements DocumentListener {
125 125
         topicText.setRows(5);
126 126
         topicText.setColumns(30);
127 127
         final SwingInputHandler handler = new SwingInputHandler(serviceManager, topicText,
128
-                commandController, groupChat.getWindowModel().getCommandParser(),
128
+                commandController,
129
+                groupChat.getWindowModel().getInputModel().get().getCommandParser(),
129 130
                 channelWindow.getContainer(), tabCompleterUtils, groupChat.getEventBus());
130 131
         handler.setTypes(true, false, true, false);
131
-        handler.setTabCompleter(groupChat.getWindowModel().getTabCompleter());
132
+        handler.setTabCompleter(groupChat.getWindowModel().getInputModel().get().getTabCompleter());
132 133
 
133 134
         topicText.getActionMap().put("paste-from-clipboard",
134 135
                 new ReplacePasteAction(clipboard, "(\r\n|\n|\r)", " "));

+ 5
- 5
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/paste/PasteDialog.java View File

@@ -147,14 +147,14 @@ public final class PasteDialog extends StandardDialog implements ActionListener,
147 147
         setResizable(false);
148 148
 
149 149
         infoLabel.setText("This will be sent as "
150
-                + parent.getContainer().getNumLines(textField.getText())
150
+                + parent.getContainer().getInputModel().get().getNumLines(textField.getText())
151 151
                 + " lines. Are you sure you want to continue?");
152 152
 
153 153
         textField.setColumns(50);
154 154
         textField.setRows(10);
155 155
 
156 156
         new SwingInputHandler(serviceManager, textField, commandController,
157
-                parent.getContainer().getCommandParser(),
157
+                parent.getContainer().getInputModel().get().getCommandParser(),
158 158
                 parent.getContainer(), tabCompleterUtils, eventBus)
159 159
                 .setTypes(false, false, true,false);
160 160
 
@@ -218,7 +218,7 @@ public final class PasteDialog extends StandardDialog implements ActionListener,
218 218
                         Integer.MAX_VALUE);
219 219
                 for (final String line : lines) {
220 220
                     if (!line.isEmpty()) {
221
-                        parent.getContainer().sendLine(line);
221
+                        parent.getContainer().getInputModel().ifPresent(im -> im.sendLine(line));
222 222
                         parent.getInputHandler().addToBuffer(line);
223 223
                     }
224 224
                 }
@@ -229,7 +229,7 @@ public final class PasteDialog extends StandardDialog implements ActionListener,
229 229
             setResizable(true);
230 230
             scrollPane.setVisible(true);
231 231
             infoLabel.setText("This will be sent as "
232
-                    + parent.getContainer().getNumLines(textField.getText())
232
+                    + parent.getContainer().getInputModel().get().getNumLines(textField.getText())
233 233
                     + " lines.");
234 234
             setResizable(true);
235 235
             pack();
@@ -242,7 +242,7 @@ public final class PasteDialog extends StandardDialog implements ActionListener,
242 242
     @Override
243 243
     public void keyTyped(final KeyEvent e) {
244 244
         infoLabel.setText("This will be sent as "
245
-                + parent.getContainer().getNumLines(textField.getText())
245
+                + parent.getContainer().getInputModel().get().getNumLines(textField.getText())
246 246
                 + " lines.");
247 247
     }
248 248
 

+ 1
- 1
ui_web2/src/com/dmdirc/addons/ui_web2/serialisers/WindowModelSerialiser.java View File

@@ -53,7 +53,7 @@ public class WindowModelSerialiser implements JsonSerializer<WindowModel> {
53 53
         res.addProperty("name", src.getName());
54 54
         res.addProperty("icon", src.getIcon());
55 55
         res.addProperty("title", src.getTitle());
56
-        res.addProperty("writable", src.isWritable());
56
+        res.addProperty("writable", src.getInputModel().isPresent());
57 57
         res.add("children", context.serialize(windowManager.getChildren(src)));
58 58
         res.add("components", context.serialize(src.getComponents()));
59 59
         res.add("backbuffer", context.serialize(src.getBackBuffer()));

Loading…
Cancel
Save