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