Przeglądaj źródła

* Added me/0 and me commands for query windows

* Updated help command to show query commands
* Javadoc'd and tidied up server commands and the CommandManager

git-svn-id: http://svn.dmdirc.com/trunk@270 00569f92-eb28-0410-84fd-f71c24880f
tags/0.2
Chris Smith 17 lat temu
rodzic
commit
e1dfd37dce

+ 25
- 10
src/uk/org/ownage/dmdirc/commandparser/CommandManager.java Wyświetl plik

@@ -26,6 +26,7 @@ import java.util.Vector;
26 26
 import uk.org.ownage.dmdirc.commandparser.commands.*;
27 27
 import uk.org.ownage.dmdirc.commandparser.commands.server.*;
28 28
 import uk.org.ownage.dmdirc.commandparser.commands.channel.*;
29
+import uk.org.ownage.dmdirc.commandparser.commands.query.*;
29 30
 
30 31
 /**
31 32
  * The command manager creates and manages a single instance of all commands,
@@ -94,6 +95,9 @@ public class CommandManager {
94 95
     static void loadQueryCommands(QueryCommandParser parser) {
95 96
         if (queryCommands == null)    {
96 97
             queryCommands = new Vector<Command>(0,1);
98
+            
99
+            queryCommands.add(new QueryMe());
100
+            queryCommands.add(new QueryMeEmpty());
97 101
         }
98 102
         
99 103
         for (Command com : queryCommands) {
@@ -141,20 +145,31 @@ public class CommandManager {
141 145
         return null;
142 146
     }
143 147
     
144
-    public static Vector<Command> getServerCommands() {
145
-        if (serverCommands == null) {
146
-            return null;
147
-        }
148
-        
148
+    /**
149
+     * Returns a Vector containing the server commands that have been initialised
150
+     * by this command manager
151
+     * @return A Vector of server commands, or null if none have been loaded
152
+     */
153
+    public static Vector<Command> getServerCommands() {       
149 154
         return serverCommands;
150 155
     }
151 156
     
152
-    public static Vector<Command> getChannelCommands() {
153
-        if (channelCommands == null) {
154
-            return null;
155
-        }
156
-        
157
+    /**
158
+     * Returns a Vector containing the channel commands that have been initialised
159
+     * by this command manager
160
+     * @return A Vector of channel commands, or null if none have been loaded
161
+     */    
162
+    public static Vector<Command> getChannelCommands() {       
157 163
         return channelCommands;
158 164
     }
159 165
     
166
+    /**
167
+     * Returns a Vector containing the query commands that have been initialised
168
+     * by this command manager
169
+     * @return A Vector of query commands, or null if none have been loaded
170
+     */    
171
+    public static Vector<Command> getQueryCommands() {       
172
+        return queryCommands;
173
+    }    
174
+    
160 175
 }

+ 57
- 0
src/uk/org/ownage/dmdirc/commandparser/commands/query/QueryMe.java Wyświetl plik

@@ -0,0 +1,57 @@
1
+/*
2
+ * Copyright (c) 2006-2007 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 uk.org.ownage.dmdirc.commandparser.commands.query;
24
+
25
+import uk.org.ownage.dmdirc.Query;
26
+import uk.org.ownage.dmdirc.Server;
27
+import uk.org.ownage.dmdirc.commandparser.QueryCommand;
28
+import uk.org.ownage.dmdirc.commandparser.CommandWindow;
29
+
30
+/**
31
+ * Represents the /me command used in a query window.
32
+ * @author chris
33
+ */
34
+public class QueryMe extends QueryCommand {
35
+    
36
+    /** Creates a new instance of QueryMe */
37
+    public QueryMe() {
38
+        description = "sends an action to the query receipient";
39
+        arguments = "<action>";
40
+        polyadic = true;
41
+        arity = 0;
42
+        name = "me";
43
+        show = true;
44
+    }
45
+
46
+    /**
47
+     * Executes this command
48
+     * @param origin The frame in which this command was issued
49
+     * @param server The server object that this command is associated with
50
+     * @param query The query object that this command is associated with
51
+     * @param args The user supplied arguments
52
+     */
53
+    public void execute(CommandWindow origin, Server server, Query query, String... args) {
54
+        query.sendAction(implodeArgs(args));
55
+    }
56
+    
57
+}

+ 59
- 0
src/uk/org/ownage/dmdirc/commandparser/commands/query/QueryMeEmpty.java Wyświetl plik

@@ -0,0 +1,59 @@
1
+/*
2
+ * Copyright (c) 2006-2007 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 uk.org.ownage.dmdirc.commandparser.commands.query;
24
+
25
+import uk.org.ownage.dmdirc.Query;
26
+import uk.org.ownage.dmdirc.Config;
27
+import uk.org.ownage.dmdirc.Server;
28
+import uk.org.ownage.dmdirc.commandparser.QueryCommand;
29
+import uk.org.ownage.dmdirc.commandparser.CommandWindow;
30
+
31
+/**
32
+ * Represents the /me command used in a query window, with no parameters.
33
+ * Informs the user of the correct usage
34
+ * @author chris
35
+ */
36
+public class QueryMeEmpty extends QueryCommand {
37
+    
38
+    /** Creates a new instance of QueryMeEmpty */
39
+    public QueryMeEmpty() {
40
+        description = "informs the user of the correct usage of the me command";
41
+        arguments = "";
42
+        polyadic = false;
43
+        arity = 0;
44
+        name = "me";
45
+        show = false;
46
+    }
47
+    
48
+    /**
49
+     * Executes this command
50
+     * @param origin The frame in which this command was issued
51
+     * @param server The server object that this command is associated with
52
+     * @param query The query object that this command is associated with
53
+     * @param args The user supplied arguments
54
+     */
55
+    public void execute(CommandWindow origin, Server server, Query query, String... args) {
56
+        origin.addLine("Usage: "+Config.getOption("general","commandchar")+"me <action>");
57
+    }
58
+    
59
+}

+ 19
- 2
src/uk/org/ownage/dmdirc/commandparser/commands/server/Help.java Wyświetl plik

@@ -29,15 +29,18 @@ import uk.org.ownage.dmdirc.commandparser.CommandManager;
29 29
 import uk.org.ownage.dmdirc.commandparser.CommandWindow;
30 30
 import uk.org.ownage.dmdirc.commandparser.ServerCommand;
31 31
 import uk.org.ownage.dmdirc.ui.ChannelFrame;
32
+import uk.org.ownage.dmdirc.ui.QueryFrame;
32 33
 
33 34
 /**
34
- *
35
+ * The help command shows the user a list of available commands, along with
36
+ * their arguments, and a description. It is context-aware, so channel commands
37
+ * are only displayed when in a channel window, for example.
35 38
  * @author chris
36 39
  */
37 40
 public class Help extends ServerCommand {
38 41
     
39 42
     /**
40
-     * Creates a new instance of QuitDefault
43
+     * Creates a new instance of Help
41 44
      */
42 45
     public Help() {
43 46
         description = "Displays usage information for all implemented commands";
@@ -48,6 +51,12 @@ public class Help extends ServerCommand {
48 51
         show = true;
49 52
     }
50 53
     
54
+    /**
55
+     * Executes this command
56
+     * @param origin The frame in which this command was issued
57
+     * @param server The server object that this command is associated with
58
+     * @param args The user supplied arguments
59
+     */    
51 60
     public void execute(CommandWindow origin, Server server, String... args) {
52 61
         origin.addLine("-- Server commands ----------------------------------");
53 62
         for (Command com : CommandManager.getServerCommands()) {
@@ -63,6 +72,14 @@ public class Help extends ServerCommand {
63 72
                 }
64 73
             }
65 74
         }
75
+        if (origin instanceof QueryFrame) {
76
+            origin.addLine("-- Query commands -----------------------------------");
77
+            for (Command com : CommandManager.getQueryCommands()) {
78
+                if (com.showInHelp()) {
79
+                    origin.addLine(com.getHelp());
80
+                }
81
+            }
82
+        }
66 83
         origin.addLine("-----------------------------------------------------");
67 84
     }
68 85
     

+ 10
- 3
src/uk/org/ownage/dmdirc/commandparser/commands/server/Join.java Wyświetl plik

@@ -28,13 +28,14 @@ import uk.org.ownage.dmdirc.commandparser.CommandWindow;
28 28
 import uk.org.ownage.dmdirc.commandparser.ServerCommand;
29 29
 
30 30
 /**
31
- *
31
+ * The join command allows users to join a channel, or a comma-seperated list
32
+ * of channels.
32 33
  * @author chris
33 34
  */
34 35
 public class Join extends ServerCommand {
35 36
     
36 37
     /**
37
-     * Creates a new instance of QuitDefault
38
+     * Creates a new instance of Join
38 39
      */
39 40
     public Join () {
40 41
         description = "Joins the specified channel. Multiple channels may be seperated by commas.";
@@ -44,7 +45,13 @@ public class Join extends ServerCommand {
44 45
         name = "join";
45 46
         show = true;
46 47
     }
47
-    
48
+
49
+    /**
50
+     * Executes this command
51
+     * @param origin The frame in which this command was issued
52
+     * @param server The server object that this command is associated with
53
+     * @param args The user supplied arguments
54
+     */    
48 55
     public void execute(CommandWindow origin, Server server, String... args) {
49 56
         server.getParser().joinChannel(args[0]);
50 57
     }

+ 10
- 2
src/uk/org/ownage/dmdirc/commandparser/commands/server/Quit.java Wyświetl plik

@@ -29,13 +29,15 @@ import uk.org.ownage.dmdirc.commandparser.CommandWindow;
29 29
 import uk.org.ownage.dmdirc.commandparser.ServerCommand;
30 30
 
31 31
 /**
32
- *
32
+ * The quit command allows the user to quit DMDirc with a custom quit message.
33
+ * When the client quits, it disconnects all servers (with the quit message
34
+ * supplied) and saves the config file.
33 35
  * @author chris
34 36
  */
35 37
 public class Quit extends ServerCommand {
36 38
     
37 39
     /**
38
-     * Creates a new instance of QuitDefault
40
+     * Creates a new instance of Quit
39 41
      */
40 42
     public Quit() {
41 43
         description = "Quits DMDirc, sending the specified quit message to all servers";
@@ -46,6 +48,12 @@ public class Quit extends ServerCommand {
46 48
         show = true;
47 49
     }
48 50
     
51
+    /**
52
+     * Executes this command
53
+     * @param origin The frame in which this command was issued
54
+     * @param server The server object that this command is associated with
55
+     * @param args The user supplied arguments
56
+     */    
49 57
     public void execute(CommandWindow origin, Server server, String... args) {
50 58
         ServerManager.getServerManager().disconnectAll(implodeArgs(args));
51 59
         Config.save();

+ 13
- 5
src/uk/org/ownage/dmdirc/commandparser/commands/server/QuitDefault.java Wyświetl plik

@@ -29,7 +29,9 @@ import uk.org.ownage.dmdirc.commandparser.CommandWindow;
29 29
 import uk.org.ownage.dmdirc.commandparser.ServerCommand;
30 30
 
31 31
 /**
32
- *
32
+ * Represents the quit/0 command (i.e., a quit with no arguments). Reads the
33
+ * default quit message from the config file and calls the normal quit command
34
+ * with it as an argument.
33 35
  * @author chris
34 36
  */
35 37
 public class QuitDefault extends ServerCommand {
@@ -41,11 +43,17 @@ public class QuitDefault extends ServerCommand {
41 43
         description = "Quits DMDirc, sending a default quit message to all servers";
42 44
         arguments = "";
43 45
         polyadic = false;
44
-        arity = 0;            
45
-        name = "quit";        
46
-        show = true;        
46
+        arity = 0;
47
+        name = "quit";
48
+        show = true;
47 49
     }
48
-
50
+    
51
+    /**
52
+     * Executes this command
53
+     * @param origin The frame in which this command was issued
54
+     * @param server The server object that this command is associated with
55
+     * @param args The user supplied arguments
56
+     */
49 57
     public void execute(CommandWindow origin, Server server, String... args) {
50 58
         String def = Config.getOption("general","quitmessage");
51 59
         CommandManager.getServerCommad("quit").execute(origin, server, def);

Ładowanie…
Anuluj
Zapisz