From fb0887ebf03d4047944fd440bf830ae9ed2b9d5c Mon Sep 17 00:00:00 2001 From: michael starke Date: Tue, 9 Jul 2013 21:58:28 +0200 Subject: [PATCH] Refactored Undo/Redo --- HNHUi | 2 +- MacPass.xcodeproj/project.pbxproj | 12 +- MacPass/KdbEntry+Undo.h | 7 +- MacPass/KdbEntry+Undo.m | 79 +++++++++++-- MacPass/KdbGroup+MPAdditions.m | 9 +- MacPass/KdbGroup+Undo.h | 7 ++ MacPass/KdbGroup+Undo.m | 80 +++++++++++++ MacPass/MPDocument.h | 14 +-- MacPass/MPDocument.m | 107 +++++------------- MacPass/MPEntryViewController.m | 2 +- MacPass/MPInspectorViewController.m | 2 +- MacPass/MPOutlineDataSource.m | 5 +- MacPass/MPOutlineViewController.m | 12 +- MacPass/MacPass-Info.plist | 2 +- MacPass/NSString+MPPasswordAnalysis.h | 23 ---- MacPass/NSString+PasswordStrength.h | 17 +++ ...Analysis.m => NSString+PasswordStrength.m} | 8 +- 17 files changed, 237 insertions(+), 151 deletions(-) delete mode 100644 MacPass/NSString+MPPasswordAnalysis.h create mode 100644 MacPass/NSString+PasswordStrength.h rename MacPass/{NSString+MPPasswordAnalysis.m => NSString+PasswordStrength.m} (54%) diff --git a/HNHUi b/HNHUi index 260aa47e..b1cfe0ed 160000 --- a/HNHUi +++ b/HNHUi @@ -1 +1 @@ -Subproject commit 260aa47e80c53df5a0648f868482ba767cfd1fc2 +Subproject commit b1cfe0edc4d43334e4c53cc294493746cfbf59f9 diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index c77cbf51..ab695197 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -64,7 +64,7 @@ 4C431BCD16E2A82800700A81 /* MPPasteBoardController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C431BCC16E2A82700700A81 /* MPPasteBoardController.m */; }; 4C431BCF16E2BAB000700A81 /* OverlayWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C431BCE16E2BAB000700A81 /* OverlayWindow.xib */; }; 4C46B88517063A070046109A /* NSString+MPPasswordCreation.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C46B88417063A070046109A /* NSString+MPPasswordCreation.m */; }; - 4C46B88817063A170046109A /* NSString+MPPasswordAnalysis.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C46B88717063A170046109A /* NSString+MPPasswordAnalysis.m */; }; + 4C46B88817063A170046109A /* NSString+PasswordStrength.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C46B88717063A170046109A /* NSString+PasswordStrength.m */; }; 4C46E09E17673A0A00DA62E8 /* HNHShadowBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C46E09D17673A0A00DA62E8 /* HNHShadowBox.m */; }; 4C4A100F176286FD00BBF2CA /* MPTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4A100E176286FD00BBF2CA /* MPTableView.m */; }; 4C4A101217629DA900BBF2CA /* KdbGroup+KVOAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4A101117629DA900BBF2CA /* KdbGroup+KVOAdditions.m */; }; @@ -309,8 +309,8 @@ 4C431BCE16E2BAB000700A81 /* OverlayWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OverlayWindow.xib; sourceTree = ""; }; 4C46B88317063A070046109A /* NSString+MPPasswordCreation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MPPasswordCreation.h"; sourceTree = ""; }; 4C46B88417063A070046109A /* NSString+MPPasswordCreation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MPPasswordCreation.m"; sourceTree = ""; }; - 4C46B88617063A170046109A /* NSString+MPPasswordAnalysis.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MPPasswordAnalysis.h"; sourceTree = ""; }; - 4C46B88717063A170046109A /* NSString+MPPasswordAnalysis.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MPPasswordAnalysis.m"; sourceTree = ""; }; + 4C46B88617063A170046109A /* NSString+PasswordStrength.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+PasswordStrength.h"; sourceTree = ""; }; + 4C46B88717063A170046109A /* NSString+PasswordStrength.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+PasswordStrength.m"; sourceTree = ""; }; 4C46E09C17673A0A00DA62E8 /* HNHShadowBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHShadowBox.h; sourceTree = ""; }; 4C46E09D17673A0A00DA62E8 /* HNHShadowBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHShadowBox.m; sourceTree = ""; }; 4C4A100D176286FD00BBF2CA /* MPTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPTableView.h; sourceTree = ""; }; @@ -880,8 +880,8 @@ children = ( 4C46B88317063A070046109A /* NSString+MPPasswordCreation.h */, 4C46B88417063A070046109A /* NSString+MPPasswordCreation.m */, - 4C46B88617063A170046109A /* NSString+MPPasswordAnalysis.h */, - 4C46B88717063A170046109A /* NSString+MPPasswordAnalysis.m */, + 4C46B88617063A170046109A /* NSString+PasswordStrength.h */, + 4C46B88717063A170046109A /* NSString+PasswordStrength.m */, ); name = "Security Additions"; sourceTree = ""; @@ -1454,7 +1454,7 @@ 4CE39ABF16ECE34A000FE29D /* MPIconSelectViewController.m in Sources */, 4CE39AC416ECE4F7000FE29D /* MPPopupImageView.m in Sources */, 4C46B88517063A070046109A /* NSString+MPPasswordCreation.m in Sources */, - 4C46B88817063A170046109A /* NSString+MPPasswordAnalysis.m in Sources */, + 4C46B88817063A170046109A /* NSString+PasswordStrength.m in Sources */, 4C5A11FE1708DE8700223D8A /* MPPasswordCreatorViewController.m in Sources */, 4CE5B54B173AFBA700207B39 /* MPDocument.m in Sources */, 4C22040D1746ED160054C916 /* KdbGroup+Undo.m in Sources */, diff --git a/MacPass/KdbEntry+Undo.h b/MacPass/KdbEntry+Undo.h index 4f04cc64..69ca3c8f 100644 --- a/MacPass/KdbEntry+Undo.h +++ b/MacPass/KdbEntry+Undo.h @@ -17,8 +17,6 @@ APPKIT_EXTERN NSString *const MPEntryNotesUndoableKey; @interface KdbEntry (Undo) -+ (NSUndoManager *)undoManager; - - (NSString *)titleUndoable; - (NSString *)usernameUndoable; - (NSString *)passwordUndoable; @@ -31,4 +29,9 @@ APPKIT_EXTERN NSString *const MPEntryNotesUndoableKey; - (void)setUrlUndoable:(NSString *)url; - (void)setNotesUndoable:(NSString *)notes; +- (void)deleteUndoable; +- (void)moveToGroupUndoable:(KdbGroup *)group atIndex:(NSUInteger)index; +- (void)moveToTrashUndoable:(KdbGroup *)trash atIndex:(NSUInteger)index; +- (void)restoreFromTrashUndoable:(KdbGroup *)group atIndex:(NSUInteger)index; + @end diff --git a/MacPass/KdbEntry+Undo.m b/MacPass/KdbEntry+Undo.m index 0be9b928..09b8fee5 100644 --- a/MacPass/KdbEntry+Undo.m +++ b/MacPass/KdbEntry+Undo.m @@ -7,6 +7,8 @@ // #import "KdbEntry+Undo.h" +#import "KdbGroup+Undo.h" +#import "KdbGroup+KVOAdditions.h" #import "KdbGroup+MPTreeTools.h" NSString *const MPEntryTitleUndoableKey = @"titleUndoable"; @@ -17,7 +19,7 @@ NSString *const MPEntryNotesUndoableKey = @"notesUndoable"; @implementation KdbEntry (Undo) -+ (NSUndoManager *)undoManager { +- (NSUndoManager *)undoManager { return [[[NSDocumentController sharedDocumentController] currentDocument] undoManager]; } @@ -43,38 +45,93 @@ NSString *const MPEntryNotesUndoableKey = @"notesUndoable"; - (void)setTitleUndoable:(NSString *)title { - [[KdbEntry undoManager] registerUndoWithTarget:self selector:@selector(setTitleUndoable:) object:self.title]; - [[KdbEntry undoManager] setActionName:NSLocalizedString(@"UNDO_SET_TITLE", "Undo set title")]; + [[self undoManager] registerUndoWithTarget:self selector:@selector(setTitleUndoable:) object:self.title]; + [[self undoManager] setActionName:NSLocalizedString(@"UNDO_SET_TITLE", "Undo set title")]; [self setLastModificationTime:[NSDate date]]; [self setTitle:title]; } - (void)setUsernameUndoable:(NSString *)username { - [[KdbEntry undoManager] registerUndoWithTarget:self selector:@selector(setUsernameUndoable:) object:self.username]; - [[KdbEntry undoManager] setActionName:NSLocalizedString(@"UNDO_SET_USERNAME", "Undo set username")]; + [[self undoManager] registerUndoWithTarget:self selector:@selector(setUsernameUndoable:) object:self.username]; + [[self undoManager] setActionName:NSLocalizedString(@"UNDO_SET_USERNAME", "Undo set username")]; [self setLastModificationTime:[NSDate date]]; [self setUsername:username]; } - (void)setPasswordUndoable:(NSString *)password { - [[KdbEntry undoManager] registerUndoWithTarget:self selector:@selector(setPasswordUndoable:) object:self.password]; - [[KdbEntry undoManager] setActionName:NSLocalizedString(@"UNDO_SET_PASSWORT", "Undo set password")]; + [[self undoManager] registerUndoWithTarget:self selector:@selector(setPasswordUndoable:) object:self.password]; + [[self undoManager] setActionName:NSLocalizedString(@"UNDO_SET_PASSWORT", "Undo set password")]; [self setLastModificationTime:[NSDate date]]; [self setPassword:password]; } - (void)setUrlUndoable:(NSString *)url { - [[KdbEntry undoManager] registerUndoWithTarget:self selector:@selector(setUrlUndoable:) object:self.url]; - [[KdbEntry undoManager] setActionName:NSLocalizedString(@"UNDO_SET_URL", "Undo set URL")]; + [[self undoManager] registerUndoWithTarget:self selector:@selector(setUrlUndoable:) object:self.url]; + [[self undoManager] setActionName:NSLocalizedString(@"UNDO_SET_URL", "Undo set URL")]; [self setLastModificationTime:[NSDate date]]; [self setUrl:url]; } - (void)setNotesUndoable:(NSString *)notes { - [[KdbEntry undoManager] registerUndoWithTarget:self selector:@selector(setNotesUndoable:) object:self.notes]; - [[KdbEntry undoManager] setActionName:NSLocalizedString(@"UNDO_SET_NOTES", "Undo set notes")]; + [[self undoManager] registerUndoWithTarget:self selector:@selector(setNotesUndoable:) object:self.notes]; + [[self undoManager] setActionName:NSLocalizedString(@"UNDO_SET_NOTES", "Undo set notes")]; [self setLastModificationTime:[NSDate date]]; [self setNotes:notes]; } +- (void)deleteUndoable { + if(!self.parent) { + return; // No parent to be removed from + } + NSUInteger oldIndex = [self.parent.entries indexOfObject:self]; + if(oldIndex == NSNotFound) { + return; // We're not in our parents entries list + } + [[[self undoManager] prepareWithInvocationTarget:self.parent] addEntryUndoable:self atIndex:oldIndex]; + [[self undoManager] setActionName:@"Delete Entry"]; + [self.parent removeObjectFromEntriesAtIndex:oldIndex]; +} + +- (void)moveToGroupUndoable:(KdbGroup *)group atIndex:(NSUInteger)index { + if(!group || !self.parent) { + return; // Nothing to be moved about + } + NSUInteger oldIndex = [self.parent.entries indexOfObject:self]; + if(oldIndex == NSNotFound) { + return; // Not found in entries of parent! + } + [[[self undoManager] prepareWithInvocationTarget:self] moveToGroupUndoable:self.parent atIndex:oldIndex]; + [[self undoManager] setActionName:@"Move Entry"]; + [self.parent removeObjectFromEntriesAtIndex:oldIndex]; + [group insertObject:self inEntriesAtIndex:index]; +} +- (void)moveToTrashUndoable:(KdbGroup *)trash atIndex:(NSUInteger)index { + if(!trash || !self.parent) { + return; // Nothing to be moved about + } + NSUInteger oldIndex = [self.parent.entries indexOfObject:self]; + if(oldIndex == NSNotFound) { + return; // Not found in entries of parent! + } + [[[self undoManager] prepareWithInvocationTarget:self] restoreFromTrashUndoable:self.parent atIndex:oldIndex]; + [[self undoManager] setActionName:@"Trash Entry"]; + [self.parent removeObjectFromEntriesAtIndex:oldIndex]; + [trash insertObject:self inEntriesAtIndex:index]; +} + +- (void)restoreFromTrashUndoable:(KdbGroup *)group atIndex:(NSUInteger)index { + if(!group || !self.parent) { + return; // Nothing to be moved about + } + NSUInteger oldIndex = [self.parent.entries indexOfObject:self]; + if(oldIndex == NSNotFound) { + return; // Not found in entries of parent! + } + [[[self undoManager] prepareWithInvocationTarget:self] moveToTrashUndoable:self.parent atIndex:oldIndex]; + [[self undoManager] setActionName:@"Restore Entry"]; + [self.parent removeObjectFromEntriesAtIndex:oldIndex]; + [group insertObject:self inEntriesAtIndex:index]; + +} + @end \ No newline at end of file diff --git a/MacPass/KdbGroup+MPAdditions.m b/MacPass/KdbGroup+MPAdditions.m index 655d8363..6904e672 100644 --- a/MacPass/KdbGroup+MPAdditions.m +++ b/MacPass/KdbGroup+MPAdditions.m @@ -24,12 +24,13 @@ } - (void)clear { - NSUInteger groupCount = [_groups count]; - for(NSInteger index = (groupCount - 1); index > -1; index--) { + for(KdbGroup *group in self.groups) { + [group clear]; + NSUInteger index = [self.groups indexOfObject:group]; [self removeObjectFromGroupsAtIndex:index]; } - NSUInteger entryCount = [_entries count]; - for(NSInteger index = (entryCount - 1); index > -1; index--) { + for(KdbEntry *entry in self.entries) { + NSUInteger index = [self.entries indexOfObject:entry]; [self removeObjectFromEntriesAtIndex:index]; } } diff --git a/MacPass/KdbGroup+Undo.h b/MacPass/KdbGroup+Undo.h index 2ba766ec..dfddcfc3 100644 --- a/MacPass/KdbGroup+Undo.h +++ b/MacPass/KdbGroup+Undo.h @@ -17,4 +17,11 @@ APPKIT_EXTERN NSString *const MPGroupNameUndoableKey; - (NSString *)nameUndoable; - (void)setNameUndoable:(NSString *)newName; +- (void)deleteUndoable; +- (void)addGroupUndoable:(KdbGroup *)group atIndex:(NSUInteger)index; +- (void)addEntryUndoable:(KdbEntry *)entry atIndex:(NSUInteger)index; +- (void)moveToGroupUndoable:(KdbGroup *)group atIndex:(NSUInteger)index; +- (void)moveToTrashUndoable:(KdbGroup *)trash atIndex:(NSUInteger)index; +- (void)restoreFromTrahsUndoable:(KdbGroup *)group atIndex:(NSUInteger)index; + @end diff --git a/MacPass/KdbGroup+Undo.m b/MacPass/KdbGroup+Undo.m index 9bb5ddaf..8980984f 100644 --- a/MacPass/KdbGroup+Undo.m +++ b/MacPass/KdbGroup+Undo.m @@ -8,6 +8,7 @@ #import "KdbGroup+Undo.h" #import "KdbGroup+KVOAdditions.h" +#import "KdbEntry+Undo.h" NSString *const MPGroupNameUndoableKey = @"nameUndoable"; @@ -27,4 +28,83 @@ NSString *const MPGroupNameUndoableKey = @"nameUndoable"; self.name = newName; } +- (void)deleteUndoable { + if(!self.parent) { + return; + } + NSUInteger oldIndex = [self.parent.groups indexOfObject:self]; + if(oldIndex == NSNotFound) { + return; // Inconsistent data + } + [[[self undoManager] prepareWithInvocationTarget:self.parent] addGroupUndoable:self atIndex:oldIndex]; + [self.parent removeObjectFromGroupsAtIndex:[self.parent.groups indexOfObject:self]]; +} + +- (void)addGroupUndoable:(KdbGroup *)group atIndex:(NSUInteger)index { + if(!group) { + return; + } + if(index < [group.groups count]) { + return; // Wrong index! + } + [[[self undoManager] prepareWithInvocationTarget:group] deleteUndoable]; + //[[self undoManager] setActionName:NSLocalizedString(@"UNDO_ADD_GROUP", @"Create Group Undo")]; + [[self undoManager] setActionName:@"Add Group"]; + [self insertObject:group inGroupsAtIndex:index]; +} + +- (void)addEntryUndoable:(KdbEntry *)entry atIndex:(NSUInteger)index { + if(!entry) { + return; + } + if(index > [self.entries count]) { + return; // Wrong index! + } + [[[self undoManager] prepareWithInvocationTarget:entry] deleteUndoable]; + [[self undoManager] setActionName:@"Add Entry"]; + [self insertObject:entry inEntriesAtIndex:index]; +} + +- (void)moveToGroupUndoable:(KdbGroup *)group atIndex:(NSUInteger)index { + if(!self.parent || !group) { + return; // No target or origin + } + NSUInteger oldIndex = [self.parent.groups indexOfObject:self]; + if(index == NSNotFound) { + return; // We aren't in our parents groups list. + } + [[[self undoManager] prepareWithInvocationTarget:self] moveToGroupUndoable:self.parent atIndex:oldIndex]; + [[self undoManager] setActionName:@"Move Group"]; + [self.parent removeObjectFromGroupsAtIndex:oldIndex]; + [group insertObject:self inGroupsAtIndex:index]; +} + +- (void)moveToTrashUndoable:(KdbGroup *)trash atIndex:(NSUInteger)index { + if(!self.parent || !trash) { + return; // No target or origin + } + NSUInteger oldIndex = [self.parent.groups indexOfObject:self]; + if(index == NSNotFound) { + return; // We aren't in our parents groups list. + } + [[[self undoManager] prepareWithInvocationTarget:self] restoreFromTrahsUndoable:self.parent atIndex:oldIndex]; + [[self undoManager] setActionName:@"Trash Group"]; + [self.parent removeObjectFromGroupsAtIndex:oldIndex]; + [trash insertObject:self inGroupsAtIndex:index]; +} + +- (void)restoreFromTrahsUndoable:(KdbGroup *)group atIndex:(NSUInteger)index { + if(!self.parent || !group) { + return; // No target or origin + } + NSUInteger oldIndex = [self.parent.groups indexOfObject:self]; + if(index == NSNotFound) { + return; // We aren't in our parents groups list. + } + [[[self undoManager] prepareWithInvocationTarget:self] moveToTrashUndoable:self.parent atIndex:oldIndex]; + [[self undoManager] setActionName:@"Restore Group"]; + [self.parent removeObjectFromGroupsAtIndex:oldIndex]; + [group insertObject:self inGroupsAtIndex:index]; +} + @end diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index 82dd8cdd..b4b1e406 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -73,18 +73,14 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey; /* All non-setter undoable actions */ - -- (void)moveGroup:(KdbGroup *)group toGroup:(KdbGroup *)target index:(NSInteger)index; - (BOOL)group:(KdbGroup *)group isMoveableToGroup:(KdbGroup *)target; -- (void)moveEntry:(KdbEntry *)entry toGroup:(KdbGroup *)target index:(NSInteger)index; -- (void)group:(KdbGroup *)group addEntry:(KdbEntry *)entry atIndex:(NSUInteger)index; -- (void)group:(KdbGroup *)group addGroup:(KdbGroup *)aGroup atIndex:(NSUInteger)index; -- (void)group:(KdbGroup *)group removeEntry:(KdbEntry *)entry; -- (void)group:(KdbGroup *)group removeGroup:(KdbGroup *)aGroup; +/* TODO in UNDO auslagen */ +- (void)addStringField:(StringField *)field toEntry:(Kdb4Entry *)entry atIndex:(NSUInteger)index; +- (void)removeStringField:(StringField *)field formEntry:(Kdb4Entry *)entry; -- (void)entry:(Kdb4Entry *)entry addStringField:(StringField *)field atIndex:(NSUInteger)index; -- (void)entry:(Kdb4Entry *)entry removeStringField:(StringField *)field; +- (void)deleteGroup:(KdbGroup *)group; +- (void)deleteEntry:(KdbEntry *)entry; - (void)emptyTrash:(id)sender; diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index ef9e51ae..1d7ac9bb 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -121,15 +121,15 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; - (BOOL)readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError { /* FIXME: Logfile handling - self.lockFileURL = [url URLByAppendingPathExtension:@"lock"]; - if([[NSFileManager defaultManager] fileExistsAtPath:[_lockFileURL path]]) { - self.readOnly = YES; - } - else { - [[NSFileManager defaultManager] createFileAtPath:[_lockFileURL path] contents:nil attributes:nil]; - _didLockFile = YES; - self.readOnly = NO; - } + self.lockFileURL = [url URLByAppendingPathExtension:@"lock"]; + if([[NSFileManager defaultManager] fileExistsAtPath:[_lockFileURL path]]) { + self.readOnly = YES; + } + else { + [[NSFileManager defaultManager] createFileAtPath:[_lockFileURL path] contents:nil attributes:nil]; + _didLockFile = YES; + self.readOnly = NO; + } */ self.decrypted = NO; return YES; @@ -294,7 +294,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; if(self.treeV4 && ([self.treeV4.defaultUserName length] > 0)) { newEntry.title = self.treeV4.defaultUserName; } - [self group:parent addEntry:newEntry atIndex:[parent.entries count]]; + [parent addEntryUndoable:newEntry atIndex:[parent.entries count]]; NSDictionary *userInfo = @{ MPDocumentEntryKey : newEntry }; [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddEntryNotification object:self userInfo:userInfo]; return newEntry; @@ -307,7 +307,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; KdbGroup *newGroup = [self.tree createGroup:parent]; newGroup.name = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group"); newGroup.image = MPIconFolder; - [self group:parent addGroup:newGroup atIndex:[parent.groups count]]; + [parent addGroupUndoable:newGroup atIndex:[parent.groups count]]; NSDictionary *userInfo = @{ MPDocumentGroupKey : newGroup }; [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddGroupNotification object:self userInfo:userInfo]; return newGroup; @@ -322,7 +322,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; NSString *title = NSLocalizedString(@"DEFAULT_CUSTOM_FIELD_TITLE", @"Default Titel for new Custom-Fields"); NSString *value = NSLocalizedString(@"DEFAULT_CUSTOM_FIELD_VALUE", @"Default Value for new Custom-Fields"); StringField *newStringField = [StringField stringFieldWithKey:title andValue:value]; - [self entry:entryV4 addStringField:newStringField atIndex:[entryV4.stringFields count]]; + [self addStringField:newStringField toEntry:entryV4 atIndex:[entryV4.stringFields count]]; return newStringField; } @@ -363,91 +363,44 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; return isMovable; } -- (void)moveEntry:(KdbEntry *)entry toGroup:(KdbGroup *)target index:(NSInteger)index { - NSInteger oldIndex = [entry.parent.entries indexOfObject:entry]; - if(entry.parent == target && oldIndex == index) { - return; // No changes - } - [[[self undoManager] prepareWithInvocationTarget:self] moveEntry:entry toGroup:entry.parent index:oldIndex]; - if(self.trash == target || self.trash == entry.parent) { - [[self undoManager] setActionName:@"UNDO_DELETE_ENTRY"]; +- (void)deleteEntry:(KdbEntry *)entry { + if(self.useTrash) { + if(!self.trash) { + [self _createTrashGroup]; + } + [entry moveToTrashUndoable:self.trash atIndex:[self.trash.entries count]]; } else { - [[self undoManager] setActionName:@"MOVE_ENTRY"]; + [entry deleteUndoable]; } - [entry.parent removeObjectFromEntriesAtIndex:oldIndex]; - if(index < 0 || index > [target.groups count] ) { - index = [target.groups count]; - } - [target insertObject:entry inEntriesAtIndex:index]; } -- (void)group:(KdbGroup *)group addEntry:(KdbEntry *)entry atIndex:(NSUInteger)index { - [[[self undoManager] prepareWithInvocationTarget:self] group:group removeEntry:entry]; - [[self undoManager] setActionName:NSLocalizedString(@"UNDO_ADD_ENTRY", "Undo adding of entry")]; - [group insertObject:entry inEntriesAtIndex:index]; -} - -- (void)group:(KdbGroup *)group addGroup:(KdbGroup *)aGroup atIndex:(NSUInteger)index { - [[[self undoManager] prepareWithInvocationTarget:self] group:group removeGroup:aGroup]; - [[self undoManager] setActionName:NSLocalizedString(@"UNDO_ADD_GROUP", @"Create Group Undo")]; - [group insertObject:aGroup inGroupsAtIndex:index]; -} - -- (void)group:(KdbGroup *)group removeEntry:(KdbEntry *)entry { - NSInteger index = [group.entries indexOfObject:entry]; - if(NSNotFound == index) { - return; // No object found; - } +- (void)deleteGroup:(KdbGroup *)group { if(self.useTrash) { if(!self.trash) { [self _createTrashGroup]; } - [self moveEntry:entry toGroup:self.trash index:[self.trash.entries count]]; - return; + [group moveToTrashUndoable:self.trash atIndex:[self.trash.groups count]]; + } + else { + [group deleteUndoable]; } - [[[self undoManager] prepareWithInvocationTarget:self] group:group addEntry:entry atIndex:index]; - [[self undoManager] setActionName:NSLocalizedString(@"UNDO_DELETE_ENTRY", "Undo deleting of entry")]; - [group removeObjectFromEntriesAtIndex:index]; } -- (void)group:(KdbGroup *)group removeGroup:(KdbGroup *)aGroup { - NSInteger index = [group.groups indexOfObject:aGroup]; - if(NSNotFound == index) { - return; // No object found - } - if(self.trash == aGroup) { - return; - // delete Trash? - } - /* - Cleaning the recyclebin is not undoable - So we do this in a separate action - */ - if(self.useTrash) { - if(!self.trash) { - [self _createTrashGroup]; - } - [self moveGroup:aGroup toGroup:self.trash index:[self.trash.groups count]]; - return; // Done! - } - [[[self undoManager] prepareWithInvocationTarget:self] group:group addGroup:aGroup atIndex:index]; - [[self undoManager] setActionName:NSLocalizedString(@"UNDO_DELETE_GROUP", @"Delete Group Undo")]; - [group removeObjectFromGroupsAtIndex:index]; -} +#pragma mark CustomFields -- (void)entry:(Kdb4Entry *)entry addStringField:(StringField *)field atIndex:(NSUInteger)index { - [[[self undoManager] prepareWithInvocationTarget:self] entry:entry removeStringField:field]; +- (void)addStringField:(StringField *)field toEntry:(Kdb4Entry *)entry atIndex:(NSUInteger)index { + [[[self undoManager] prepareWithInvocationTarget:self] removeStringField:field formEntry:entry]; [[self undoManager] setActionName:NSLocalizedString(@"UNDO_ADD_STRING_FIELD", @"Add Stringfield Undo")]; [entry insertObject:field inStringFieldsAtIndex:index]; } -- (void)entry:(Kdb4Entry *)entry removeStringField:(StringField *)field { +- (void)removeStringField:(StringField *)field formEntry:(Kdb4Entry *)entry { NSInteger index = [entry.stringFields indexOfObject:field]; if(NSNotFound == index) { return; // Nothing found to be removed } - [[[self undoManager] prepareWithInvocationTarget:self] entry:entry addStringField:field atIndex:index]; + [[[self undoManager] prepareWithInvocationTarget:self] addStringField:field toEntry:entry atIndex:index]; [[self undoManager] setActionName:NSLocalizedString(@"UNDO_DELETE_STRING_FIELD", @"Delte Stringfield undo")]; [entry removeObjectFromStringFieldsAtIndex:index]; } @@ -455,8 +408,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; #pragma mark Actions - (void)emptyTrash:(id)sender { - [[self undoManager] setActionIsDiscardable:YES]; [self.trash clear]; + // TODO: Notify that entries should be deslected } - (BOOL)validateMenuItem:(NSMenuItem *)menuItem { diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index ae3fd76e..a5b01997 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -481,7 +481,7 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername"; - (void)deleteNode:(id)sender { KdbEntry *entry =[self _clickedOrSelectedEntry]; MPDocument *document = [[self windowController] document]; - [document group:entry.parent removeEntry:entry]; + [document deleteEntry:entry]; } - (void)_toggleFilterSpace:(id)sender { diff --git a/MacPass/MPInspectorViewController.m b/MacPass/MPInspectorViewController.m index c41a398d..3f20930e 100644 --- a/MacPass/MPInspectorViewController.m +++ b/MacPass/MPInspectorViewController.m @@ -323,7 +323,7 @@ enum { MPDocument *document = [[self windowController] document]; NSUInteger index = [sender tag]; Kdb4Entry *entry = (Kdb4Entry *)self.selectedEntry; - [document entry:entry removeStringField:(entry.stringFields)[index]]; + [document removeStringField:(entry.stringFields)[index] formEntry:entry]; } - (IBAction)saveAttachment:(id)sender { diff --git a/MacPass/MPOutlineDataSource.m b/MacPass/MPOutlineDataSource.m index 0e99fb45..32bf232f 100644 --- a/MacPass/MPOutlineDataSource.m +++ b/MacPass/MPOutlineDataSource.m @@ -13,6 +13,7 @@ #import "KdbLib.h" #import "KdbGroup+Undo.h" +#import "KdbEntry+Undo.h" #import "KdbGroup+MPTreeTools.h" #import "KdbEntry+MPTreeTools.h" @@ -79,7 +80,7 @@ MPDocument *document = [[[outlineView window] windowController] document]; accepted = [document group:_draggedItem isMoveableToGroup:target]; if( accepted ) { - [document moveGroup:_draggedItem toGroup:target index:index]; + [_draggedItem moveToGroupUndoable:target atIndex:index]; } info.animatesToDestination = !accepted; return accepted; @@ -94,7 +95,7 @@ KdbEntry *draggedEntry = [rootGroup entryForUUID:uuid]; if(draggedEntry) { if(draggedEntry.parent != target && index == NSOutlineViewDropOnItemIndex) { - [document moveEntry:draggedEntry toGroup:target index:index]; + [draggedEntry moveToGroupUndoable:target atIndex:index]; return YES; } } diff --git a/MacPass/MPOutlineViewController.m b/MacPass/MPOutlineViewController.m index 349cf55e..d441a425 100644 --- a/MacPass/MPOutlineViewController.m +++ b/MacPass/MPOutlineViewController.m @@ -121,18 +121,12 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell"; } - (void)createEntry:(id)sender { - KdbGroup *group = [self _clickedOrSelectedGroup]; - if(group) { - MPDocument *document = [[self windowController] document]; - [document createEntry:group]; - } + MPDocument *document = [[self windowController] document]; + [document createEntry:[self _clickedOrSelectedGroup]]; } - (void)deleteNode:(id)sender { - KdbGroup *group = [self _clickedOrSelectedGroup]; - if(group && group.parent) { - [[[self windowController] document] group:group.parent removeGroup:group]; - } + [[[self windowController] document] deleteGroup:[self _clickedOrSelectedGroup]]; } #pragma mark NSOutlineViewDelegate diff --git a/MacPass/MacPass-Info.plist b/MacPass/MacPass-Info.plist index e28404f1..b67bad09 100644 --- a/MacPass/MacPass-Info.plist +++ b/MacPass/MacPass-Info.plist @@ -48,7 +48,7 @@ CFBundleSignature ???? CFBundleVersion - 2301 + 2323 LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSHumanReadableCopyright diff --git a/MacPass/NSString+MPPasswordAnalysis.h b/MacPass/NSString+MPPasswordAnalysis.h deleted file mode 100644 index 1cddda16..00000000 --- a/MacPass/NSString+MPPasswordAnalysis.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// NSString+MPPasswordAnalysis.h -// MacPass -// -// Created by Michael Starke on 29.03.13. -// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. -// - -#import - -typedef NS_ENUM(NSUInteger, MPPasswordStrength) { - MPPasswordWeak, - MPPasswordOK, - MPPasswordGood, - MPPasswordStrong, - MPPasswordExcelent, -}; - -@interface NSString (MPPasswordAnalysis) - -- (MPPasswordStrength)passwordStrenght; - -@end diff --git a/MacPass/NSString+PasswordStrength.h b/MacPass/NSString+PasswordStrength.h new file mode 100644 index 00000000..df7eaab2 --- /dev/null +++ b/MacPass/NSString+PasswordStrength.h @@ -0,0 +1,17 @@ +// +// NSString+MPPasswordAnalysis.h +// MacPass +// +// Created by Michael Starke on 29.03.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import + + +@interface NSString (PasswordStrenght) + +- (NSUInteger)passwordStrenght; + + +@end diff --git a/MacPass/NSString+MPPasswordAnalysis.m b/MacPass/NSString+PasswordStrength.m similarity index 54% rename from MacPass/NSString+MPPasswordAnalysis.m rename to MacPass/NSString+PasswordStrength.m index a3eb9438..5dc95086 100644 --- a/MacPass/NSString+MPPasswordAnalysis.m +++ b/MacPass/NSString+PasswordStrength.m @@ -6,12 +6,12 @@ // Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. // -#import "NSString+MPPasswordAnalysis.h" +#import "NSString+PasswordStrength.h" -@implementation NSString (MPPasswordAnalysis) +@implementation NSString (PasswordStrenght) -- (MPPasswordStrength)passwordStrenght { - return MPPasswordOK; +- (NSUInteger)passwordStrenght { + return 0; } @end