diff --git a/KeePassKit b/KeePassKit index 4aaf8d26..1b5da6d4 160000 --- a/KeePassKit +++ b/KeePassKit @@ -1 +1 @@ -Subproject commit 4aaf8d2642cbd681102a00463df9712fe8200934 +Subproject commit 1b5da6d4f6e55307675b04209bf7f9997ec18f2c diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index a1936d62..c95bc1e5 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -23,15 +23,24 @@ #import #import "KPKVersion.h" +/** + * Postes when a new group was added by the document. This is only fired when the user caused this by adding. Undo/Redo does NOT post this + * The userInfo dictionary conatins one the added group at MPDocumentGroupKey + */ APPKIT_EXTERN NSString *const MPDocumentDidAddGroupNotification; +/** + * Posted when the used has added a new entry. Not posted on undo/redo. + * The userInfo dictionary contains the added entry at MPDocumentEntryKey + */ +APPKIT_EXTERN NSString *const MPDocumentDidAddEntryNotification; APPKIT_EXTERN NSString *const MPDocumentDidRevertNotifiation; APPKIT_EXTERN NSString *const MPDocumentDidLockDatabaseNotification; APPKIT_EXTERN NSString *const MPDocumentDidUnlockDatabaseNotification; -FOUNDATION_EXTERN NSString *const MPDocumentCurrentItemChangedNotification; -FOUNDATION_EXTERN NSString *const MPDocumentDidAddEntryNotification; +APPKIT_EXTERN NSString *const MPDocumentCurrentItemChangedNotification; +/* Keys used in userInfo NSDictionaries on notifications */ APPKIT_EXTERN NSString *const MPDocumentEntryKey; APPKIT_EXTERN NSString *const MPDocumentGroupKey; diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 06733812..6ed90806 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -47,13 +47,14 @@ #import "NSString+MPPasswordCreation.h" NSString *const MPDocumentDidAddGroupNotification = @"com.hicknhack.macpass.MPDocumentDidAddGroupNotification"; +NSString *const MPDocumentDidAddEntryNotification = @"com.hicknhack.macpass.MPDocumentDidAddEntryNotification"; + NSString *const MPDocumentDidRevertNotifiation = @"com.hicknhack.macpass.MPDocumentDidRevertNotifiation"; NSString *const MPDocumentDidLockDatabaseNotification = @"com.hicknhack.macpass.MPDocumentDidLockDatabaseNotification"; NSString *const MPDocumentDidUnlockDatabaseNotification = @"com.hicknhack.macpass.MPDocumentDidUnlockDatabaseNotification"; NSString *const MPDocumentCurrentItemChangedNotification = @"com.hicknhack.macpass.MPDocumentCurrentItemChangedNotification"; -NSString *const MPDocumentDidAddEntryNotification = @"com.hicknhack.macpass.MPDocumentDidAddEntryNotification"; NSString *const MPDocumentEntryKey = @"MPDocumentEntryKey"; NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; @@ -454,7 +455,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey } [parent addEntry:newEntry]; [parent.undoManager setActionName:NSLocalizedString(@"ADD_ENTRY", "")]; - [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddEntryNotification object:self]; + NSDictionary *userInfo = @{ MPDocumentEntryKey: newEntry }; + [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddEntryNotification object:self userInfo:userInfo]; return newEntry; } diff --git a/MacPass/MPOutlineViewController.m b/MacPass/MPOutlineViewController.m index 32b18e79..5db89ade 100644 --- a/MacPass/MPOutlineViewController.m +++ b/MacPass/MPOutlineViewController.m @@ -159,7 +159,18 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; # pragma mark MPDocument Notifications - (void)_didAddGroup:(NSNotification *)notification { - //TODO: find group to expand! + NSDictionary *userInfo = [notification userInfo]; + KPKGroup *group = userInfo[MPDocumentGroupKey]; + NSIndexPath *groupIndexPath = [group indexPath]; + NSTreeNode *groupNode = [[self.treeController arrangedObjects] descendantNodeAtIndexPath:groupIndexPath]; + [self.outlineView expandItem:groupNode.parentNode]; + /* TODO: Select created Group + NSUInteger row = 0; + for(NSUInteger index = 0; index < [groupIndexPath length]; index++ ) { + row += [groupIndexPath indexAtPosition:index]; + } + [self.outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO]; + */ } - (id)itemUnderMouse { @@ -242,6 +253,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; id representedObject = [item representedObject]; if([representedObject isKindOfClass:[KPKGroup class]]) { KPKGroup *group = (KPKGroup *)representedObject; + NSLog(@"IndexPath for %@: %@ vs. %@", group.name, [item indexPath], [group indexPath]); group.isExpanded = YES; } }