Skip to content

Commit

Permalink
Removed 'protect' option from configs
Browse files Browse the repository at this point in the history
  • Loading branch information
fyhuang committed Mar 31, 2013
1 parent 919442d commit f2e854d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 40 deletions.
2 changes: 0 additions & 2 deletions Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

@interface Config : NSObject {
NSString *name;
BOOL protect;
NSMutableDictionary *entries;
}

@property(readwrite) BOOL protect;
@property(readwrite, copy) NSString* name;
@property(readonly) NSMutableDictionary* entries;

Expand Down
2 changes: 1 addition & 1 deletion Config.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ -(id) init {
return self;
}

@synthesize protect, name, entries;
@synthesize name, entries;

-(void) setTarget:(Target*)target forAction:(id)jsa {
[entries setValue:target forKey: [jsa stringify]];
Expand Down
4 changes: 3 additions & 1 deletion ConfigsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

-(void) loadAllFromDir: (NSURL*)dir;
-(NSDictionary*) dumpAll;
-(void) loadAllFrom: (NSDictionary*) dict;

@property(readonly) Config* currentConfig;
@property(readonly) Config* currentNeutralConfig;
Expand All @@ -44,4 +43,7 @@
-(void) makeMappingsDirectory;
-(NSURL*) getMappingFilenameFor: (Config*) config;

// Legacy loading code from Enjoy2 v1.1
-(void) ver11LoadConfigsFrom: (NSDictionary*) dict;

@end
75 changes: 39 additions & 36 deletions ConfigsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ -(id) init {
// Make (default) config
currentConfig = [[Config alloc] init];
[currentConfig setName: @"Default"];
[currentConfig setProtect: YES];
[configs addObject: currentConfig];
}
return self;
Expand Down Expand Up @@ -48,7 +47,9 @@ -(void) activateConfig: (Config*)config forApplication: (ProcessSerialNumber*) p
[targetController reset];
}
currentConfig = config;
[removeButton setEnabled: ![config protect]];
//[removeButton setEnabled: YES];
// TODO: quick hack
[removeButton setEnabled:([configs count] > 0)];
[targetController load];
[appController configChanged];
[tableView selectRow: [configs indexOfObject: config] byExtendingSelection: NO];
Expand All @@ -67,8 +68,6 @@ -(IBAction) removePressed: (id)sender {
// save changes first
[tableView reloadData];
Config* current_config = [configs objectAtIndex: [tableView selectedRow]];
if([current_config protect])
return;
[configs removeObjectAtIndex: [tableView selectedRow]];

// remove all "switch to configuration" actions
Expand Down Expand Up @@ -109,7 +108,7 @@ -(int)numberOfRowsInTableView: (NSTableView*)table {
}

-(BOOL)tableView: (NSTableView*)view shouldEditTableColumn: (NSTableColumn*) column row: (int) index {
return ![[configs objectAtIndex: index] protect];
return YES;
}

-(Config*) currentConfig {
Expand Down Expand Up @@ -196,37 +195,6 @@ -(NSDictionary*) dumpAll {
[envelope setObject: [NSNumber numberWithInt: [configs indexOfObject: [self currentNeutralConfig] ] ] forKey: @"selectedIndex"];
return envelope;
}
-(void) loadAllFrom: (NSDictionary*) envelope{
if(envelope == NULL)
return;
NSArray* ary = [envelope objectForKey: @"configurationList"];

NSMutableArray* newConfigs = [[NSMutableArray alloc] init];
// have to do two passes in case config1 refers to config2 via a TargetConfig
for(int i=0; i<[ary count]; i++) {
Config* cfg = [[Config alloc] init];
[cfg setName: [[ary objectAtIndex:i] objectForKey:@"name"]];
[newConfigs addObject: cfg];
}
[[configs objectAtIndex:0] setProtect: YES];
for(int i=0; i<[ary count]; i++) {
NSDictionary* dict = [[ary objectAtIndex:i] objectForKey:@"entries"];
for(id key in dict) {
[[[newConfigs objectAtIndex:i] entries]
setObject: [Target unstringify: [dict objectForKey: key] withConfigList: newConfigs]
forKey: key];
}
}

configs = newConfigs;
currentConfig = NULL;

[tableView reloadData];
[appController configsListChanged];

int index = [[envelope objectForKey: @"selectedIndex"] intValue];
[self activateConfig: [configs objectAtIndex:index] forApplication: NULL];
}

-(void) applicationSwitchedTo: (NSString*) name withPsn: (ProcessSerialNumber) psn {
for(int i=0; i<[configs count]; i++) {
Expand Down Expand Up @@ -280,4 +248,39 @@ -(ProcessSerialNumber*) targetApplication {
return NULL;
}


///////////////////////////////////////
// Legacy loading code from Enjoy2 v1.1

-(void) ver11LoadConfigsFrom: (NSDictionary*) envelope{
if(envelope == NULL)
return;
NSArray* ary = [envelope objectForKey: @"configurationList"];

NSMutableArray* newConfigs = [[NSMutableArray alloc] init];
// have to do two passes in case config1 refers to config2 via a TargetConfig
for(int i=0; i<[ary count]; i++) {
Config* cfg = [[Config alloc] init];
[cfg setName: [[ary objectAtIndex:i] objectForKey:@"name"]];
[newConfigs addObject: cfg];
}
for(int i=0; i<[ary count]; i++) {
NSDictionary* dict = [[ary objectAtIndex:i] objectForKey:@"entries"];
for(id key in dict) {
[[[newConfigs objectAtIndex:i] entries]
setObject: [Target unstringify: [dict objectForKey: key] withConfigList: newConfigs]
forKey: key];
}
}

configs = newConfigs;
currentConfig = NULL;

[tableView reloadData];
[appController configsListChanged];

int index = [[envelope objectForKey: @"selectedIndex"] intValue];
[self activateConfig: [configs objectAtIndex:index] forApplication: NULL];
}

@end

0 comments on commit f2e854d

Please sign in to comment.