Selaa lähdekoodia

massive command parser butchering

git-svn-id: http://svn.dmdirc.com/trunk@2702 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5.5
Chris Smith 16 vuotta sitten
vanhempi
commit
071567bbac

+ 5
- 4
src/com/dmdirc/Channel.java Näytä tiedosto

@@ -25,6 +25,7 @@ package com.dmdirc;
25 25
 import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.actions.CoreActionType;
27 27
 import com.dmdirc.commandparser.CommandManager;
28
+import com.dmdirc.commandparser.CommandType;
28 29
 import com.dmdirc.interfaces.ConfigChangeListener;
29 30
 import com.dmdirc.config.ConfigManager;
30 31
 import com.dmdirc.parser.ChannelClientInfo;
@@ -123,8 +124,8 @@ public final class Channel extends MessageTarget
123 124
         icon = IconManager.getIconManager().getIcon("channel");
124 125
         
125 126
         tabCompleter = new TabCompleter(server.getTabCompleter());
126
-        tabCompleter.addEntries(CommandManager.getChannelCommandNames());
127
-        tabCompleter.addEntries(CommandManager.getChatCommandNames());
127
+        tabCompleter.addEntries(CommandManager.getCommandNames(CommandType.TYPE_CHANNEL));
128
+        tabCompleter.addEntries(CommandManager.getCommandNames(CommandType.TYPE_CHAT));
128 129
         
129 130
         window = Main.getUI().getChannel(Channel.this);
130 131
         WindowManager.addWindow(server.getFrame(), window);
@@ -424,8 +425,8 @@ public final class Channel extends MessageTarget
424 425
         }
425 426
         
426 427
         tabCompleter.replaceEntries(names);
427
-        tabCompleter.addEntries(CommandManager.getChannelCommandNames());
428
-        tabCompleter.addEntries(CommandManager.getChatCommandNames());
428
+        tabCompleter.addEntries(CommandManager.getCommandNames(CommandType.TYPE_CHANNEL));
429
+        tabCompleter.addEntries(CommandManager.getCommandNames(CommandType.TYPE_CHAT));
429 430
         
430 431
         ActionManager.processEvent(CoreActionType.CHANNEL_GOTNAMES, null, this);
431 432
     }

+ 2
- 1
src/com/dmdirc/GlobalWindow.java Näytä tiedosto

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.commandparser.CommandManager;
26
+import com.dmdirc.commandparser.CommandType;
26 27
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
27 28
 import com.dmdirc.config.ConfigManager;
28 29
 import com.dmdirc.config.IdentityManager;
@@ -45,7 +46,7 @@ public class GlobalWindow extends WritableFrameContainer {
45 46
         super();
46 47
         
47 48
         final TabCompleter tabCompleter = new TabCompleter();
48
-        tabCompleter.addEntries(CommandManager.getGlobalCommandNames());
49
+        tabCompleter.addEntries(CommandManager.getCommandNames(CommandType.TYPE_GLOBAL));
49 50
         
50 51
         window = Main.getUI().getInputWindow(this, GlobalCommandParser.getGlobalCommandParser());
51 52
         

+ 3
- 2
src/com/dmdirc/Query.java Näytä tiedosto

@@ -25,6 +25,7 @@ package com.dmdirc;
25 25
 import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.actions.CoreActionType;
27 27
 import com.dmdirc.commandparser.CommandManager;
28
+import com.dmdirc.commandparser.CommandType;
28 29
 import com.dmdirc.logger.ErrorLevel;
29 30
 import com.dmdirc.logger.Logger;
30 31
 import com.dmdirc.parser.ClientInfo;
@@ -96,8 +97,8 @@ public final class Query extends MessageTarget implements
96 97
         }
97 98
         
98 99
         tabCompleter = new TabCompleter(server.getTabCompleter());
99
-        tabCompleter.addEntries(CommandManager.getQueryCommandNames());
100
-        tabCompleter.addEntries(CommandManager.getChatCommandNames());
100
+        tabCompleter.addEntries(CommandManager.getCommandNames(CommandType.TYPE_QUERY));
101
+        tabCompleter.addEntries(CommandManager.getCommandNames(CommandType.TYPE_CHAT));
101 102
         window.getInputHandler().setTabCompleter(tabCompleter);
102 103
         
103 104
         reregister();

+ 3
- 2
src/com/dmdirc/Server.java Näytä tiedosto

@@ -26,6 +26,7 @@ import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.actions.CoreActionType;
27 27
 import com.dmdirc.actions.wrappers.AliasWrapper;
28 28
 import com.dmdirc.commandparser.CommandManager;
29
+import com.dmdirc.commandparser.CommandType;
29 30
 import com.dmdirc.config.ConfigManager;
30 31
 import com.dmdirc.config.Identity;
31 32
 import com.dmdirc.config.IdentityManager;
@@ -170,8 +171,8 @@ public final class Server extends WritableFrameContainer implements Serializable
170 171
 
171 172
         window.open();
172 173
 
173
-        tabCompleter.addEntries(CommandManager.getServerCommandNames());
174
-        tabCompleter.addEntries(CommandManager.getGlobalCommandNames());
174
+        tabCompleter.addEntries(CommandManager.getCommandNames(CommandType.TYPE_SERVER));
175
+        tabCompleter.addEntries(CommandManager.getCommandNames(CommandType.TYPE_GLOBAL));
175 176
 
176 177
         this.autochannels = autochannels;
177 178
 

+ 77
- 0
src/com/dmdirc/commandparser/CommandInfo.java Näytä tiedosto

@@ -0,0 +1,77 @@
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 com.dmdirc.commandparser;
24
+
25
+/**
26
+ *
27
+ * @author chris
28
+ */
29
+public abstract class CommandInfo {
30
+    
31
+    /**
32
+     * Returns the signature of this command. For polyadic commands, the signature
33
+     * is simply the name. For other commands, the signature is a concatenation of
34
+     * the name, a literal "/", and the arity.
35
+     * @return The signature of this command
36
+     */
37
+    public final String getSignature() {
38
+        if (isPolyadic()) {
39
+            return getName();
40
+        } else {
41
+            return getName() + "/" + getArity();
42
+        }
43
+    }
44
+        
45
+    /**
46
+     * Returns this command's name.
47
+     * @return The name of this command
48
+     */
49
+    public abstract String getName();
50
+    
51
+    /**
52
+     * Returns whether or not this command should be shown in help messages.
53
+     * @return True iff the command should be shown, false otherwise
54
+     */
55
+    public abstract boolean showInHelp();
56
+    
57
+    /**
58
+     * Indicates whether this command is polyadic or not.
59
+     * @return True iff this command is polyadic, false otherwise
60
+     */
61
+    public abstract boolean isPolyadic();
62
+    
63
+    /**
64
+     * Returns the arity of this command.
65
+     * @return This command's arity
66
+     */
67
+    public abstract int getArity();
68
+    
69
+    /**
70
+     * Returns a string representing the help message for this command.
71
+     * @return the help message for this command
72
+     */
73
+    public abstract String getHelp();
74
+    
75
+    public abstract CommandType getType();
76
+
77
+}

+ 63
- 327
src/com/dmdirc/commandparser/CommandManager.java Näytä tiedosto

@@ -41,10 +41,13 @@ import com.dmdirc.config.IdentityManager;
41 41
 import com.dmdirc.logger.ErrorLevel;
42 42
 import com.dmdirc.logger.Logger;
43 43
 import com.dmdirc.ui.input.TabCompleter;
44
+import com.dmdirc.util.MapList;
44 45
 import com.dmdirc.util.WeakList;
45 46
 
46 47
 import java.util.ArrayList;
48
+import java.util.HashMap;
47 49
 import java.util.List;
50
+import java.util.Map;
48 51
 
49 52
 /**
50 53
  * The command manager creates and manages a single instance of all commands,
@@ -54,44 +57,14 @@ import java.util.List;
54 57
  */
55 58
 public final class CommandManager {
56 59
     
57
-    /**
58
-     * The global commands that have been instansiated.
59
-     */
60
-    private static final List<Command> globalCommands = new ArrayList<Command>();
61
-    /**
62
-     * The server commands that have been instansiated.
63
-     */
64
-    private static final List<Command> serverCommands = new ArrayList<Command>();
65
-    /**
66
-     * The channel commands that have been instansiated.
67
-     */
68
-    private static final List<Command> channelCommands = new ArrayList<Command>();
69
-    /**
70
-     * The query commands that have been instansiated.
71
-     */
72
-    private static final List<Command> queryCommands = new ArrayList<Command>();
73
-    /**
74
-     * The "chat" commands that have been instansiated.
75
-     */
76
-    private static final List<Command> chatCommands = new ArrayList<Command>();
77
-    
78
-    /**
79
-     * The parsers that have requested global commands.
80
-     */
81
-    private static final List<CommandParser> globalParsers = new WeakList<CommandParser>();
82
-    /**
83
-     * The parsers that have requested server commands.
84
-     */
85
-    private static final List<CommandParser> serverParsers = new WeakList<CommandParser>();
86
-    /**
87
-     * The parsers that have requested channel commands.
88
-     */
89
-    private static final List<CommandParser> channelParsers = new WeakList<CommandParser>();
90
-    /**
91
-     * The parsers that have requested query commands.
92
-     */
93
-    private static final List<CommandParser> queryParsers = new WeakList<CommandParser>();
60
+    /** A list of commands that have been instansiated. */
61
+    private static final Map<CommandInfo, Command> commands
62
+            = new HashMap<CommandInfo, Command>();
94 63
     
64
+    /** A list of command parsers that have been instansiated. */
65
+    private static final MapList<CommandType, CommandParser> parsers
66
+            = new MapList<CommandType, CommandParser>();
67
+           
95 68
     /**
96 69
      * Channel commands that have been registered to appear in the nicklist
97 70
      * popup.
@@ -160,21 +133,16 @@ public final class CommandManager {
160 133
         boolean canContinue = true;
161 134
         
162 135
         if (command instanceof ChannelCommand) {
163
-            registerCommand(command, channelParsers, register);
164
-            channelCommands.add(command);
136
+            registerCommand(command, parsers.get(CommandType.TYPE_CHANNEL), register);
165 137
         } else if (command instanceof ServerCommand) {
166
-            registerCommand(command, serverParsers, register);
167
-            serverCommands.add(command);
138
+            registerCommand(command, parsers.get(CommandType.TYPE_SERVER), register);
168 139
         } else if (command instanceof QueryCommand) {
169
-            registerCommand(command, queryParsers, register);
170
-            queryCommands.add(command);
140
+            registerCommand(command, parsers.get(CommandType.TYPE_QUERY), register);
171 141
         } else if (command instanceof GlobalCommand) {
172
-            registerCommand(command, globalParsers, register);
173
-            globalCommands.add(command);
142
+            registerCommand(command, parsers.get(CommandType.TYPE_GLOBAL), register);
174 143
         } else if (command instanceof ChatCommand) {
175
-            registerCommand(command, queryParsers, register);
176
-            registerCommand(command, channelParsers, register);
177
-            chatCommands.add(command);
144
+            registerCommand(command, parsers.get(CommandType.TYPE_QUERY), register);
145
+            registerCommand(command, parsers.get(CommandType.TYPE_CHANNEL), register);
178 146
         } else {
179 147
             canContinue = false;
180 148
             
@@ -183,6 +151,7 @@ public final class CommandManager {
183 151
         }
184 152
         
185 153
         if (canContinue) {
154
+            commands.put(command, command);
186 155
             registerCommandName(command, register);
187 156
         }
188 157
     }
@@ -194,7 +163,11 @@ public final class CommandManager {
194 163
      * @param parsers The parsers to register the command with
195 164
      */
196 165
     private static void registerCommand(final Command command,
197
-            final List<CommandParser> parsers, final boolean register) {
166
+            final List<? extends CommandParser> parsers, final boolean register) {
167
+        if (parsers == null) {
168
+            return;
169
+        }
170
+        
198 171
         for (CommandParser parser : parsers) {
199 172
             if (register) {
200 173
                 parser.registerCommand(command);
@@ -224,13 +197,15 @@ public final class CommandManager {
224 197
             
225 198
             if (command instanceof ChannelCommand || command instanceof ChatCommand) {
226 199
                 for (String channelName : server.getChannels()) {
227
-                    registerCommandName(server.getChannel(channelName).getTabCompleter(), commandName, register);
200
+                    registerCommandName(server.getChannel(channelName).getTabCompleter(),
201
+                            commandName, register);
228 202
                 }
229 203
             }
230 204
             
231 205
             if (command instanceof QueryCommand || command instanceof ChatCommand) {
232 206
                 for (String queryName : server.getQueries()) {
233
-                    registerCommandName(server.getQuery(queryName).getTabCompleter(), commandName, register);
207
+                    registerCommandName(server.getQuery(queryName).getTabCompleter(),
208
+                            commandName, register);
234 209
                 }
235 210
             }
236 211
         }
@@ -284,12 +259,9 @@ public final class CommandManager {
284 259
         new Ban();
285 260
         new ChannelSettings();
286 261
         new Cycle();
287
-        new Kick();
288
-        new KickEmpty();
289 262
         new KickReason();
290 263
         new Mode();
291 264
         new Part();
292
-        new PartDefault();
293 265
         new SetNickColour();
294 266
         new SetTopic();
295 267
         new ShowTopic();
@@ -327,7 +299,6 @@ public final class CommandManager {
327 299
         new Debug();
328 300
         new Echo();
329 301
         new Exit();
330
-        new ExitDefault();
331 302
         new Ifplugin();
332 303
         new NewServer();
333 304
         new Notify();
@@ -360,15 +331,15 @@ public final class CommandManager {
360 331
      * @param parser The parser to load commands into
361 332
      */
362 333
     public static void loadChannelCommands(final CommandParser parser) {
363
-        for (Command com : channelCommands) {
334
+        for (Command com : getCommands(CommandType.TYPE_CHANNEL, null, null)) {
364 335
             parser.registerCommand(com);
365 336
         }
366 337
         
367
-        for (Command com : chatCommands) {
338
+        for (Command com : getCommands(CommandType.TYPE_CHAT, null, null)) {
368 339
             parser.registerCommand(com);
369 340
         }
370 341
         
371
-        channelParsers.add(parser);
342
+        parsers.add(CommandType.TYPE_CHANNEL, parser);
372 343
     }
373 344
     
374 345
     /**
@@ -377,11 +348,11 @@ public final class CommandManager {
377 348
      * @param parser The parser to load commands into
378 349
      */
379 350
     public static void loadServerCommands(final CommandParser parser) {
380
-        for (Command command : serverCommands) {
351
+        for (Command command : getCommands(CommandType.TYPE_SERVER, null, null)) {
381 352
             parser.registerCommand(command);
382 353
         }
383 354
         
384
-        serverParsers.add(parser);
355
+        parsers.add(CommandType.TYPE_SERVER, parser);
385 356
     }
386 357
     
387 358
     /**
@@ -390,11 +361,11 @@ public final class CommandManager {
390 361
      * @param parser The parser to load commands into
391 362
      */
392 363
     public static void loadGlobalCommands(final CommandParser parser) {
393
-        for (Command com : globalCommands) {
364
+        for (Command com : getCommands(CommandType.TYPE_GLOBAL, null, null)) {
394 365
             parser.registerCommand(com);
395 366
         }
396 367
         
397
-        globalParsers.add(parser);
368
+        parsers.add(CommandType.TYPE_GLOBAL, parser);
398 369
     }
399 370
     
400 371
     /**
@@ -403,15 +374,15 @@ public final class CommandManager {
403 374
      * @param parser The parser to load commands into
404 375
      */
405 376
     public static void loadQueryCommands(final CommandParser parser) {
406
-        for (Command com : queryCommands) {
377
+        for (Command com : getCommands(CommandType.TYPE_QUERY, null, null)) {
407 378
             parser.registerCommand(com);
408 379
         }
409 380
         
410
-        for (Command com : chatCommands) {
381
+        for (Command com : getCommands(CommandType.TYPE_CHAT, null, null)) {
411 382
             parser.registerCommand(com);
412 383
         }
413 384
         
414
-        queryParsers.add(parser);
385
+        parsers.add(CommandType.TYPE_QUERY, parser);
415 386
     }
416 387
     
417 388
     /**
@@ -422,195 +393,16 @@ public final class CommandManager {
422 393
      * @return A command with a matching signature, or null if none were found
423 394
      */
424 395
     public static Command getCommand(final String name) {
425
-        if (getGlobalCommandByName(name) != null) {
426
-            return getGlobalCommandByName(name);
427
-        } else if (getServerCommandByName(name) != null) {
428
-            return getServerCommandByName(name);
429
-        } else if (getChannelCommandByName(name) != null) {
430
-            return getChannelCommandByName(name);
431
-        } else if (getChatCommandByName(name) != null) {
432
-            return getChatCommandByName(name);
433
-        } else {
434
-            return getChannelCommandByName(name);
435
-        }
436
-    }
437
-    
438
-    /**
439
-     * Retrieves the server command identified by the specified signature.
440
-     * 
441
-     * @param signature The signature to look for
442
-     * @return A server command with a matching signature, or null if none
443
-     * were found.
444
-     */
445
-    public static ServerCommand getServerCommand(final String signature) {
446
-        for (Command com : serverCommands) {
447
-            if (com.getSignature().equalsIgnoreCase(signature)) {
448
-                return (ServerCommand) com;
449
-            }
450
-        }
451
-        
452
-        return null;
453
-    }
454
-    
455
-    /**
456
-     * Retrieves the server command identified by the specified name.
457
-     * 
458
-     * @param name The name to look for
459
-     * @return A server command with a matching name, or null if none were found
460
-     */
461
-    public static ServerCommand getServerCommandByName(final String name) {
462
-        return (ServerCommand) getCommandByName(name, serverCommands);
463
-    }
464
-    
465
-    /**
466
-     * Retrieves the global command identified by the specified signature.
467
-     * 
468
-     * @param signature The signature to look for
469
-     * @return A global command with a matching signature, or null if none
470
-     * were found.
471
-     */
472
-    public static GlobalCommand getGlobalCommand(final String signature) {
473
-        for (Command com : globalCommands) {
474
-            if (com.getSignature().equalsIgnoreCase(signature)) {
475
-                return (GlobalCommand) com;
476
-            }
477
-        }
478
-        
479
-        return null;
480
-    }
481
-    
482
-    /**
483
-     * Retrieves the global command identified by the specified name.
484
-     * 
485
-     * @param name The name to look for
486
-     * @return A global command with a matching name, or null if none were found
487
-     */
488
-    public static GlobalCommand getGlobalCommandByName(final String name) {
489
-        return (GlobalCommand) getCommandByName(name, globalCommands);
490
-    }
491
-    
492
-    /**
493
-     * Retrieves the channel command identified by the specified signature.
494
-     * 
495
-     * @param signature The signature to look for
496
-     * @return A channel command with a matching signature, or null if none
497
-     * were found.
498
-     */
499
-    public static ChannelCommand getChannelCommand(final String signature) {
500
-        for (Command com : channelCommands) {
501
-            if (com.getSignature().equalsIgnoreCase(signature)) {
502
-                return (ChannelCommand) com;
503
-            }
504
-        }
505
-        
506
-        return null;
507
-    }
508
-    
509
-    /**
510
-     * Retrieves the channel command identified by the specified name.
511
-     * 
512
-     * @param name The name to look for
513
-     * @return A channel command with a matching name, or null if none were found
514
-     */
515
-    public static ChannelCommand getChannelCommandByName(final String name) {
516
-        return (ChannelCommand) getCommandByName(name, channelCommands);
517
-    }
518
-    
519
-    /**
520
-     * Retrieves the chat command identified by the specified signature.
521
-     * 
522
-     * @param signature The signature to look for
523
-     * @return A chat command with a matching signature, or null if none
524
-     * were found.
525
-     */
526
-    public static ChatCommand getChatCommand(final String signature) {
527
-        for (Command com : chatCommands) {
528
-            if (com.getSignature().equalsIgnoreCase(signature)) {
529
-                return (ChatCommand) com;
530
-            }
531
-        }
532
-        
533
-        return null;
534
-    }
535
-    
536
-    /**
537
-     * Retrieves the chat command identified by the specified name.
538
-     * 
539
-     * @param name The name to look for
540
-     * @return A chat command with a matching name, or null if none were found
541
-     */
542
-    public static ChatCommand getChatCommandByName(final String name) {
543
-        return (ChatCommand) getCommandByName(name, chatCommands);
396
+        return getCommand(null, name, null);
544 397
     }
545 398
     
546
-    /**
547
-     * Retrieves the command identified by the specified name.
548
-     * 
549
-     * @param name The name to look for
550
-     * @param list The list to look in
551
-     * @return A command with a matching name, or null if none were found
552
-     */
553
-    private static Command getCommandByName(final String name,
554
-            final List<Command> list) {
555
-        for (Command com : list) {
556
-            if (com.getName().equalsIgnoreCase(name)) {
557
-                return com;
558
-            }
559
-        }
399
+    public static Command getCommand(final CommandType type, final String name,
400
+            final String signature) {
401
+        final List<Command> res = getCommands(type, name, signature);
560 402
         
561
-        return null;
562
-    }
563
-    
564
-    /**
565
-     * Returns a list containing the global commands that have been initialised
566
-     * by this command manager.
567
-     * 
568
-     * @return An ArrayList of global commands, or null if none have been loaded
569
-     */
570
-    public static List<Command> getGlobalCommands() {
571
-        return globalCommands;
572
-    }
573
-    
574
-    /**
575
-     * Returns a list containing the server commands that have been initialised
576
-     * by this command manager.
577
-     * 
578
-     * @return An ArrayList of server commands, or null if none have been loaded
579
-     */
580
-    public static List<Command> getServerCommands() {
581
-        return serverCommands;
582
-    }
583
-    
584
-    /**
585
-     * Returns a list containing the channel commands that have been initialised
586
-     * by this command manager.
587
-     * 
588
-     * @return An ArrayList of channel commands, or null if none have been loaded
589
-     */
590
-    public static List<Command> getChannelCommands() {
591
-        return channelCommands;
592
-    }
593
-    
594
-    /**
595
-     * Returns a list containing the chat commands that have been initialised
596
-     * by this command manager.
597
-     * 
598
-     * @return An ArrayList of chat commands, or null if none have been loaded
599
-     */
600
-    public static List<Command> getChatCommands() {
601
-        return chatCommands;
602
-    }
603
-    
604
-    /**
605
-     * Returns a list containing the query commands that have been initialised
606
-     * by this command manager.
607
-     * 
608
-     * @return An ArrayList of query commands, or null if none have been loaded
609
-     */
610
-    public static List<Command> getQueryCommands() {
611
-        return queryCommands;
612
-    }
613
-    
403
+        return res.isEmpty() ? null : res.get(0);
404
+    }    
405
+     
614 406
     /**
615 407
      * Determines if the specified command is a valid channel command.
616 408
      * 
@@ -618,90 +410,34 @@ public final class CommandManager {
618 410
      * @return True iff the command is a channel command, false otherwise
619 411
      */
620 412
     public static boolean isChannelCommand(final String command) {
621
-        for (Command chanCommand : channelCommands) {
622
-            if (chanCommand.getName().equalsIgnoreCase(command)) {
623
-                return true;
624
-            }
625
-        }
413
+        return getCommand(CommandType.TYPE_CHANNEL, command, null) != null
414
+                || getCommand(CommandType.TYPE_CHAT, command, null) != null;
415
+    }
416
+       
417
+    public static List<String> getCommandNames(final CommandType type) {
418
+        final List<String> res = new ArrayList<String>();
626 419
         
627
-        for (Command chanCommand : chatCommands) {
628
-            if (chanCommand.getName().equalsIgnoreCase(command)) {
629
-                return true;
630
-            }
420
+        for (Command command : getCommands(type, null, null)) {
421
+            res.add(getCommandChar() + command.getName());
631 422
         }
632 423
         
633
-        return false;
634
-    }
635
-    
636
-    /**
637
-     * Returns the names (including command char) of all registered server
638
-     * commands.
639
-     * 
640
-     * @return An ArrayList&lt;String&gt; containing all registered server command
641
-     * names
642
-     */
643
-    public static List<String> getServerCommandNames() {
644
-        return getCommandNames(serverCommands);
645
-    }
646
-    
647
-    /**
648
-     * Returns the names (including command char) of all registered global
649
-     * commands.
650
-     * 
651
-     * @return An ArrayList&lt;String&gt; containing all registered global command
652
-     * names
653
-     */
654
-    public static List<String> getGlobalCommandNames() {
655
-        return getCommandNames(globalCommands);
656
-    }
657
-    
658
-    /**
659
-     * Returns the names (including command char) of all registered channel
660
-     * commands.
661
-     * 
662
-     * @return A list containing all registered channel command names
663
-     */
664
-    public static List<String> getChannelCommandNames() {
665
-        return getCommandNames(channelCommands);
666
-    }
667
-    
668
-    /**
669
-     * Returns the names (including command char) of all registered query
670
-     * commands.
671
-     * 
672
-     * @return A list containing all registered query command names
673
-     */
674
-    public static List<String> getQueryCommandNames() {
675
-        return getCommandNames(queryCommands);
424
+        return res;
676 425
     }
677 426
     
678
-    /**
679
-     * Returns the names (including command char) of all registered chat
680
-     * commands.
681
-     * 
682
-     * @return An ArrayList&lt;String&gt; containing all registered chat command
683
-     * names
684
-     */
685
-    public static List<String> getChatCommandNames() {
686
-        return getCommandNames(chatCommands);
427
+    public static List<Command> getCommands(final CommandType type) {    
428
+        return getCommands(type, null, null);
687 429
     }
688 430
     
689
-    /**
690
-     * Iterates through the specified source and returns a list of the names
691
-     * of all commands found in it.
692
-     * 
693
-     * @param source The source vector to iterate over
694
-     * @return A list of all commands in the source
695
-     */
696
-    private static List<String> getCommandNames(final List<Command> source) {
697
-        if (source == null) {
698
-            return null;
699
-        }
431
+    private static List<Command> getCommands(final CommandType type,
432
+            final String name, final String signature) {
433
+        final List<Command> res = new ArrayList<Command>();
700 434
         
701
-        final List<String> res = new ArrayList<String>();
702
-        
703
-        for (Command command : source) {
704
-            res.add(getCommandChar() + command.getName());
435
+        for (Map.Entry<CommandInfo, Command> entry : commands.entrySet()) {
436
+            if ((type == null || type.equals(entry.getKey().getType()))
437
+                    && (name == null || name.equals(entry.getKey().getName()))
438
+                    && (signature == null || signature.equals(entry.getKey().getSignature()))) {
439
+                res.add(entry.getValue());
440
+            }
705 441
         }
706 442
         
707 443
         return res;

+ 60
- 0
src/com/dmdirc/commandparser/CommandType.java Näytä tiedosto

@@ -0,0 +1,60 @@
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 com.dmdirc.commandparser;
24
+
25
+import com.dmdirc.commandparser.commands.ChannelCommand;
26
+import com.dmdirc.commandparser.commands.ChatCommand;
27
+import com.dmdirc.commandparser.commands.Command;
28
+import com.dmdirc.commandparser.commands.GlobalCommand;
29
+import com.dmdirc.commandparser.commands.QueryCommand;
30
+import com.dmdirc.commandparser.commands.ServerCommand;
31
+
32
+/**
33
+ *
34
+ * @author chris
35
+ */
36
+public enum CommandType {
37
+    
38
+    TYPE_GLOBAL,
39
+    TYPE_SERVER,
40
+    TYPE_CHAT,
41
+    TYPE_CHANNEL,
42
+    TYPE_QUERY;
43
+    
44
+    public static CommandType fromCommand(final Command command) {
45
+        if (command instanceof GlobalCommand) {
46
+            return TYPE_GLOBAL;
47
+        } else if (command instanceof ServerCommand) {
48
+            return TYPE_SERVER;
49
+        } else if (command instanceof ChatCommand) {
50
+            return TYPE_CHAT;
51
+        } else if (command instanceof ChannelCommand) {
52
+            return TYPE_CHANNEL;
53
+        } else if (command instanceof QueryCommand) {
54
+            return TYPE_QUERY;
55
+        } else {
56
+            return null;
57
+        }
58
+    }
59
+
60
+}

+ 12
- 46
src/com/dmdirc/commandparser/commands/Command.java Näytä tiedosto

@@ -22,65 +22,23 @@
22 22
 
23 23
 package com.dmdirc.commandparser.commands;
24 24
 
25
+import com.dmdirc.commandparser.CommandInfo;
25 26
 import com.dmdirc.commandparser.CommandManager;
27
+import com.dmdirc.commandparser.CommandType;
26 28
 import com.dmdirc.ui.interfaces.InputWindow;
27 29
 
28 30
 /**
29 31
  * Represents a generic command.
30 32
  * @author chris
31 33
  */
32
-public abstract class Command implements Comparable<Command> {
34
+public abstract class Command extends CommandInfo implements Comparable<Command> {
33 35
     
34 36
     /** The format name used for command output. */
35 37
     protected static final String FORMAT_OUTPUT = "commandOutput";
36 38
     
37 39
     /** The format name used for command errors. */
38 40
     protected static final String FORMAT_ERROR = "commandError";
39
-            
40
-    /**
41
-     * Returns the signature of this command. For polyadic commands, the signature
42
-     * is simply the name. For other commands, the signature is a concatenation of
43
-     * the name, a literal "/", and the arity.
44
-     * @return The signature of this command
45
-     */
46
-    public final String getSignature() {
47
-        if (isPolyadic()) {
48
-            return getName();
49
-        } else {
50
-            return getName() + "/" + getArity();
51
-        }
52
-    }
53
-        
54
-    /**
55
-     * Returns this command's name.
56
-     * @return The name of this command
57
-     */
58
-    public abstract String getName();
59
-    
60
-    /**
61
-     * Returns whether or not this command should be shown in help messages.
62
-     * @return True iff the command should be shown, false otherwise
63
-     */
64
-    public abstract boolean showInHelp();
65
-    
66
-    /**
67
-     * Indicates whether this command is polyadic or not.
68
-     * @return True iff this command is polyadic, false otherwise
69
-     */
70
-    public abstract boolean isPolyadic();
71
-    
72
-    /**
73
-     * Returns the arity of this command.
74
-     * @return This command's arity
75
-     */
76
-    public abstract int getArity();
77
-    
78
-    /**
79
-     * Returns a string representing the help message for this command.
80
-     * @return the help message for this command
81
-     */
82
-    public abstract String getHelp();
83
-    
41
+               
84 42
     /**
85 43
      * Implodes the given list of arguments.
86 44
      * @param offset The index to start at
@@ -137,7 +95,15 @@ public abstract class Command implements Comparable<Command> {
137 95
     }    
138 96
     
139 97
     /** {@inheritDoc} */
98
+    @Override
140 99
     public final int compareTo(final Command o) {
141 100
         return getSignature().compareTo(o.getSignature());
142 101
     }
102
+
103
+    /** {@inheritDoc} */
104
+    @Override
105
+    public CommandType getType() {
106
+        return CommandType.fromCommand(this);
107
+    }
108
+
143 109
 }

+ 0
- 87
src/com/dmdirc/commandparser/commands/channel/Kick.java Näytä tiedosto

@@ -1,87 +0,0 @@
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 com.dmdirc.commandparser.commands.channel;
24
-
25
-import com.dmdirc.Channel;
26
-import com.dmdirc.Server;
27
-import com.dmdirc.commandparser.commands.ChannelCommand;
28
-import com.dmdirc.commandparser.CommandManager;
29
-import com.dmdirc.ui.interfaces.InputWindow;
30
-
31
-/**
32
- * The kick command kicks a specified user from the channel.
33
- * @author chris
34
- */
35
-public final class Kick extends ChannelCommand {
36
-    
37
-    /** Creates a new instance of Kick. */
38
-    public Kick() {
39
-        super();
40
-        
41
-        CommandManager.registerCommand(this);
42
-        CommandManager.registerPopupCommand(this);
43
-    }
44
-    
45
-    /**
46
-     * Executes this command.
47
-     * @param origin The frame in which this command was issued
48
-     * @param server The server object that this command is associated with
49
-     * @param channel The channel object that this command is associated with
50
-     * @param isSilent Whether this command is silenced or not
51
-     * @param args The user supplied arguments
52
-     */
53
-    public void execute(final InputWindow origin, final Server server,
54
-            final Channel channel, final boolean isSilent, final String... args) {
55
-        final String[] newArgs = new String[2];
56
-        newArgs[0] = args[0]; // Nickname
57
-        newArgs[1] = origin.getConfigManager().getOption("general", "kickmessage");
58
-        
59
-        CommandManager.getChannelCommand("kick").execute(origin, server, channel, isSilent, newArgs);
60
-    }
61
-    
62
-    /** {@inheritDoc}. */
63
-    public String getName() {
64
-        return "kick";
65
-    }
66
-    
67
-    /** {@inheritDoc}. */
68
-    public boolean showInHelp() {
69
-        return true;
70
-    }
71
-    
72
-    /** {@inheritDoc}. */
73
-    public boolean isPolyadic() {
74
-        return false;
75
-    }
76
-    
77
-    /** {@inheritDoc}. */
78
-    public int getArity() {
79
-        return 1;
80
-    }
81
-    
82
-    /** {@inheritDoc}. */
83
-    public String getHelp() {
84
-        return "kick <user> - kicks the specified user from the channel";
85
-    }
86
-    
87
-}

+ 0
- 82
src/com/dmdirc/commandparser/commands/channel/KickEmpty.java Näytä tiedosto

@@ -1,82 +0,0 @@
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 com.dmdirc.commandparser.commands.channel;
24
-
25
-import com.dmdirc.Channel;
26
-import com.dmdirc.Server;
27
-import com.dmdirc.commandparser.commands.ChannelCommand;
28
-import com.dmdirc.commandparser.CommandManager;
29
-import com.dmdirc.ui.interfaces.InputWindow;
30
-
31
-/**
32
- * The kick/0 command informs the user of the correct usage of /kick.
33
- * @author chris
34
- */
35
-public final class KickEmpty extends ChannelCommand {
36
-    
37
-    /** Creates a new instance of KickEmpty. */
38
-    public KickEmpty() {
39
-        super();
40
-        
41
-        CommandManager.registerCommand(this);
42
-    }
43
-    
44
-    /**
45
-     * Executes this command.
46
-     * @param origin The frame in which this command was issued
47
-     * @param server The server object that this command is associated with
48
-     * @param channel The channel object that this command is associated with
49
-     * @param isSilent Whether this command is silenced or not
50
-     * @param args The user supplied arguments
51
-     */
52
-    public void execute(final InputWindow origin, final Server server,
53
-            final Channel channel, final boolean isSilent, final String... args) {
54
-        showUsage(origin, isSilent, "kick", "<user> [reason]");
55
-    }
56
-    
57
-    /** {@inheritDoc}. */
58
-    public String getName() {
59
-        return "kick";
60
-    }
61
-    
62
-    /** {@inheritDoc}. */
63
-    public boolean showInHelp() {
64
-        return false;
65
-    }
66
-    
67
-    /** {@inheritDoc}. */
68
-    public boolean isPolyadic() {
69
-        return false;
70
-    }
71
-    
72
-    /** {@inheritDoc}. */
73
-    public int getArity() {
74
-        return 0;
75
-    }
76
-    
77
-    /** {@inheritDoc}. */
78
-    public String getHelp() {
79
-        return null;
80
-    }
81
-    
82
-}

+ 6
- 2
src/com/dmdirc/commandparser/commands/channel/KickReason.java Näytä tiedosto

@@ -53,13 +53,17 @@ public final class KickReason extends ChannelCommand {
53 53
      */
54 54
     public void execute(final InputWindow origin, final Server server,
55 55
             final Channel channel, final boolean isSilent, final String... args) {
56
+        if (args.length == 0) {
57
+            showUsage(origin, isSilent, "kick", "<user> [reason]");
58
+            return;
59
+        }
56 60
         
57 61
         final ChannelClientInfo victim = channel.getChannelInfo().getUser(args[0]);
58 62
         
59 63
         if (victim == null) {
60 64
             sendLine(origin, isSilent, FORMAT_ERROR, "User not found: " + args[0]);
61 65
         } else {
62
-            victim.kick(implodeArgs(1, args));
66
+            victim.kick(args.length > 1 ? implodeArgs(1, args) : origin.getConfigManager().getOption("general", "kickmessage"));
63 67
         }
64 68
     }
65 69
     
@@ -85,7 +89,7 @@ public final class KickReason extends ChannelCommand {
85 89
     
86 90
     /** {@inheritDoc}. */
87 91
     public String getHelp() {
88
-        return "kick <user> <reason> - kicks the specified user from the channel";
92
+        return "kick <user> [reason] - kicks the specified user from the channel";
89 93
     }
90 94
     
91 95
 }

+ 2
- 1
src/com/dmdirc/commandparser/commands/channel/Part.java Näytä tiedosto

@@ -51,7 +51,8 @@ public final class Part extends ChannelCommand {
51 51
      */
52 52
     public void execute(final InputWindow origin, final Server server,
53 53
             final Channel channel, final boolean isSilent, final String... args) {
54
-        channel.part(implodeArgs(args));
54
+        channel.part(args.length > 0 ? implodeArgs(args)
55
+                : origin.getConfigManager().getOption("general", "partmessage"));
55 56
         channel.closeWindow();
56 57
     }
57 58
     

+ 0
- 86
src/com/dmdirc/commandparser/commands/channel/PartDefault.java Näytä tiedosto

@@ -1,86 +0,0 @@
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 com.dmdirc.commandparser.commands.channel;
24
-
25
-import com.dmdirc.Channel;
26
-import com.dmdirc.Server;
27
-import com.dmdirc.commandparser.commands.ChannelCommand;
28
-import com.dmdirc.commandparser.CommandManager;
29
-import com.dmdirc.ui.interfaces.InputWindow;
30
-
31
-/**
32
- * The PartDefault command (part/0) is used when the user does not specify a
33
- * part message to use. It retrieves the default part message from the config,
34
- * and calls the main Part command.
35
- * @author chris
36
- */
37
-public final class PartDefault extends ChannelCommand {
38
-    
39
-    /** Creates a new instance of PartDefault. */
40
-    public PartDefault() {
41
-        super();
42
-        
43
-        CommandManager.registerCommand(this);
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 channel The channel object that this command is associated with
51
-     * @param isSilent Whether this command is silenced or not
52
-     * @param args The user supplied arguments
53
-     */
54
-    public void execute(final InputWindow origin, final Server server,
55
-            final Channel channel, final boolean isSilent, final String... args) {
56
-        final ChannelCommand com = CommandManager.getChannelCommand("part");
57
-        com.execute(origin, server, channel, isSilent, origin.getConfigManager().getOption("general", "partmessage"));
58
-    }
59
-    
60
-    /** {@inheritDoc}. */
61
-    public String getName() {
62
-        return "part";
63
-    }
64
-    
65
-    /** {@inheritDoc}. */
66
-    public boolean showInHelp() {
67
-        return true;
68
-    }
69
-    
70
-    /** {@inheritDoc}. */
71
-    public boolean isPolyadic() {
72
-        return false;
73
-    }
74
-    
75
-    /** {@inheritDoc}. */
76
-    public int getArity() {
77
-        return 0;
78
-    }
79
-    
80
-    /** {@inheritDoc}. */
81
-    public String getHelp() {
82
-        return "part - parts the channel with the default message";
83
-    }
84
-    
85
-}
86
-

+ 4
- 3
src/com/dmdirc/commandparser/commands/global/Exit.java Näytä tiedosto

@@ -46,8 +46,9 @@ public final class Exit extends GlobalCommand {
46 46
     
47 47
     /** {@inheritDoc} */
48 48
     public void execute(final InputWindow origin, final boolean isSilent,
49
-            final String... args) {
50
-        Main.quit(implodeArgs(args));
49
+            final String... args) {                
50
+        Main.quit(args.length > 0 ? implodeArgs(args)
51
+                : origin.getConfigManager().getOption("general", "closemessage"));
51 52
     }
52 53
     
53 54
     
@@ -73,7 +74,7 @@ public final class Exit extends GlobalCommand {
73 74
     
74 75
     /** {@inheritDoc}. */
75 76
     public String getHelp() {
76
-        return "exit <reason> - exits the client with the specified reason";
77
+        return "exit [reason] - exits the client";
77 78
     }
78 79
     
79 80
 }

+ 0
- 87
src/com/dmdirc/commandparser/commands/global/ExitDefault.java Näytä tiedosto

@@ -1,87 +0,0 @@
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 com.dmdirc.commandparser.commands.global;
24
-
25
-import com.dmdirc.commandparser.CommandManager;
26
-import com.dmdirc.commandparser.commands.GlobalCommand;
27
-import com.dmdirc.config.IdentityManager;
28
-import com.dmdirc.ui.interfaces.InputWindow;
29
-
30
-/**
31
- * Represents the exit/0 command (i.e., an exit with no arguments). Reads the
32
- * default exit message from the config file and calls the normal exit command
33
- * with it as an argument.
34
- * @author chris
35
- */
36
-public final class ExitDefault extends GlobalCommand {
37
-    
38
-    /**
39
-     * Creates a new instance of ExitDefault.
40
-     */
41
-    public ExitDefault() {
42
-        super();
43
-        
44
-        CommandManager.registerCommand(this);
45
-    }
46
-    
47
-    /** {@inheritDoc} */
48
-    public void execute(final InputWindow origin, final boolean isSilent,
49
-            final String... args) {
50
-        String def;
51
-        
52
-        if (origin == null) {
53
-            def = IdentityManager.getGlobalConfig().getOption("general", "closemessage");
54
-        } else {
55
-            def = origin.getConfigManager().getOption("general", "closemessage");
56
-        }
57
-        
58
-        CommandManager.getGlobalCommand("exit").execute(origin, isSilent, def);
59
-    }
60
-    
61
-    
62
-    /** {@inheritDoc}. */
63
-    public String getName() {
64
-        return "exit";
65
-    }
66
-    
67
-    /** {@inheritDoc}. */
68
-    public boolean showInHelp() {
69
-        return true;
70
-    }
71
-    
72
-    /** {@inheritDoc}. */
73
-    public boolean isPolyadic() {
74
-        return false;
75
-    }
76
-    
77
-    /** {@inheritDoc}. */
78
-    public int getArity() {
79
-        return 0;
80
-    }
81
-    
82
-    /** {@inheritDoc}. */
83
-    public String getHelp() {
84
-        return "exit - exits the client with the default closing message";
85
-    }
86
-    
87
-}

+ 5
- 4
src/com/dmdirc/commandparser/commands/global/Help.java Näytä tiedosto

@@ -25,6 +25,7 @@ package com.dmdirc.commandparser.commands.global;
25 25
 import com.dmdirc.Server;
26 26
 import com.dmdirc.commandparser.commands.Command;
27 27
 import com.dmdirc.commandparser.CommandManager;
28
+import com.dmdirc.commandparser.CommandType;
28 29
 import com.dmdirc.commandparser.commands.ServerCommand;
29 30
 import com.dmdirc.ui.interfaces.ChannelWindow;
30 31
 import com.dmdirc.ui.interfaces.InputWindow;
@@ -61,22 +62,22 @@ public final class Help extends ServerCommand {
61 62
     public void execute(final InputWindow origin, final Server server,
62 63
             final boolean isSilent, final String... args) {
63 64
         sendLine(origin, isSilent, FORMAT_OUTPUT, "-- Global commands ----------------------------------");
64
-        showCommands(CommandManager.getGlobalCommands(), origin, isSilent);
65
+        showCommands(CommandManager.getCommands(CommandType.TYPE_GLOBAL), origin, isSilent);
65 66
         
66 67
         if (origin instanceof ServerWindow || origin instanceof ChannelWindow
67 68
                 || origin instanceof QueryWindow) {
68 69
             sendLine(origin, isSilent, FORMAT_OUTPUT, "-- Server commands ----------------------------------");
69
-            showCommands(CommandManager.getServerCommands(), origin, isSilent);
70
+            showCommands(CommandManager.getCommands(CommandType.TYPE_SERVER), origin, isSilent);
70 71
         }
71 72
         
72 73
             if (origin instanceof ChannelWindow) {
73 74
             sendLine(origin, isSilent, FORMAT_OUTPUT, "-- Channel commands ---------------------------------");
74
-            showCommands(CommandManager.getChannelCommands(), origin, isSilent);
75
+            showCommands(CommandManager.getCommands(CommandType.TYPE_CHANNEL), origin, isSilent);
75 76
         }
76 77
         
77 78
         if (origin instanceof QueryWindow) {
78 79
             sendLine(origin, isSilent, FORMAT_OUTPUT, "-- Query commands -----------------------------------");
79
-            showCommands(CommandManager.getQueryCommands(), origin, isSilent);
80
+            showCommands(CommandManager.getCommands(CommandType.TYPE_QUERY), origin, isSilent);
80 81
             
81 82
         }
82 83
         

Loading…
Peruuta
Tallenna