@property (copy) NSString *name;
@property (readonly) NSMutableDictionary *entries;
+- (id)initWithName:(NSString *)name;
- (Target *)objectForKeyedSubscript:(JSAction *)action;
- (void)setObject:(Target *)target forKeyedSubscript:(JSAction *)action;
#import "JSAction.h"
-@implementation Config {
- NSMutableDictionary *entries;
-}
-
-@synthesize name;
-@synthesize entries;
+@implementation Config
-- (id)init {
+- (id)initWithName:(NSString *)name {
if ((self = [super init])) {
- entries = [[NSMutableDictionary alloc] init];
+ self.name = name;
+ _entries = [[NSMutableDictionary alloc] init];
}
return self;
}
- (Target *)objectForKeyedSubscript:(JSAction *)action {
- return action ? entries[action.uid] : nil;
+ return action ? _entries[action.uid] : nil;
}
- (void)setObject:(Target *)target forKeyedSubscript:(JSAction *)action {
if (action) {
if (target)
- entries[action.uid] = target;
+ _entries[action.uid] = target;
else
- [entries removeObjectForKey:action.uid];
+ [_entries removeObjectForKey:action.uid];
}
}
- (id)init {
if ((self = [super init])) {
configs = [[NSMutableArray alloc] init];
- currentConfig = [[Config alloc] init];
- currentConfig.name = @"(default)";
+ currentConfig = [[Config alloc] initWithName:@"(default)"];
manualConfig = currentConfig;
[configs addObject:currentConfig];
}
}
- (IBAction)addPressed:(id)sender {
- Config *newConfig = [[Config alloc] init];
- newConfig.name = @"untitled";
+ Config *newConfig = [[Config alloc] initWithName:@"Untitled"];
[configs addObject:newConfig];
[(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged];
[tableView reloadData];
// have to do two passes in case config1 refers to config2 via a TargetConfig
for (NSDictionary *storedConfig in storedConfigs) {
- Config *cfg = [[Config alloc] init];
- cfg.name = storedConfig[@"name"];
+ Config *cfg = [[Config alloc] initWithName:storedConfig[@"name"]];
[newConfigs addObject:cfg];
}