Save after deleting a config. Reset target to no-op when deleting its config, rather...
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Fri, 1 Mar 2013 17:11:14 +0000 (18:11 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Fri, 1 Mar 2013 17:11:14 +0000 (18:11 +0100)
Config.m
ConfigsController.m
TargetConfig.m
TargetController.m

index 55162b0..046ccc2 100644 (file)
--- a/Config.m
+++ b/Config.m
 
 - (NSDictionary *)serialize {
     NSMutableDictionary* cfgEntries = [[NSMutableDictionary alloc] initWithCapacity:_entries.count];
-    for (id key in _entries)
-        cfgEntries[key] = [_entries[key] serialize];
+    for (id key in _entries) {
+        id serialized = [_entries[key] serialize];
+        if (serialized)
+            cfgEntries[key] = serialized;
+    }
     return @{ @"name": _name, @"entries": cfgEntries };
 }
 
index 9693985..a9f3f3e 100644 (file)
@@ -77,6 +77,7 @@
     
     [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged];
     [tableView reloadData];
+    [self save];
 }
 
 -(void)tableViewSelectionDidChange:(NSNotification *)notify {
     for (unsigned i = 0; i < storedConfigs.count; ++i) {
         NSDictionary *entries = storedConfigs[i][@"entries"];
         Config *config = newConfigs[i];
-        for (id key in entries)
-            config.entries[key] = [Target targetDeserialize:entries[key]
-                                                withConfigs:newConfigs];
+        for (id key in entries) {
+            Target *target = [Target targetDeserialize:entries[key]
+                                            withConfigs:newConfigs];
+            if (target)
+                config.entries[key] = target;
+        }
     }
     
     if (newConfigs.count) {
index e9c374e..a06f3fb 100644 (file)
@@ -20,7 +20,7 @@
 - (NSDictionary *)serialize {
     return _config
         ? @{ @"type": @"cfg", @"name": _config.name }
-        : @{};
+        : nil;
 }
 
 + (TargetConfig *)targetDeserialize:(NSDictionary *)serialization
index 86fe968..7a4fd05 100644 (file)
         keyInput.vk = [(TargetKeyboard*)target vk];
     } else if ([target isKindOfClass:[TargetConfig class]]) {
         [radioButtons selectCellAtRow:2 column:0];
-        [configPopup selectItemAtIndex:[configsController.configs
-                                        indexOfObject:[(TargetConfig *)target config]]];
+        NSUInteger idx = [configsController.configs
+                          indexOfObject:[(TargetConfig *)target config]];
+        if (idx == NSNotFound) {
+            [radioButtons selectCellAtRow:self.enabled ? 0 : -1 column:0];
+            [configPopup selectItemAtIndex:-1];
+        } else
+            [configPopup selectItemAtIndex:idx];
     }
     else if ([target isKindOfClass:[TargetMouseMove class]]) {
         [radioButtons selectCellAtRow:3 column:0];