Explorar el Código

PopupManager: now non-stupid

git-svn-id: http://svn.dmdirc.com/trunk@2389 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5.5
Chris Smith hace 16 años
padre
commit
5ccc1ce2d8

+ 17
- 5
src/com/dmdirc/commandparser/PopupManager.java Ver fichero

@@ -24,6 +24,7 @@ package com.dmdirc.commandparser;
24 24
 
25 25
 import com.dmdirc.config.ConfigManager;
26 26
 import java.util.HashMap;
27
+import java.util.List;
27 28
 import java.util.Map;
28 29
 
29 30
 /**
@@ -42,20 +43,31 @@ public class PopupManager {
42 43
     
43 44
     /**
44 45
      * Retrieves a map of the menu items that should be in a certain menu type.
46
+     * If the command is equal to "-", the entry should be treated as a divider.
45 47
      *
46 48
      * @param menuType The type of menu that is being built
47 49
      * @param configManager The config manager for the current context
50
+     * @param arguments Any arguments appropriate for the menuType
51
+     * 
48 52
      * @return A map of "friendly names" to commands (without command characters)
49 53
      */
50 54
     public static Map<String, String> getMenuItems(final PopupType menuType,
51
-            final ConfigManager configManager) {
55
+            final ConfigManager configManager, final Object ... arguments) {
52 56
         final Map<String, String> res = new HashMap<String, String>();
53 57
         
58
+        int dividerCount = 0;
59
+        
54 60
         for (String domain : menuType.getDomains()) {
55
-            for (String option : configManager.getOptions(domain)) {
56
-                final String command = configManager.getOption(domain, option);
57
-                if (!command.isEmpty()) {
58
-                    res.put(option, command);
61
+            final List<String> commands = configManager.getOptionList("popups", domain);
62
+            
63
+            for (String command : commands) {
64
+                if ("-".equals(command)) {
65
+                    res.put("divider" + (++dividerCount), "-");
66
+                } else {
67
+                    final String name = command.substring(0, command.indexOf(':'));
68
+                    final String value = command.substring(command.indexOf(':'));
69
+                    
70
+                    res.put(name, String.format(value, arguments));
59 71
                 }
60 72
             }
61 73
         }

+ 26
- 7
src/com/dmdirc/commandparser/PopupType.java Ver fichero

@@ -30,14 +30,33 @@ package com.dmdirc.commandparser;
30 30
  */
31 31
 public enum PopupType {
32 32
     
33
-    /** The menu that appears when right clicking in a channel's nicklist. */
34
-    CHAN_NICKLIST("chan-nick-list", "chan-nick", "nick"),
35
-    /** The menu that appears when right clicking on a nickname in normal channel text. */
36
-    CHAN_NICKTEXT("chan-nick-text", "chan-nick", "nick", "chan"),
37
-    /** The menu that appears when right clicking in a channel window. */
33
+    /**
34
+     * The menu that appears when right clicking in a channel's nicklist.
35
+     * 
36
+     * Expected arguments: the nickname of the user who was clicked on.
37
+     */
38
+    CHAN_NICKLIST("nick", "chan-nick", "chan-nick-list"),
39
+    
40
+    /**
41
+     * The menu that appears when right clicking on a nickname in normal channel text.
42
+     * 
43
+     * Expected arguments: the nickname of the user who was clicked on.
44
+     */
45
+    CHAN_NICKTEXT("nick", "chan-nick", "chan-nick-text"),
46
+    
47
+    /**
48
+     * The menu that appears when right clicking in a channel window.
49
+     * 
50
+     * Expected arguments: none.
51
+     */
38 52
     CHAN_CHAN("chan"),
39
-    /** The menu that appears when right clicking in a query window. */
40
-    QUERY_QUERY("query", "nick");
53
+    
54
+    /**
55
+     * The menu that appears when right clicking in a query window.
56
+     * 
57
+     * Expected arguments: the nickname of the user who the query is with.
58
+     */
59
+    QUERY_QUERY("nick", "query");
41 60
     
42 61
     private final String[] domains;
43 62
     

+ 2
- 1
src/com/dmdirc/config/ConfigManager.java Ver fichero

@@ -242,7 +242,8 @@ public final class ConfigManager implements Serializable, ConfigChangeListener {
242 242
     }
243 243
     
244 244
     /**
245
-     * Returns the name of all the options in the specified domain.
245
+     * Returns the name of all the options in the specified domain. If the
246
+     * domain doesn't exist, an empty list is returned.
246 247
      *
247 248
      * @param domain The domain to search
248 249
      * @return A list of options in the specified domain

+ 4
- 1
src/com/dmdirc/config/defaults/defaults Ver fichero

@@ -105,4 +105,7 @@ updater.lastcheck=0
105 105
         
106 106
 actions.textcolour=12
107 107
 actions.eventcolour=3
108
-actions.highlightcolour=4
108
+actions.highlightcolour=4
109
+
110
+popups.nick=Query:query %1$s\nWhois:whois %1$s
111
+popups.chan-nick=\n-\nBan:ban %1$s\nKick:kick %1$s

Loading…
Cancelar
Guardar