Browse Source

Added some initial support for silent commands

git-svn-id: http://svn.dmdirc.com/trunk@1267 00569f92-eb28-0410-84fd-f71c24880f
tags/0.4
Chris Smith 17 years ago
parent
commit
afdb7f3822

+ 3
- 8
src/uk/org/ownage/dmdirc/commandparser/ChannelCommandParser.java View File

60
         CommandManager.loadChannelCommands(this);
60
         CommandManager.loadChannelCommands(this);
61
     }
61
     }
62
     
62
     
63
-    /**
64
-     * Executes the specified command with the given arguments.
65
-     * @param origin The window in which the command was typed
66
-     * @param command The command to be executed
67
-     * @param args The arguments to the command
68
-     */
63
+    /** {@inheritDoc} */
69
     protected void executeCommand(final CommandWindow origin,
64
     protected void executeCommand(final CommandWindow origin,
70
-            final Command command, final String... args) {
65
+            final boolean isSilent, final Command command, final String... args) {
71
         if (command instanceof ChannelCommand) {
66
         if (command instanceof ChannelCommand) {
72
             ((ChannelCommand) command).execute(origin, server, channel, args);
67
             ((ChannelCommand) command).execute(origin, server, channel, args);
73
         } else if (command instanceof ServerCommand) {
68
         } else if (command instanceof ServerCommand) {
74
             ((ServerCommand) command).execute(origin, server, args);
69
             ((ServerCommand) command).execute(origin, server, args);
75
         } else {
70
         } else {
76
-            ((GlobalCommand) command).execute(origin, args);
71
+            ((GlobalCommand) command).execute(origin, isSilent, args);
77
         }
72
         }
78
     }
73
     }
79
     
74
     

+ 14
- 0
src/uk/org/ownage/dmdirc/commandparser/Command.java View File

99
         return implodeArgs(0, args);
99
         return implodeArgs(0, args);
100
     } 
100
     } 
101
     
101
     
102
+    /**
103
+     * Sends a line, if appropriate, to the specified target.
104
+     * @param target The command window to send the line to
105
+     * @param isSilent Whether this command is being silenced or not
106
+     * @param type The type of message to send
107
+     * @param args The arguments of the message
108
+     */
109
+    protected final void sendLine(final CommandWindow target,
110
+            final boolean isSilent, final String type, final Object ... args) {
111
+        if (!isSilent && target != null) {
112
+            target.addLine(type, args);
113
+        }
114
+    }
115
+    
102
     /** {@inheritDoc} */
116
     /** {@inheritDoc} */
103
     public int compareTo(final Command o) {
117
     public int compareTo(final Command o) {
104
         return getSignature().compareTo(o.getSignature());
118
         return getSignature().compareTo(o.getSignature());

+ 4
- 3
src/uk/org/ownage/dmdirc/commandparser/CommandParser.java View File

116
             // have error handlers if there are too few arguments (e.g., msg/0 and
116
             // have error handlers if there are too few arguments (e.g., msg/0 and
117
             // msg/1 would return errors, so msg only gets called with 2+ args).
117
             // msg/1 would return errors, so msg only gets called with 2+ args).
118
             if (commands.containsKey(signature.toLowerCase())) {
118
             if (commands.containsKey(signature.toLowerCase())) {
119
-                executeCommand(origin, commands.get(signature.toLowerCase()), comargs);
119
+                executeCommand(origin, false, commands.get(signature.toLowerCase()), comargs);
120
             } else if (commands.containsKey(command.toLowerCase())) {
120
             } else if (commands.containsKey(command.toLowerCase())) {
121
-                executeCommand(origin, commands.get(command.toLowerCase()), comargs);
121
+                executeCommand(origin, false, commands.get(command.toLowerCase()), comargs);
122
             } else {
122
             } else {
123
                 handleInvalidCommand(origin, command, comargs);
123
                 handleInvalidCommand(origin, command, comargs);
124
             }
124
             }
149
     /**
149
     /**
150
      * Executes the specified command with the given arguments.
150
      * Executes the specified command with the given arguments.
151
      * @param origin The window in which the command was typed
151
      * @param origin The window in which the command was typed
152
+     * @param isSilent Whether the command is being silenced or not
152
      * @param command The command to be executed
153
      * @param command The command to be executed
153
      * @param args The arguments to the command
154
      * @param args The arguments to the command
154
      */
155
      */
155
     protected abstract void executeCommand(final CommandWindow origin,
156
     protected abstract void executeCommand(final CommandWindow origin,
156
-            final Command command, final String... args);
157
+            final boolean isSilent, final Command command, final String... args);
157
     
158
     
158
     /**
159
     /**
159
      * Called when the user attempted to issue a command (i.e., used the command
160
      * Called when the user attempted to issue a command (i.e., used the command

+ 2
- 1
src/uk/org/ownage/dmdirc/commandparser/GlobalCommand.java View File

33
      * Executes this command. Note that for global commands, origin may be
33
      * Executes this command. Note that for global commands, origin may be
34
      * null.
34
      * null.
35
      * @param origin The window in which the command was typed
35
      * @param origin The window in which the command was typed
36
+     * @param isSilent Whetehr this command is silenced or not
36
      * @param args Arguments passed to this command
37
      * @param args Arguments passed to this command
37
      */
38
      */
38
-    public abstract void execute(CommandWindow origin, String ... args);
39
+    public abstract void execute(CommandWindow origin, boolean isSilent, String ... args);
39
 }
40
 }

+ 4
- 9
src/uk/org/ownage/dmdirc/commandparser/GlobalCommandParser.java View File

48
      * Retrieves a singleton instance of the global command parser.
48
      * Retrieves a singleton instance of the global command parser.
49
      * @return A GlobalCommandParser
49
      * @return A GlobalCommandParser
50
      */
50
      */
51
-    public static synchronized  GlobalCommandParser getGlobalCommandParser() {
51
+    public static synchronized GlobalCommandParser getGlobalCommandParser() {
52
         if (me == null) {
52
         if (me == null) {
53
             me = new GlobalCommandParser();
53
             me = new GlobalCommandParser();
54
         }
54
         }
61
         CommandManager.loadGlobalCommands(this);
61
         CommandManager.loadGlobalCommands(this);
62
     }
62
     }
63
     
63
     
64
-    /**
65
-     * Executes the specified command with the given arguments.
66
-     * @param origin The window in which the command was typed
67
-     * @param command The command to be executed
68
-     * @param args The arguments to the command
69
-     */
64
+    /** {@inheritDoc} */
70
     protected void executeCommand(final CommandWindow origin,
65
     protected void executeCommand(final CommandWindow origin,
71
-            final Command command, final String... args) {
72
-        ((GlobalCommand) command).execute(origin, args);
66
+            final boolean isSilent, final Command command, final String... args) {
67
+        ((GlobalCommand) command).execute(origin, isSilent, args);
73
     }
68
     }
74
     
69
     
75
     /**
70
     /**

+ 3
- 8
src/uk/org/ownage/dmdirc/commandparser/QueryCommandParser.java View File

60
         CommandManager.loadQueryCommands(this);
60
         CommandManager.loadQueryCommands(this);
61
     }
61
     }
62
     
62
     
63
-    /**
64
-     * Executes the specified command with the given arguments.
65
-     * @param origin The window in which the command was typed
66
-     * @param command The command to be executed
67
-     * @param args The arguments to the command
68
-     */
63
+    /** {@inheritDoc} */
69
     protected void executeCommand(final CommandWindow origin,
64
     protected void executeCommand(final CommandWindow origin,
70
-            final Command command, final String... args) {
65
+            final boolean isSilent, final Command command, final String... args) {
71
         if (command instanceof QueryCommand) {
66
         if (command instanceof QueryCommand) {
72
             ((QueryCommand) command).execute(origin, server, query, args);
67
             ((QueryCommand) command).execute(origin, server, query, args);
73
         } else if (command instanceof ServerCommand) {
68
         } else if (command instanceof ServerCommand) {
74
             ((ServerCommand) command).execute(origin, server, args);
69
             ((ServerCommand) command).execute(origin, server, args);
75
         } else {
70
         } else {
76
-            ((GlobalCommand) command).execute(origin, args);
71
+            ((GlobalCommand) command).execute(origin, isSilent, args);
77
         }
72
         }
78
     }
73
     }
79
     
74
     

+ 3
- 8
src/uk/org/ownage/dmdirc/commandparser/ServerCommandParser.java View File

51
         CommandManager.loadServerCommands(this);
51
         CommandManager.loadServerCommands(this);
52
     }
52
     }
53
     
53
     
54
-    /**
55
-     * Executes the specified command with the given arguments.
56
-     * @param origin The window in which the command was typed
57
-     * @param command The command to be executed
58
-     * @param args The arguments to the command
59
-     */
54
+    /** {@inheritDoc} */
60
     protected void executeCommand(final CommandWindow origin,
55
     protected void executeCommand(final CommandWindow origin,
61
-            final Command command, final String... args) {
56
+            final boolean isSilent, final Command command, final String... args) {
62
         if (command instanceof ServerCommand) {
57
         if (command instanceof ServerCommand) {
63
             ((ServerCommand) command).execute(origin, server, args);
58
             ((ServerCommand) command).execute(origin, server, args);
64
         } else {
59
         } else {
65
-            ((GlobalCommand) command).execute(origin, args);
60
+            ((GlobalCommand) command).execute(origin, isSilent, args);
66
         }
61
         }
67
     }
62
     }
68
     
63
     

+ 3
- 6
src/uk/org/ownage/dmdirc/commandparser/commands/global/AllServers.java View File

41
         CommandManager.registerCommand(this);
41
         CommandManager.registerCommand(this);
42
     }
42
     }
43
     
43
     
44
-    /**
45
-     * Executes this command.
46
-     * @param origin The frame in which this command was issued
47
-     * @param args The user supplied arguments
48
-     */
49
-    public void execute(final CommandWindow origin, final String... args) {
44
+    /** {@inheritDoc} */
45
+    public void execute(final CommandWindow origin, final boolean isSilent,
46
+            final String... args) {
50
         final String command = implodeArgs(args);
47
         final String command = implodeArgs(args);
51
         CommandWindow window;
48
         CommandWindow window;
52
         
49
         

+ 3
- 2
src/uk/org/ownage/dmdirc/commandparser/commands/global/Exit.java View File

44
         CommandManager.registerCommand(this);
44
         CommandManager.registerCommand(this);
45
     }
45
     }
46
     
46
     
47
-    /** {@inheritDoc}  */
48
-    public void execute(final CommandWindow origin, final String... args) {
47
+    /** {@inheritDoc} */
48
+    public void execute(final CommandWindow origin, final boolean isSilent,
49
+            final String... args) {
49
         Main.quit(implodeArgs(args));
50
         Main.quit(implodeArgs(args));
50
     }
51
     }
51
     
52
     

+ 4
- 3
src/uk/org/ownage/dmdirc/commandparser/commands/global/ExitDefault.java View File

44
         CommandManager.registerCommand(this);
44
         CommandManager.registerCommand(this);
45
     }
45
     }
46
     
46
     
47
-    /** {@inheritDoc}  */
48
-    public void execute(final CommandWindow origin, final String... args) {
47
+    /** {@inheritDoc} */
48
+    public void execute(final CommandWindow origin, final boolean isSilent,
49
+            final String... args) {
49
         String def;
50
         String def;
50
         
51
         
51
         if (origin == null) {
52
         if (origin == null) {
54
             def = origin.getConfigManager().getOption("general", "closemessage");
55
             def = origin.getConfigManager().getOption("general", "closemessage");
55
         }
56
         }
56
         
57
         
57
-        CommandManager.getGlobalCommand("exit").execute(origin, def);
58
+        CommandManager.getGlobalCommand("exit").execute(origin, isSilent, def);
58
     }
59
     }
59
     
60
     
60
     
61
     

+ 3
- 6
src/uk/org/ownage/dmdirc/commandparser/commands/global/LoadFormatter.java View File

42
         CommandManager.registerCommand(this);
42
         CommandManager.registerCommand(this);
43
     }
43
     }
44
     
44
     
45
-    /**
46
-     * Executes this command.
47
-     * @param origin The frame in which this command was issued
48
-     * @param args The user supplied arguments
49
-     */
50
-    public void execute(final CommandWindow origin, final String... args) {
45
+    /** {@inheritDoc} */
46
+    public void execute(final CommandWindow origin, final boolean isSilent,
47
+            final String... args) {
51
         if (Formatter.loadFile(args[0])) {
48
         if (Formatter.loadFile(args[0])) {
52
             origin.addLine("commandOutput", "Formatter loaded.");
49
             origin.addLine("commandOutput", "Formatter loaded.");
53
         } else {
50
         } else {

+ 3
- 6
src/uk/org/ownage/dmdirc/commandparser/commands/global/LoadPlugin.java View File

42
         CommandManager.registerCommand(this);
42
         CommandManager.registerCommand(this);
43
     }
43
     }
44
     
44
     
45
-    /**
46
-     * Executes this command.
47
-     * @param origin The frame in which this command was issued
48
-     * @param args The user supplied arguments
49
-     */
50
-    public void execute(final CommandWindow origin, final String... args) {
45
+    /** {@inheritDoc} */
46
+    public void execute(final CommandWindow origin, final boolean isSilent,
47
+            final String... args) {
51
         if (PluginManager.getPluginManager().addPlugin(args[0])) {
48
         if (PluginManager.getPluginManager().addPlugin(args[0])) {
52
             PluginManager.getPluginManager().getPlugin(args[0]).setActive(true);
49
             PluginManager.getPluginManager().getPlugin(args[0]).setActive(true);
53
             origin.addLine("commandOutput", "Plugin loaded.");
50
             origin.addLine("commandOutput", "Plugin loaded.");

+ 3
- 2
src/uk/org/ownage/dmdirc/commandparser/commands/global/NewServer.java View File

45
         CommandManager.registerCommand(this);
45
         CommandManager.registerCommand(this);
46
     }
46
     }
47
     
47
     
48
-    /** {@inheritDoc}  */
49
-    public void execute(final CommandWindow origin, final String... args) {
48
+    /** {@inheritDoc} */
49
+    public void execute(final CommandWindow origin, final boolean isSilent,
50
+            final String... args) {
50
         if (args.length == 0) {
51
         if (args.length == 0) {
51
             origin.addLine("commandUsage", Config.getCommandChar(), "newserver",
52
             origin.addLine("commandUsage", Config.getCommandChar(), "newserver",
52
                     "[--ssl] <host[:port]> [password]");
53
                     "[--ssl] <host[:port]> [password]");

+ 3
- 6
src/uk/org/ownage/dmdirc/commandparser/commands/global/ReloadActions.java View File

42
         CommandManager.registerCommand(this);
42
         CommandManager.registerCommand(this);
43
     }
43
     }
44
     
44
     
45
-    /**
46
-     * Executes this command.
47
-     * @param origin The frame in which this command was issued
48
-     * @param args The user supplied arguments
49
-     */
50
-    public void execute(final CommandWindow origin, final String... args) {
45
+    /** {@inheritDoc} */
46
+    public void execute(final CommandWindow origin, final boolean isSilent,
47
+            final String... args) {
51
         ActionManager.loadActions();
48
         ActionManager.loadActions();
52
         origin.addLine("commandOutput", "Actions reloaded.");
49
         origin.addLine("commandOutput", "Actions reloaded.");
53
     }
50
     }

+ 3
- 6
src/uk/org/ownage/dmdirc/commandparser/commands/global/ReloadFormatter.java View File

42
         CommandManager.registerCommand(this);
42
         CommandManager.registerCommand(this);
43
     }
43
     }
44
     
44
     
45
-    /**
46
-     * Executes this command.
47
-     * @param origin The frame in which this command was issued
48
-     * @param args The user supplied arguments
49
-     */
50
-    public void execute(final CommandWindow origin, final String... args) {
45
+    /** {@inheritDoc} */
46
+    public void execute(final CommandWindow origin, final boolean isSilent,
47
+            final String... args) {
51
         Formatter.reload();
48
         Formatter.reload();
52
         origin.addLine("commandOutput", "Formatter reloaded.");
49
         origin.addLine("commandOutput", "Formatter reloaded.");
53
     }
50
     }

+ 3
- 6
src/uk/org/ownage/dmdirc/commandparser/commands/global/ReloadPlugin.java View File

43
         CommandManager.registerCommand(this);
43
         CommandManager.registerCommand(this);
44
     }
44
     }
45
     
45
     
46
-    /**
47
-     * Executes this command.
48
-     * @param origin The frame in which this command was issued
49
-     * @param args The user supplied arguments
50
-     */
51
-    public void execute(final CommandWindow origin, final String... args) {
46
+    /** {@inheritDoc} */
47
+    public void execute(final CommandWindow origin, final boolean isSilent,
48
+            final String... args) {
52
         Plugin plugin = PluginManager.getPluginManager().getPlugin(args[0]);
49
         Plugin plugin = PluginManager.getPluginManager().getPlugin(args[0]);
53
         if (plugin != null) {
50
         if (plugin != null) {
54
             boolean isActive = plugin.isActive();
51
             boolean isActive = plugin.isActive();

+ 3
- 6
src/uk/org/ownage/dmdirc/commandparser/commands/global/SaveFormatter.java View File

42
         CommandManager.registerCommand(this);
42
         CommandManager.registerCommand(this);
43
     }
43
     }
44
     
44
     
45
-    /**
46
-     * Executes this command.
47
-     * @param origin The frame in which this command was issued
48
-     * @param args The user supplied arguments
49
-     */
50
-    public void execute(final CommandWindow origin, final String... args) {
45
+    /** {@inheritDoc} */
46
+    public void execute(final CommandWindow origin, final boolean isSilent,
47
+            final String... args) {
51
         if (Formatter.saveAs(args[0])) {
48
         if (Formatter.saveAs(args[0])) {
52
             origin.addLine("commandOutput", "Formatter saved.");
49
             origin.addLine("commandOutput", "Formatter saved.");
53
         } else {
50
         } else {

+ 3
- 6
src/uk/org/ownage/dmdirc/commandparser/commands/global/Set.java View File

42
         CommandManager.registerCommand(this);
42
         CommandManager.registerCommand(this);
43
     }
43
     }
44
     
44
     
45
-    /**
46
-     * Executes this command.
47
-     * @param origin The frame in which this command was issued
48
-     * @param args The user supplied arguments
49
-     */
50
-    public void execute(final CommandWindow origin, final String... args) {
45
+    /** {@inheritDoc} */
46
+    public void execute(final CommandWindow origin, final boolean isSilent,
47
+            final String... args) {
51
         switch (args.length) {
48
         switch (args.length) {
52
             case 0:
49
             case 0:
53
                 doDomainList(origin);
50
                 doDomainList(origin);

Loading…
Cancel
Save