-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an "Add" button to the bottom of the Whitelist table, wired up …
…entirely with bindings. Changed format of whitelist pref to be site info array-of-dictionaries to support this (and reworked the migration code). Removed remnants of add/remove code that isn't needed now that bindings can do (most of) that work.
- Loading branch information
Otyr Ugla
committed
Feb 12, 2009
1 parent
a253dc5
commit 1da9679
Showing
4 changed files
with
213 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,19 @@ | ||
#import "CTFWhitelistWindowController.h" | ||
|
||
extern NSString *sHostWhitelistDefaultsKey; | ||
extern NSString *sCTFWhitelistAdditionMade; | ||
|
||
@implementation CTFWhitelistWindowController | ||
|
||
- (id)init | ||
{ | ||
NSBundle * myBundle = [NSBundle bundleForClass:[self class]]; | ||
NSString * nibPath = [myBundle pathForResource:@"WhitelistPanel" ofType:@"nib"]; | ||
if (nibPath == nil) | ||
{ | ||
NSBundle *myBundle = [NSBundle bundleForClass:[self class]]; | ||
NSString *nibPath = [myBundle pathForResource:@"WhitelistPanel" ofType:@"nib"]; | ||
if (nibPath == nil) { | ||
[self dealloc]; | ||
return nil; | ||
} | ||
|
||
self = [super initWithWindowNibPath: nibPath owner: self]; | ||
|
||
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(whitelistChanged:) name: sCTFWhitelistAdditionMade object: nil]; | ||
_sites = [[NSMutableArray array] retain]; | ||
|
||
[self whitelistChanged: nil]; | ||
|
||
return self; | ||
} | ||
|
||
- (void) dealloc { | ||
[_sites release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (void) whitelistChanged: (NSNotification *) note { | ||
NSArray *currentSites = [[NSUserDefaults standardUserDefaults] valueForKey: sHostWhitelistDefaultsKey]; | ||
NSEnumerator *enumerator = [currentSites objectEnumerator]; | ||
NSString *site; | ||
|
||
[_sites removeAllObjects]; | ||
|
||
while (site = [enumerator nextObject]) { | ||
[_sites addObject: [NSMutableDictionary dictionaryWithObject: site forKey: @"description"]]; | ||
} | ||
[_controller setContent: _sites]; | ||
} | ||
|
||
- (IBAction) removeWhitelistSite: (id) sender { | ||
[_controller remove: nil]; | ||
[self saveWhitelist: nil]; | ||
} | ||
|
||
- (IBAction) addWhitelistSite: (id) sender { | ||
[_controller insertObject: [NSMutableDictionary dictionaryWithObject: @"" forKey: @"description"] atArrangedObjectIndex: _sites.count]; | ||
[_controller setSelectionIndex: _sites.count - 1]; | ||
[self saveWhitelist: nil]; | ||
} | ||
|
||
- (void) saveWhitelist: (id) sender { | ||
NSMutableArray *sites = [NSMutableArray array]; | ||
NSEnumerator *enumerator = [_sites objectEnumerator]; | ||
NSDictionary *site; | ||
|
||
while (site = [enumerator nextObject]) { | ||
[sites addObject: [site valueForKey: @"description"]]; | ||
} | ||
|
||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | ||
|
||
[defaults setValue: sites forKey: sHostWhitelistDefaultsKey]; | ||
} | ||
|
||
- (void) windowWillClose: (NSNotification *) notification { | ||
[self saveWhitelist: nil]; | ||
} | ||
|
||
@end |
Oops, something went wrong.