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 55162b081baa3270f35037fe0c00caed42bd18e2..046ccc2c6fa22980952d76ab84f0b59c76bea1a6 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 969398515b4a5d235e41d48da9dca73dd2035c14..a9f3f3ed855f8cb33fde224efe7de148a67a32a6 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 e9c374ed5ec6d5df44e7dafd9c43c37f88750352..a06f3fb4f00b5ea1fdc7c911f3c2d6f39177e93b 100644 (file)
@@ -20,7 +20,7 @@
 - (NSDictionary *)serialize {
     return _config
         ? @{ @"type": @"cfg", @"name": _config.name }
-        : @{};
+        : nil;
 }
 
 + (TargetConfig *)targetDeserialize:(NSDictionary *)serialization
index 86fe9688aaa21d029a125c90d635026b673d6119..7a4fd058e470d6238dd5b285d3a03770129e0c41 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];