From d8e28b75c1e66625fe6c30e30af3ed828c4e481a Mon Sep 17 00:00:00 2001 From: michael starke Date: Wed, 13 Feb 2013 23:55:16 +0100 Subject: [PATCH] Working on Open File --- MacPass/MPAppDelegate.m | 25 +++-- MacPass/MPMainWindowController.h | 7 ++ MacPass/MPMainWindowController.m | 32 +++++- MacPass/MPOutlineDataSource.m | 18 +++- MacPass/MainWindow.xib | 172 ++++++++----------------------- MacPass/PasswordView.xib | 82 ++++++++++++++- 6 files changed, 188 insertions(+), 148 deletions(-) diff --git a/MacPass/MPAppDelegate.m b/MacPass/MPAppDelegate.m index 03cbd8e5..4d50822c 100644 --- a/MacPass/MPAppDelegate.m +++ b/MacPass/MPAppDelegate.m @@ -24,20 +24,19 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - _mainWindowController = [[MPMainWindowController alloc] init]; - [_mainWindowController showWindow:[_mainWindowController window]]; + self.mainWindowController = [[[MPMainWindowController alloc] init] autorelease]; + [self.mainWindowController showWindow:[self.mainWindowController window]]; } #pragma mark Menu Actions - (void)showPreferences:(id)sender { - if(_settingsController == nil) { - _settingsController = [[MPSettingsController alloc] init]; + if(self.settingsController == nil) { + self.settingsController = [[[MPSettingsController alloc] init] autorelease]; } - [_settingsController showWindow:_settingsController.window]; + [self.settingsController showWindow:_settingsController.window]; } - (void)newDocument:(id)sender { - [[MPDatabaseController defaultController] createDatabase]; } - (void)performClose:(id)sender { @@ -45,7 +44,19 @@ } - (void)openDocument:(id)sender { - [[MPDatabaseController defaultController] openDatabase]; + NSOpenPanel *openPanel = [NSOpenPanel openPanel]; + [openPanel setCanChooseDirectories:NO]; + [openPanel setCanChooseFiles:YES]; + [openPanel setCanCreateDirectories:NO]; + [openPanel setAllowsMultipleSelection:NO]; + [openPanel beginSheetModalForWindow:[self.mainWindowController window] completionHandler:^(NSInteger result){ + if(result == NSFileHandlingPanelOKButton) { + NSURL *file = [[openPanel URLs] lastObject]; + if(file) { + [self.mainWindowController presentPasswordInput]; + } + } + }]; } diff --git a/MacPass/MPMainWindowController.h b/MacPass/MPMainWindowController.h index 8afb8f4b..b7e90120 100644 --- a/MacPass/MPMainWindowController.h +++ b/MacPass/MPMainWindowController.h @@ -8,8 +8,15 @@ #import +APPKIT_EXTERN NSString *const MPMainWindowControllerPasswordKey; +APPKIT_EXTERN NSString *const MPMainWindowControllerKeyfileKey; + @class MPDatabaseDocument; @interface MPMainWindowController : NSWindowController + @property (readonly, retain) MPDatabaseDocument *database; + +- (void)presentPasswordInput; + @end diff --git a/MacPass/MPMainWindowController.m b/MacPass/MPMainWindowController.m index d6831a33..b9cc26d4 100644 --- a/MacPass/MPMainWindowController.m +++ b/MacPass/MPMainWindowController.m @@ -10,6 +10,10 @@ #import "MPOutlineDataSource.h" #import "MPOutlineViewDelegate.h" #import "MPMainWindowDelegate.h" +#import "MPDatabaseController.h" + +NSString *const MPMainWindowControllerPasswordKey = @"MPMainWindowControllerPasswordKey"; +NSString *const MPMainWindowControllerKeyfileKey = @"MPMainWindowControllerKeyfileKey"; NSString *const kColumnIdentifier = @"OutlineColumn"; NSString *const kOutlineViewIdentifier = @"OutlineView"; @@ -18,10 +22,17 @@ NSString *const kOutlineViewIdentifier = @"OutlineView"; @interface MPMainWindowController () @property (assign) IBOutlet NSOutlineView *outlineView; +@property (retain) IBOutlet NSView *passwordView; + +@property (assign) IBOutlet NSTextField *passwordTextField; +@property (assign) IBOutlet NSPathControl *keyPathControl; +@property (assign) IBOutlet NSView *contentView; + @property (retain) MPOutlineDataSource *datasource; @property (retain) MPOutlineViewDelegate *outlineDelegate; @property (retain) MPMainWindowDelegate *windowDelegate; +- (IBAction)usePassword:(id)sender; - (void)updateData; @end @@ -32,9 +43,9 @@ NSString *const kOutlineViewIdentifier = @"OutlineView"; -(id)init { self = [super initWithWindowNibName:@"MainWindow" owner:self]; if( self ) { - _windowDelegate = [[MPMainWindowDelegate alloc] init]; - _outlineDelegate = [[MPOutlineViewDelegate alloc] init]; - _datasource = [[MPOutlineDataSource alloc] init]; + self.windowDelegate = [[[MPMainWindowDelegate alloc] init] autorelease]; + self.outlineDelegate = [[[MPOutlineViewDelegate alloc] init] autorelease]; + self.datasource = [[[MPOutlineDataSource alloc] init] autorelease]; } return self; } @@ -47,12 +58,23 @@ NSString *const kOutlineViewIdentifier = @"OutlineView"; */ [self.window setDelegate:self.windowDelegate]; - [[_outlineView outlineTableColumn] setIdentifier:kColumnIdentifier]; - [_outlineView setDelegate:_outlineDelegate]; + [[self.outlineView outlineTableColumn] setIdentifier:kColumnIdentifier]; + [self.outlineView setDelegate:self.outlineDelegate]; } - (void)updateData { [_outlineView reloadData]; } +- (void)presentPasswordInput { + NSArray *topLevelObjects; + [[NSBundle mainBundle] loadNibNamed:@"PasswordView" owner:self topLevelObjects:&topLevelObjects]; + [self.contentView addSubview:self.passwordView]; +} + +- (void)usePassword:(id)sender { + [[MPDatabaseController defaultController] openDatabase:nil password:nil keyfile:nil]; + [self updateData]; +} + @end diff --git a/MacPass/MPOutlineDataSource.m b/MacPass/MPOutlineDataSource.m index b4db20e2..8c5e7d52 100644 --- a/MacPass/MPOutlineDataSource.m +++ b/MacPass/MPOutlineDataSource.m @@ -8,17 +8,29 @@ #import "MPOutlineDataSource.h" #import "MPDatabaseDocument.h" +#import "KdbLib.h" @implementation MPOutlineDataSource - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item { - return 1; + + if( [item isKindOfClass:[KdbGroup class]]) { + KdbGroup *group = item; + return [[group groups] count]; + } + return 0; } - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item { - return @"Super"; + if( [item isKindOfClass:[KdbGroup class]]) { + KdbGroup *group = item; + if( [[group groups] count] > index ) { + return [group groups][index]; + } + } + return nil; } - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item { - return YES; + return [item isKindOfClass:[KdbGroup class]]; } @end diff --git a/MacPass/MainWindow.xib b/MacPass/MainWindow.xib index 0ec4bb7e..3cdaf245 100644 --- a/MacPass/MainWindow.xib +++ b/MacPass/MainWindow.xib @@ -12,7 +12,6 @@ IBNSLayoutConstraint - NSBox NSButton NSButtonCell NSCustomObject @@ -301,45 +300,11 @@ 274 - - - - 12 - {{-2, 0}, {5, 567}} - - - - _NS:9 - {0, 0} - - 67108864 - 0 - Box - - - 6 - System - textBackgroundColor - - 3 - MQA - - - - 3 - MCAwLjgwMDAwMDAxMTkAA - - - 3 - 2 - 0 - NO - - + {{192, 0}, {633, 567}} - + _NS:13 @@ -357,7 +322,7 @@ - {{0, 0}, {2560, 1418}} + {{0, 0}, {1680, 1028}} {10000000000000, 10000000000000} NO 32 @@ -382,6 +347,14 @@ 501 + + + contentView + + + + 502 + textField @@ -1108,79 +1081,8 @@ 469 - - - - - 4 - 0 - - 4 - 1 - - 0.0 - - 1000 - - 8 - 29 - 3 - - - - 5 - 0 - - 5 - 1 - - 0.0 - - 1000 - - 9 - 40 - 3 - - - - 3 - 0 - - 3 - 1 - - 0.0 - - 1000 - - 9 - 40 - 3 - - - - - - 486 - - - - - 490 - - - - - 494 - - - - - 488 - - + @@ -1278,41 +1180,55 @@ 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 - 501 + 502 MPMainWindowController NSWindowController - - outlineView - NSOutlineView + + usePassword: + id - - outlineView - + + usePassword: + + usePassword: + id + + + + NSView + NSPathControl + NSOutlineView + NSTextField + + + + contentView + NSView + + + keyPathControl + NSPathControl + + outlineView NSOutlineView - + + passwordTextField + NSTextField + + IBProjectSource ./Classes/MPMainWindowController.h diff --git a/MacPass/PasswordView.xib b/MacPass/PasswordView.xib index 7f48b310..04e2bbdf 100644 --- a/MacPass/PasswordView.xib +++ b/MacPass/PasswordView.xib @@ -32,7 +32,7 @@ - NSObject + MPMainWindowController FirstResponder @@ -128,7 +128,6 @@ 2 - NO @@ -250,12 +249,37 @@ - + + + + passwordTextField + + + + 99 + + + + keyPathControl + + + + 100 + + + + passwordView + + + + 101 + + 0 - + @@ -662,10 +686,58 @@ - 98 + 101 + + MPMainWindowController + NSWindowController + + usePassword: + id + + + usePassword: + + usePassword: + id + + + + NSView + NSPathControl + NSOutlineView + NSTextField + NSView + + + + contentView + NSView + + + keyPathControl + NSPathControl + + + outlineView + NSOutlineView + + + passwordTextField + NSTextField + + + passwordView + NSView + + + + IBProjectSource + ./Classes/MPMainWindowController.h + + NSLayoutConstraint NSObject