Working on Open File

This commit is contained in:
michael starke
2013-02-13 23:55:16 +01:00
parent cdaa61f2e6
commit d8e28b75c1
6 changed files with 188 additions and 148 deletions

View File

@@ -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];
}
}
}];
}

View File

@@ -8,8 +8,15 @@
#import <Cocoa/Cocoa.h>
APPKIT_EXTERN NSString *const MPMainWindowControllerPasswordKey;
APPKIT_EXTERN NSString *const MPMainWindowControllerKeyfileKey;
@class MPDatabaseDocument;
@interface MPMainWindowController : NSWindowController
@property (readonly, retain) MPDatabaseDocument *database;
- (void)presentPasswordInput;
@end

View File

@@ -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

View File

@@ -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

View File

@@ -12,7 +12,6 @@
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBNSLayoutConstraint</string>
<string>NSBox</string>
<string>NSButton</string>
<string>NSButtonCell</string>
<string>NSCustomObject</string>
@@ -301,45 +300,11 @@
<object class="NSView" id="561162642">
<reference key="NSNextResponder" ref="777456971"/>
<int key="NSvFlags">274</int>
<array class="NSMutableArray" key="NSSubviews">
<object class="NSBox" id="703539409">
<reference key="NSNextResponder" ref="561162642"/>
<int key="NSvFlags">12</int>
<string key="NSFrame">{{-2, 0}, {5, 567}}</string>
<reference key="NSSuperview" ref="561162642"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="64441800"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<string key="NSOffsets">{0, 0}</string>
<object class="NSTextFieldCell" key="NSTitleCell">
<int key="NSCellFlags">67108864</int>
<int key="NSCellFlags2">0</int>
<string key="NSContents">Box</string>
<reference key="NSSupport" ref="776065329"/>
<object class="NSColor" key="NSBackgroundColor">
<int key="NSColorSpace">6</int>
<string key="NSCatalogName">System</string>
<string key="NSColorName">textBackgroundColor</string>
<object class="NSColor" key="NSColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
</object>
</object>
<object class="NSColor" key="NSTextColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MCAwLjgwMDAwMDAxMTkAA</bytes>
</object>
</object>
<int key="NSBorderType">3</int>
<int key="NSBoxType">2</int>
<int key="NSTitlePosition">0</int>
<bool key="NSTransparent">NO</bool>
</object>
</array>
<array class="NSMutableArray" key="NSSubviews"/>
<string key="NSFrame">{{192, 0}, {633, 567}}</string>
<reference key="NSSuperview" ref="777456971"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="703539409"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:13</string>
</object>
</array>
@@ -357,7 +322,7 @@
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="777456971"/>
</object>
<string key="NSScreenRect">{{0, 0}, {2560, 1418}}</string>
<string key="NSScreenRect">{{0, 0}, {1680, 1028}}</string>
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
<bool key="NSAutorecalculatesContentBorderThicknessMinY">NO</bool>
<double key="NSContentBorderThicknessMinY">32</double>
@@ -382,6 +347,14 @@
</object>
<int key="connectionID">501</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">contentView</string>
<reference key="source" ref="1001"/>
<reference key="destination" ref="561162642"/>
</object>
<int key="connectionID">502</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">textField</string>
@@ -1108,79 +1081,8 @@
<object class="IBObjectRecord">
<int key="objectID">469</int>
<reference key="object" ref="561162642"/>
<array class="NSMutableArray" key="children">
<reference ref="703539409"/>
<object class="IBNSLayoutConstraint" id="556511210">
<reference key="firstItem" ref="703539409"/>
<int key="firstAttribute">4</int>
<int key="relation">0</int>
<reference key="secondItem" ref="561162642"/>
<int key="secondAttribute">4</int>
<float key="multiplier">1</float>
<object class="IBLayoutConstant" key="constant">
<double key="value">0.0</double>
</object>
<float key="priority">1000</float>
<reference key="containingView" ref="561162642"/>
<int key="scoringType">8</int>
<float key="scoringTypeFloat">29</float>
<int key="contentType">3</int>
</object>
<object class="IBNSLayoutConstraint" id="390145290">
<reference key="firstItem" ref="703539409"/>
<int key="firstAttribute">5</int>
<int key="relation">0</int>
<reference key="secondItem" ref="561162642"/>
<int key="secondAttribute">5</int>
<float key="multiplier">1</float>
<object class="IBLayoutConstant" key="constant">
<double key="value">0.0</double>
</object>
<float key="priority">1000</float>
<reference key="containingView" ref="561162642"/>
<int key="scoringType">9</int>
<float key="scoringTypeFloat">40</float>
<int key="contentType">3</int>
</object>
<object class="IBNSLayoutConstraint" id="918096569">
<reference key="firstItem" ref="703539409"/>
<int key="firstAttribute">3</int>
<int key="relation">0</int>
<reference key="secondItem" ref="561162642"/>
<int key="secondAttribute">3</int>
<float key="multiplier">1</float>
<object class="IBLayoutConstant" key="constant">
<double key="value">0.0</double>
</object>
<float key="priority">1000</float>
<reference key="containingView" ref="561162642"/>
<int key="scoringType">9</int>
<float key="scoringTypeFloat">40</float>
<int key="contentType">3</int>
</object>
</array>
<reference key="parent" ref="777456971"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">486</int>
<reference key="object" ref="703539409"/>
<array class="NSMutableArray" key="children"/>
<reference key="parent" ref="561162642"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">490</int>
<reference key="object" ref="390145290"/>
<reference key="parent" ref="561162642"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">494</int>
<reference key="object" ref="556511210"/>
<reference key="parent" ref="561162642"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">488</int>
<reference key="object" ref="918096569"/>
<reference key="parent" ref="561162642"/>
<reference key="parent" ref="777456971"/>
</object>
</array>
</object>
@@ -1278,41 +1180,55 @@
<string key="451.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="452.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="453.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<array class="NSMutableArray" key="469.IBNSViewMetadataConstraints">
<reference ref="918096569"/>
<reference ref="390145290"/>
<reference ref="556511210"/>
</array>
<string key="469.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="475.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<boolean value="NO" key="486.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
<string key="486.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="488.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="490.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="494.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">501</int>
<int key="maxID">502</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">MPMainWindowController</string>
<string key="superclassName">NSWindowController</string>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">outlineView</string>
<string key="NS.object.0">NSOutlineView</string>
<object class="NSMutableDictionary" key="actions">
<string key="NS.key.0">usePassword:</string>
<string key="NS.object.0">id</string>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<string key="NS.key.0">outlineView</string>
<object class="IBToOneOutletInfo" key="NS.object.0">
<object class="NSMutableDictionary" key="actionInfosByName">
<string key="NS.key.0">usePassword:</string>
<object class="IBActionInfo" key="NS.object.0">
<string key="name">usePassword:</string>
<string key="candidateClassName">id</string>
</object>
</object>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="contentView">NSView</string>
<string key="keyPathControl">NSPathControl</string>
<string key="outlineView">NSOutlineView</string>
<string key="passwordTextField">NSTextField</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
<object class="IBToOneOutletInfo" key="contentView">
<string key="name">contentView</string>
<string key="candidateClassName">NSView</string>
</object>
<object class="IBToOneOutletInfo" key="keyPathControl">
<string key="name">keyPathControl</string>
<string key="candidateClassName">NSPathControl</string>
</object>
<object class="IBToOneOutletInfo" key="outlineView">
<string key="name">outlineView</string>
<string key="candidateClassName">NSOutlineView</string>
</object>
</object>
<object class="IBToOneOutletInfo" key="passwordTextField">
<string key="name">passwordTextField</string>
<string key="candidateClassName">NSTextField</string>
</object>
</dictionary>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/MPMainWindowController.h</string>

View File

@@ -32,7 +32,7 @@
</object>
<array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
<object class="NSCustomObject" id="1001">
<string key="NSClassName">NSObject</string>
<string key="NSClassName">MPMainWindowController</string>
</object>
<object class="NSCustomObject" id="1003">
<string key="NSClassName">FirstResponder</string>
@@ -128,7 +128,6 @@
</array>
<int key="NSPathStyle">2</int>
<reference key="NSDelegate" ref="1038415954"/>
<array key="NSAllowedTypes" id="0"/>
</object>
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
</object>
@@ -250,12 +249,37 @@
</object>
</array>
<object class="IBObjectContainer" key="IBDocument.Objects">
<array class="NSMutableArray" key="connectionRecords"/>
<array class="NSMutableArray" key="connectionRecords">
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">passwordTextField</string>
<reference key="source" ref="1001"/>
<reference key="destination" ref="83199440"/>
</object>
<int key="connectionID">99</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">keyPathControl</string>
<reference key="source" ref="1001"/>
<reference key="destination" ref="1038415954"/>
</object>
<int key="connectionID">100</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">passwordView</string>
<reference key="source" ref="1001"/>
<reference key="destination" ref="1005"/>
</object>
<int key="connectionID">101</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
<object class="IBObjectRecord">
<int key="objectID">0</int>
<reference key="object" ref="0"/>
<array key="object" id="0"/>
<reference key="children" ref="1000"/>
<nil key="parent"/>
</object>
@@ -662,10 +686,58 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">98</int>
<int key="maxID">101</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">MPMainWindowController</string>
<string key="superclassName">NSWindowController</string>
<object class="NSMutableDictionary" key="actions">
<string key="NS.key.0">usePassword:</string>
<string key="NS.object.0">id</string>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<string key="NS.key.0">usePassword:</string>
<object class="IBActionInfo" key="NS.object.0">
<string key="name">usePassword:</string>
<string key="candidateClassName">id</string>
</object>
</object>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="contentView">NSView</string>
<string key="keyPathControl">NSPathControl</string>
<string key="outlineView">NSOutlineView</string>
<string key="passwordTextField">NSTextField</string>
<string key="passwordView">NSView</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
<object class="IBToOneOutletInfo" key="contentView">
<string key="name">contentView</string>
<string key="candidateClassName">NSView</string>
</object>
<object class="IBToOneOutletInfo" key="keyPathControl">
<string key="name">keyPathControl</string>
<string key="candidateClassName">NSPathControl</string>
</object>
<object class="IBToOneOutletInfo" key="outlineView">
<string key="name">outlineView</string>
<string key="candidateClassName">NSOutlineView</string>
</object>
<object class="IBToOneOutletInfo" key="passwordTextField">
<string key="name">passwordTextField</string>
<string key="candidateClassName">NSTextField</string>
</object>
<object class="IBToOneOutletInfo" key="passwordView">
<string key="name">passwordView</string>
<string key="candidateClassName">NSView</string>
</object>
</dictionary>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/MPMainWindowController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NSLayoutConstraint</string>
<string key="superclassName">NSObject</string>