Adopting new KeePassKit API.

Signed-off-by: michael starke <michael.starke@hicknhack-software.com>
This commit is contained in:
michael starke
2015-08-03 12:56:35 +02:00
parent 0de6f214e6
commit 83a9bc1f74
9 changed files with 25 additions and 23 deletions

View File

@@ -8,7 +8,7 @@
#import "MPDocument.h" #import "MPDocument.h"
@class MPEditSession; @class MPEditingSession;
@interface MPDocument (EditingSession) @interface MPDocument (EditingSession)

View File

@@ -9,7 +9,7 @@
#import "MPDocument+EditingSession.h" #import "MPDocument+EditingSession.h"
#import "KPKNode.h" #import "KPKNode.h"
#import "MPEditSession.h" #import "MPEditingSession.h"
@implementation MPDocument (EditingSession) @implementation MPDocument (EditingSession)
@@ -26,7 +26,7 @@
} }
#pragma mark Private #pragma mark Private
- (void)_commitEditingSession:(MPEditSession *)session { - (void)_commitEditingSession:(MPEditingSession *)session {
if(nil == session) { if(nil == session) {
return; // No session to commit return; // No session to commit
} }
@@ -35,13 +35,13 @@
} }
} }
- (void)_cancelEditingSession:(MPEditSession *)session { - (void)_cancelEditingSession:(MPEditingSession *)session {
if(nil == session) { if(nil == session) {
return; // No session to cancel return; // No session to cancel
} }
[[self.undoManager prepareWithInvocationTarget:self] _commitEditingSession:session]; [[self.undoManager prepareWithInvocationTarget:self] _commitEditingSession:session];
if(session.hasChanges) { if(session.hasChanges) {
[session.node updateTo:session.rollbackNode]; [session.node updateToNode:session.rollbackNode];
} }
} }

View File

@@ -58,7 +58,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
@class KPKAttribute; @class KPKAttribute;
@class KPKCompositeKey; @class KPKCompositeKey;
@class KPKNode; @class KPKNode;
@class MPEditSession; @class MPEditingSession;
@interface MPDocument : NSDocument <MPTargetNodeResolving> @interface MPDocument : NSDocument <MPTargetNodeResolving>
@@ -91,7 +91,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
/* /*
Editing Session Editing Session
*/ */
@property (nonatomic, strong) MPEditSession *editingSession; @property (nonatomic, strong) MPEditingSession *editingSession;
+ (KPKVersion)versionForFileType:(NSString *)fileType; + (KPKVersion)versionForFileType:(NSString *)fileType;
+ (NSString *)fileTypeForVersion:(KPKVersion)version; + (NSString *)fileTypeForVersion:(KPKVersion)version;

View File

@@ -408,7 +408,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
- (void)setTree:(KPKTree *)tree { - (void)setTree:(KPKTree *)tree {
if(_tree != tree) { if(_tree != tree) {
_tree = tree; _tree = tree;
_tree.undoManager = [self undoManager];
if(nil == _treeDelgate) { if(nil == _treeDelgate) {
_treeDelgate = [[MPTreeDelegate alloc] initWithDocument:self]; _treeDelgate = [[MPTreeDelegate alloc] initWithDocument:self];
} }
@@ -516,7 +515,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
if(!self.trash) { if(!self.trash) {
[self _createTrashGroup]; [self _createTrashGroup];
} }
[entry moveToGroup:self.trash atIndex:[self.trash.entries count]]; [entry moveToGroup:self.trash];
[[self undoManager] setActionName:NSLocalizedString(@"TRASH_ENTRY", "Move Entry to Trash")]; [[self undoManager] setActionName:NSLocalizedString(@"TRASH_ENTRY", "Move Entry to Trash")];
} }
else { else {
@@ -626,8 +625,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
- (void)duplicateEntry:(id)sender { - (void)duplicateEntry:(id)sender {
KPKEntry *duplicate = [self.selectedEntry copyWithTitle:nil]; KPKEntry *duplicate = [self.selectedEntry copyWithTitle:nil];
NSInteger index = [self.selectedEntry.parent.entries indexOfObject:self.selectedEntry]; [self.selectedEntry.parent addEntry:duplicate];
[self.selectedEntry.parent addEntry:duplicate atIndex:index+1];
[self.undoManager setActionName:NSLocalizedString(@"DUPLICATE_ENTRY", "")]; [self.undoManager setActionName:NSLocalizedString(@"DUPLICATE_ENTRY", "")];
} }

View File

@@ -12,10 +12,10 @@
@interface MPEditingSession : NSObject @interface MPEditingSession : NSObject
@property (strong, readonly) KPKNode *node; @property (copy, readonly) KPKNode *node;
@property (copy, readonly) KPKNode *rollbackNode; @property (weak, readonly) KPKNode *source;
- (instancetype)initWithNode:(KPKNode *)node; - (instancetype)initWithSource:(KPKNode *)node;
- (BOOL)hasChanges; - (BOOL)hasChanges;

View File

@@ -11,29 +11,29 @@
@interface MPEditingSession () @interface MPEditingSession ()
@property (strong) KPKNode *node; @property (copy) KPKNode *node;
@property (copy) KPKNode *rollbackNode; @property (weak) KPKNode *source;
@end @end
@implementation MPEditingSession @implementation MPEditingSession
- (instancetype)init { - (instancetype)init {
self = [self initWithNode:nil]; self = [self initWithSource:nil];
return self; return self;
} }
- (instancetype)initWithNode:(KPKNode *)node { - (instancetype)initWithSource:(KPKNode *)node {
self = [super init]; self = [super init];
if(self) { if(self) {
self.node = node; self.node = node;
self.rollbackNode = node; self.source = node;
} }
return self; return self;
} }
- (BOOL)hasChanges { - (BOOL)hasChanges {
return [self.node isEqual:self.rollbackNode]; return ![self.node isEqual:self.source];
} }
@end @end

View File

@@ -160,12 +160,12 @@
else if(draggedEntry) { else if(draggedEntry) {
if(copyItem || (nil == self.localDraggedEntry)) { if(copyItem || (nil == self.localDraggedEntry)) {
draggedEntry = [draggedEntry copyWithTitle:nil]; draggedEntry = [draggedEntry copyWithTitle:nil];
[targetGroup addEntry:draggedEntry atIndex:index]; [targetGroup addEntry:draggedEntry];
[targetGroup.undoManager setActionName:NSLocalizedString(@"COPY_ENTRY", "")]; [targetGroup.undoManager setActionName:NSLocalizedString(@"COPY_ENTRY", "")];
return YES; return YES;
} }
else if(self.localDraggedEntry) { else if(self.localDraggedEntry) {
[self.localDraggedEntry moveToGroup:targetGroup atIndex:index]; [self.localDraggedEntry moveToGroup:targetGroup];
[self.localDraggedEntry.undoManager setActionName:NSLocalizedString(@"MOVE_ENTRY", "")]; [self.localDraggedEntry.undoManager setActionName:NSLocalizedString(@"MOVE_ENTRY", "")];
return YES; return YES;
} }

View File

@@ -36,4 +36,8 @@
return (NO == self.document.isReadOnly); return (NO == self.document.isReadOnly);
} }
- (NSUndoManager *)undoManagerForTree:(KPKTree *)tree {
return self.document.undoManager;
}
@end @end