Browse Source

Merge pull request #458 from csmith/master

Separate InputModel functions from FrameContainer.
pull/459/head
Greg Holmes 8 years ago
parent
commit
91edd4c549

+ 7
- 8
dcc/src/com/dmdirc/addons/dcc/ChatContainer.java View File

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

+ 0
- 13
dcc/src/com/dmdirc/addons/dcc/DCCFrameContainer.java View File

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

+ 0
- 10
debug/src/com/dmdirc/addons/debug/RawWindow.java View File

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

+ 15
- 5
debug/src/com/dmdirc/addons/debug/RawWindowFactory.java View File

22
 
22
 
23
 package com.dmdirc.addons.debug;
23
 package com.dmdirc.addons.debug;
24
 
24
 
25
+import com.dmdirc.DefaultInputModel;
26
+import com.dmdirc.commandparser.CommandType;
25
 import com.dmdirc.commandparser.parsers.ServerCommandParser;
27
 import com.dmdirc.commandparser.parsers.ServerCommandParser;
26
 import com.dmdirc.interfaces.CommandController;
28
 import com.dmdirc.interfaces.CommandController;
27
 import com.dmdirc.interfaces.Connection;
29
 import com.dmdirc.interfaces.Connection;
58
     public RawWindow getRawWindow(final Connection connection) {
60
     public RawWindow getRawWindow(final Connection connection) {
59
         final RawWindow rawWindow = new RawWindow(connection,
61
         final RawWindow rawWindow = new RawWindow(connection,
60
                 tabCompleterFactory,  backBufferFactory);
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
         windowManager.addWindow(connection.getWindowModel(), rawWindow);
76
         windowManager.addWindow(connection.getWindowModel(), rawWindow);
67
         return rawWindow;
77
         return rawWindow;
68
     }
78
     }

+ 2
- 12
redirect/src/com/dmdirc/addons/redirect/FakeWriteableFrameContainer.java View File

48
             final BackBufferFactory backBufferFactory) {
48
             final BackBufferFactory backBufferFactory) {
49
         super(target.getIcon(), target.getName(), target.getTitle(),
49
         super(target.getIcon(), target.getName(), target.getTitle(),
50
                 target.getConfigManager(), backBufferFactory,
50
                 target.getConfigManager(), backBufferFactory,
51
-                target.getInputModel().get().getTabCompleter(), eventBus,
51
+                eventBus,
52
                 Collections.<String>emptyList());
52
                 Collections.<String>emptyList());
53
         this.target = target;
53
         this.target = target;
54
         initBackBuffer();
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
     @Override
58
     @Override

Loading…
Cancel
Save