Skip to content

Commit

Permalink
Added an "Add" button to the bottom of the Whitelist table, wired up …
Browse files Browse the repository at this point in the history
…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
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 166 deletions.
14 changes: 7 additions & 7 deletions Plugin/CTFWhitelistWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

@interface CTFWhitelistWindowController : NSWindowController {
IBOutlet NSArrayController *_controller;
NSMutableArray *_sites;
// NSMutableArray *_sites;
}

- (IBAction) addWhitelistSite: (id) sender;
- (IBAction) removeWhitelistSite: (id) sender;

- (void) saveWhitelist: (id) sender;
- (void) whitelistChanged: (NSNotification *) note;
//
//- (IBAction) addWhitelistSite: (id) sender;
//- (IBAction) removeWhitelistSite: (id) sender;
//
//- (void) saveWhitelist: (id) sender;
//- (void) whitelistChanged: (NSNotification *) note;
@end

62 changes: 3 additions & 59 deletions Plugin/CTFWhitelistWindowController.m
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

0 comments on commit 1da9679

Please sign in to comment.