More use of properties. Fixed wrongfull controller bindings

This commit is contained in:
michael starke
2015-04-05 21:15:48 +02:00
parent 6c4daebb33
commit 580787353e
5 changed files with 26 additions and 29 deletions

View File

@@ -29,9 +29,10 @@
@interface MPDatabaseSettingsWindowController () { @interface MPDatabaseSettingsWindowController () {
MPDocument *_document;
NSString *_missingFeature; NSString *_missingFeature;
} }
@property (nonatomic, weak) MPDocument *document;
@property (nonatomic,assign) BOOL trashEnabled; @property (nonatomic,assign) BOOL trashEnabled;
@end @end
@@ -50,7 +51,7 @@
- (id)initWithDocument:(MPDocument *)document { - (id)initWithDocument:(MPDocument *)document {
self = [super initWithWindow:nil]; self = [super initWithWindow:nil];
if(self) { if(self) {
_document = document; self.document = document;
_missingFeature = NSLocalizedString(@"KDBX_ONLY_FEATURE", "Feature only available in kdbx databases"); _missingFeature = NSLocalizedString(@"KDBX_ONLY_FEATURE", "Feature only available in kdbx databases");
} }
return self; return self;
@@ -59,7 +60,7 @@
- (void)windowDidLoad { - (void)windowDidLoad {
[super windowDidLoad]; [super windowDidLoad];
NSAssert(_document != nil, @"Document needs to be present"); NSAssert(self.document != nil, @"Document needs to be present");
[self.sectionTabView setDelegate:self]; [self.sectionTabView setDelegate:self];
[self.encryptionRoundsTextField setFormatter:[[MPNumericalInputFormatter alloc] init]]; [self.encryptionRoundsTextField setFormatter:[[MPNumericalInputFormatter alloc] init]];
@@ -69,7 +70,7 @@
- (IBAction)save:(id)sender { - (IBAction)save:(id)sender {
/* General */ /* General */
KPKMetaData *metaData = _document.tree.metaData; KPKMetaData *metaData = self.document.tree.metaData;
metaData.databaseDescription = [self.databaseDescriptionTextView string]; metaData.databaseDescription = [self.databaseDescriptionTextView string];
metaData.databaseName = [self.databaseNameTextField stringValue]; metaData.databaseName = [self.databaseNameTextField stringValue];
@@ -89,11 +90,11 @@
metaData.recycleBinEnabled = self.trashEnabled; metaData.recycleBinEnabled = self.trashEnabled;
NSMenuItem *trashMenuItem = [self.selectRecycleBinGroupPopUpButton selectedItem]; NSMenuItem *trashMenuItem = [self.selectRecycleBinGroupPopUpButton selectedItem];
KPKGroup *trashGroup = [trashMenuItem representedObject]; KPKGroup *trashGroup = [trashMenuItem representedObject];
_document.trash = trashGroup; self.document.trash = trashGroup;
NSMenuItem *templateMenuItem = [self.templateGroupPopUpButton selectedItem]; NSMenuItem *templateMenuItem = [self.templateGroupPopUpButton selectedItem];
KPKGroup *templateGroup = [templateMenuItem representedObject]; KPKGroup *templateGroup = [templateMenuItem representedObject];
_document.templates = templateGroup; self.document.templates = templateGroup;
BOOL enforceMasterKeyChange = HNHBoolForState([self.enforceKeyChangeCheckButton state]); BOOL enforceMasterKeyChange = HNHBoolForState([self.enforceKeyChangeCheckButton state]);
@@ -130,7 +131,7 @@
metaData.rounds = MAX(0,[self.encryptionRoundsTextField integerValue]); metaData.rounds = MAX(0,[self.encryptionRoundsTextField integerValue]);
/* Register an action to enable promts when user cloeses without saving */ /* Register an action to enable promts when user cloeses without saving */
[_document updateChangeCount:NSChangeDone]; [self.document updateChangeCount:NSChangeDone];
[self close:nil]; [self close:nil];
} }
@@ -151,10 +152,10 @@
return; return;
} }
/* Update all stuff that might have changed */ /* Update all stuff that might have changed */
KPKMetaData *metaData = _document.tree.metaData; KPKMetaData *metaData = self.document.tree.metaData;
[self _setupDatabaseTab:metaData]; [self _setupDatabaseTab:metaData];
[self _setupProtectionTab:metaData]; [self _setupProtectionTab:metaData];
[self _setupAdvancedTab:_document.tree]; [self _setupAdvancedTab:self.document.tree];
self.isDirty = NO; self.isDirty = NO;
} }

View File

@@ -62,7 +62,6 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
@interface MPDocument : NSDocument <MPTargetNodeResolving> @interface MPDocument : NSDocument <MPTargetNodeResolving>
@property (nonatomic, readonly, assign) BOOL encrypted; @property (nonatomic, readonly, assign) BOOL encrypted;
@property (nonatomic, readonly, assign) NSUInteger unlockCount; // Amount of times the Document was unlocked; @property (nonatomic, readonly, assign) NSUInteger unlockCount; // Amount of times the Document was unlocked;

View File

@@ -67,8 +67,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
@interface MPDocument () { @interface MPDocument () {
@private @private
BOOL _didLockFile; BOOL _didLockFile;
NSData *_encryptedData;
MPTreeDelegate *_treeDelgate;
} }
@property (nonatomic, assign) NSUInteger unlockCount; @property (nonatomic, assign) NSUInteger unlockCount;
@@ -78,6 +76,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
@property (strong, nonatomic) KPKTree *tree; @property (strong, nonatomic) KPKTree *tree;
@property (weak, nonatomic) KPKGroup *root; @property (weak, nonatomic) KPKGroup *root;
@property (nonatomic, strong) KPKCompositeKey *compositeKey; @property (nonatomic, strong) KPKCompositeKey *compositeKey;
@property (nonatomic, strong) NSData *encryptedData;
@property (nonatomic, strong) MPTreeDelegate *treeDelgate;
@property (assign) BOOL readOnly; @property (assign) BOOL readOnly;
@property (strong) NSURL *lockFileURL; @property (strong) NSURL *lockFileURL;
@@ -87,7 +88,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
@end @end
@implementation MPDocument @implementation MPDocument
+ (NSSet *)keyPathsForValuesAffectingRoot { + (NSSet *)keyPathsForValuesAffectingRoot {
@@ -124,10 +124,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
- (id)init { - (id)init {
self = [super init]; self = [super init];
if(self) { if(self) {
_encryptedData = nil;
_didLockFile = NO; _didLockFile = NO;
_readOnly = NO; _readOnly = NO;
self.tree = [KPKTree templateTree]; self.tree = [KPKTree allocTemplateTree];
self.tree.metaData.rounds = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyDefaultPasswordRounds]; self.tree.metaData.rounds = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyDefaultPasswordRounds];
} }
return self; return self;
@@ -209,7 +208,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
Delete our old Tree, and just grab the data Delete our old Tree, and just grab the data
*/ */
self.tree = nil; self.tree = nil;
_encryptedData = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:outError]; self.encryptedData = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:outError];
return YES; return YES;
} }
@@ -271,7 +270,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
NSError *error; NSError *error;
self.tree = [[KPKTree alloc] initWithXmlContentsOfURL:url error:&error]; self.tree = [[KPKTree alloc] initWithXmlContentsOfURL:url error:&error];
self.compositeKey = nil; self.compositeKey = nil;
_encryptedData = Nil; self.encryptedData = nil;
} }
#pragma mark Lock/Unlock/Decrypt #pragma mark Lock/Unlock/Decrypt
@@ -284,14 +283,14 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
[self exitSearch:self]; [self exitSearch:self];
NSError *error; NSError *error;
/* Locking needs to be lossless hence just use the XML format */ /* Locking needs to be lossless hence just use the XML format */
_encryptedData = [self.tree encryptWithPassword:self.compositeKey forVersion:KPKXmlVersion error:&error]; self.encryptedData = [self.tree encryptWithPassword:self.compositeKey forVersion:KPKXmlVersion error:&error];
self.tree = nil; self.tree = nil;
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidLockDatabaseNotification object:self]; [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidLockDatabaseNotification object:self];
} }
- (BOOL)unlockWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL error:(NSError *__autoreleasing*)error{ - (BOOL)unlockWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL error:(NSError *__autoreleasing*)error{
self.compositeKey = [[KPKCompositeKey alloc] initWithPassword:password key:keyFileURL]; self.compositeKey = [[KPKCompositeKey alloc] initWithPassword:password key:keyFileURL];
self.tree = [[KPKTree alloc] initWithData:_encryptedData password:self.compositeKey error:error]; self.tree = [[KPKTree alloc] initWithData:self.encryptedData password:self.compositeKey error:error];
BOOL isUnlocked = (nil != self.tree); BOOL isUnlocked = (nil != self.tree);
if(isUnlocked) { if(isUnlocked) {

View File

@@ -368,8 +368,8 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
if(!document.selectedGroup && !document.hasSearch) { if(!document.selectedGroup && !document.hasSearch) {
/* no group selection out of search is wrong */ /* no group selection out of search is wrong */
[self.entryArrayController unbind:NSContentArrayBinding]; //[self.entryArrayController unbind:NSContentArrayBinding];
[self.entryArrayController setContent:nil]; self.entryArrayController.content = nil;
return; return;
} }
/* /*
@@ -387,7 +387,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
return; // we are showing the correct object right now. return; // we are showing the correct object right now.
} }
} }
[self.entryArrayController bind:NSContentArrayBinding toObject:document.selectedGroup withKeyPath:NSStringFromSelector(@selector(entries)) options:nil]; self.entryArrayController.content = document.selectedGroup.entries;
} }
[self _updateContextBar]; [self _updateContextBar];
} }
@@ -422,8 +422,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
NSArray *result = [notification userInfo][kMPDocumentSearchResultsKey]; NSArray *result = [notification userInfo][kMPDocumentSearchResultsKey];
NSAssert(result != nil, @"Resutls should never be nil"); NSAssert(result != nil, @"Resutls should never be nil");
self.filteredEntries = result; self.filteredEntries = result;
[self.entryArrayController unbind:NSContentArrayBinding]; self.entryArrayController.content = self.filteredEntries;
[self.entryArrayController setContent:self.filteredEntries];
[[self.entryTable tableColumnWithIdentifier:MPEntryTableParentColumnIdentifier] setHidden:NO]; [[self.entryTable tableColumnWithIdentifier:MPEntryTableParentColumnIdentifier] setHidden:NO];
} }
@@ -433,8 +432,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
MPDocument *document = [[self windowController] document]; MPDocument *document = [[self windowController] document];
document.selectedItem = document.selectedGroup; document.selectedItem = document.selectedGroup;
if( nil == document.selectedItem && nil == document.selectedGroup ) { if( nil == document.selectedItem && nil == document.selectedGroup ) {
[self.entryArrayController unbind:NSContentArrayBinding]; self.entryArrayController.content = nil;
[self.entryArrayController setContent:nil];
} }
[self _updateContextBar]; [self _updateContextBar];
} }
@@ -456,7 +454,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
[self _showContextBar]; [self _showContextBar];
/* TODO: Show modification date column if not present? */ /* TODO: Show modification date column if not present? */
MPDocument *document = [[self windowController] document]; MPDocument *document = [[self windowController] document];
[self.entryArrayController bind:NSContentArrayBinding toObject:document.selectedEntry withKeyPath:NSStringFromSelector(@selector(history)) options:nil]; self.entryArrayController.content = document.selectedEntry.history;
} }
- (void)_didExitHistory:(NSNotification *)notification { - (void)_didExitHistory:(NSNotification *)notification {

View File

@@ -13,8 +13,8 @@
@interface MPSavePanelAccessoryViewController : MPViewController @interface MPSavePanelAccessoryViewController : MPViewController
@property (nonatomic, assign) NSSavePanel *savePanel; @property (nonatomic, weak) NSSavePanel *savePanel;
@property (nonatomic, assign) MPDocument *document; @property (nonatomic, weak) MPDocument *document;
@property (nonatomic, assign, readonly) KPKVersion selectedVersion; @property (nonatomic, assign, readonly) KPKVersion selectedVersion;
@property (nonatomic, weak) IBOutlet NSPopUpButton *fileTypePopupButton; @property (nonatomic, weak) IBOutlet NSPopUpButton *fileTypePopupButton;