diff --git a/MacPass/MPAppDelegate.m b/MacPass/MPAppDelegate.m index 71dbb904..85a78224 100644 --- a/MacPass/MPAppDelegate.m +++ b/MacPass/MPAppDelegate.m @@ -57,7 +57,7 @@ [[NSBundle mainBundle] loadNibNamed:@"PasswordCreatorWindow"owner:self topLevelObjects:nil]; } if(!self.passwordCreatorController) { - self.passwordCreatorController = [[MPPasswordCreatorViewController alloc] init]; + self.passwordCreatorController = [[[MPPasswordCreatorViewController alloc] init] autorelease]; } [self.passwordCreatorWindow setContentView:[self.passwordCreatorController view]]; [self.passwordCreatorWindow makeKeyAndOrderFront:self.passwordCreatorWindow]; diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index 9f838726..15368e3e 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -9,6 +9,15 @@ #import #import "MPDatabaseVersion.h" + +APPKIT_EXTERN NSString *const MPDocumentDidAddGroupNotification; +APPKIT_EXTERN NSString *const MPDocumentDidDelteGroupNotification; +APPKIT_EXTERN NSString *const MPDocumentDidAddEntryNotification; +APPKIT_EXTERN NSString *const MPDocumentDidDeleteEntryNotification; + +APPKIT_EXTERN NSString *const MPDocumentEntryKey; +APPKIT_EXTERN NSString *const MPDocumentGroupKey; + @class KdbGroup; @class KdbEntry; @@ -24,8 +33,12 @@ - (id)initWithVersion:(MPDatabaseVersion)version; - (BOOL)decryptWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL; + + - (KdbGroup *)createGroup:(KdbGroup *)parent; - (KdbEntry *)createEntry:(KdbGroup *)parent; + +- (void)addGroup:(NSArray *)groupAndParent; - (void)deleteEntry:(KdbEntry *)entry; - (void)deleteGroup:(KdbGroup *)group; diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 0bcf59fc..df610950 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -14,6 +14,15 @@ #import "KdbPassword.h" #import "MPDatabaseVersion.h" +NSString *const MPDocumentDidAddGroupNotification = @"MPDocumentDidAddGroupNotification"; +NSString *const MPDocumentDidDelteGroupNotification = @"MPDocumentDidDelteGroupNotification"; +NSString *const MPDocumentDidAddEntryNotification = @"MPDocumentDidAddEntryNotification"; +NSString *const MPDocumentDidDeleteEntryNotification = @"MPDocumentDidDeleteEntryNotification"; + +NSString *const MPDocumentEntryKey = @"MPDocumentEntryKey"; +NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; + + @interface MPDocument () @property (retain) KdbTree *tree; @@ -58,6 +67,7 @@ - (void) makeWindowControllers { MPDocumentWindowController *windowController = [[MPDocumentWindowController alloc] init]; [self addWindowController:windowController]; + [windowController release]; } - (void)windowControllerDidLoadNib:(NSWindowController *)aController @@ -128,7 +138,7 @@ - (KdbEntry *)createEntry:(KdbGroup *)parent { KdbEntry *newEntry = [self.tree createEntry:parent]; newEntry.title = NSLocalizedString(@"DEFAULT_ENTRY_TITLE", @"Title for a newly created entry"); - [[[self undoManager] prepareWithInvocationTarget:self] deleteEntry:newEntry]; + [[self undoManager] registerUndoWithTarget:self selector:@selector(deleteEntry:) object:newEntry]; [[self undoManager] setActionName:NSLocalizedString(@"ADD_ENTRY_UNDO", @"Create Entry Undo")]; [parent addEntry:newEntry]; return newEntry; @@ -138,13 +148,24 @@ KdbGroup *newGroup = [self.tree createGroup:parent]; newGroup.name = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group"); - [[[self undoManager] prepareWithInvocationTarget:self] deleteGroup:newGroup]; + [[self undoManager] registerUndoWithTarget:self selector:@selector(deleteGroup:) object:newGroup]; [[self undoManager] setActionName:NSLocalizedString(@"ADD_GROUP_UNDO", @"Create Group Undo")]; [parent addGroup:newGroup]; + NSDictionary *userInfo = @{ MPDocumentGroupKey:newGroup }; + [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddGroupNotification object:self userInfo:userInfo]; + self.isDirty = YES; return newGroup; } +- (void)addGroup:(NSArray *)groupAndParent{ + KdbGroup *parent = groupAndParent[0]; + KdbGroup *group = groupAndParent[1]; + NSDictionary *userInfo = @{ MPDocumentGroupKey:group }; + [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddGroupNotification object:self userInfo:userInfo]; + [parent addGroup:group]; +} + - (void)deleteEntry:(KdbEntry *)entry { if(entry.parent) { [entry.parent removeEntry:entry]; @@ -154,7 +175,12 @@ - (void)deleteGroup:(KdbGroup *)group { if(group.parent) { + [[self undoManager] registerUndoWithTarget:self selector:@selector(addGroup:) object:@[group.parent, group]]; + [[self undoManager] setActionName:NSLocalizedString(@"DELETE_GROUP_UNDO", @"Create Group Undo")]; [group.parent removeGroup:group]; + NSDictionary *userInfo = @{ MPDocumentEntryKey:group }; + [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidDelteGroupNotification object:self userInfo:userInfo]; + self.isDirty = YES; } } diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index 6e2c9da7..9b85a28a 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -151,6 +151,14 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername"; [passwordColumn setIdentifier:MPEntryTablePasswordColumnIdentifier]; [urlColumn setIdentifier:MPEntryTableURLColumnIdentifier]; + NSSortDescriptor *titleColumSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES selector:@selector(compare:)]; + NSSortDescriptor *userNameSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"username" ascending:YES selector:@selector(compare:)]; + NSSortDescriptor *urlSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"url" ascending:YES selector:@selector(compare:)]; + + [titleColumn setSortDescriptorPrototype:titleColumSortDescriptor]; + [userNameColumn setSortDescriptorPrototype:userNameSortDescriptor]; + [urlColumn setSortDescriptorPrototype:urlSortDescriptor]; + [[parentColumn headerCell] setStringValue:@"Group"]; [[titleColumn headerCell] setStringValue:@"Title"]; [[userNameColumn headerCell] setStringValue:@"Username"]; @@ -158,6 +166,8 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername"; [[urlColumn headerCell] setStringValue:@"URL"]; [self.entryTable bind:NSContentBinding toObject:self.entryArrayController withKeyPath:@"arrangedObjects" options:nil]; + [self.entryTable bind:NSSortDescriptorsBinding toObject:self.entryArrayController withKeyPath:@"sortDescriptors" options:nil]; + [parentColumn setHidden:YES]; } #pragma mark NSTableViewDelgate diff --git a/MacPass/MPOutlineViewController.m b/MacPass/MPOutlineViewController.m index 0be1594b..939df76a 100644 --- a/MacPass/MPOutlineViewController.m +++ b/MacPass/MPOutlineViewController.m @@ -22,6 +22,7 @@ @property (retain) NSMenu *menu; +- (void)_didUpdateData:(NSNotification *)notification; - (NSMenu *)_contextMenu; - (KdbGroup *)_clickedOrSelectedGroup; @@ -38,6 +39,18 @@ if (self) { self.outlineDelegate = [[[MPOutlineViewDelegate alloc] init] autorelease]; self.datasource = [[[MPOutlineDataSource alloc] init] autorelease]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(_didUpdateData:) + name:MPDocumentDidAddGroupNotification + object:[[self windowController] document]]; + + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(_didUpdateData:) + name:MPDocumentDidDelteGroupNotification + object:[[self windowController] document]]; + } return self; @@ -116,5 +129,9 @@ return [self.outlineView itemAtRow:row]; } +- (void)_didUpdateData:(NSNotification *)notification { + [self.outlineView reloadData]; +} + @end diff --git a/MacPass/MPPasswordEditViewController.m b/MacPass/MPPasswordEditViewController.m index 73e0537d..0d9a48fa 100644 --- a/MacPass/MPPasswordEditViewController.m +++ b/MacPass/MPPasswordEditViewController.m @@ -36,7 +36,7 @@ } - (void)dealloc { - [self.pathControlDelegate release]; + [_pathControlDelegate release]; [super dealloc]; } diff --git a/MacPass/MacPass-Info.plist b/MacPass/MacPass-Info.plist index 617f4b9e..23d1bdcd 100644 --- a/MacPass/MacPass-Info.plist +++ b/MacPass/MacPass-Info.plist @@ -46,7 +46,7 @@ CFBundleSignature ???? CFBundleVersion - 67C + 69B LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSHumanReadableCopyright