diff --git a/MacPass/EntryView.xib b/MacPass/EntryView.xib index 7fe5b5f2..1872f5b3 100644 --- a/MacPass/EntryView.xib +++ b/MacPass/EntryView.xib @@ -18,6 +18,7 @@ NSTableHeaderView NSTableView NSTextFieldCell + NSUserDefaultsController com.apple.InterfaceBuilder.CocoaPlugin @@ -47,7 +48,7 @@ 256 - {703, 547} + {569, 506} @@ -58,7 +59,7 @@ 256 - {703, 17} + {569, 17} @@ -73,10 +74,10 @@ _NS:19 - - 116 - 40 - 1000 + + 64 + 10 + 3.4028234663852886e+38 75497536 2048 @@ -86,9 +87,14 @@ 11 3100 - - 3 - MC4zMzMzMzI5ODU2AA + + 6 + System + headerColor + + 3 + MQA + 6 @@ -100,7 +106,7 @@ - + 337641536 2048 Text Cell @@ -131,19 +137,45 @@ YES - - 581 - 40 - 1000 + + 64 + 10 + 3.4028234663852886e+38 75497536 2048 - + - + + 337641536 + 2048 + Text Cell + + + + + + 3 + YES + YES + + + + 432 + 10 + 3.4028234663852886e+38 + + 75497536 + 2048 + + + + + + 337641536 2048 Text Cell @@ -160,10 +192,7 @@ 3 2 - - 3 - MQA - + 6 System @@ -174,18 +203,18 @@ 17 - -700448768 + -692060160 4 15 0 YES - 0 + 1 1 - {{0, 17}, {703, 547}} + {{0, 17}, {569, 506}} @@ -214,7 +243,6 @@ {{1, 119}, {223, 15}} - _NS:60 NO 1 @@ -228,7 +256,7 @@ - {703, 17} + {569, 17} @@ -238,7 +266,7 @@ 4 - {703, 564} + {569, 523} @@ -253,6 +281,9 @@ 4 1 + + YES + @@ -264,6 +295,14 @@ 85 + + + entryTable + + + + 111 + @@ -306,8 +345,9 @@ 55 - - + + + @@ -327,30 +367,48 @@ - 59 - + 115 + + + + + 117 + - + - 60 - + 118 + + + + + 119 + - + - 61 - - + 120 + + - 62 - - + 121 + + + + + + + + 122 + + @@ -358,27 +416,42 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + NSSecureTextFieldCell + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - 110 + 122 MPEntryViewController MPViewController + + entryTable + NSTableView + + + entryTable + + entryTable + NSTableView + + IBProjectSource ./Classes/MPEntryViewController.h diff --git a/MacPass/MPDatabaseController.m b/MacPass/MPDatabaseController.m index e0943743..f276a5a6 100644 --- a/MacPass/MPDatabaseController.m +++ b/MacPass/MPDatabaseController.m @@ -58,11 +58,13 @@ NSString *const MPDatabaseControllerDatabaseKey = @"MPDatabaseControllerDatabase userInfo:userInfo]; } [_database release]; - _database = [database retain]; - NSDictionary *userInfo = @{ MPDatabaseControllerDatabaseKey: _database }; - [[NSNotificationCenter defaultCenter] postNotificationName:MPDatabaseControllerDidLoadDatabaseNotification - object:self - userInfo:userInfo]; + if(database) { + _database = [database retain]; + NSDictionary *userInfo = @{ MPDatabaseControllerDatabaseKey: _database }; + [[NSNotificationCenter defaultCenter] postNotificationName:MPDatabaseControllerDidLoadDatabaseNotification + object:self + userInfo:userInfo]; + } } } diff --git a/MacPass/MPDatabaseDocument.m b/MacPass/MPDatabaseDocument.m index 90db2539..ecc24843 100644 --- a/MacPass/MPDatabaseDocument.m +++ b/MacPass/MPDatabaseDocument.m @@ -72,7 +72,7 @@ NSString *const MPDidLoadDataBaseNotification = @"DidLoadDataBaseNotification"; @catch (NSException *exception) { NSLog(@"%@", [exception description]); [self release]; - return self; + return nil; } if([self.tree isKindOfClass:[Kdb4Tree class]]) { diff --git a/MacPass/MPEntryViewController.h b/MacPass/MPEntryViewController.h index 243c3ff1..5fcff30d 100644 --- a/MacPass/MPEntryViewController.h +++ b/MacPass/MPEntryViewController.h @@ -8,6 +8,13 @@ #import "MPViewController.h" +@class KdbGroup; +@class MPOutlineViewDelegate; + @interface MPEntryViewController : MPViewController +@property (nonatomic, assign) id outlineViewDelegate; +@property (assign) KdbGroup *activeGroup; +@property (readonly, retain) NSArrayController *entryArrayController; + @end diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index a2542619..89e917b6 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -7,10 +7,18 @@ // #import "MPEntryViewController.h" +#import "MPOutlineViewDelegate.h" + +NSString *const _MPUserNameColumnIdentifier = @"MPUserNameColumnIdentifier"; +NSString *const _MPTitleColumnIdentifier = @"MPTitleColumnIdentifier"; +NSString *const _MPPasswordColumnIdentifier = @"MPPasswordColumnIdentifier"; @interface MPEntryViewController () @property (retain) NSArrayController *entryArrayController; +@property (assign) IBOutlet NSTableView *entryTable; + +- (void)didChangeGroupSelectionInOutlineView:(NSNotification *)notification; @end @@ -23,9 +31,42 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if(self) { - self.entryArrayController = [[[NSArrayController alloc] init] autorelease]; + _entryArrayController = [[NSArrayController alloc] init]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(didChangeGroupSelectionInOutlineView:) + name:MPOutlineViewDidChangeGroupSelection + object:nil]; } return self; } +- (void)didLoadView { + NSTableColumn *nameColumn = [self.entryTable tableColumns][0]; + NSTableColumn *userNameColumn = [self.entryTable tableColumns][1]; + NSTableColumn *passwordColumn = [self.entryTable tableColumns][2]; + + [nameColumn setIdentifier:_MPTitleColumnIdentifier]; + [userNameColumn setIdentifier:_MPUserNameColumnIdentifier]; + [passwordColumn setIdentifier:_MPPasswordColumnIdentifier]; + + [[nameColumn headerCell] setStringValue:@"Title"]; + [[userNameColumn headerCell] setStringValue:@"Username"]; + [[passwordColumn headerCell] setStringValue:@"Password"]; + + [nameColumn bind:NSValueBinding toObject:self.entryArrayController withKeyPath:@"arrangedObjects.title" options:nil]; + [userNameColumn bind:NSValueBinding toObject:self.entryArrayController withKeyPath:@"arrangedObjects.username" options:nil]; + [passwordColumn bind:NSValueBinding toObject:self.entryArrayController withKeyPath:@"arrangedObjects.password" options:nil]; +} + +- (void)didChangeGroupSelectionInOutlineView:(NSNotification *)notification { + MPOutlineViewDelegate *delegate = [notification object]; + KdbGroup *group = delegate.selectedGroup; + if(group) { + [self.entryArrayController bind:NSContentArrayBinding toObject:group withKeyPath:@"entries" options:nil]; + } + else { + [self.entryArrayController setContent:nil]; + } +} + @end diff --git a/MacPass/MPOutlineViewController.h b/MacPass/MPOutlineViewController.h index 371fd517..47182644 100644 --- a/MacPass/MPOutlineViewController.h +++ b/MacPass/MPOutlineViewController.h @@ -10,4 +10,6 @@ @interface MPOutlineViewController : MPViewController +@property (retain, readonly) NSMenu *menu; + @end diff --git a/MacPass/MPOutlineViewController.m b/MacPass/MPOutlineViewController.m index 5e706477..2928237d 100644 --- a/MacPass/MPOutlineViewController.m +++ b/MacPass/MPOutlineViewController.m @@ -56,7 +56,6 @@ } - (void)didLoadView { - //[[self.outlineView outlineTableColumn] setIdentifier:kColumnIdentifier]; [self.outlineView setDataSource:self.datasource]; [self.outlineView setDelegate:self.outlineDelegate]; [self.outlineView setMenu:self.menu]; @@ -65,7 +64,9 @@ - (void)didOpenDocument:(NSNotification *)notification { [self.outlineView reloadData]; MPDatabaseController *dbContoller = [MPDatabaseController defaultController]; - [self.outlineView expandItem:dbContoller.database.root expandChildren:NO]; + if(dbContoller.database) { + [self.outlineView expandItem:dbContoller.database.root expandChildren:NO]; + } } - (void)setupMenu { diff --git a/MacPass/MPOutlineViewDelegate.h b/MacPass/MPOutlineViewDelegate.h index 1d59e513..a6639a68 100644 --- a/MacPass/MPOutlineViewDelegate.h +++ b/MacPass/MPOutlineViewDelegate.h @@ -8,6 +8,12 @@ #import +APPKIT_EXTERN NSString *const MPOutlineViewDidChangeGroupSelection; + +@class KdbGroup; + @interface MPOutlineViewDelegate : NSObject +@property (assign, readonly) KdbGroup *selectedGroup; + @end diff --git a/MacPass/MPOutlineViewDelegate.m b/MacPass/MPOutlineViewDelegate.m index 2e670476..40167c5a 100644 --- a/MacPass/MPOutlineViewDelegate.m +++ b/MacPass/MPOutlineViewDelegate.m @@ -10,9 +10,17 @@ #import "MPIconHelper.h" #import "KdbLib.h" +NSString *const MPOutlineViewDidChangeGroupSelection = @"MPOutlineViewDidChangeGroupSelection"; + NSString *const _MPOutlineViewDataViewIdentifier = @"DataCell"; NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; +@interface MPOutlineViewDelegate () + +@property (assign) KdbGroup *selectedGroup; + +@end + @implementation MPOutlineViewDelegate - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item { @@ -47,4 +55,12 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; return (nil != [group parent]); } +- (void)outlineViewSelectionDidChange:(NSNotification *)notification { + NSOutlineView *outlineView = [notification object]; + KdbGroup *selectedGroup = [outlineView itemAtRow:[outlineView selectedRow]]; + self.selectedGroup = selectedGroup; + NSLog(@"Selected: %@", self.selectedGroup); + [[NSNotificationCenter defaultCenter] postNotificationName:MPOutlineViewDidChangeGroupSelection object:self userInfo:nil]; +} + @end diff --git a/MacPass/MacPass-Info.plist b/MacPass/MacPass-Info.plist index 6b8cc046..51a4a249 100644 --- a/MacPass/MacPass-Info.plist +++ b/MacPass/MacPass-Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 76 + B9 LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSHumanReadableCopyright