Просмотр исходного кода

Added WrappableCommand (implemented by /query and /msg), and support to the InputHandler.

Fixes issue 907.

git-svn-id: http://svn.dmdirc.com/trunk@3851 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 лет назад
Родитель
Сommit
bcf2feb532

+ 47
- 0
src/com/dmdirc/commandparser/commands/WrappableCommand.java Просмотреть файл

@@ -0,0 +1,47 @@
1
+/*
2
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.commandparser.commands;
24
+
25
+import com.dmdirc.ui.interfaces.InputWindow;
26
+
27
+import java.util.List;
28
+
29
+/**
30
+ * Wrapping commands are commands whose aruments may be wrapped into multiple
31
+ * lines when sending.
32
+ * 
33
+ * @author chris
34
+ */
35
+public interface WrappableCommand {
36
+    
37
+    /**
38
+     * Determines the number of lines that the specified arguments will be
39
+     * wrapped as.
40
+     * 
41
+     * @param origin The window the command is being executed in
42
+     * @param arguments The arguments that the user has entered (so far)
43
+     * @return The number of lines that the arguments will result in
44
+     */
45
+    int getLineCount(InputWindow origin, List<String> arguments);
46
+
47
+}

+ 16
- 2
src/com/dmdirc/commandparser/commands/server/Message.java Просмотреть файл

@@ -26,6 +26,7 @@ import com.dmdirc.Server;
26 26
 import com.dmdirc.commandparser.CommandManager;
27 27
 import com.dmdirc.commandparser.commands.IntelligentCommand;
28 28
 import com.dmdirc.commandparser.commands.ServerCommand;
29
+import com.dmdirc.commandparser.commands.WrappableCommand;
29 30
 import com.dmdirc.ui.input.AdditionalTabTargets;
30 31
 import com.dmdirc.ui.input.TabCompletionType;
31 32
 import com.dmdirc.ui.interfaces.InputWindow;
@@ -36,7 +37,8 @@ import java.util.List;
36 37
  * Allows the user to send privmsgs.
37 38
  * @author chris
38 39
  */
39
-public final class Message extends ServerCommand implements IntelligentCommand {
40
+public final class Message extends ServerCommand implements IntelligentCommand,
41
+        WrappableCommand {
40 42
     
41 43
     /**
42 44
      * Creates a new instance of Message.
@@ -92,6 +94,18 @@ public final class Message extends ServerCommand implements IntelligentCommand {
92 94
         }
93 95
         
94 96
         return res;
95
-    } 
97
+    }
98
+
99
+    /** {@inheritDoc} */
100
+    @Override
101
+    public int getLineCount(final InputWindow origin, final List<String> arguments) {
102
+        if (arguments.size() >= 2) {
103
+            final String target = arguments.get(0);
104
+            return origin.getContainer().getServer().getNumLines("PRIVMSG "
105
+                    + target + " :" + implodeArgs(1, arguments.toArray(new String[0])));
106
+        } else {
107
+            return 1;
108
+        }
109
+    }
96 110
     
97 111
 }

+ 20
- 5
src/com/dmdirc/commandparser/commands/server/OpenQuery.java Просмотреть файл

@@ -26,17 +26,20 @@ import com.dmdirc.Server;
26 26
 import com.dmdirc.commandparser.CommandManager;
27 27
 import com.dmdirc.commandparser.commands.IntelligentCommand;
28 28
 import com.dmdirc.commandparser.commands.ServerCommand;
29
+import com.dmdirc.commandparser.commands.WrappableCommand;
29 30
 import com.dmdirc.ui.input.AdditionalTabTargets;
30 31
 import com.dmdirc.ui.input.TabCompletionType;
31 32
 import com.dmdirc.ui.interfaces.InputWindow;
32 33
 import com.dmdirc.ui.messages.Styliser;
34
+
33 35
 import java.util.List;
34 36
 
35 37
 /**
36 38
  * Allows the user to open a query dialog with another user.
37 39
  * @author chris
38 40
  */
39
-public final class OpenQuery extends ServerCommand implements IntelligentCommand {
41
+public final class OpenQuery extends ServerCommand implements
42
+        IntelligentCommand, WrappableCommand {
40 43
     
41 44
     /**
42 45
      * Creates a new instance of Query.
@@ -57,9 +60,9 @@ public final class OpenQuery extends ServerCommand implements IntelligentCommand
57 60
         }
58 61
             
59 62
         if (server.getParser().isValidChannelName(args[0])) {
60
-            sendLine(origin, isSilent, FORMAT_ERROR, "You can't open a query " +
61
-                    "with a channel; maybe you meant " + Styliser.CODE_FIXED +
62
-                    Styliser.CODE_BOLD + CommandManager.getCommandChar()
63
+            sendLine(origin, isSilent, FORMAT_ERROR, "You can't open a query "
64
+                    + "with a channel; maybe you meant " + Styliser.CODE_FIXED
65
+                    + Styliser.CODE_BOLD + CommandManager.getCommandChar()
63 66
                     + (args.length > 1 ? "msg" : "join") + " " + implodeArgs(args)
64 67
                     + Styliser.CODE_BOLD + Styliser.CODE_FIXED + "?");
65 68
             return;
@@ -107,6 +110,18 @@ public final class OpenQuery extends ServerCommand implements IntelligentCommand
107 110
         }
108 111
         
109 112
         return targets;
110
-    }    
113
+    }
114
+    
115
+    /** {@inheritDoc} */
116
+    @Override
117
+    public int getLineCount(final InputWindow origin, final List<String> arguments) {
118
+        if (arguments.size() >= 2) {
119
+            final String target = arguments.get(0);
120
+            return origin.getContainer().getServer().getNumLines("PRIVMSG "
121
+                    + target + " :" + implodeArgs(1, arguments.toArray(new String[0])));
122
+        } else {
123
+            return 1;
124
+        }
125
+    }
111 126
     
112 127
 }

+ 8
- 1
src/com/dmdirc/ui/input/InputHandler.java Просмотреть файл

@@ -27,6 +27,7 @@ import com.dmdirc.actions.CoreActionType;
27 27
 import com.dmdirc.commandparser.CommandManager;
28 28
 import com.dmdirc.commandparser.commands.Command;
29 29
 import com.dmdirc.commandparser.commands.ValidatingCommand;
30
+import com.dmdirc.commandparser.commands.WrappableCommand;
30 31
 import com.dmdirc.commandparser.parsers.CommandParser;
31 32
 import com.dmdirc.config.prefs.validator.ValidationResponse;
32 33
 import com.dmdirc.interfaces.ConfigChangeListener;
@@ -233,7 +234,13 @@ public abstract class InputHandler implements ConfigChangeListener {
233 234
                 }
234 235
             }
235 236
             
236
-            // TODO: Wrapping commands
237
+            if (command instanceof WrappableCommand) {
238
+                final int count = ((WrappableCommand) command).getLineCount(parentWindow, args);
239
+                
240
+                if (count > 1) {
241
+                    fireLineWrap(count);
242
+                }
243
+            }
237 244
         } else {
238 245
             final int lines = parentWindow.getContainer().getNumLines(text);
239 246
             if (lines > 1) {

+ 2
- 1
src/com/dmdirc/ui/swing/components/ColourPickerPanel.java Просмотреть файл

@@ -113,7 +113,8 @@ public final class ColourPickerPanel extends JPanel implements MouseListener, Mo
113 113
         this.showIrc = newShowIrc;
114 114
         this.showHex = newShowHex;
115 115
         
116
-        final int height = 65 + (showIrc ? 30 : 0) + (showHex ? 145 : 0)  + (showHex & showIrc ? 10 : 0);
116
+        final int height = 65 + (showIrc ? 30 : 0) + (showHex ? 145 : 0) 
117
+                + (showHex & showIrc ? 10 : 0);
117 118
         
118 119
         setPreferredSize(new Dimension(160, height));
119 120
         

Загрузка…
Отмена
Сохранить