浏览代码

Merge pull request #458 from csmith/master

Separate InputModel functions from FrameContainer.
pull/459/head
Greg Holmes 8 年前
父节点
当前提交
91edd4c549

+ 7
- 8
dcc/src/com/dmdirc/addons/dcc/ChatContainer.java 查看文件

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.addons.dcc;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26
+import com.dmdirc.DefaultInputModel;
26 27
 import com.dmdirc.addons.dcc.events.DccChatMessageEvent;
27 28
 import com.dmdirc.addons.dcc.events.DccChatSelfMessageEvent;
28 29
 import com.dmdirc.addons.dcc.events.DccChatSocketClosedEvent;
@@ -30,7 +31,6 @@ import com.dmdirc.addons.dcc.events.DccChatSocketOpenedEvent;
30 31
 import com.dmdirc.addons.dcc.io.DCCChat;
31 32
 import com.dmdirc.events.CommandErrorEvent;
32 33
 import com.dmdirc.interfaces.CommandController;
33
-import com.dmdirc.interfaces.WindowModel;
34 34
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
35 35
 import com.dmdirc.ui.core.components.WindowComponent;
36 36
 import com.dmdirc.ui.input.TabCompleterFactory;
@@ -38,8 +38,6 @@ import com.dmdirc.ui.messages.BackBufferFactory;
38 38
 
39 39
 import java.util.Arrays;
40 40
 
41
-import javax.annotation.Nullable;
42
-
43 41
 /**
44 42
  * This class links DCC Chat objects to a window.
45 43
  */
@@ -57,7 +55,6 @@ public class ChatContainer extends DCCFrameContainer implements DCCChatHandler {
57 55
     /**
58 56
      * Creates a new instance of DCCChatWindow with a given DCCChat object.
59 57
      *
60
-     * @param parent              The parent of this frame container, if any.
61 58
      * @param dcc                 The DCCChat object this window wraps around
62 59
      * @param configManager       Config manager
63 60
      * @param commandController   The controller to use in the command parser.
@@ -78,12 +75,15 @@ public class ChatContainer extends DCCFrameContainer implements DCCChatHandler {
78 75
             final TabCompleterFactory tabCompleterFactory,
79 76
             final DMDircMBassador eventBus) {
80 77
         super(title, "dcc-chat-inactive", configManager, backBufferFactory,
81
-                new DCCCommandParser(configManager, commandController, eventBus),
82
-                tabCompleterFactory,
83 78
                 eventBus,
84 79
                 Arrays.asList(
85 80
                         WindowComponent.TEXTAREA.getIdentifier(),
86 81
                         WindowComponent.INPUTFIELD.getIdentifier()));
82
+        setInputModel(new DefaultInputModel(
83
+                this::sendLine,
84
+                new DCCCommandParser(configManager, commandController, eventBus),
85
+                tabCompleterFactory.getTabCompleter(configManager),
86
+                () -> 512));
87 87
         dccChat = dcc;
88 88
         dcc.setHandler(this);
89 89
         nickname = nick;
@@ -101,8 +101,7 @@ public class ChatContainer extends DCCFrameContainer implements DCCChatHandler {
101 101
         return dccChat;
102 102
     }
103 103
 
104
-    @Override
105
-    public void sendLine(final String line) {
104
+    private void sendLine(final String line) {
106 105
         if (dccChat.isWriteable()) {
107 106
             eventBus.publishAsync(new DccChatSelfMessageEvent(this, nickname, line));
108 107
             dccChat.sendLine(line);

+ 0
- 13
dcc/src/com/dmdirc/addons/dcc/DCCFrameContainer.java 查看文件

@@ -24,10 +24,8 @@ package com.dmdirc.addons.dcc;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.FrameContainer;
27
-import com.dmdirc.commandparser.parsers.CommandParser;
28 27
 import com.dmdirc.interfaces.Connection;
29 28
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
30
-import com.dmdirc.ui.input.TabCompleterFactory;
31 29
 import com.dmdirc.ui.messages.BackBufferFactory;
32 30
 
33 31
 import java.util.Collection;
@@ -47,8 +45,6 @@ public abstract class DCCFrameContainer extends FrameContainer {
47 45
      * @param title               The title of this window
48 46
      * @param icon                The icon to use
49 47
      * @param configManager       Config manager
50
-     * @param parser              Command parser to use for this window
51
-     * @param tabCompleterFactory The factory to use to create tab completers.
52 48
      * @param eventBus            The bus to dispatch events on.
53 49
      * @param components          The UI components that this frame requires
54 50
      */
@@ -57,21 +53,12 @@ public abstract class DCCFrameContainer extends FrameContainer {
57 53
             final String icon,
58 54
             final AggregateConfigProvider configManager,
59 55
             final BackBufferFactory backBufferFactory,
60
-            final CommandParser parser,
61
-            final TabCompleterFactory tabCompleterFactory,
62 56
             final DMDircMBassador eventBus,
63 57
             final Collection<String> components) {
64 58
         super(icon, title, title, configManager, backBufferFactory,
65
-                tabCompleterFactory.getTabCompleter(configManager),
66 59
                 eventBus,
67 60
                 components);
68 61
         initBackBuffer();
69
-        setCommandParser(parser);
70
-    }
71
-
72
-    @Override
73
-    public int getMaxLineLength() {
74
-        return 512;
75 62
     }
76 63
 
77 64
     @Override

+ 0
- 10
debug/src/com/dmdirc/addons/debug/RawWindow.java 查看文件

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.addons.debug;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
-import com.dmdirc.commandparser.CommandType;
27 26
 import com.dmdirc.events.ServerConnectingEvent;
28 27
 import com.dmdirc.interfaces.Connection;
29 28
 import com.dmdirc.parser.events.DataInEvent;
@@ -52,10 +51,6 @@ public class RawWindow extends FrameContainer {
52 51
         super("raw", "Raw", "(Raw log)",
53 52
                 connection.getWindowModel().getConfigManager(),
54 53
                 backBufferFactory,
55
-                tabCompleterFactory.getTabCompleter(
56
-                        connection.getWindowModel().getInputModel().get().getTabCompleter(),
57
-                        connection.getWindowModel().getConfigManager(),
58
-                        CommandType.TYPE_QUERY, CommandType.TYPE_CHAT),
59 54
                 connection.getWindowModel().getEventBus(),
60 55
                 Arrays.asList(WindowComponent.TEXTAREA.getIdentifier(),
61 56
                         WindowComponent.INPUTFIELD.getIdentifier()));
@@ -78,11 +73,6 @@ public class RawWindow extends FrameContainer {
78 73
         super.close();
79 74
     }
80 75
 
81
-    @Override
82
-    public int getMaxLineLength() {
83
-        return -1;
84
-    }
85
-
86 76
     @Handler
87 77
     public void handleServerConnecting(final ServerConnectingEvent connectingEvent) {
88 78
         connection.getParser().map(Parser::getCallbackManager).ifPresent(c -> c.subscribe(this));

+ 15
- 5
debug/src/com/dmdirc/addons/debug/RawWindowFactory.java 查看文件

@@ -22,6 +22,8 @@
22 22
 
23 23
 package com.dmdirc.addons.debug;
24 24
 
25
+import com.dmdirc.DefaultInputModel;
26
+import com.dmdirc.commandparser.CommandType;
25 27
 import com.dmdirc.commandparser.parsers.ServerCommandParser;
26 28
 import com.dmdirc.interfaces.CommandController;
27 29
 import com.dmdirc.interfaces.Connection;
@@ -58,11 +60,19 @@ public class RawWindowFactory {
58 60
     public RawWindow getRawWindow(final Connection connection) {
59 61
         final RawWindow rawWindow = new RawWindow(connection,
60 62
                 tabCompleterFactory,  backBufferFactory);
61
-        rawWindow.setCommandParser(new ServerCommandParser(
62
-                connection.getWindowModel().getConfigManager(),
63
-                commandController,
64
-                connection.getWindowModel().getEventBus(),
65
-                connection));
63
+        rawWindow.setInputModel(
64
+                new DefaultInputModel(
65
+                        connection::sendLine,
66
+                        new ServerCommandParser(
67
+                                connection.getWindowModel().getConfigManager(),
68
+                                commandController,
69
+                                connection.getWindowModel().getEventBus(),
70
+                                connection),
71
+                        tabCompleterFactory.getTabCompleter(
72
+                                connection.getWindowModel().getInputModel().get().getTabCompleter(),
73
+                                connection.getWindowModel().getConfigManager(),
74
+                                CommandType.TYPE_QUERY, CommandType.TYPE_CHAT),
75
+                        () -> -1));
66 76
         windowManager.addWindow(connection.getWindowModel(), rawWindow);
67 77
         return rawWindow;
68 78
     }

+ 2
- 12
redirect/src/com/dmdirc/addons/redirect/FakeWriteableFrameContainer.java 查看文件

@@ -48,21 +48,11 @@ 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.getInputModel().get().getTabCompleter(), eventBus,
51
+                eventBus,
52 52
                 Collections.<String>emptyList());
53 53
         this.target = target;
54 54
         initBackBuffer();
55
-        setCommandParser(target.getInputModel().get().getCommandParser());
56
-    }
57
-
58
-    @Override
59
-    public void sendLine(final String line) {
60
-        target.getInputModel().ifPresent(im -> im.sendLine(line));
61
-    }
62
-
63
-    @Override
64
-    public int getMaxLineLength() {
65
-        return target.getInputModel().get().getMaxLineLength();
55
+        setInputModel(target.getInputModel().orElse(null));
66 56
     }
67 57
 
68 58
     @Override

正在加载...
取消
保存