Refactored Undo/Redo

This commit is contained in:
michael starke
2013-07-09 21:58:28 +02:00
parent 6ba8b1445d
commit fb0887ebf0
17 changed files with 237 additions and 151 deletions

2
HNHUi

Submodule HNHUi updated: 260aa47e80...b1cfe0edc4

View File

@@ -64,7 +64,7 @@
4C431BCD16E2A82800700A81 /* MPPasteBoardController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C431BCC16E2A82700700A81 /* MPPasteBoardController.m */; }; 4C431BCD16E2A82800700A81 /* MPPasteBoardController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C431BCC16E2A82700700A81 /* MPPasteBoardController.m */; };
4C431BCF16E2BAB000700A81 /* OverlayWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C431BCE16E2BAB000700A81 /* OverlayWindow.xib */; }; 4C431BCF16E2BAB000700A81 /* OverlayWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C431BCE16E2BAB000700A81 /* OverlayWindow.xib */; };
4C46B88517063A070046109A /* NSString+MPPasswordCreation.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C46B88417063A070046109A /* NSString+MPPasswordCreation.m */; }; 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 */; }; 4C46E09E17673A0A00DA62E8 /* HNHShadowBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C46E09D17673A0A00DA62E8 /* HNHShadowBox.m */; };
4C4A100F176286FD00BBF2CA /* MPTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4A100E176286FD00BBF2CA /* MPTableView.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 */; }; 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 = "<group>"; }; 4C431BCE16E2BAB000700A81 /* OverlayWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OverlayWindow.xib; sourceTree = "<group>"; };
4C46B88317063A070046109A /* NSString+MPPasswordCreation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MPPasswordCreation.h"; sourceTree = "<group>"; }; 4C46B88317063A070046109A /* NSString+MPPasswordCreation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MPPasswordCreation.h"; sourceTree = "<group>"; };
4C46B88417063A070046109A /* NSString+MPPasswordCreation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MPPasswordCreation.m"; sourceTree = "<group>"; }; 4C46B88417063A070046109A /* NSString+MPPasswordCreation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MPPasswordCreation.m"; sourceTree = "<group>"; };
4C46B88617063A170046109A /* NSString+MPPasswordAnalysis.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MPPasswordAnalysis.h"; sourceTree = "<group>"; }; 4C46B88617063A170046109A /* NSString+PasswordStrength.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+PasswordStrength.h"; sourceTree = "<group>"; };
4C46B88717063A170046109A /* NSString+MPPasswordAnalysis.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MPPasswordAnalysis.m"; sourceTree = "<group>"; }; 4C46B88717063A170046109A /* NSString+PasswordStrength.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+PasswordStrength.m"; sourceTree = "<group>"; };
4C46E09C17673A0A00DA62E8 /* HNHShadowBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHShadowBox.h; sourceTree = "<group>"; }; 4C46E09C17673A0A00DA62E8 /* HNHShadowBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHShadowBox.h; sourceTree = "<group>"; };
4C46E09D17673A0A00DA62E8 /* HNHShadowBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHShadowBox.m; sourceTree = "<group>"; }; 4C46E09D17673A0A00DA62E8 /* HNHShadowBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHShadowBox.m; sourceTree = "<group>"; };
4C4A100D176286FD00BBF2CA /* MPTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPTableView.h; sourceTree = "<group>"; }; 4C4A100D176286FD00BBF2CA /* MPTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPTableView.h; sourceTree = "<group>"; };
@@ -880,8 +880,8 @@
children = ( children = (
4C46B88317063A070046109A /* NSString+MPPasswordCreation.h */, 4C46B88317063A070046109A /* NSString+MPPasswordCreation.h */,
4C46B88417063A070046109A /* NSString+MPPasswordCreation.m */, 4C46B88417063A070046109A /* NSString+MPPasswordCreation.m */,
4C46B88617063A170046109A /* NSString+MPPasswordAnalysis.h */, 4C46B88617063A170046109A /* NSString+PasswordStrength.h */,
4C46B88717063A170046109A /* NSString+MPPasswordAnalysis.m */, 4C46B88717063A170046109A /* NSString+PasswordStrength.m */,
); );
name = "Security Additions"; name = "Security Additions";
sourceTree = "<group>"; sourceTree = "<group>";
@@ -1454,7 +1454,7 @@
4CE39ABF16ECE34A000FE29D /* MPIconSelectViewController.m in Sources */, 4CE39ABF16ECE34A000FE29D /* MPIconSelectViewController.m in Sources */,
4CE39AC416ECE4F7000FE29D /* MPPopupImageView.m in Sources */, 4CE39AC416ECE4F7000FE29D /* MPPopupImageView.m in Sources */,
4C46B88517063A070046109A /* NSString+MPPasswordCreation.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 */, 4C5A11FE1708DE8700223D8A /* MPPasswordCreatorViewController.m in Sources */,
4CE5B54B173AFBA700207B39 /* MPDocument.m in Sources */, 4CE5B54B173AFBA700207B39 /* MPDocument.m in Sources */,
4C22040D1746ED160054C916 /* KdbGroup+Undo.m in Sources */, 4C22040D1746ED160054C916 /* KdbGroup+Undo.m in Sources */,

View File

@@ -17,8 +17,6 @@ APPKIT_EXTERN NSString *const MPEntryNotesUndoableKey;
@interface KdbEntry (Undo) @interface KdbEntry (Undo)
+ (NSUndoManager *)undoManager;
- (NSString *)titleUndoable; - (NSString *)titleUndoable;
- (NSString *)usernameUndoable; - (NSString *)usernameUndoable;
- (NSString *)passwordUndoable; - (NSString *)passwordUndoable;
@@ -31,4 +29,9 @@ APPKIT_EXTERN NSString *const MPEntryNotesUndoableKey;
- (void)setUrlUndoable:(NSString *)url; - (void)setUrlUndoable:(NSString *)url;
- (void)setNotesUndoable:(NSString *)notes; - (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 @end

View File

@@ -7,6 +7,8 @@
// //
#import "KdbEntry+Undo.h" #import "KdbEntry+Undo.h"
#import "KdbGroup+Undo.h"
#import "KdbGroup+KVOAdditions.h"
#import "KdbGroup+MPTreeTools.h" #import "KdbGroup+MPTreeTools.h"
NSString *const MPEntryTitleUndoableKey = @"titleUndoable"; NSString *const MPEntryTitleUndoableKey = @"titleUndoable";
@@ -17,7 +19,7 @@ NSString *const MPEntryNotesUndoableKey = @"notesUndoable";
@implementation KdbEntry (Undo) @implementation KdbEntry (Undo)
+ (NSUndoManager *)undoManager { - (NSUndoManager *)undoManager {
return [[[NSDocumentController sharedDocumentController] currentDocument] undoManager]; return [[[NSDocumentController sharedDocumentController] currentDocument] undoManager];
} }
@@ -43,38 +45,93 @@ NSString *const MPEntryNotesUndoableKey = @"notesUndoable";
- (void)setTitleUndoable:(NSString *)title { - (void)setTitleUndoable:(NSString *)title {
[[KdbEntry undoManager] registerUndoWithTarget:self selector:@selector(setTitleUndoable:) object:self.title]; [[self undoManager] registerUndoWithTarget:self selector:@selector(setTitleUndoable:) object:self.title];
[[KdbEntry undoManager] setActionName:NSLocalizedString(@"UNDO_SET_TITLE", "Undo set title")]; [[self undoManager] setActionName:NSLocalizedString(@"UNDO_SET_TITLE", "Undo set title")];
[self setLastModificationTime:[NSDate date]]; [self setLastModificationTime:[NSDate date]];
[self setTitle:title]; [self setTitle:title];
} }
- (void)setUsernameUndoable:(NSString *)username { - (void)setUsernameUndoable:(NSString *)username {
[[KdbEntry undoManager] registerUndoWithTarget:self selector:@selector(setUsernameUndoable:) object:self.username]; [[self undoManager] registerUndoWithTarget:self selector:@selector(setUsernameUndoable:) object:self.username];
[[KdbEntry undoManager] setActionName:NSLocalizedString(@"UNDO_SET_USERNAME", "Undo set username")]; [[self undoManager] setActionName:NSLocalizedString(@"UNDO_SET_USERNAME", "Undo set username")];
[self setLastModificationTime:[NSDate date]]; [self setLastModificationTime:[NSDate date]];
[self setUsername:username]; [self setUsername:username];
} }
- (void)setPasswordUndoable:(NSString *)password { - (void)setPasswordUndoable:(NSString *)password {
[[KdbEntry undoManager] registerUndoWithTarget:self selector:@selector(setPasswordUndoable:) object:self.password]; [[self undoManager] registerUndoWithTarget:self selector:@selector(setPasswordUndoable:) object:self.password];
[[KdbEntry undoManager] setActionName:NSLocalizedString(@"UNDO_SET_PASSWORT", "Undo set password")]; [[self undoManager] setActionName:NSLocalizedString(@"UNDO_SET_PASSWORT", "Undo set password")];
[self setLastModificationTime:[NSDate date]]; [self setLastModificationTime:[NSDate date]];
[self setPassword:password]; [self setPassword:password];
} }
- (void)setUrlUndoable:(NSString *)url { - (void)setUrlUndoable:(NSString *)url {
[[KdbEntry undoManager] registerUndoWithTarget:self selector:@selector(setUrlUndoable:) object:self.url]; [[self undoManager] registerUndoWithTarget:self selector:@selector(setUrlUndoable:) object:self.url];
[[KdbEntry undoManager] setActionName:NSLocalizedString(@"UNDO_SET_URL", "Undo set URL")]; [[self undoManager] setActionName:NSLocalizedString(@"UNDO_SET_URL", "Undo set URL")];
[self setLastModificationTime:[NSDate date]]; [self setLastModificationTime:[NSDate date]];
[self setUrl:url]; [self setUrl:url];
} }
- (void)setNotesUndoable:(NSString *)notes { - (void)setNotesUndoable:(NSString *)notes {
[[KdbEntry undoManager] registerUndoWithTarget:self selector:@selector(setNotesUndoable:) object:self.notes]; [[self undoManager] registerUndoWithTarget:self selector:@selector(setNotesUndoable:) object:self.notes];
[[KdbEntry undoManager] setActionName:NSLocalizedString(@"UNDO_SET_NOTES", "Undo set notes")]; [[self undoManager] setActionName:NSLocalizedString(@"UNDO_SET_NOTES", "Undo set notes")];
[self setLastModificationTime:[NSDate date]]; [self setLastModificationTime:[NSDate date]];
[self setNotes:notes]; [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 @end

View File

@@ -24,12 +24,13 @@
} }
- (void)clear { - (void)clear {
NSUInteger groupCount = [_groups count]; for(KdbGroup *group in self.groups) {
for(NSInteger index = (groupCount - 1); index > -1; index--) { [group clear];
NSUInteger index = [self.groups indexOfObject:group];
[self removeObjectFromGroupsAtIndex:index]; [self removeObjectFromGroupsAtIndex:index];
} }
NSUInteger entryCount = [_entries count]; for(KdbEntry *entry in self.entries) {
for(NSInteger index = (entryCount - 1); index > -1; index--) { NSUInteger index = [self.entries indexOfObject:entry];
[self removeObjectFromEntriesAtIndex:index]; [self removeObjectFromEntriesAtIndex:index];
} }
} }

View File

@@ -17,4 +17,11 @@ APPKIT_EXTERN NSString *const MPGroupNameUndoableKey;
- (NSString *)nameUndoable; - (NSString *)nameUndoable;
- (void)setNameUndoable:(NSString *)newName; - (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 @end

View File

@@ -8,6 +8,7 @@
#import "KdbGroup+Undo.h" #import "KdbGroup+Undo.h"
#import "KdbGroup+KVOAdditions.h" #import "KdbGroup+KVOAdditions.h"
#import "KdbEntry+Undo.h"
NSString *const MPGroupNameUndoableKey = @"nameUndoable"; NSString *const MPGroupNameUndoableKey = @"nameUndoable";
@@ -27,4 +28,83 @@ NSString *const MPGroupNameUndoableKey = @"nameUndoable";
self.name = newName; 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 @end

View File

@@ -73,18 +73,14 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
/* /*
All non-setter undoable actions All non-setter undoable actions
*/ */
- (void)moveGroup:(KdbGroup *)group toGroup:(KdbGroup *)target index:(NSInteger)index;
- (BOOL)group:(KdbGroup *)group isMoveableToGroup:(KdbGroup *)target; - (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; /* TODO in UNDO auslagen */
- (void)group:(KdbGroup *)group addGroup:(KdbGroup *)aGroup atIndex:(NSUInteger)index; - (void)addStringField:(StringField *)field toEntry:(Kdb4Entry *)entry atIndex:(NSUInteger)index;
- (void)group:(KdbGroup *)group removeEntry:(KdbEntry *)entry; - (void)removeStringField:(StringField *)field formEntry:(Kdb4Entry *)entry;
- (void)group:(KdbGroup *)group removeGroup:(KdbGroup *)aGroup;
- (void)entry:(Kdb4Entry *)entry addStringField:(StringField *)field atIndex:(NSUInteger)index; - (void)deleteGroup:(KdbGroup *)group;
- (void)entry:(Kdb4Entry *)entry removeStringField:(StringField *)field; - (void)deleteEntry:(KdbEntry *)entry;
- (void)emptyTrash:(id)sender; - (void)emptyTrash:(id)sender;

View File

@@ -121,15 +121,15 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
- (BOOL)readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError { - (BOOL)readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
/* FIXME: Logfile handling /* FIXME: Logfile handling
self.lockFileURL = [url URLByAppendingPathExtension:@"lock"]; self.lockFileURL = [url URLByAppendingPathExtension:@"lock"];
if([[NSFileManager defaultManager] fileExistsAtPath:[_lockFileURL path]]) { if([[NSFileManager defaultManager] fileExistsAtPath:[_lockFileURL path]]) {
self.readOnly = YES; self.readOnly = YES;
} }
else { else {
[[NSFileManager defaultManager] createFileAtPath:[_lockFileURL path] contents:nil attributes:nil]; [[NSFileManager defaultManager] createFileAtPath:[_lockFileURL path] contents:nil attributes:nil];
_didLockFile = YES; _didLockFile = YES;
self.readOnly = NO; self.readOnly = NO;
} }
*/ */
self.decrypted = NO; self.decrypted = NO;
return YES; return YES;
@@ -294,7 +294,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
if(self.treeV4 && ([self.treeV4.defaultUserName length] > 0)) { if(self.treeV4 && ([self.treeV4.defaultUserName length] > 0)) {
newEntry.title = self.treeV4.defaultUserName; 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 }; NSDictionary *userInfo = @{ MPDocumentEntryKey : newEntry };
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddEntryNotification object:self userInfo:userInfo]; [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddEntryNotification object:self userInfo:userInfo];
return newEntry; return newEntry;
@@ -307,7 +307,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
KdbGroup *newGroup = [self.tree createGroup:parent]; KdbGroup *newGroup = [self.tree createGroup:parent];
newGroup.name = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group"); newGroup.name = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group");
newGroup.image = MPIconFolder; newGroup.image = MPIconFolder;
[self group:parent addGroup:newGroup atIndex:[parent.groups count]]; [parent addGroupUndoable:newGroup atIndex:[parent.groups count]];
NSDictionary *userInfo = @{ MPDocumentGroupKey : newGroup }; NSDictionary *userInfo = @{ MPDocumentGroupKey : newGroup };
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddGroupNotification object:self userInfo:userInfo]; [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddGroupNotification object:self userInfo:userInfo];
return newGroup; return newGroup;
@@ -322,7 +322,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
NSString *title = NSLocalizedString(@"DEFAULT_CUSTOM_FIELD_TITLE", @"Default Titel for new Custom-Fields"); 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"); NSString *value = NSLocalizedString(@"DEFAULT_CUSTOM_FIELD_VALUE", @"Default Value for new Custom-Fields");
StringField *newStringField = [StringField stringFieldWithKey:title andValue:value]; 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; return newStringField;
} }
@@ -363,91 +363,44 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
return isMovable; return isMovable;
} }
- (void)moveEntry:(KdbEntry *)entry toGroup:(KdbGroup *)target index:(NSInteger)index { - (void)deleteEntry:(KdbEntry *)entry {
NSInteger oldIndex = [entry.parent.entries indexOfObject:entry]; if(self.useTrash) {
if(entry.parent == target && oldIndex == index) { if(!self.trash) {
return; // No changes [self _createTrashGroup];
} }
[[[self undoManager] prepareWithInvocationTarget:self] moveEntry:entry toGroup:entry.parent index:oldIndex]; [entry moveToTrashUndoable:self.trash atIndex:[self.trash.entries count]];
if(self.trash == target || self.trash == entry.parent) {
[[self undoManager] setActionName:@"UNDO_DELETE_ENTRY"];
} }
else { 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 { - (void)deleteGroup:(KdbGroup *)group {
[[[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;
}
if(self.useTrash) { if(self.useTrash) {
if(!self.trash) { if(!self.trash) {
[self _createTrashGroup]; [self _createTrashGroup];
} }
[self moveEntry:entry toGroup:self.trash index:[self.trash.entries count]]; [group moveToTrashUndoable:self.trash atIndex:[self.trash.groups count]];
return; }
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 { #pragma mark CustomFields
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];
}
- (void)entry:(Kdb4Entry *)entry addStringField:(StringField *)field atIndex:(NSUInteger)index { - (void)addStringField:(StringField *)field toEntry:(Kdb4Entry *)entry atIndex:(NSUInteger)index {
[[[self undoManager] prepareWithInvocationTarget:self] entry:entry removeStringField:field]; [[[self undoManager] prepareWithInvocationTarget:self] removeStringField:field formEntry:entry];
[[self undoManager] setActionName:NSLocalizedString(@"UNDO_ADD_STRING_FIELD", @"Add Stringfield Undo")]; [[self undoManager] setActionName:NSLocalizedString(@"UNDO_ADD_STRING_FIELD", @"Add Stringfield Undo")];
[entry insertObject:field inStringFieldsAtIndex:index]; [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]; NSInteger index = [entry.stringFields indexOfObject:field];
if(NSNotFound == index) { if(NSNotFound == index) {
return; // Nothing found to be removed 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")]; [[self undoManager] setActionName:NSLocalizedString(@"UNDO_DELETE_STRING_FIELD", @"Delte Stringfield undo")];
[entry removeObjectFromStringFieldsAtIndex:index]; [entry removeObjectFromStringFieldsAtIndex:index];
} }
@@ -455,8 +408,8 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
#pragma mark Actions #pragma mark Actions
- (void)emptyTrash:(id)sender { - (void)emptyTrash:(id)sender {
[[self undoManager] setActionIsDiscardable:YES];
[self.trash clear]; [self.trash clear];
// TODO: Notify that entries should be deslected
} }
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem { - (BOOL)validateMenuItem:(NSMenuItem *)menuItem {

View File

@@ -481,7 +481,7 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
- (void)deleteNode:(id)sender { - (void)deleteNode:(id)sender {
KdbEntry *entry =[self _clickedOrSelectedEntry]; KdbEntry *entry =[self _clickedOrSelectedEntry];
MPDocument *document = [[self windowController] document]; MPDocument *document = [[self windowController] document];
[document group:entry.parent removeEntry:entry]; [document deleteEntry:entry];
} }
- (void)_toggleFilterSpace:(id)sender { - (void)_toggleFilterSpace:(id)sender {

View File

@@ -323,7 +323,7 @@ enum {
MPDocument *document = [[self windowController] document]; MPDocument *document = [[self windowController] document];
NSUInteger index = [sender tag]; NSUInteger index = [sender tag];
Kdb4Entry *entry = (Kdb4Entry *)self.selectedEntry; Kdb4Entry *entry = (Kdb4Entry *)self.selectedEntry;
[document entry:entry removeStringField:(entry.stringFields)[index]]; [document removeStringField:(entry.stringFields)[index] formEntry:entry];
} }
- (IBAction)saveAttachment:(id)sender { - (IBAction)saveAttachment:(id)sender {

View File

@@ -13,6 +13,7 @@
#import "KdbLib.h" #import "KdbLib.h"
#import "KdbGroup+Undo.h" #import "KdbGroup+Undo.h"
#import "KdbEntry+Undo.h"
#import "KdbGroup+MPTreeTools.h" #import "KdbGroup+MPTreeTools.h"
#import "KdbEntry+MPTreeTools.h" #import "KdbEntry+MPTreeTools.h"
@@ -79,7 +80,7 @@
MPDocument *document = [[[outlineView window] windowController] document]; MPDocument *document = [[[outlineView window] windowController] document];
accepted = [document group:_draggedItem isMoveableToGroup:target]; accepted = [document group:_draggedItem isMoveableToGroup:target];
if( accepted ) { if( accepted ) {
[document moveGroup:_draggedItem toGroup:target index:index]; [_draggedItem moveToGroupUndoable:target atIndex:index];
} }
info.animatesToDestination = !accepted; info.animatesToDestination = !accepted;
return accepted; return accepted;
@@ -94,7 +95,7 @@
KdbEntry *draggedEntry = [rootGroup entryForUUID:uuid]; KdbEntry *draggedEntry = [rootGroup entryForUUID:uuid];
if(draggedEntry) { if(draggedEntry) {
if(draggedEntry.parent != target && index == NSOutlineViewDropOnItemIndex) { if(draggedEntry.parent != target && index == NSOutlineViewDropOnItemIndex) {
[document moveEntry:draggedEntry toGroup:target index:index]; [draggedEntry moveToGroupUndoable:target atIndex:index];
return YES; return YES;
} }
} }

View File

@@ -121,18 +121,12 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
} }
- (void)createEntry:(id)sender { - (void)createEntry:(id)sender {
KdbGroup *group = [self _clickedOrSelectedGroup]; MPDocument *document = [[self windowController] document];
if(group) { [document createEntry:[self _clickedOrSelectedGroup]];
MPDocument *document = [[self windowController] document];
[document createEntry:group];
}
} }
- (void)deleteNode:(id)sender { - (void)deleteNode:(id)sender {
KdbGroup *group = [self _clickedOrSelectedGroup]; [[[self windowController] document] deleteGroup:[self _clickedOrSelectedGroup]];
if(group && group.parent) {
[[[self windowController] document] group:group.parent removeGroup:group];
}
} }
#pragma mark NSOutlineViewDelegate #pragma mark NSOutlineViewDelegate

View File

@@ -48,7 +48,7 @@
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>2301</string> <string>2323</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string> <string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key> <key>NSHumanReadableCopyright</key>

View File

@@ -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 <Foundation/Foundation.h>
typedef NS_ENUM(NSUInteger, MPPasswordStrength) {
MPPasswordWeak,
MPPasswordOK,
MPPasswordGood,
MPPasswordStrong,
MPPasswordExcelent,
};
@interface NSString (MPPasswordAnalysis)
- (MPPasswordStrength)passwordStrenght;
@end

View File

@@ -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 <Foundation/Foundation.h>
@interface NSString (PasswordStrenght)
- (NSUInteger)passwordStrenght;
@end

View File

@@ -6,12 +6,12 @@
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. // 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 { - (NSUInteger)passwordStrenght {
return MPPasswordOK; return 0;
} }
@end @end