Browse Source

Actions are now saved when the client exits (in addition to anywhere the UI cares to save them; fixes issue 453)

Updated umodes action pack to have correct component number
Changed a couple of listener lists from WeakMapLists to MapLists so AICs don't get GC'd
Deprecated the old actions methods so they're easy to spot for removal post-0.6

git-svn-id: http://svn.dmdirc.com/trunk@3121 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 years ago
parent
commit
d9688be750

+ 1
- 1
src/com/dmdirc/Main.java View File

69
      * @Deprecated No longer needed, remove post-0.6
69
      * @Deprecated No longer needed, remove post-0.6
70
      */
70
      */
71
     @Deprecated
71
     @Deprecated
72
-    private static final int ADDON_REVISION = 9;
72
+    private static final int ADDON_REVISION = 10;
73
     
73
     
74
     /**
74
     /**
75
      * Feedback nag delay.
75
      * Feedback nag delay.

+ 13
- 0
src/com/dmdirc/actions/Action.java View File

103
 
103
 
104
     /**
104
     /**
105
      * Loads this action from a properties file.
105
      * Loads this action from a properties file.
106
+     * 
107
+     * @Deprecated Remove post 0.6
106
      */
108
      */
109
+    @Deprecated
107
     private void loadProperties() {
110
     private void loadProperties() {
108
         try {
111
         try {
109
             final FileInputStream inputStream = new FileInputStream(file);
112
             final FileInputStream inputStream = new FileInputStream(file);
294
 
297
 
295
     /**
298
     /**
296
      * Loads the various attributes of this action from the properties instance.
299
      * Loads the various attributes of this action from the properties instance.
300
+     * 
301
+     * @Deprecated Remove post-0.6
297
      */
302
      */
303
+    @Deprecated
298
     private void loadActionFromProperties() {
304
     private void loadActionFromProperties() {
299
         // Read the triggers
305
         // Read the triggers
300
         if (properties.containsKey("trigger")) {
306
         if (properties.containsKey("trigger")) {
358
         }
364
         }
359
 
365
 
360
         ActionManager.registerAction(this);
366
         ActionManager.registerAction(this);
367
+        modified = true;
361
         save();
368
         save();
362
     }
369
     }
363
 
370
 
365
      * Called to save the action.
372
      * Called to save the action.
366
      */
373
      */
367
     public void save() {
374
     public void save() {
375
+        if (!isModified()) {
376
+            return;
377
+        }
378
+        
368
         final ConfigFile newConfig = new ConfigFile(location);
379
         final ConfigFile newConfig = new ConfigFile(location);
369
 
380
 
370
         final List<String> triggerNames = new ArrayList<String>();
381
         final List<String> triggerNames = new ArrayList<String>();
541
      *
552
      *
542
      * @param condition Condition number to read
553
      * @param condition Condition number to read
543
      * @return True if the condition was read successfully.
554
      * @return True if the condition was read successfully.
555
+     * @deprecated Remove post-0.6
544
      */
556
      */
557
+    @Deprecated
545
     private boolean readCondition(final int condition) {
558
     private boolean readCondition(final int condition) {
546
         // It may help to close your eyes while reading this method.
559
         // It may help to close your eyes while reading this method.
547
 
560
 

+ 144
- 123
src/com/dmdirc/actions/ActionManager.java View File

22
 
22
 
23
 package com.dmdirc.actions;
23
 package com.dmdirc.actions;
24
 
24
 
25
-import com.dmdirc.actions.interfaces.ActionType;
26
-import com.dmdirc.actions.interfaces.ActionComponent;
27
-import com.dmdirc.actions.interfaces.ActionComparison;
28
 import com.dmdirc.Main;
25
 import com.dmdirc.Main;
29
 import com.dmdirc.Precondition;
26
 import com.dmdirc.Precondition;
27
+import com.dmdirc.actions.interfaces.ActionComparison;
28
+import com.dmdirc.actions.interfaces.ActionComponent;
29
+import com.dmdirc.actions.interfaces.ActionType;
30
 import com.dmdirc.actions.wrappers.ActionWrapper;
30
 import com.dmdirc.actions.wrappers.ActionWrapper;
31
 import com.dmdirc.actions.wrappers.AliasWrapper;
31
 import com.dmdirc.actions.wrappers.AliasWrapper;
32
 import com.dmdirc.actions.wrappers.PerformWrapper;
32
 import com.dmdirc.actions.wrappers.PerformWrapper;
33
 import com.dmdirc.config.ConfigTarget;
33
 import com.dmdirc.config.ConfigTarget;
34
 import com.dmdirc.config.Identity;
34
 import com.dmdirc.config.Identity;
35
-import com.dmdirc.interfaces.ConfigChangeListener;
36
 import com.dmdirc.config.IdentityManager;
35
 import com.dmdirc.config.IdentityManager;
37
 import com.dmdirc.interfaces.ActionListener;
36
 import com.dmdirc.interfaces.ActionListener;
37
+import com.dmdirc.interfaces.ConfigChangeListener;
38
 import com.dmdirc.logger.ErrorLevel;
38
 import com.dmdirc.logger.ErrorLevel;
39
 import com.dmdirc.logger.Logger;
39
 import com.dmdirc.logger.Logger;
40
 import com.dmdirc.updater.components.ActionGroupComponent;
40
 import com.dmdirc.updater.components.ActionGroupComponent;
41
 import com.dmdirc.util.MapList;
41
 import com.dmdirc.util.MapList;
42
-import com.dmdirc.util.WeakMapList;
43
-
44
 import com.dmdirc.util.resourcemanager.ZipResourceManager;
42
 import com.dmdirc.util.resourcemanager.ZipResourceManager;
43
+
45
 import java.io.File;
44
 import java.io.File;
46
 import java.io.IOException;
45
 import java.io.IOException;
47
 import java.util.ArrayList;
46
 import java.util.ArrayList;
56
  * @author chris
55
  * @author chris
57
  */
56
  */
58
 public final class ActionManager {
57
 public final class ActionManager {
59
-    
58
+
60
     /** A list of registered action types. */
59
     /** A list of registered action types. */
61
     private final static List<ActionType> actionTypes
60
     private final static List<ActionType> actionTypes
62
             = new ArrayList<ActionType>();
61
             = new ArrayList<ActionType>();
63
-    
62
+
64
     /** A list of registered action components. */
63
     /** A list of registered action components. */
65
     private final static List<ActionComponent> actionComponents
64
     private final static List<ActionComponent> actionComponents
66
             = new ArrayList<ActionComponent>();
65
             = new ArrayList<ActionComponent>();
67
-    
66
+
68
     /** A list of registered action comparisons. */
67
     /** A list of registered action comparisons. */
69
     private final static List<ActionComparison> actionComparisons
68
     private final static List<ActionComparison> actionComparisons
70
             = new ArrayList<ActionComparison>();
69
             = new ArrayList<ActionComparison>();
71
-    
70
+
72
     /** A list of all action wrappers that have registered with us. */
71
     /** A list of all action wrappers that have registered with us. */
73
     private final static List<ActionWrapper> actionWrappers
72
     private final static List<ActionWrapper> actionWrappers
74
             = new ArrayList<ActionWrapper>();
73
             = new ArrayList<ActionWrapper>();
75
-    
74
+
76
     /** A map linking types and a list of actions that're registered for them. */
75
     /** A map linking types and a list of actions that're registered for them. */
77
     private final static MapList<ActionType, Action> actions
76
     private final static MapList<ActionType, Action> actions
78
             = new MapList<ActionType, Action>();
77
             = new MapList<ActionType, Action>();
79
-    
78
+
80
     /** A map linking groups and a list of actions that're in them. */
79
     /** A map linking groups and a list of actions that're in them. */
81
     private final static Map<String, ActionGroup> groups
80
     private final static Map<String, ActionGroup> groups
82
             = new HashMap<String, ActionGroup>();
81
             = new HashMap<String, ActionGroup>();
83
-    
82
+
84
     /** A map of the action type groups to the action types within. */
83
     /** A map of the action type groups to the action types within. */
85
     private final static MapList<String, ActionType> actionTypeGroups
84
     private final static MapList<String, ActionType> actionTypeGroups
86
             = new MapList<String, ActionType>();
85
             = new MapList<String, ActionType>();
87
-    
86
+
88
     /** The listeners that we have registered. */
87
     /** The listeners that we have registered. */
89
-    private final static WeakMapList<ActionType, ActionListener> listeners
90
-            = new WeakMapList<ActionType, ActionListener>();
91
-    
88
+    private final static MapList<ActionType, ActionListener> listeners
89
+            = new MapList<ActionType, ActionListener>();
90
+
92
     /** The identity we're using for action defaults. */
91
     /** The identity we're using for action defaults. */
93
     private static Identity defaultsIdentity;
92
     private static Identity defaultsIdentity;
94
-    
93
+
95
     /** Indicates whether or not user actions should be killed (not processed). */
94
     /** Indicates whether or not user actions should be killed (not processed). */
96
     private static boolean killSwitch
95
     private static boolean killSwitch
97
             = IdentityManager.getGlobalConfig().getOptionBool("actions", "killswitch", false);
96
             = IdentityManager.getGlobalConfig().getOptionBool("actions", "killswitch", false);
98
-    
99
-    static {
100
-        final ConfigTarget target = new ConfigTarget();
101
-        final Properties properties = new Properties();
102
-        target.setGlobalDefault();
103
-        target.setOrder(500000);
104
-        properties.setProperty("identity.name", "Action defaults");
105
-        defaultsIdentity = new Identity(properties, target);
106
-    }
107
-   
97
+
108
     /** Creates a new instance of ActionManager. */
98
     /** Creates a new instance of ActionManager. */
109
     private ActionManager() {
99
     private ActionManager() {
110
         // Shouldn't be instansiated
100
         // Shouldn't be instansiated
111
     }
101
     }
112
-    
102
+
113
     /**
103
     /**
114
      * Initialises the action manager.
104
      * Initialises the action manager.
115
      */
105
      */
117
         registerActionTypes(CoreActionType.values());
107
         registerActionTypes(CoreActionType.values());
118
         registerActionComparisons(CoreActionComparison.values());
108
         registerActionComparisons(CoreActionComparison.values());
119
         registerActionComponents(CoreActionComponent.values());
109
         registerActionComponents(CoreActionComponent.values());
120
-        
110
+
121
         registerWrapper(AliasWrapper.getAliasWrapper());
111
         registerWrapper(AliasWrapper.getAliasWrapper());
122
         registerWrapper(PerformWrapper.getPerformWrapper());
112
         registerWrapper(PerformWrapper.getPerformWrapper());
113
+
114
+        // Set up the identity used for our defaults
115
+        final ConfigTarget target = new ConfigTarget();
116
+        final Properties properties = new Properties();
117
+        target.setGlobalDefault();
118
+        target.setOrder(500000);
119
+        properties.setProperty("identity.name", "Action defaults");
120
+        defaultsIdentity = new Identity(properties, target);
123
         
121
         
122
+        // Register a listener for the closing event, so we can save actions
123
+        addListener(new ActionListener() {
124
+            /** {@inheritDoc} */
125
+            @Override
126
+            public void processEvent(final ActionType type, final StringBuffer format,
127
+                    final Object... arguments) {
128
+                saveActions();
129
+            }
130
+        }, CoreActionType.CLIENT_CLOSED);
131
+
132
+        // Make sure we listen for the killswitch
124
         IdentityManager.getGlobalConfig().addChangeListener("actions", "killswitch",
133
         IdentityManager.getGlobalConfig().addChangeListener("actions", "killswitch",
125
                 new ConfigChangeListener() {
134
                 new ConfigChangeListener() {
135
+            /** {@inheritDoc} */
126
             @Override
136
             @Override
127
             public void configChanged(final String domain, final String key) {
137
             public void configChanged(final String domain, final String key) {
128
                 killSwitch
138
                 killSwitch
132
         });
142
         });
133
     }
143
     }
134
     
144
     
145
+    /**
146
+     * Saves all actions.
147
+     */
148
+    public static void saveActions() {
149
+        for (ActionGroup group : groups.values()) {
150
+            for (Action action : group) {
151
+                action.save();
152
+            }
153
+        }
154
+    }
155
+
135
     /**
156
     /**
136
      * Registers the specified default setting for actions.
157
      * Registers the specified default setting for actions.
137
-     * 
158
+     *
138
      * @param name The name of the setting to be registered
159
      * @param name The name of the setting to be registered
139
      * @param value The default value for the setting
160
      * @param value The default value for the setting
140
      */
161
      */
141
     public static void registerDefault(final String name, final String value) {
162
     public static void registerDefault(final String name, final String value) {
142
         defaultsIdentity.setOption("actions", name, value);
163
         defaultsIdentity.setOption("actions", name, value);
143
     }
164
     }
144
-    
165
+
145
     /**
166
     /**
146
      * Registers the specified action wrapper with the manager.
167
      * Registers the specified action wrapper with the manager.
147
      *
168
      *
155
         assert(wrapper != null);
176
         assert(wrapper != null);
156
         assert(wrapper.getGroupName() != null);
177
         assert(wrapper.getGroupName() != null);
157
         assert(!wrapper.getGroupName().isEmpty());
178
         assert(!wrapper.getGroupName().isEmpty());
158
-        
179
+
159
         actionWrappers.add(wrapper);
180
         actionWrappers.add(wrapper);
160
     }
181
     }
161
-    
182
+
162
     /**
183
     /**
163
      * Registers a set of actiontypes with the manager.
184
      * Registers a set of actiontypes with the manager.
164
      *
185
      *
168
     public static void registerActionTypes(final ActionType[] types) {
189
     public static void registerActionTypes(final ActionType[] types) {
169
         for (ActionType type : types) {
190
         for (ActionType type : types) {
170
             assert(type != null);
191
             assert(type != null);
171
-            
192
+
172
             actionTypes.add(type);
193
             actionTypes.add(type);
173
             actionTypeGroups.add(type.getType().getGroup(), type);
194
             actionTypeGroups.add(type.getType().getGroup(), type);
174
         }
195
         }
175
     }
196
     }
176
-    
197
+
177
     /**
198
     /**
178
      * Registers a set of action components with the manager.
199
      * Registers a set of action components with the manager.
179
      *
200
      *
183
     public static void registerActionComponents(final ActionComponent[] comps) {
204
     public static void registerActionComponents(final ActionComponent[] comps) {
184
         for (ActionComponent comp : comps) {
205
         for (ActionComponent comp : comps) {
185
             assert(comp != null);
206
             assert(comp != null);
186
-            
207
+
187
             actionComponents.add(comp);
208
             actionComponents.add(comp);
188
         }
209
         }
189
     }
210
     }
190
-    
211
+
191
     /**
212
     /**
192
      * Registers a set of action comparisons with the manager.
213
      * Registers a set of action comparisons with the manager.
193
      *
214
      *
197
     public static void registerActionComparisons(final ActionComparison[] comps) {
218
     public static void registerActionComparisons(final ActionComparison[] comps) {
198
         for (ActionComparison comp : comps) {
219
         for (ActionComparison comp : comps) {
199
             assert(comp != null);
220
             assert(comp != null);
200
-            
221
+
201
             actionComparisons.add(comp);
222
             actionComparisons.add(comp);
202
         }
223
         }
203
     }
224
     }
204
-    
225
+
205
     /**
226
     /**
206
      * Returns a map of groups to action lists.
227
      * Returns a map of groups to action lists.
207
      *
228
      *
210
     public static Map<String, ActionGroup> getGroups() {
231
     public static Map<String, ActionGroup> getGroups() {
211
         return groups;
232
         return groups;
212
     }
233
     }
213
-    
234
+
214
     /**
235
     /**
215
      * Returns a map of type groups to types.
236
      * Returns a map of type groups to types.
216
      *
237
      *
219
     public static MapList<String, ActionType> getTypeGroups() {
240
     public static MapList<String, ActionType> getTypeGroups() {
220
         return actionTypeGroups;
241
         return actionTypeGroups;
221
     }
242
     }
222
-    
243
+
223
     /**
244
     /**
224
      * Loads actions from the user's directory.
245
      * Loads actions from the user's directory.
225
      */
246
      */
226
     public static void loadActions() {
247
     public static void loadActions() {
227
         actions.clear();
248
         actions.clear();
228
         groups.clear();
249
         groups.clear();
229
-        
250
+
230
         for (ActionWrapper wrapper : actionWrappers) {
251
         for (ActionWrapper wrapper : actionWrappers) {
231
             wrapper.clearActions();
252
             wrapper.clearActions();
232
         }
253
         }
233
-        
254
+
234
         final File dir = new File(getDirectory());
255
         final File dir = new File(getDirectory());
235
-        
256
+
236
         if (!dir.exists()) {
257
         if (!dir.exists()) {
237
             try {
258
             try {
238
                 dir.mkdirs();
259
                 dir.mkdirs();
242
                         + ex.getMessage());
263
                         + ex.getMessage());
243
             }
264
             }
244
         }
265
         }
245
-        
266
+
246
         if (dir.listFiles() == null) {
267
         if (dir.listFiles() == null) {
247
             Logger.userError(ErrorLevel.MEDIUM, "Unable to load user action files");
268
             Logger.userError(ErrorLevel.MEDIUM, "Unable to load user action files");
248
         } else {
269
         } else {
249
             for (File file : dir.listFiles()) {
270
             for (File file : dir.listFiles()) {
250
-                if (file.isDirectory()) {                    
271
+                if (file.isDirectory()) {
251
                     loadActions(file);
272
                     loadActions(file);
252
                 }
273
                 }
253
             }
274
             }
254
         }
275
         }
255
-        
276
+
256
         registerComponents();
277
         registerComponents();
257
     }
278
     }
258
-    
279
+
259
     /**
280
     /**
260
      * Creates new ActionGroupComponents for each action group.
281
      * Creates new ActionGroupComponents for each action group.
261
      */
282
      */
264
             new ActionGroupComponent(group);
285
             new ActionGroupComponent(group);
265
         }
286
         }
266
     }
287
     }
267
-    
288
+
268
     /**
289
     /**
269
      * Retrieves the action wrapper with the specified group name.
290
      * Retrieves the action wrapper with the specified group name.
270
      *
291
      *
275
     private static ActionWrapper getWrapper(final String name) {
296
     private static ActionWrapper getWrapper(final String name) {
276
         assert(name != null);
297
         assert(name != null);
277
         assert(!name.isEmpty());
298
         assert(!name.isEmpty());
278
-        
299
+
279
         for (ActionWrapper wrapper : actionWrappers) {
300
         for (ActionWrapper wrapper : actionWrappers) {
280
             if (name.equals(wrapper.getGroupName())) {
301
             if (name.equals(wrapper.getGroupName())) {
281
                 return wrapper;
302
                 return wrapper;
282
             }
303
             }
283
         }
304
         }
284
-        
305
+
285
         return null;
306
         return null;
286
     }
307
     }
287
-    
308
+
288
     /**
309
     /**
289
      * Determines whether the specified group name is one used by an action
310
      * Determines whether the specified group name is one used by an action
290
      * wrapper.
311
      * wrapper.
296
     private static boolean isWrappedGroup(final String name) {
317
     private static boolean isWrappedGroup(final String name) {
297
         assert(name != null);
318
         assert(name != null);
298
         assert(!name.isEmpty());
319
         assert(!name.isEmpty());
299
-        
320
+
300
         return getWrapper(name) != null;
321
         return getWrapper(name) != null;
301
     }
322
     }
302
-    
323
+
303
     /**
324
     /**
304
      * Loads action files from a specified group directory.
325
      * Loads action files from a specified group directory.
305
      *
326
      *
309
     private static void loadActions(final File dir) {
330
     private static void loadActions(final File dir) {
310
         assert(dir != null);
331
         assert(dir != null);
311
         assert(dir.isDirectory());
332
         assert(dir.isDirectory());
312
-        
333
+
313
         for (File file : dir.listFiles()) {
334
         for (File file : dir.listFiles()) {
314
             new Action(dir.getName(), file.getName());
335
             new Action(dir.getName(), file.getName());
315
         }
336
         }
316
     }
337
     }
317
-    
338
+
318
     /**
339
     /**
319
      * Registers an action with the manager.
340
      * Registers an action with the manager.
320
      *
341
      *
323
     @Precondition("The specified action is not null")
344
     @Precondition("The specified action is not null")
324
     public static void registerAction(final Action action) {
345
     public static void registerAction(final Action action) {
325
         assert(action != null);
346
         assert(action != null);
326
-        
347
+
327
         for (ActionType trigger : action.getTriggers()) {
348
         for (ActionType trigger : action.getTriggers()) {
328
             actions.add(trigger, action);
349
             actions.add(trigger, action);
329
         }
350
         }
330
-        
351
+
331
         if (isWrappedGroup(action.getGroup())) {
352
         if (isWrappedGroup(action.getGroup())) {
332
             getWrapper(action.getGroup()).registerAction(action);
353
             getWrapper(action.getGroup()).registerAction(action);
333
         } else {
354
         } else {
334
             getGroup(action.getGroup()).add(action);
355
             getGroup(action.getGroup()).add(action);
335
         }
356
         }
336
     }
357
     }
337
-    
358
+
338
     /**
359
     /**
339
      * Retrieves the action group with the specified name. A new group is
360
      * Retrieves the action group with the specified name. A new group is
340
      * created if it doesn't already exist.
361
      * created if it doesn't already exist.
341
-     * 
362
+     *
342
      * @param name The name of the group to retrieve
363
      * @param name The name of the group to retrieve
343
      * @return The corresponding ActionGroup
364
      * @return The corresponding ActionGroup
344
      */
365
      */
346
         if (!groups.containsKey(name)) {
367
         if (!groups.containsKey(name)) {
347
             groups.put(name, new ActionGroup(name));
368
             groups.put(name, new ActionGroup(name));
348
         }
369
         }
349
-        
370
+
350
         return groups.get(name);
371
         return groups.get(name);
351
     }
372
     }
352
-    
373
+
353
     /**
374
     /**
354
      * Unregisters an action with the manager.
375
      * Unregisters an action with the manager.
355
      *
376
      *
358
     @Precondition("The specified action is not null")
379
     @Precondition("The specified action is not null")
359
     public static void unregisterAction(final Action action) {
380
     public static void unregisterAction(final Action action) {
360
         assert(action != null);
381
         assert(action != null);
361
-        
382
+
362
         actions.removeFromAll(action);
383
         actions.removeFromAll(action);
363
         getGroup(action.getGroup()).remove(action);
384
         getGroup(action.getGroup()).remove(action);
364
     }
385
     }
365
-    
386
+
366
     /**
387
     /**
367
      * Reregisters the specified action. Should be used when the action's
388
      * Reregisters the specified action. Should be used when the action's
368
      * triggers change.
389
      * triggers change.
369
-     * 
390
+     *
370
      * @param action The action to be reregistered
391
      * @param action The action to be reregistered
371
      */
392
      */
372
     public static void reregisterAction(final Action action) {
393
     public static void reregisterAction(final Action action) {
373
         unregisterAction(action);
394
         unregisterAction(action);
374
         reregisterAction(action);
395
         reregisterAction(action);
375
     }
396
     }
376
-    
397
+
377
     /**
398
     /**
378
      * Deletes the specified action.
399
      * Deletes the specified action.
379
      *
400
      *
382
     @Precondition("The specified Action is not null")
403
     @Precondition("The specified Action is not null")
383
     public static void deleteAction(final Action action) {
404
     public static void deleteAction(final Action action) {
384
         assert(action != null);
405
         assert(action != null);
385
-        
406
+
386
         unregisterAction(action);
407
         unregisterAction(action);
387
-        
408
+
388
         action.delete();
409
         action.delete();
389
     }
410
     }
390
-    
411
+
391
     /**
412
     /**
392
      * Processes an event of the specified type.
413
      * Processes an event of the specified type.
393
      *
414
      *
406
         assert(type != null);
427
         assert(type != null);
407
         assert(type.getType() != null);
428
         assert(type.getType() != null);
408
         assert(type.getType().getArity() == arguments.length);
429
         assert(type.getType().getArity() == arguments.length);
409
-        
430
+
410
         if (listeners.containsKey(type)) {
431
         if (listeners.containsKey(type)) {
411
             for (ActionListener listener : listeners.get(type)) {
432
             for (ActionListener listener : listeners.get(type)) {
412
                 listener.processEvent(type, format, arguments);
433
                 listener.processEvent(type, format, arguments);
413
             }
434
             }
414
         }
435
         }
415
-        
436
+
416
         if (!killSwitch) {
437
         if (!killSwitch) {
417
             triggerActions(type, format, arguments);
438
             triggerActions(type, format, arguments);
418
         }
439
         }
419
     }
440
     }
420
-    
441
+
421
     /**
442
     /**
422
      * Triggers actions that respond to the specified type.
443
      * Triggers actions that respond to the specified type.
423
      *
444
      *
430
     private static void triggerActions(final ActionType type,
451
     private static void triggerActions(final ActionType type,
431
             final StringBuffer format, final Object ... arguments) {
452
             final StringBuffer format, final Object ... arguments) {
432
         assert(type != null);
453
         assert(type != null);
433
-        
454
+
434
         if (actions.containsKey(type)) {
455
         if (actions.containsKey(type)) {
435
             for (Action action : actions.get(type)) {
456
             for (Action action : actions.get(type)) {
436
                 action.trigger(format, arguments);
457
                 action.trigger(format, arguments);
437
             }
458
             }
438
         }
459
         }
439
     }
460
     }
440
-    
461
+
441
     /**
462
     /**
442
      * Returns the directory that should be used to store actions.
463
      * Returns the directory that should be used to store actions.
443
      *
464
      *
446
     public static String getDirectory() {
467
     public static String getDirectory() {
447
         return Main.getConfigDir() + "actions" + System.getProperty("file.separator");
468
         return Main.getConfigDir() + "actions" + System.getProperty("file.separator");
448
     }
469
     }
449
-    
470
+
450
     /**
471
     /**
451
      * Creates a new group with the specified name.
472
      * Creates a new group with the specified name.
452
      *
473
      *
460
         assert(group != null);
481
         assert(group != null);
461
         assert(!group.isEmpty());
482
         assert(!group.isEmpty());
462
         assert(!groups.containsKey(group));
483
         assert(!groups.containsKey(group));
463
-        
484
+
464
         if (new File(getDirectory() + group).mkdir()) {
485
         if (new File(getDirectory() + group).mkdir()) {
465
             groups.put(group, new ActionGroup(group));
486
             groups.put(group, new ActionGroup(group));
466
         }
487
         }
467
     }
488
     }
468
-    
489
+
469
     /**
490
     /**
470
      * Removes the group with the specified name.
491
      * Removes the group with the specified name.
471
      *
492
      *
474
     @Precondition({
495
     @Precondition({
475
         "The specified group is non-null and not empty",
496
         "The specified group is non-null and not empty",
476
         "The specified group is an existing group"
497
         "The specified group is an existing group"
477
-    })    
498
+    })
478
     public static void removeGroup(final String group) {
499
     public static void removeGroup(final String group) {
479
         assert(group != null);
500
         assert(group != null);
480
         assert(!group.isEmpty());
501
         assert(!group.isEmpty());
481
         assert(groups.containsKey(group));
502
         assert(groups.containsKey(group));
482
-        
503
+
483
         for (Action action : new ArrayList<Action>(groups.get(group))) {
504
         for (Action action : new ArrayList<Action>(groups.get(group))) {
484
             unregisterAction(action);
505
             unregisterAction(action);
485
         }
506
         }
486
-        
507
+
487
         final File dir = new File(getDirectory() + group);
508
         final File dir = new File(getDirectory() + group);
488
-        
509
+
489
         for (File file : dir.listFiles()) {
510
         for (File file : dir.listFiles()) {
490
             if (!file.delete()) {
511
             if (!file.delete()) {
491
                 Logger.userError(ErrorLevel.MEDIUM, "Unable to remove file: "
512
                 Logger.userError(ErrorLevel.MEDIUM, "Unable to remove file: "
493
                 return;
514
                 return;
494
             }
515
             }
495
         }
516
         }
496
-        
517
+
497
         if (!dir.delete()) {
518
         if (!dir.delete()) {
498
             Logger.userError(ErrorLevel.MEDIUM, "Unable to remove directory: "
519
             Logger.userError(ErrorLevel.MEDIUM, "Unable to remove directory: "
499
                     + dir.getAbsolutePath());
520
                     + dir.getAbsolutePath());
500
             return;
521
             return;
501
         }
522
         }
502
-        
523
+
503
         groups.remove(group);
524
         groups.remove(group);
504
     }
525
     }
505
-    
526
+
506
     /**
527
     /**
507
      * Renames the specified group.
528
      * Renames the specified group.
508
      *
529
      *
515
         "The new name is non-null and not empty",
536
         "The new name is non-null and not empty",
516
         "The new name is not an existing group",
537
         "The new name is not an existing group",
517
         "The old name does not equal the new name"
538
         "The old name does not equal the new name"
518
-    })    
539
+    })
519
     public static void renameGroup(final String oldName, final String newName) {
540
     public static void renameGroup(final String oldName, final String newName) {
520
         assert(oldName != null);
541
         assert(oldName != null);
521
         assert(!oldName.isEmpty());
542
         assert(!oldName.isEmpty());
524
         assert(groups.containsKey(oldName));
545
         assert(groups.containsKey(oldName));
525
         assert(!groups.containsKey(newName));
546
         assert(!groups.containsKey(newName));
526
         assert(!newName.equals(oldName));
547
         assert(!newName.equals(oldName));
527
-        
548
+
528
         makeGroup(newName);
549
         makeGroup(newName);
529
-        
550
+
530
         for (Action action : groups.get(oldName)) {
551
         for (Action action : groups.get(oldName)) {
531
             action.setGroup(newName);
552
             action.setGroup(newName);
532
             getGroup(newName).add(action);
553
             getGroup(newName).add(action);
533
         }
554
         }
534
-        
555
+
535
         groups.remove(oldName);
556
         groups.remove(oldName);
536
-        
557
+
537
         removeGroup(oldName);
558
         removeGroup(oldName);
538
     }
559
     }
539
-    
560
+
540
     /**
561
     /**
541
      * Returns the action comparison specified by the given string, or null if it
562
      * Returns the action comparison specified by the given string, or null if it
542
      * doesn't match a valid registered action comparison.
563
      * doesn't match a valid registered action comparison.
548
         if (type == null || type.isEmpty()) {
569
         if (type == null || type.isEmpty()) {
549
             return null;
570
             return null;
550
         }
571
         }
551
-        
572
+
552
         for (ActionType target : actionTypes) {
573
         for (ActionType target : actionTypes) {
553
             if (((Enum) target).name().equals(type)) {
574
             if (((Enum) target).name().equals(type)) {
554
                 return target;
575
                 return target;
555
             }
576
             }
556
         }
577
         }
557
-        
578
+
558
         return null;
579
         return null;
559
     }
580
     }
560
-    
581
+
561
     /**
582
     /**
562
      * Returns a list of action types that are compatible with the one
583
      * Returns a list of action types that are compatible with the one
563
      * specified.
584
      * specified.
568
     @Precondition("The specified type is not null")
589
     @Precondition("The specified type is not null")
569
     public static List<ActionType> getCompatibleTypes(final ActionType type) {
590
     public static List<ActionType> getCompatibleTypes(final ActionType type) {
570
         assert(type != null);
591
         assert(type != null);
571
-        
592
+
572
         final List<ActionType> res = new ArrayList<ActionType>();
593
         final List<ActionType> res = new ArrayList<ActionType>();
573
         for (ActionType target : actionTypes) {
594
         for (ActionType target : actionTypes) {
574
             if (!target.equals(type) && target.getType().equals(type.getType())) {
595
             if (!target.equals(type) && target.getType().equals(type.getType())) {
575
                 res.add(target);
596
                 res.add(target);
576
             }
597
             }
577
         }
598
         }
578
-        
599
+
579
         return res;
600
         return res;
580
     }
601
     }
581
-    
602
+
582
     /**
603
     /**
583
      * Returns a list of action components that are compatible with the
604
      * Returns a list of action components that are compatible with the
584
      * specified class.
605
      * specified class.
589
     @Precondition("The specified target is not null")
610
     @Precondition("The specified target is not null")
590
     public static List<ActionComponent> getCompatibleComponents(final Class target) {
611
     public static List<ActionComponent> getCompatibleComponents(final Class target) {
591
         assert(target != null);
612
         assert(target != null);
592
-        
613
+
593
         final List<ActionComponent> res = new ArrayList<ActionComponent>();
614
         final List<ActionComponent> res = new ArrayList<ActionComponent>();
594
         for (ActionComponent subject : actionComponents) {
615
         for (ActionComponent subject : actionComponents) {
595
             if (subject.appliesTo().equals(target)) {
616
             if (subject.appliesTo().equals(target)) {
596
                 res.add(subject);
617
                 res.add(subject);
597
             }
618
             }
598
         }
619
         }
599
-        
620
+
600
         return res;
621
         return res;
601
     }
622
     }
602
-    
623
+
603
     /**
624
     /**
604
      * Returns a list of action comparisons that are compatible with the
625
      * Returns a list of action comparisons that are compatible with the
605
      * specified class.
626
      * specified class.
610
     @Precondition("The specified target is not null")
631
     @Precondition("The specified target is not null")
611
     public static List<ActionComparison> getCompatibleComparisons(final Class target) {
632
     public static List<ActionComparison> getCompatibleComparisons(final Class target) {
612
         assert(target != null);
633
         assert(target != null);
613
-        
634
+
614
         final List<ActionComparison> res = new ArrayList<ActionComparison>();
635
         final List<ActionComparison> res = new ArrayList<ActionComparison>();
615
         for (ActionComparison subject : actionComparisons) {
636
         for (ActionComparison subject : actionComparisons) {
616
             if (subject.appliesTo().equals(target)) {
637
             if (subject.appliesTo().equals(target)) {
617
                 res.add(subject);
638
                 res.add(subject);
618
             }
639
             }
619
         }
640
         }
620
-        
641
+
621
         return res;
642
         return res;
622
     }
643
     }
623
-    
644
+
624
     /**
645
     /**
625
      * Returns a list of all the action types registered by this manager.
646
      * Returns a list of all the action types registered by this manager.
626
      *
647
      *
629
     public static List<ActionType> getTypes() {
650
     public static List<ActionType> getTypes() {
630
         return actionTypes;
651
         return actionTypes;
631
     }
652
     }
632
-    
653
+
633
     /**
654
     /**
634
      * Returns a list of all the action types registered by this manager.
655
      * Returns a list of all the action types registered by this manager.
635
      *
656
      *
638
     public static List<ActionComparison> getComparisons() {
659
     public static List<ActionComparison> getComparisons() {
639
         return actionComparisons;
660
         return actionComparisons;
640
     }
661
     }
641
-    
662
+
642
     /**
663
     /**
643
      * Returns the action component specified by the given string, or null if it
664
      * Returns the action component specified by the given string, or null if it
644
      * doesn't match a valid registered action component.
665
      * doesn't match a valid registered action component.
650
     public static ActionComponent getActionComponent(final String type) {
671
     public static ActionComponent getActionComponent(final String type) {
651
         assert(type != null);
672
         assert(type != null);
652
         assert(!type.isEmpty());
673
         assert(!type.isEmpty());
653
-        
674
+
654
         for (ActionComponent target : actionComponents) {
675
         for (ActionComponent target : actionComponents) {
655
             if (((Enum) target).name().equals(type)) {
676
             if (((Enum) target).name().equals(type)) {
656
                 return target;
677
                 return target;
657
             }
678
             }
658
         }
679
         }
659
-        
680
+
660
         return null;
681
         return null;
661
     }
682
     }
662
-    
683
+
663
     /**
684
     /**
664
      * Returns the action type specified by the given string, or null if it
685
      * Returns the action type specified by the given string, or null if it
665
      * doesn't match a valid registered action type.
686
      * doesn't match a valid registered action type.
671
     public static ActionComparison getActionComparison(final String type) {
692
     public static ActionComparison getActionComparison(final String type) {
672
         assert(type != null);
693
         assert(type != null);
673
         assert(!type.isEmpty());
694
         assert(!type.isEmpty());
674
-        
695
+
675
         for (ActionComparison target : actionComparisons) {
696
         for (ActionComparison target : actionComparisons) {
676
             if (((Enum) target).name().equals(type)) {
697
             if (((Enum) target).name().equals(type)) {
677
                 return target;
698
                 return target;
678
             }
699
             }
679
         }
700
         }
680
-        
701
+
681
         return null;
702
         return null;
682
     }
703
     }
683
-    
704
+
684
     /**
705
     /**
685
      * Installs an action pack located at the specified path.
706
      * Installs an action pack located at the specified path.
686
-     * 
707
+     *
687
      * @param path The full path of the action pack .zip.
708
      * @param path The full path of the action pack .zip.
688
      * @throws IOException If the zip cannot be extracted
709
      * @throws IOException If the zip cannot be extracted
689
      */
710
      */
690
     public static void installActionPack(final String path) throws IOException {
711
     public static void installActionPack(final String path) throws IOException {
691
         final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
712
         final ZipResourceManager ziprm = ZipResourceManager.getInstance(path);
692
-        
713
+
693
         ziprm.extractResources("", getDirectory());
714
         ziprm.extractResources("", getDirectory());
694
-        
715
+
695
         loadActions();
716
         loadActions();
696
-        
697
-        new File(path).delete();        
717
+
718
+        new File(path).delete();
698
     }
719
     }
699
-    
720
+
700
     /**
721
     /**
701
      * Adds a new listener for the specified action type.
722
      * Adds a new listener for the specified action type.
702
-     * 
723
+     *
703
      * @param types The action types that are to be listened for
724
      * @param types The action types that are to be listened for
704
      * @param listener The listener to be added
725
      * @param listener The listener to be added
705
      */
726
      */
708
             listeners.add(type, listener);
729
             listeners.add(type, listener);
709
         }
730
         }
710
     }
731
     }
711
-    
732
+
712
     /**
733
     /**
713
      * Removes a listener for the specified action type.
734
      * Removes a listener for the specified action type.
714
-     * 
735
+     *
715
      * @param types The action types that were being listened for
736
      * @param types The action types that were being listened for
716
      * @param listener The listener to be removed
737
      * @param listener The listener to be removed
717
      */
738
      */
720
             listeners.remove(type, listener);
741
             listeners.remove(type, listener);
721
         }
742
         }
722
     }
743
     }
723
-    
744
+
724
     /**
745
     /**
725
      * Removes a listener for all action types.
746
      * Removes a listener for all action types.
726
-     * 
747
+     *
727
      * @param listener The listener to be removed
748
      * @param listener The listener to be removed
728
      */
749
      */
729
     public static void removeListener(final ActionListener listener) {
750
     public static void removeListener(final ActionListener listener) {
730
         listeners.removeFromAll(listener);
751
         listeners.removeFromAll(listener);
731
-    }    
752
+    }
732
 }
753
 }

+ 1
- 1
src/com/dmdirc/actions/defaults/umodes/ov View File

24
   description=Automatically sets the popup.umodes setting when connecting to a server, so that the correct user modes appear in the nicklist popup.
24
   description=Automatically sets the popup.umodes setting when connecting to a server, so that the correct user modes appear in the nicklist popup.
25
   author=Chris <chris@dmdirc.com>
25
   author=Chris <chris@dmdirc.com>
26
   version=2
26
   version=2
27
-  component=umodes
27
+  component=19

+ 3
- 3
src/com/dmdirc/config/ConfigManager.java View File

23
 package com.dmdirc.config;
23
 package com.dmdirc.config;
24
 
24
 
25
 import com.dmdirc.interfaces.ConfigChangeListener;
25
 import com.dmdirc.interfaces.ConfigChangeListener;
26
-import com.dmdirc.util.WeakMapList;
26
+import com.dmdirc.util.MapList;
27
 
27
 
28
 import java.io.Serializable;
28
 import java.io.Serializable;
29
 import java.util.ArrayList;
29
 import java.util.ArrayList;
56
     private List<Identity> sources;
56
     private List<Identity> sources;
57
     
57
     
58
     /** The listeners registered for this manager. */
58
     /** The listeners registered for this manager. */
59
-    private final WeakMapList<String, ConfigChangeListener> listeners
60
-            = new WeakMapList<String, ConfigChangeListener>();
59
+    private final MapList<String, ConfigChangeListener> listeners
60
+            = new MapList<String, ConfigChangeListener>();
61
     
61
     
62
     /** The ircd this manager is for. */
62
     /** The ircd this manager is for. */
63
     private final String ircd;
63
     private final String ircd;

Loading…
Cancel
Save