Переглянути джерело

Command and Silence chars are now accessible via the CommandManager

git-svn-id: http://svn.dmdirc.com/trunk@2260 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5.1
Chris Smith 16 роки тому
джерело
коміт
0fb0fac751

+ 1
- 2
src/com/dmdirc/GlobalWindow.java Переглянути файл

@@ -74,8 +74,7 @@ public class GlobalWindow extends WritableFrameContainer {
74 74
 
75 75
     public void sendLine(final String line) {
76 76
         GlobalCommandParser.getGlobalCommandParser().parseCommand(window, 
77
-                IdentityManager.getGlobalConfig().getOption("general", "commandchar")
78
-                + line);
77
+                CommandManager.getCommandChar() + line);
79 78
     }
80 79
 
81 80
     public int getMaxLineLength() {

+ 2
- 3
src/com/dmdirc/actions/wrappers/AliasWrapper.java Переглянути файл

@@ -27,7 +27,7 @@ import com.dmdirc.ServerManager;
27 27
 import com.dmdirc.actions.Action;
28 28
 import com.dmdirc.actions.ActionCondition;
29 29
 import com.dmdirc.actions.CoreActionType;
30
-import com.dmdirc.config.IdentityManager;
30
+import com.dmdirc.commandparser.CommandManager;
31 31
 import com.dmdirc.logger.ErrorLevel;
32 32
 import com.dmdirc.logger.Logger;
33 33
 
@@ -124,8 +124,7 @@ public final class AliasWrapper extends ActionWrapper {
124 124
     private String getCommandName(final Action action) {
125 125
         for (ActionCondition condition : action.getConditions()) {
126 126
             if (condition.getArg() == 1) {
127
-                return IdentityManager.getGlobalConfig()
128
-                        .getOption("general", "commandchar") + condition.getTarget();
127
+                return CommandManager.getCommandChar() + condition.getTarget();
129 128
             }
130 129
         }
131 130
         

+ 1
- 2
src/com/dmdirc/commandparser/Command.java Переглянути файл

@@ -126,8 +126,7 @@ public abstract class Command implements Comparable<Command> {
126 126
      */
127 127
     protected final void showUsage(final InputWindow target,
128 128
             final boolean isSilent, final String name, final String args) {
129
-        sendLine(target, isSilent, "commandUsage",
130
-                IdentityManager.getGlobalConfig().getOption("general", "commandchar"),
129
+        sendLine(target, isSilent, "commandUsage", CommandManager.getCommandChar(),
131 130
                 name, args);
132 131
     }    
133 132
     

+ 42
- 3
src/com/dmdirc/commandparser/CommandManager.java Переглянути файл

@@ -29,6 +29,7 @@ import com.dmdirc.commandparser.commands.chat.*;
29 29
 import com.dmdirc.commandparser.commands.global.*;
30 30
 //import com.dmdirc.commandparser.commands.query.*;
31 31
 import com.dmdirc.commandparser.commands.server.*;
32
+import com.dmdirc.config.ConfigChangeListener;
32 33
 import com.dmdirc.config.IdentityManager;
33 34
 import com.dmdirc.logger.ErrorLevel;
34 35
 import com.dmdirc.logger.Logger;
@@ -88,6 +89,14 @@ public final class CommandManager {
88 89
      */
89 90
     private static List<Command> channelPopupCommands = new ArrayList<Command>();
90 91
     
92
+    /** The command char we're using. */
93
+    private static char commandChar = IdentityManager.getGlobalConfig()
94
+            .getOption("general", "commandchar").charAt(0);
95
+    
96
+    /** The silence char we're using. */
97
+    private static char silenceChar = IdentityManager.getGlobalConfig()
98
+            .getOption("general", "silencechar").charAt(0);
99
+    
91 100
     /**
92 101
      * Prevents creation of a new command manager.
93 102
      */
@@ -95,6 +104,24 @@ public final class CommandManager {
95 104
         //do nothing
96 105
     }
97 106
     
107
+    /**
108
+     * Returns the current command character.
109
+     * 
110
+     * @return the current command char
111
+     */
112
+    public static char getCommandChar() {
113
+        return commandChar;
114
+    }
115
+
116
+    /**
117
+     * Returns the current silence character.
118
+     * 
119
+     * @return the current silence char
120
+     */    
121
+    public static char getSilenceChar() {
122
+        return silenceChar;
123
+    }
124
+    
98 125
     /**
99 126
      * Registers a command with the command manager.
100 127
      * @param command The command to be registered
@@ -179,8 +206,7 @@ public final class CommandManager {
179 206
     private static void registerCommandName(final Command command,
180 207
             final boolean register) {
181 208
         // Do tab completion
182
-        final String commandName = IdentityManager.getGlobalConfig()
183
-                .getOption("general", "commandchar") + command.getName();
209
+        final String commandName = getCommandChar() + command.getName();
184 210
         
185 211
         for (Server server : ServerManager.getServerManager().getServers()) {
186 212
             if (command instanceof ServerCommand || command instanceof GlobalCommand) {
@@ -303,6 +329,19 @@ public final class CommandManager {
303 329
         new SaveConfig();
304 330
         new SaveFormatter();
305 331
         new Set();
332
+        
333
+        // Set up a listener for config changes
334
+        final ConfigChangeListener listener = new ConfigChangeListener() {
335
+            public void configChanged(String domain, String key, String oldValue, String newValue) {
336
+                commandChar = IdentityManager.getGlobalConfig()
337
+                        .getOption("general", "commandchar").charAt(0);
338
+                silenceChar = IdentityManager.getGlobalConfig()
339
+                        .getOption("general", "silencechar").charAt(0);
340
+            }
341
+        };
342
+        
343
+        IdentityManager.getGlobalConfig().addChangeListener("general", "commandchar", listener);
344
+        IdentityManager.getGlobalConfig().addChangeListener("general", "silencechar", listener);
306 345
     }
307 346
     
308 347
     /**
@@ -627,7 +666,7 @@ public final class CommandManager {
627 666
         final List<String> res = new ArrayList<String>();
628 667
         
629 668
         for (Command command : source) {
630
-            res.add(IdentityManager.getGlobalConfig().getOption("general", "commandchar") + command.getName());
669
+            res.add(getCommandChar() + command.getName());
631 670
         }
632 671
         
633 672
         return res;

+ 2
- 5
src/com/dmdirc/commandparser/CommandParser.java Переглянути файл

@@ -97,14 +97,11 @@ public abstract class CommandParser implements Serializable {
97 97
             return;
98 98
         }
99 99
         
100
-        if (line.charAt(0) == IdentityManager.getGlobalConfig()
101
-                .getOption("general", "commandchar").charAt(0)) {
100
+        if (line.charAt(0) == CommandManager.getCommandChar()) {
102 101
             int offset = 1;
103 102
             boolean silent = false;
104 103
             
105
-            if (line.length() > offset
106
-                    && line.charAt(offset) == IdentityManager.getGlobalConfig()
107
-                    .getOption("general", "silencechar").charAt(0)) {
104
+            if (line.length() > offset && line.charAt(offset) == CommandManager.getSilenceChar()) {
108 105
                 silent = true;
109 106
                 offset++;
110 107
             }

+ 1
- 1
src/com/dmdirc/commandparser/commands/global/Set.java Переглянути файл

@@ -79,7 +79,7 @@ public final class Set extends GlobalCommand implements IntelligentCommand {
79 79
         final StringBuffer output = new StringBuffer(67);
80 80
         
81 81
         output.append("Valid domains (use ");
82
-        output.append(IdentityManager.getGlobalConfig().getOption("general", "commandchar"));
82
+        output.append(CommandManager.getCommandChar());
83 83
         output.append("set <domain> to see options within a domain): ");
84 84
         
85 85
         for (String domain : IdentityManager.getGlobalConfig().getDomains()) {

+ 1
- 3
src/com/dmdirc/ui/input/InputHandler.java Переглянути файл

@@ -290,9 +290,7 @@ public final class InputHandler implements KeyListener, ActionListener {
290 290
             end = start;
291 291
         }
292 292
         
293
-        if (start > 0
294
-                && text.charAt(0) == IdentityManager.getGlobalConfig()
295
-                .getOption("general", "commandchar").charAt(0)) {
293
+        if (start > 0 && text.charAt(0) == CommandManager.getCommandChar()) {
296 294
             doCommandTabCompletion(text, start, end);
297 295
         } else {
298 296
             doNormalTabCompletion(text, start, end, null);

Завантаження…
Відмінити
Зберегти