From: Joe Wreschnig Date: Fri, 1 Mar 2013 17:11:14 +0000 (+0100) Subject: Save after deleting a config. Reset target to no-op when deleting its config, rather... X-Git-Tag: version-1.0~69 X-Git-Url: https://git.yukkurigames.com/?a=commitdiff_plain;h=44a44209d4ce26fb30102014d7040975aea51f93;p=enjoyable.git Save after deleting a config. Reset target to no-op when deleting its config, rather than to the default config. --- diff --git a/Config.m b/Config.m index 55162b0..046ccc2 100644 --- a/Config.m +++ b/Config.m @@ -34,8 +34,11 @@ - (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 }; } diff --git a/ConfigsController.m b/ConfigsController.m index 9693985..a9f3f3e 100644 --- a/ConfigsController.m +++ b/ConfigsController.m @@ -77,6 +77,7 @@ [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged]; [tableView reloadData]; + [self save]; } -(void)tableViewSelectionDidChange:(NSNotification *)notify { @@ -132,9 +133,12 @@ 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) { diff --git a/TargetConfig.m b/TargetConfig.m index e9c374e..a06f3fb 100644 --- a/TargetConfig.m +++ b/TargetConfig.m @@ -20,7 +20,7 @@ - (NSDictionary *)serialize { return _config ? @{ @"type": @"cfg", @"name": _config.name } - : @{}; + : nil; } + (TargetConfig *)targetDeserialize:(NSDictionary *)serialization diff --git a/TargetController.m b/TargetController.m index 86fe968..7a4fd05 100644 --- a/TargetController.m +++ b/TargetController.m @@ -175,8 +175,13 @@ 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];