KeePassKit API changes. Fixed binding leak issue preventing the document from being deallocated

This commit is contained in:
michael starke
2015-06-08 17:11:00 +02:00
parent 9a99261edd
commit cbeb16c70d
5 changed files with 58 additions and 35 deletions

View File

@@ -212,10 +212,11 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
}
- (void)lockAllDocuments {
for(NSDocument *document in [[NSDocumentController sharedDocumentController] documents]) {
NSArray *windowControllers = [document windowControllers];
if([windowControllers count] > 0) {
[windowControllers[0] lock:nil];
for(NSDocument *document in ((NSDocumentController *)[NSDocumentController sharedDocumentController]).documents) {
for(id windowController in document.windowControllers) {
if([windowController respondsToSelector:@selector(lock)]) {
[windowController lock];
}
}
}
}
@@ -235,6 +236,12 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
NSArray *documents = [documentController documents];
BOOL restoredWindows = [documents count] > 0;
for(NSDocument *document in documents) {
for(NSWindowController *windowController in [document windowControllers]) {
[windowController.window.contentView layout];
}
}
BOOL reopen = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyReopenLastDatabaseOnLaunch];
BOOL showWelcomeScreen = !restoredWindows && !_shouldOpenFile;
if(reopen && !restoredWindows && !_shouldOpenFile) {

View File

@@ -126,8 +126,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
if(self) {
_didLockFile = NO;
_readOnly = NO;
self.tree = [KPKTree allocTemplateTree];
self.tree.metaData.rounds = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyDefaultPasswordRounds];
}
return self;
}
@@ -136,6 +134,15 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
[self _cleanupLock];
}
- (instancetype)initWithType:(NSString *)typeName error:(NSError *__autoreleasing *)outError {
self = [self init];
if(self) {
self.tree = [[KPKTree alloc] initWithTemplateContents];
self.tree.metaData.rounds = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyDefaultPasswordRounds];
}
return self;
}
- (void)makeWindowControllers {
MPDocumentWindowController *windowController = [[MPDocumentWindowController alloc] init];
[self addWindowController:windowController];
@@ -234,6 +241,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
if([[self fileURL] isFileURL]) {
[[NSUserDefaults standardUserDefaults] setObject:[self.fileURL absoluteString] forKey:kMPSettingsKeyLastDatabasePath];
}
self.tree = nil;
[super close];
}
@@ -410,16 +418,16 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentCurrentItemChangedNotification object:self];
}
}
- (void)setTree:(KPKTree *)tree {
if(_tree != tree) {
_tree = tree;
_tree.undoManager = [self undoManager];
if(nil == _treeDelgate) {
_treeDelgate = [[MPTreeDelegate alloc] initWithDocument:self];
}
_tree.delegate = _treeDelgate;
}
}
//- (void)setTree:(KPKTree *)tree {
// if(_tree != tree) {
// _tree = tree;
// _tree.undoManager = [self undoManager];
// if(nil == _treeDelgate) {
// _treeDelgate = [[MPTreeDelegate alloc] initWithDocument:self];
// }
// _tree.delegate = _treeDelgate;
// }
//}
#pragma mark Data Accesors

View File

@@ -124,6 +124,8 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
}
- (void)dealloc {
[self.entryTable unbind:NSContentArrayBinding];
[self.entryArrayController unbind:NSContentArrayBinding];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@@ -387,6 +389,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
return; // we are showing the correct object right now.
}
}
[self.entryArrayController unbind:NSContentArrayBinding];
[self.entryArrayController bind:NSContentArrayBinding toObject:document.selectedGroup withKeyPath:NSStringFromSelector(@selector(entries)) options:nil];
}
[self _updateContextBar];
@@ -423,7 +426,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
NSAssert(result != nil, @"Resutls should never be nil");
self.filteredEntries = result;
[self.entryArrayController unbind:NSContentArrayBinding];
[self.entryArrayController setContent:self.filteredEntries];
[self.entryArrayController bind:NSContentArrayBinding toObject:self withKeyPath:NSStringFromSelector(@selector(filteredEntries)) options:nil];
[[self.entryTable tableColumnWithIdentifier:MPEntryTableParentColumnIdentifier] setHidden:NO];
}
@@ -432,6 +435,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
[[self.entryTable tableColumnWithIdentifier:MPEntryTableParentColumnIdentifier] setHidden:YES];
MPDocument *document = [[self windowController] document];
document.selectedItem = document.selectedGroup;
// TODO: really necessary?
if( nil == document.selectedItem && nil == document.selectedGroup ) {
[self.entryArrayController unbind:NSContentArrayBinding];
[self.entryArrayController setContent:nil];
@@ -737,6 +741,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
#pragma mark periodic UI Update
- (void)_updateExpirationDisplay {
return;
/* items are all entries */
[[self.entryArrayController arrangedObjects] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[[obj timeInfo] isExpired];

View File

@@ -72,6 +72,8 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
}
- (void)dealloc {
[self.outlineView unbind:NSContentBinding];
[self.treeController unbind:NSContentBinding];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self.outlineView setDelegate:nil];
}
@@ -299,6 +301,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
}
- (void)_updateExpirationDisplay {
return;
MPDocument *document = [[self windowController] document];
[document.root.timeInfo isExpired];
[[document.tree allGroups] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {