mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 14:02:28 +00:00
First running Version that used document based architecture. Search is broken.
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
|
||||
#import "MPDocumentWindowController.h"
|
||||
#import "MPSettingsWindowController.h"
|
||||
#import "MPDatabaseController.h"
|
||||
#import "MPPasswordCreatorViewController.h"
|
||||
#import "MPActionHelper.h"
|
||||
#import "MPSettingsHelper.h"
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
//
|
||||
// MPDatabaseController.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by michael starke on 13.02.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "MPDatabaseVersion.h"
|
||||
|
||||
/*
|
||||
Notification is posted, when a database is loaded
|
||||
The userInfo dictionary contains the following keys
|
||||
MPDatabaseControllerDatabaseKey
|
||||
*/
|
||||
APPKIT_EXTERN NSString *const MPDatabaseControllerDidLoadDatabaseNotification;
|
||||
APPKIT_EXTERN NSString *const MPDatabaseControllerDidCloseDatabaseNotification;
|
||||
/*
|
||||
Database loaded or closed
|
||||
*/
|
||||
APPKIT_EXTERN NSString *const MPDatabaseControllerDatabaseKey;
|
||||
|
||||
|
||||
@class MPDatabaseDocument;
|
||||
|
||||
@interface MPDatabaseController : NSObject
|
||||
|
||||
@property (retain, readonly, nonatomic) MPDatabaseDocument *database;
|
||||
|
||||
+ (MPDatabaseController *)defaultController;
|
||||
+ (BOOL)hasOpenDatabase;
|
||||
|
||||
- (MPDatabaseDocument *)createDatabase:(MPDatabaseVersion)version password:(NSString *)password keyfile:(NSURL *)key;
|
||||
- (MPDatabaseDocument *)openDatabase:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key;
|
||||
- (MPDatabaseDocument *)newDatabaseAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)version password:(NSString *)password keyfile:(NSURL *)key;
|
||||
|
||||
@end
|
||||
@@ -1,85 +0,0 @@
|
||||
//
|
||||
// MPDatabaseController.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by michael starke on 13.02.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPDatabaseController.h"
|
||||
#import "MPDatabaseDocument.h"
|
||||
|
||||
NSString *const MPDatabaseControllerDidLoadDatabaseNotification = @"com.macpass.MPDatabaseControllerDidLoadDatabaseNotification";
|
||||
NSString *const MPDatabaseControllerDidCloseDatabaseNotification = @"com.macpass.MPDatabaseControllerDidCloseDatabaseNotification";
|
||||
NSString *const MPDatabaseControllerDatabaseKey = @"com.macpass.MPDatabaseControllerDatabaseKey";
|
||||
|
||||
@interface MPDatabaseController ()
|
||||
|
||||
@property (retain) MPDatabaseDocument *database;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPDatabaseController
|
||||
|
||||
+ (MPDatabaseController *)defaultController {
|
||||
static MPDatabaseController *sharedInstance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedInstance = [[MPDatabaseController alloc] init];
|
||||
});
|
||||
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
+ (BOOL)hasOpenDatabase {
|
||||
return (nil != [MPDatabaseController defaultController].database);
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
// nothing to do;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
self.database = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (MPDatabaseDocument *)createDatabase:(MPDatabaseVersion)version password:(NSString *)password keyfile:(NSURL *)key {
|
||||
return self.database;
|
||||
}
|
||||
|
||||
- (MPDatabaseDocument *)newDatabaseAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)version password:(NSString *)password keyfile:(NSURL *)key {
|
||||
self.database = [MPDatabaseDocument newDocumentAtURL:url databaseVersion:version password:password keyfile:key];
|
||||
return self.database;
|
||||
}
|
||||
|
||||
- (MPDatabaseDocument *)openDatabase:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key {
|
||||
self.database = [MPDatabaseDocument documentWithFile:file password:password keyfile:key];
|
||||
return self.database;
|
||||
}
|
||||
|
||||
- (void)setDatabase:(MPDatabaseDocument *)database {
|
||||
if(_database != database) {
|
||||
if(_database) {
|
||||
NSDictionary *userInfo = @{ MPDatabaseControllerDatabaseKey: _database };
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPDatabaseControllerDidCloseDatabaseNotification
|
||||
object:self
|
||||
userInfo:userInfo];
|
||||
}
|
||||
[_database release];
|
||||
_database = [database retain];
|
||||
if(database) {
|
||||
NSDictionary *userInfo = @{ MPDatabaseControllerDatabaseKey: _database };
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPDatabaseControllerDidLoadDatabaseNotification
|
||||
object:self
|
||||
userInfo:userInfo];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,46 +0,0 @@
|
||||
//
|
||||
// MPDocument.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 21.07.12.
|
||||
// Copyright (c) 2012 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "MPDatabaseVersion.h"
|
||||
|
||||
APPKIT_EXTERN NSString *const MPDidLoadDatabaseNotification;
|
||||
APPKIT_EXTERN NSString *const MPDatabaseDocumentDocumentKey;
|
||||
|
||||
@class KdbPassword;
|
||||
@class KdbGroup;
|
||||
@class KdbEntry;
|
||||
|
||||
@interface MPDatabaseDocument : NSObject
|
||||
|
||||
@property (assign, readonly) KdbGroup *root;
|
||||
@property (retain, readonly) NSURL *file;
|
||||
@property (nonatomic,retain) NSString *password;
|
||||
@property (nonatomic, retain) NSURL *key;
|
||||
@property (assign, readonly) MPDatabaseVersion version;
|
||||
|
||||
+ (id)documentWithFile:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key;
|
||||
+ (id)newDocument:(MPDatabaseVersion)version;
|
||||
+ (id)newDocumentAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)dbversion password:(NSString *)password keyfile:(NSURL *)key;
|
||||
- (id)initWithFile:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key;
|
||||
- (id)initWithNewDatabase:(MPDatabaseVersion)version;
|
||||
- (id)initNewDocumentAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)dbversion password:(NSString *)password keyfile:(NSURL *)key;
|
||||
/*
|
||||
Saves the current database to the filesystem
|
||||
Tries to use the stored password and file path
|
||||
|
||||
If self.file and self.password aren't valid, the save does not get executed
|
||||
*/
|
||||
- (BOOL)save;
|
||||
- (BOOL)saveAsFile:(NSURL *)file withPassword:(NSString *)password keyfile:(NSURL *)key;
|
||||
|
||||
- (KdbGroup *)createGroup:(KdbGroup *)parent;
|
||||
- (KdbEntry *)createEntry:(KdbGroup *)parent;
|
||||
|
||||
|
||||
@end
|
||||
@@ -1,170 +0,0 @@
|
||||
//
|
||||
// MPDocument.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 21.07.12.
|
||||
// Copyright (c) 2012 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPDatabaseDocument.h"
|
||||
#import "KdbLib.h"
|
||||
#import "Kdb4Node.h"
|
||||
#import "Kdb3Node.h"
|
||||
|
||||
NSString *const MPDidLoadDatabaseNotification = @"DidLoadDataBaseNotification";
|
||||
|
||||
@interface MPDatabaseDocument ()
|
||||
|
||||
@property (retain) KdbTree *tree;
|
||||
@property (retain) NSURL *file;
|
||||
@property (nonatomic, readonly) KdbPassword *passwordHash;
|
||||
@property (assign) MPDatabaseVersion version;
|
||||
@property (readonly)BOOL isNewFile;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPDatabaseDocument
|
||||
|
||||
+ (id)documentWithFile:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key {
|
||||
return [[[MPDatabaseDocument alloc] initWithFile:file password:password keyfile:key] autorelease];
|
||||
}
|
||||
|
||||
+ (id)newDocument:(MPDatabaseVersion)version {
|
||||
return [[[MPDatabaseDocument alloc] initWithNewDatabase:version] autorelease];
|
||||
}
|
||||
|
||||
+ (id)newDocumentAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)dbversion password:(NSString *)password keyfile:(NSURL *)key {
|
||||
return [[[MPDatabaseDocument alloc] initNewDocumentAtURL:url databaseVersion:dbversion password:password keyfile:key] autorelease];
|
||||
}
|
||||
|
||||
- (id)init {
|
||||
// create empty document
|
||||
return [self initWithFile:nil password:nil keyfile:nil];
|
||||
}
|
||||
|
||||
|
||||
- (id)initNewDocumentAtURL:(NSURL *)url databaseVersion:(MPDatabaseVersion)dbversion password:(NSString *)password keyfile:(NSURL *)key
|
||||
{
|
||||
self = [self initWithNewDatabase:dbversion];
|
||||
if(self) {
|
||||
self.file = url;
|
||||
self.password = password;
|
||||
self.key = key;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
Initalizer for creating
|
||||
*/
|
||||
- (id)initWithNewDatabase:(MPDatabaseVersion)version {
|
||||
self = [super init];
|
||||
if(self) {
|
||||
switch(version) {
|
||||
case MPDatabaseVersion3:
|
||||
self.tree = [[[Kdb3Tree alloc] init] autorelease];
|
||||
break;
|
||||
case MPDatabaseVersion4:
|
||||
self.tree = [[[Kdb4Tree alloc] init] autorelease];
|
||||
break;
|
||||
default:
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
KdbGroup *newGroup = [self.tree createGroup:self.tree.root];
|
||||
newGroup.name = @"Default";
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
Designated initalizer for loading
|
||||
*/
|
||||
- (id)initWithFile:(NSURL *)file password:(NSString *)password keyfile:(NSURL *)key
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
/*
|
||||
Create an empty file
|
||||
*/
|
||||
self.file = file;
|
||||
self.key = key;
|
||||
self.password = password;
|
||||
@try {
|
||||
self.tree = [KdbReaderFactory load:[self.file path] withPassword:self.passwordHash];
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
NSLog(@"%@", [exception description]);
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
if([self.tree isKindOfClass:[Kdb4Tree class]]) {
|
||||
self.version = MPDatabaseVersion4;
|
||||
}
|
||||
else if( [self.tree isKindOfClass:[Kdb3Tree class]]) {
|
||||
self.version = MPDatabaseVersion3;
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
self.tree = nil;
|
||||
self.file = nil;
|
||||
self.password = nil;
|
||||
self.key = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (KdbGroup *)root {
|
||||
return [self.tree root];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)save {
|
||||
NSError *fileError;
|
||||
if(self.isNewFile || [self.file checkResourceIsReachableAndReturnError:&fileError] ) {
|
||||
@try {
|
||||
[KdbWriterFactory persist:self.tree file:[self.file path] withPassword:self.passwordHash];
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
NSLog(@"%@", [exception description]);
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
else {
|
||||
NSLog(@"File Error: %@", fileError);
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)saveAsFile:(NSURL *)file withPassword:(NSString *)password keyfile:(NSURL *)key {
|
||||
self.file = file;
|
||||
self.password = password;
|
||||
self.key = key;
|
||||
return [self save];
|
||||
}
|
||||
|
||||
- (KdbPassword *)passwordHash {
|
||||
// TODO: Use defaults to determine Encoding?
|
||||
return [[[KdbPassword alloc] initWithPassword:self.password passwordEncoding:NSUTF8StringEncoding keyFile:[self.key path]] autorelease];
|
||||
}
|
||||
|
||||
- (KdbEntry *)createEntry:(KdbGroup *)parent {
|
||||
KdbEntry *newEntry = [self.tree createEntry:parent];
|
||||
newEntry.title = NSLocalizedString(@"DEFAULT_ENTRY_TITLE", @"Title for a newly created entry");
|
||||
[parent addEntry:newEntry];
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
- (KdbGroup *)createGroup:(KdbGroup *)parent {
|
||||
KdbGroup *newGroup = [self.tree createGroup:parent];
|
||||
newGroup.name = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group");
|
||||
[parent addGroup:newGroup];
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -10,6 +10,7 @@
|
||||
#import "MPDatabaseVersion.h"
|
||||
|
||||
@class KdbGroup;
|
||||
@class KdbEntry;
|
||||
|
||||
@interface MPDocument : NSDocument
|
||||
|
||||
@@ -18,8 +19,12 @@
|
||||
@property (nonatomic,retain) NSString *password;
|
||||
@property (nonatomic, retain) NSURL *key;
|
||||
@property (assign, readonly) MPDatabaseVersion version;
|
||||
@property (assign, readonly) BOOL isDecrypted;
|
||||
|
||||
- (id)initWithVersion:(MPDatabaseVersion)version;
|
||||
- (BOOL)decryptWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL;
|
||||
|
||||
- (KdbGroup *)createGroup:(KdbGroup *)parent;
|
||||
- (KdbEntry *)createEntry:(KdbGroup *)parent;
|
||||
|
||||
@end
|
||||
|
||||
@@ -14,15 +14,13 @@
|
||||
#import "KdbPassword.h"
|
||||
#import "MPDatabaseVersion.h"
|
||||
|
||||
@interface MPDocument () {
|
||||
@private
|
||||
BOOL _isDecrypted;
|
||||
}
|
||||
@interface MPDocument ()
|
||||
|
||||
@property (retain) KdbTree *tree;
|
||||
@property (retain) NSURL *file;
|
||||
@property (nonatomic, readonly) KdbPassword *passwordHash;
|
||||
@property (assign) MPDatabaseVersion version;
|
||||
@property (assign) BOOL isDecrypted;
|
||||
|
||||
@end
|
||||
|
||||
@@ -37,7 +35,7 @@
|
||||
- (id)initWithVersion:(MPDatabaseVersion)version {
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_isDecrypted = NO;
|
||||
_isDecrypted = YES;
|
||||
switch(version) {
|
||||
case MPDatabaseVersion3:
|
||||
self.tree = [[[Kdb3Tree alloc] init] autorelease];
|
||||
@@ -56,15 +54,13 @@
|
||||
}
|
||||
|
||||
- (void) makeWindowControllers {
|
||||
|
||||
MPDocumentWindowController *windowController = [[MPDocumentWindowController alloc] init];
|
||||
[self addWindowController:windowController];
|
||||
[self addWindowController:windowController];
|
||||
}
|
||||
|
||||
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
|
||||
{
|
||||
[super windowControllerDidLoadNib:aController];
|
||||
// Add any code here that needs to be executed once the windowController has loaded the document's window.
|
||||
}
|
||||
|
||||
- (BOOL)writeToURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
|
||||
@@ -84,6 +80,7 @@
|
||||
|
||||
- (BOOL)readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
|
||||
self.file = url;
|
||||
self.isDecrypted = NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -122,4 +119,22 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (KdbGroup *)root {
|
||||
return [self.tree root];
|
||||
}
|
||||
|
||||
- (KdbEntry *)createEntry:(KdbGroup *)parent {
|
||||
KdbEntry *newEntry = [self.tree createEntry:parent];
|
||||
newEntry.title = NSLocalizedString(@"DEFAULT_ENTRY_TITLE", @"Title for a newly created entry");
|
||||
[parent addEntry:newEntry];
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
- (KdbGroup *)createGroup:(KdbGroup *)parent {
|
||||
KdbGroup *newGroup = [self.tree createGroup:parent];
|
||||
newGroup.name = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group");
|
||||
[parent addGroup:newGroup];
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
//
|
||||
|
||||
#import "MPDocumentWindowController.h"
|
||||
#import "MPDatabaseController.h"
|
||||
#import "MPDatabaseDocument.h"
|
||||
#import "MPDocument.h"
|
||||
#import "MPPasswordInputController.h"
|
||||
#import "MPEntryViewController.h"
|
||||
#import "MPPasswordEditViewController.h"
|
||||
@@ -18,7 +17,10 @@
|
||||
#import "MPInspectorTabViewController.h"
|
||||
#import "MPAppDelegate.h"
|
||||
|
||||
@interface MPDocumentWindowController ()
|
||||
@interface MPDocumentWindowController () {
|
||||
@private
|
||||
BOOL _needsDecryption;
|
||||
}
|
||||
|
||||
@property (assign) IBOutlet NSView *outlineView;
|
||||
@property (assign) IBOutlet NSSplitView *splitView;
|
||||
@@ -39,7 +41,6 @@
|
||||
@property (retain) MPMainWindowSplitViewDelegate *splitViewDelegate;
|
||||
|
||||
- (void)_setContentViewController:(MPViewController *)viewController;
|
||||
- (void)_updateWindowTitle;
|
||||
|
||||
/* window reszing and content checks */
|
||||
- (BOOL)_windowsIsLargeEnoughForInspectorView;
|
||||
@@ -52,6 +53,7 @@
|
||||
-(id)init {
|
||||
self = [super initWithWindowNibName:@"MainWindow" owner:self];
|
||||
if( self ) {
|
||||
_needsDecryption = NO;
|
||||
_toolbarDelegate = [[MPToolbarDelegate alloc] init];
|
||||
_outlineViewController = [[MPOutlineViewController alloc] init];
|
||||
_inspectorTabViewController = [[MPInspectorTabViewController alloc] init];
|
||||
@@ -60,11 +62,6 @@
|
||||
|
||||
[[NSBundle mainBundle] loadNibNamed:@"WelcomeView" owner:self topLevelObjects:NULL];
|
||||
[self.welcomeView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(didOpenDocument:)
|
||||
name:MPDatabaseControllerDidLoadDatabaseNotification
|
||||
object:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -91,7 +88,6 @@
|
||||
- (void)windowDidLoad
|
||||
{
|
||||
[super windowDidLoad];
|
||||
[self _updateWindowTitle];
|
||||
|
||||
[[self.welcomeText cell] setBackgroundStyle:NSBackgroundStyleRaised];
|
||||
CGFloat minWidht = MPMainWindowSplitViewDelegateMinimumContentWidth + MPMainWindowSplitViewDelegateMinimumOutlineWidth + [self.splitView dividerThickness];
|
||||
@@ -122,6 +118,10 @@
|
||||
[self toggleInspector:nil];
|
||||
|
||||
[self _setContentViewController:nil];
|
||||
MPDocument *document = [self document];
|
||||
if(!document.isDecrypted) {
|
||||
[self showPasswordInput];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_setContentViewController:(MPViewController *)viewController {
|
||||
@@ -158,17 +158,6 @@
|
||||
[self.window makeFirstResponder:[viewController reconmendedFirstResponder]];
|
||||
}
|
||||
|
||||
- (void)_updateWindowTitle {
|
||||
if([MPDatabaseController defaultController].database) {
|
||||
NSString *appName = [(MPAppDelegate *)[NSApp delegate] applicationName];
|
||||
NSString *openFile = [[MPDatabaseController defaultController].database.file lastPathComponent];
|
||||
[self.window setTitle:[NSString stringWithFormat:@"%@ - %@", appName, openFile]];
|
||||
}
|
||||
else {
|
||||
[self.window setTitle:[(MPAppDelegate *)[NSApp delegate] applicationName]];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Actions
|
||||
|
||||
- (void)toggleInspector:(id)sender {
|
||||
@@ -276,6 +265,7 @@
|
||||
_entryViewController = [[MPEntryViewController alloc] init];
|
||||
}
|
||||
[self _setContentViewController:self.entryViewController];
|
||||
[self.outlineViewController showOutline];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
#import "MPEntryViewController.h"
|
||||
#import "MPAppDelegate.h"
|
||||
#import "MPOutlineViewDelegate.h"
|
||||
#import "MPDatabaseController.h"
|
||||
#import "MPDatabaseDocument.h"
|
||||
#import "MPDocument.h"
|
||||
#import "MPIconHelper.h"
|
||||
#import "MPDocumentWindowController.h"
|
||||
#import "MPPasteBoardController.h"
|
||||
@@ -256,36 +255,31 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
|
||||
}
|
||||
|
||||
- (void)updateFilter {
|
||||
MPDatabaseDocument *openDatabase = [MPDatabaseController defaultController].database;
|
||||
if(openDatabase) {
|
||||
[self _showFilterBarAnimated:YES];
|
||||
[self _showFilterBarAnimated:YES];
|
||||
|
||||
dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
dispatch_async(backgroundQueue, ^{
|
||||
|
||||
dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
dispatch_async(backgroundQueue, ^{
|
||||
|
||||
NSMutableArray *prediactes = [NSMutableArray arrayWithCapacity:3];
|
||||
if( [self _shouldFilterTitles] ) {
|
||||
[prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.title CONTAINS[cd] %@", self.filter]];
|
||||
}
|
||||
if( [self _shouldFilterUsernames] ) {
|
||||
[prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.username CONTAINS[cd] %@", self.filter]];
|
||||
}
|
||||
if( [self _shouldFilterURLs] ) {
|
||||
[prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.url CONTAINS[cd] %@", self.filter]];
|
||||
}
|
||||
NSPredicate *fullFilter = [NSCompoundPredicate orPredicateWithSubpredicates:prediactes];
|
||||
self.filteredEntries = [[openDatabase.root childEntries] filteredArrayUsingPredicate:fullFilter];
|
||||
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
[self.entryArrayController setContent:self.filteredEntries];
|
||||
[[self.entryTable tableColumnWithIdentifier:MPEntryTableParentColumnIdentifier] setHidden:NO];
|
||||
});
|
||||
NSMutableArray *prediactes = [NSMutableArray arrayWithCapacity:3];
|
||||
if( [self _shouldFilterTitles] ) {
|
||||
[prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.title CONTAINS[cd] %@", self.filter]];
|
||||
}
|
||||
if( [self _shouldFilterUsernames] ) {
|
||||
[prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.username CONTAINS[cd] %@", self.filter]];
|
||||
}
|
||||
if( [self _shouldFilterURLs] ) {
|
||||
[prediactes addObject:[NSPredicate predicateWithFormat:@"SELF.url CONTAINS[cd] %@", self.filter]];
|
||||
}
|
||||
NSPredicate *fullFilter = [NSCompoundPredicate orPredicateWithSubpredicates:prediactes];
|
||||
MPDocument *document = [[self windowController] document];
|
||||
self.filteredEntries = [[document.root childEntries] filteredArrayUsingPredicate:fullFilter];
|
||||
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
[self.entryArrayController setContent:self.filteredEntries];
|
||||
[[self.entryTable tableColumnWithIdentifier:MPEntryTableParentColumnIdentifier] setHidden:NO];
|
||||
});
|
||||
}
|
||||
else {
|
||||
[self.entryArrayController setContent:nil];
|
||||
self.filteredEntries = nil;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
- (void)setupFilterBar {
|
||||
@@ -301,7 +295,7 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
|
||||
|
||||
[self.filterSearchField setAction:@selector(updateFilter:)];
|
||||
[[self.filterSearchField cell] setSendsSearchStringImmediately:NO];
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#import "MPInspectorTabViewController.h"
|
||||
#import "MPEntryViewController.h"
|
||||
#import "MPOutlineViewDelegate.h"
|
||||
#import "MPDatabaseController.h"
|
||||
#import "MPShadowBox.h"
|
||||
#import "MPIconHelper.h"
|
||||
#import "MPPopupImageView.h"
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
//
|
||||
|
||||
#import "MPOutlineDataSource.h"
|
||||
#import "MPDatabaseController.h"
|
||||
#import "MPDatabaseDocument.h"
|
||||
#import "MPDocument.h"
|
||||
#import "KdbLib.h"
|
||||
|
||||
@implementation MPOutlineDataSource
|
||||
@@ -25,8 +24,8 @@
|
||||
}
|
||||
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
|
||||
if(!item) {
|
||||
MPDatabaseController *dbController = [MPDatabaseController defaultController];
|
||||
return dbController.database.root;
|
||||
MPDocument *document = [[[outlineView window] windowController] document];
|
||||
return document.root;
|
||||
}
|
||||
if( [item isKindOfClass:[KdbGroup class]]) {
|
||||
KdbGroup *group = item;
|
||||
@@ -38,8 +37,8 @@
|
||||
}
|
||||
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
|
||||
if(!item) {
|
||||
MPDatabaseController *dbController = [MPDatabaseController defaultController];
|
||||
return ([[dbController.database.root groups] count] > 0);
|
||||
MPDocument *document = [[[outlineView window] windowController] document];
|
||||
return ([[document.root groups] count] > 0);
|
||||
}
|
||||
if([item isKindOfClass:[KdbGroup class]])
|
||||
{
|
||||
|
||||
@@ -11,8 +11,11 @@
|
||||
@interface MPOutlineViewController : MPViewController
|
||||
|
||||
- (void)clearSelection;
|
||||
- (void)showOutline;
|
||||
|
||||
|
||||
- (void)createGroup:(id)sender;
|
||||
- (void)createEntry:(id)sender;
|
||||
- (void)deleteEntry:(id)sender;
|
||||
|
||||
@end
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
#import "MPOutlineViewController.h"
|
||||
#import "MPOutlineViewDelegate.h"
|
||||
#import "MPOutlineDataSource.h"
|
||||
#import "MPDatabaseController.h"
|
||||
#import "MPDatabaseDocument.h"
|
||||
#import "MPDocument.h"
|
||||
#import "MPAppDelegate.h"
|
||||
#import "KdbLib.h"
|
||||
|
||||
@@ -23,7 +22,6 @@
|
||||
@property (retain) NSMenu *menu;
|
||||
|
||||
|
||||
- (void)_didOpenDocument:(NSNotification *)notification;
|
||||
- (NSMenu *)_contextMenu;
|
||||
- (KdbGroup *)_clickedOrSelectedGroup;
|
||||
|
||||
@@ -40,11 +38,6 @@
|
||||
if (self) {
|
||||
self.outlineDelegate = [[[MPOutlineViewDelegate alloc] init] autorelease];
|
||||
self.datasource = [[[MPOutlineDataSource alloc] init] autorelease];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(_didOpenDocument:)
|
||||
name:MPDatabaseControllerDidLoadDatabaseNotification
|
||||
object:nil];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -66,13 +59,10 @@
|
||||
[self.outlineView setAllowsEmptySelection:YES];
|
||||
}
|
||||
|
||||
- (void)_didOpenDocument:(NSNotification *)notification {
|
||||
[self.outlineView deselectAll:nil];
|
||||
- (void)showOutline {
|
||||
[self.outlineView reloadData];
|
||||
MPDatabaseController *dbContoller = [MPDatabaseController defaultController];
|
||||
if(dbContoller.database) {
|
||||
[self.outlineView expandItem:dbContoller.database.root expandChildren:NO];
|
||||
}
|
||||
MPDocument *document = [[NSDocumentController sharedDocumentController] currentDocument];
|
||||
[self.outlineView expandItem:document.root expandChildren:NO];
|
||||
}
|
||||
|
||||
- (void)clearSelection {
|
||||
@@ -91,7 +81,8 @@
|
||||
- (void)createGroup:(id)sender {
|
||||
KdbGroup *group = [self _clickedOrSelectedGroup];
|
||||
if(group) {
|
||||
[[MPDatabaseController defaultController].database createGroup:group];
|
||||
MPDocument *document = [[NSDocumentController sharedDocumentController] currentDocument];
|
||||
[document createGroup:group];
|
||||
[self.outlineView reloadData];
|
||||
}
|
||||
}
|
||||
@@ -99,7 +90,8 @@
|
||||
- (void)createEntry:(id)sender {
|
||||
KdbGroup *group = [self _clickedOrSelectedGroup];
|
||||
if(group) {
|
||||
[[MPDatabaseController defaultController].database createEntry:group];
|
||||
MPDocument *document = [[NSDocumentController sharedDocumentController] currentDocument];
|
||||
[document createEntry:group];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#import "MPPasswordInputController.h"
|
||||
#import "MPDocumentWindowController.h"
|
||||
#import "MPDocument.h"
|
||||
#import "MPKeyfilePathControlDelegate.h"
|
||||
|
||||
@@ -46,15 +47,16 @@
|
||||
}
|
||||
|
||||
- (IBAction)_decrypt:(id)sender {
|
||||
MPDocument *document = [[NSDocumentController sharedDocumentController] currentDocument];
|
||||
MPDocumentWindowController *windowController = (MPDocumentWindowController *)[[[self view] window] windowController];
|
||||
MPDocument *document = [windowController document];
|
||||
if(document) {
|
||||
BOOL isOk = [document decryptWithPassword:[self.passwordTextField stringValue] keyFileURL:[self.keyPathControl URL]];
|
||||
if( isOk) {
|
||||
if(!isOk) {
|
||||
[self _showError];
|
||||
}
|
||||
}
|
||||
[self _reset];
|
||||
// show entries
|
||||
[windowController showEntries];
|
||||
}
|
||||
|
||||
- (void)_reset {
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
|
||||
- (void)didLoadView;
|
||||
- (NSResponder *)reconmendedFirstResponder;
|
||||
/* Returns the associated window controller */
|
||||
- (id)windowController;
|
||||
|
||||
- (void)updateResponderChain;
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
// override
|
||||
}
|
||||
|
||||
- (id)windowController {
|
||||
return [[[self view] window] windowController];
|
||||
}
|
||||
|
||||
- (NSResponder *)reconmendedFirstResponder {
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>64C</string>
|
||||
<string>666</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
|
||||
Reference in New Issue
Block a user