From 83a9bc1f742bbba76a8b8aa0411297aa4025b4cf Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 3 Aug 2015 12:56:35 +0200 Subject: [PATCH] Adopting new KeePassKit API. Signed-off-by: michael starke --- KeePassKit | 2 +- MacPass/MPDocument+EditingSession.h | 2 +- MacPass/MPDocument+EditingSession.m | 8 ++++---- MacPass/MPDocument.h | 4 ++-- MacPass/MPDocument.m | 6 ++---- MacPass/MPEditingSession.h | 6 +++--- MacPass/MPEditingSession.m | 12 ++++++------ MacPass/MPOutlineDataSource.m | 4 ++-- MacPass/MPTreeDelegate.m | 4 ++++ 9 files changed, 25 insertions(+), 23 deletions(-) diff --git a/KeePassKit b/KeePassKit index c3638841..25b5fd84 160000 --- a/KeePassKit +++ b/KeePassKit @@ -1 +1 @@ -Subproject commit c36388419fc8e615c8fc312446213dfc0d688900 +Subproject commit 25b5fd840b526846f442ffa1b1ca0caa5d933e02 diff --git a/MacPass/MPDocument+EditingSession.h b/MacPass/MPDocument+EditingSession.h index f4562739..ac9819dc 100644 --- a/MacPass/MPDocument+EditingSession.h +++ b/MacPass/MPDocument+EditingSession.h @@ -8,7 +8,7 @@ #import "MPDocument.h" -@class MPEditSession; +@class MPEditingSession; @interface MPDocument (EditingSession) diff --git a/MacPass/MPDocument+EditingSession.m b/MacPass/MPDocument+EditingSession.m index b35770b9..b63f952c 100644 --- a/MacPass/MPDocument+EditingSession.m +++ b/MacPass/MPDocument+EditingSession.m @@ -9,7 +9,7 @@ #import "MPDocument+EditingSession.h" #import "KPKNode.h" -#import "MPEditSession.h" +#import "MPEditingSession.h" @implementation MPDocument (EditingSession) @@ -26,7 +26,7 @@ } #pragma mark Private -- (void)_commitEditingSession:(MPEditSession *)session { +- (void)_commitEditingSession:(MPEditingSession *)session { if(nil == session) { return; // No session to commit } @@ -35,13 +35,13 @@ } } -- (void)_cancelEditingSession:(MPEditSession *)session { +- (void)_cancelEditingSession:(MPEditingSession *)session { if(nil == session) { return; // No session to cancel } [[self.undoManager prepareWithInvocationTarget:self] _commitEditingSession:session]; if(session.hasChanges) { - [session.node updateTo:session.rollbackNode]; + [session.node updateToNode:session.rollbackNode]; } } diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index 775bcfb6..1e4a341b 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -58,7 +58,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey; @class KPKAttribute; @class KPKCompositeKey; @class KPKNode; -@class MPEditSession; +@class MPEditingSession; @interface MPDocument : NSDocument @@ -91,7 +91,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey; /* Editing Session */ -@property (nonatomic, strong) MPEditSession *editingSession; +@property (nonatomic, strong) MPEditingSession *editingSession; + (KPKVersion)versionForFileType:(NSString *)fileType; + (NSString *)fileTypeForVersion:(KPKVersion)version; diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index df190d01..b5906005 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -408,7 +408,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey - (void)setTree:(KPKTree *)tree { if(_tree != tree) { _tree = tree; - _tree.undoManager = [self undoManager]; if(nil == _treeDelgate) { _treeDelgate = [[MPTreeDelegate alloc] initWithDocument:self]; } @@ -516,7 +515,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey if(!self.trash) { [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")]; } else { @@ -626,8 +625,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey - (void)duplicateEntry:(id)sender { KPKEntry *duplicate = [self.selectedEntry copyWithTitle:nil]; - NSInteger index = [self.selectedEntry.parent.entries indexOfObject:self.selectedEntry]; - [self.selectedEntry.parent addEntry:duplicate atIndex:index+1]; + [self.selectedEntry.parent addEntry:duplicate]; [self.undoManager setActionName:NSLocalizedString(@"DUPLICATE_ENTRY", "")]; } diff --git a/MacPass/MPEditingSession.h b/MacPass/MPEditingSession.h index 9e144b94..741574c4 100644 --- a/MacPass/MPEditingSession.h +++ b/MacPass/MPEditingSession.h @@ -12,10 +12,10 @@ @interface MPEditingSession : NSObject -@property (strong, readonly) KPKNode *node; -@property (copy, readonly) KPKNode *rollbackNode; +@property (copy, readonly) KPKNode *node; +@property (weak, readonly) KPKNode *source; -- (instancetype)initWithNode:(KPKNode *)node; +- (instancetype)initWithSource:(KPKNode *)node; - (BOOL)hasChanges; diff --git a/MacPass/MPEditingSession.m b/MacPass/MPEditingSession.m index 18c2536c..fc925aea 100644 --- a/MacPass/MPEditingSession.m +++ b/MacPass/MPEditingSession.m @@ -11,29 +11,29 @@ @interface MPEditingSession () -@property (strong) KPKNode *node; -@property (copy) KPKNode *rollbackNode; +@property (copy) KPKNode *node; +@property (weak) KPKNode *source; @end @implementation MPEditingSession - (instancetype)init { - self = [self initWithNode:nil]; + self = [self initWithSource:nil]; return self; } -- (instancetype)initWithNode:(KPKNode *)node { +- (instancetype)initWithSource:(KPKNode *)node { self = [super init]; if(self) { self.node = node; - self.rollbackNode = node; + self.source = node; } return self; } - (BOOL)hasChanges { - return [self.node isEqual:self.rollbackNode]; + return ![self.node isEqual:self.source]; } @end diff --git a/MacPass/MPOutlineDataSource.m b/MacPass/MPOutlineDataSource.m index 770d74e2..bf346619 100644 --- a/MacPass/MPOutlineDataSource.m +++ b/MacPass/MPOutlineDataSource.m @@ -160,12 +160,12 @@ else if(draggedEntry) { if(copyItem || (nil == self.localDraggedEntry)) { draggedEntry = [draggedEntry copyWithTitle:nil]; - [targetGroup addEntry:draggedEntry atIndex:index]; + [targetGroup addEntry:draggedEntry]; [targetGroup.undoManager setActionName:NSLocalizedString(@"COPY_ENTRY", "")]; return YES; } else if(self.localDraggedEntry) { - [self.localDraggedEntry moveToGroup:targetGroup atIndex:index]; + [self.localDraggedEntry moveToGroup:targetGroup]; [self.localDraggedEntry.undoManager setActionName:NSLocalizedString(@"MOVE_ENTRY", "")]; return YES; } diff --git a/MacPass/MPTreeDelegate.m b/MacPass/MPTreeDelegate.m index 9fa0b171..3b638c4e 100644 --- a/MacPass/MPTreeDelegate.m +++ b/MacPass/MPTreeDelegate.m @@ -36,4 +36,8 @@ return (NO == self.document.isReadOnly); } +- (NSUndoManager *)undoManagerForTree:(KPKTree *)tree { + return self.document.undoManager; +} + @end