mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 20:32:43 +00:00
Undo/Redo for add/remove of Stringfields
This commit is contained in:
@@ -24,9 +24,11 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
|
||||
@class KdbTree;
|
||||
@class Kdb4Tree;
|
||||
@class Kdb3Tree;
|
||||
@class Kdb4Entry;
|
||||
@class UUID;
|
||||
@class Binary;
|
||||
@class BinaryRef;
|
||||
@class StringField;
|
||||
@class MPRootAdapter;
|
||||
|
||||
@interface MPDocument : NSDocument
|
||||
@@ -65,6 +67,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
|
||||
/* Undoable Intiialization of elements */
|
||||
- (KdbGroup *)createGroup:(KdbGroup *)parent;
|
||||
- (KdbEntry *)createEntry:(KdbGroup *)parent;
|
||||
- (StringField *)createStringField:(KdbEntry *)entry;
|
||||
|
||||
/*
|
||||
All non-setter undoable actions
|
||||
@@ -74,12 +77,12 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
|
||||
- (BOOL)group:(KdbGroup *)group isMoveableToGroup:(KdbGroup *)target;
|
||||
- (void)moveEntry:(KdbEntry *)entry toGroup:(KdbGroup *)target index:(NSInteger)index;
|
||||
|
||||
- (void)group:(KdbGroup *)group addEntry:(KdbEntry *)entry;
|
||||
- (void)group:(KdbGroup *)group addGroup:(KdbGroup *)aGroup;
|
||||
- (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;
|
||||
|
||||
|
||||
|
||||
- (void)entry:(Kdb4Entry *)entry addStringField:(StringField *)field atIndex:(NSUInteger)index;
|
||||
- (void)entry:(Kdb4Entry *)entry removeStringField:(StringField *)field;
|
||||
|
||||
@end
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#import "KdbGroup+Undo.h"
|
||||
#import "KdbGroup+KVOAdditions.h"
|
||||
#import "Kdb4Entry+KVOAdditions.h"
|
||||
#import "KdbGroup+MPTreeTools.h"
|
||||
#import "KdbEntry+Undo.h"
|
||||
#import "Kdb3Tree+NewTree.h"
|
||||
@@ -256,7 +257,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
|
||||
if(self.treeV4 && ([self.treeV4.defaultUserName length] > 0)) {
|
||||
newEntry.title = self.treeV4.defaultUserName;
|
||||
}
|
||||
[self group:parent addEntry:newEntry];
|
||||
[self group:parent addEntry:newEntry atIndex:[parent.entries count]];
|
||||
NSDictionary *userInfo = @{ MPDocumentEntryKey : newEntry };
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddEntryNotification object:self userInfo:userInfo];
|
||||
return newEntry;
|
||||
@@ -265,12 +266,24 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
|
||||
- (KdbGroup *)createGroup:(KdbGroup *)parent {
|
||||
KdbGroup *newGroup = [self.tree createGroup:parent];
|
||||
newGroup.name = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group");
|
||||
[self group:parent addGroup:newGroup];
|
||||
[self group:parent addGroup:newGroup atIndex:[parent.groups count]];
|
||||
NSDictionary *userInfo = @{ MPDocumentGroupKey : newGroup };
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidAddGroupNotification object:self userInfo:userInfo];
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
- (StringField *)createStringField:(KdbEntry *)entry {
|
||||
// TODO: Localize!
|
||||
if(![entry isKindOfClass:[Kdb4Entry class]]) {
|
||||
return nil;
|
||||
}
|
||||
Kdb4Entry *entryV4 = (Kdb4Entry *)entry;
|
||||
StringField *newStringField = [StringField stringFieldWithKey:@"Title" andValue:@"Value"];
|
||||
[self entry:entryV4 addStringField:newStringField atIndex:[entryV4.stringFields count]];
|
||||
return newStringField;
|
||||
}
|
||||
|
||||
|
||||
- (void)moveGroup:(KdbGroup *)group toGroup:(KdbGroup *)target index:(NSInteger)index {
|
||||
NSInteger oldIndex = [group.parent.groups indexOfObject:group];
|
||||
if(group.parent == target && oldIndex == index) {
|
||||
@@ -316,16 +329,16 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
|
||||
[target insertObject:entry inEntriesAtIndex:index];
|
||||
}
|
||||
|
||||
- (void)group:(KdbGroup *)group addEntry:(KdbEntry *)entry {
|
||||
- (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:[group.entries count]];
|
||||
[group insertObject:entry inEntriesAtIndex:index];
|
||||
}
|
||||
|
||||
- (void)group:(KdbGroup *)group addGroup:(KdbGroup *)aGroup {
|
||||
- (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:[group.groups count]];
|
||||
[group insertObject:aGroup inGroupsAtIndex:index];
|
||||
}
|
||||
|
||||
- (void)group:(KdbGroup *)group removeEntry:(KdbEntry *)entry {
|
||||
@@ -333,7 +346,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
|
||||
if(NSNotFound == index) {
|
||||
return; // No object found;
|
||||
}
|
||||
[[[self undoManager] prepareWithInvocationTarget:self] group:group addEntry:entry];
|
||||
[[[self undoManager] prepareWithInvocationTarget:self] group:group addEntry:entry atIndex:index];
|
||||
[[self undoManager] setActionName:NSLocalizedString(@"UNDO_DELETE_ENTRY", "Undo deleting of entry")];
|
||||
[group removeObjectFromEntriesAtIndex:index];
|
||||
}
|
||||
@@ -343,11 +356,28 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
|
||||
if(NSNotFound == index) {
|
||||
return; // No object found
|
||||
}
|
||||
[[[self undoManager] prepareWithInvocationTarget:self] group:group addGroup:aGroup];
|
||||
[[self undoManager] setActionName:NSLocalizedString(@"UNDO_DELETE_GROUP", @"Create Group Undo")];
|
||||
[[[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 {
|
||||
[[[self undoManager] prepareWithInvocationTarget:self] entry:entry removeStringField:field];
|
||||
[[self undoManager] setActionName:NSLocalizedString(@"UNDO_ADD_STRING_FIELD", @"Add Stringfield Undo")];
|
||||
[entry insertObject:field inStringFieldsAtIndex:index];
|
||||
}
|
||||
|
||||
- (void)entry:(Kdb4Entry *)entry removeStringField:(StringField *)field {
|
||||
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] setActionName:NSLocalizedString(@"UNDO_DELETE_STRING_FIELD", @"Delte Stringfield undo")];
|
||||
[entry removeObjectFromStringFieldsAtIndex:index];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Private
|
||||
- (void)_cleanupLock {
|
||||
if(_didLockFile) {
|
||||
|
||||
@@ -303,14 +303,14 @@ enum {
|
||||
|
||||
#pragma mark Actions
|
||||
- (IBAction)addCustomField:(id)sender {
|
||||
Kdb4Entry *entry = (Kdb4Entry *)self.selectedEntry;
|
||||
StringField *stringField = [StringField stringFieldWithKey:@"Key" andValue:@"Value"];
|
||||
[entry insertObject:stringField inStringFieldsAtIndex:[entry.stringFields count]];
|
||||
MPDocument *document = [[self windowController] document];
|
||||
[document createStringField:self.selectedEntry];
|
||||
}
|
||||
- (IBAction)removeCustomField:(id)sender {
|
||||
NSButton *button = sender;
|
||||
MPDocument *document = [[self windowController] document];
|
||||
NSUInteger index = [sender tag];
|
||||
Kdb4Entry *entry = (Kdb4Entry *)self.selectedEntry;
|
||||
[entry removeObjectFromStringFieldsAtIndex:[button tag]];
|
||||
[document entry:entry removeStringField:[entry.stringFields objectAtIndex:index]];
|
||||
}
|
||||
|
||||
#pragma mark Notificiations
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1407</string>
|
||||
<string>1419</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
|
||||
Reference in New Issue
Block a user