mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 21:42:32 +00:00
Basic (buggy) Tree handling
This commit is contained in:
@@ -53,7 +53,7 @@
|
||||
if(result == NSFileHandlingPanelOKButton) {
|
||||
NSURL *file = [[openPanel URLs] lastObject];
|
||||
if(file) {
|
||||
[self.mainWindowController presentPasswordInput];
|
||||
[self.mainWindowController presentPasswordInput:(NSURL *)file];
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
@class MPDatabaseDocument;
|
||||
|
||||
|
||||
typedef enum{
|
||||
MPDatabaseVersion1,
|
||||
MPDatabaseVersion2
|
||||
|
||||
@@ -12,9 +12,11 @@ APPKIT_EXTERN NSString *const MPDidLoadDataBaseNotification;
|
||||
APPKIT_EXTERN NSString *const MPDataBaseDocumentDocumentKey;
|
||||
|
||||
@class KdbPassword;
|
||||
@class KdbGroup;
|
||||
|
||||
@interface MPDatabaseDocument : NSObject
|
||||
|
||||
@property (retain, readonly) KdbGroup *root;
|
||||
@property (retain, readonly) NSURL *file;
|
||||
@property (retain, readonly) KdbPassword *password;
|
||||
+ (id)documentWithFile:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key;
|
||||
|
||||
@@ -81,6 +81,11 @@ NSString *const MPDidLoadDataBaseNotification = @"DidLoadDataBaseNotification";
|
||||
return self;
|
||||
}
|
||||
|
||||
- (KdbGroup *)root {
|
||||
return [self.tree root];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)save {
|
||||
NSError *fileError;
|
||||
if( self.password && [self.file checkResourceIsReachableAndReturnError:&fileError] ) {
|
||||
|
||||
@@ -17,6 +17,6 @@ APPKIT_EXTERN NSString *const MPMainWindowControllerKeyfileKey;
|
||||
|
||||
@property (readonly, retain) MPDatabaseDocument *database;
|
||||
|
||||
- (void)presentPasswordInput;
|
||||
- (void)presentPasswordInput:(NSURL *)file;
|
||||
|
||||
@end
|
||||
|
||||
@@ -28,6 +28,7 @@ NSString *const kOutlineViewIdentifier = @"OutlineView";
|
||||
@property (assign) IBOutlet NSPathControl *keyPathControl;
|
||||
@property (assign) IBOutlet NSView *contentView;
|
||||
|
||||
@property (retain) NSURL *openFile;
|
||||
@property (retain) MPOutlineDataSource *datasource;
|
||||
@property (retain) MPOutlineViewDelegate *outlineDelegate;
|
||||
@property (retain) MPMainWindowDelegate *windowDelegate;
|
||||
@@ -60,20 +61,24 @@ NSString *const kOutlineViewIdentifier = @"OutlineView";
|
||||
[self.window setDelegate:self.windowDelegate];
|
||||
[[self.outlineView outlineTableColumn] setIdentifier:kColumnIdentifier];
|
||||
[self.outlineView setDelegate:self.outlineDelegate];
|
||||
[self.outlineView setDataSource:self.datasource];
|
||||
}
|
||||
|
||||
- (void)updateData {
|
||||
[_outlineView reloadData];
|
||||
[self.outlineView reloadData];
|
||||
}
|
||||
|
||||
- (void)presentPasswordInput {
|
||||
- (void)presentPasswordInput:(NSURL *)file {
|
||||
NSArray *topLevelObjects;
|
||||
self.openFile = file;
|
||||
[[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];
|
||||
NSString *password = [self.passwordTextField stringValue];
|
||||
|
||||
[[MPDatabaseController defaultController] openDatabase:self.openFile password:password keyfile:nil];
|
||||
[self updateData];
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,17 @@
|
||||
//
|
||||
|
||||
#import "MPOutlineDataSource.h"
|
||||
#import "MPDatabaseController.h"
|
||||
#import "MPDatabaseDocument.h"
|
||||
#import "KdbLib.h"
|
||||
|
||||
@implementation MPOutlineDataSource
|
||||
|
||||
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
|
||||
|
||||
if(!item) {
|
||||
MPDatabaseController *dbController = [MPDatabaseController defaultController];
|
||||
return [[dbController.database.root groups] count];
|
||||
}
|
||||
if( [item isKindOfClass:[KdbGroup class]]) {
|
||||
KdbGroup *group = item;
|
||||
return [[group groups] count];
|
||||
@@ -21,6 +25,10 @@
|
||||
return 0;
|
||||
}
|
||||
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
|
||||
if(!item) {
|
||||
MPDatabaseController *dbController = [MPDatabaseController defaultController];
|
||||
return dbController.database.root;
|
||||
}
|
||||
if( [item isKindOfClass:[KdbGroup class]]) {
|
||||
KdbGroup *group = item;
|
||||
if( [[group groups] count] > index ) {
|
||||
@@ -30,6 +38,9 @@
|
||||
return nil;
|
||||
}
|
||||
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
|
||||
if(!item) {
|
||||
return true;
|
||||
}
|
||||
return [item isKindOfClass:[KdbGroup class]];
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,17 @@
|
||||
//
|
||||
|
||||
#import "MPOutlineViewDelegate.h"
|
||||
#import "KdbLib.h"
|
||||
|
||||
@implementation MPOutlineViewDelegate
|
||||
|
||||
- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
|
||||
NSTableCellView *view = [outlineView makeViewWithIdentifier:@"DataCell" owner:self];
|
||||
[view.imageView setImage:[NSImage imageNamed:NSImageNameFolder]];
|
||||
[view.textField setStringValue:@"Test"];
|
||||
if([item isKindOfClass:[KdbGroup class]]) {
|
||||
KdbGroup *group = item;
|
||||
[view.textField setStringValue:[group name]];
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@@ -274,6 +274,14 @@
|
||||
</object>
|
||||
<int key="connectionID">101</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBActionConnection" key="connection">
|
||||
<string key="label">usePassword:</string>
|
||||
<reference key="source" ref="1001"/>
|
||||
<reference key="destination" ref="769513826"/>
|
||||
</object>
|
||||
<int key="connectionID">102</int>
|
||||
</object>
|
||||
</array>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<array key="orderedObjects">
|
||||
@@ -686,7 +694,7 @@
|
||||
<nil key="activeLocalization"/>
|
||||
<dictionary class="NSMutableDictionary" key="localizations"/>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">101</int>
|
||||
<int key="maxID">102</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
|
||||
Reference in New Issue
Block a user