From 2898431af8997cc3324feec357703bcb1460c39b Mon Sep 17 00:00:00 2001 From: michael starke Date: Sun, 9 Jun 2013 12:41:28 +0200 Subject: [PATCH] Fixed #5 Draggin to children now not possible --- MacPass/InspectorView.xib | 2 +- MacPass/MPDocument.h | 3 +++ MacPass/MPDocument.m | 31 +++++++++++++++++++++++++++++++ MacPass/MPOutlineDataSource.m | 22 +++++++++++++++++----- MacPass/MacPass-Info.plist | 2 +- 5 files changed, 53 insertions(+), 7 deletions(-) diff --git a/MacPass/InspectorView.xib b/MacPass/InspectorView.xib index c9114e3c..c23043bf 100644 --- a/MacPass/InspectorView.xib +++ b/MacPass/InspectorView.xib @@ -239,6 +239,7 @@ {{212, 286}, {32, 25}} + _NS:22 YES @@ -1422,7 +1423,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - HNHRoundedTextFieldCell com.apple.InterfaceBuilder.CocoaPlugin HNHRoundedTextFieldCell com.apple.InterfaceBuilder.CocoaPlugin diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index 53d4eee0..1fdb85f0 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -39,4 +39,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey; - (void)deleteEntry:(KdbEntry *)entry; - (void)deleteGroup:(KdbGroup *)group; +- (void)moveGroup:(KdbGroup *)group toGroup:(KdbGroup *)target index:(NSInteger)index; +- (BOOL)group:(KdbGroup *)group isMoveableToGroup:(KdbGroup *)target; + @end diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 701a13c8..06e82111 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -14,6 +14,7 @@ #import "KdbPassword.h" #import "MPDatabaseVersion.h" #import "KdbGroup+Undo.h" +#import "KdbGroup+KVOAdditions.h" #import "KdbEntry+Undo.h" NSString *const MPDocumentDidAddGroupNotification = @"MPDocumentDidAddGroupNotification"; @@ -170,5 +171,35 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; } } +- (void)moveGroup:(KdbGroup *)group toGroup:(KdbGroup *)target index:(NSInteger)index { + NSInteger oldIndex = [group.parent.groups indexOfObject:group]; + if(group.parent == target && oldIndex == index) { + return; // No changes + } + [[[self undoManager] prepareWithInvocationTarget:self] moveGroup:group toGroup:group.parent index:oldIndex]; + [[self undoManager] setActionName:@"MOVE_GROUP"]; + [group retain]; // Might get freed in the process + [group.parent removeObjectFromGroupsAtIndex:oldIndex]; + if(index < 0 || index > [target.groups count] ) { + index = [target.groups count]; + } + [target insertObject:group inGroupsAtIndex:index]; + [group release]; +} +- (BOOL)group:(KdbGroup *)group isMoveableToGroup:(KdbGroup *)target { + if(target == nil) { + return NO; + } + BOOL isMovable = YES; + KdbGroup *ancestor = target.parent; + while(ancestor.parent) { + if(ancestor == group) { + isMovable = NO; + break; + } + ancestor = ancestor.parent; + } + return isMovable; +} @end diff --git a/MacPass/MPOutlineDataSource.m b/MacPass/MPOutlineDataSource.m index 374dc274..9889de8e 100644 --- a/MacPass/MPOutlineDataSource.m +++ b/MacPass/MPOutlineDataSource.m @@ -29,14 +29,18 @@ NSString *const MPPasteBoardType = @"com.hicknhack.macpass.pasteboard"; - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id)info proposedItem:(id)item proposedChildIndex:(NSInteger)index { if(_draggedItem) { + info.animatesToDestination = YES; KdbGroup *target = [item representedObject]; if( target == nil) { return NSDragOperationNone; // Draggin over root } - BOOL validParent = ( _draggedItem.parent == target && index != NSOutlineViewDropOnItemIndex); - if(validParent || _draggedItem.parent != target) { + BOOL validTarget = YES; + if( _draggedItem.parent == target ) { + validTarget &= index != NSOutlineViewDropOnItemIndex; + validTarget &= index != [_draggedItem.parent.groups indexOfObject:_draggedItem]; + } + if( validTarget ) { return NSDragOperationMove; - info.animatesToDestination = YES; } } return NSDragOperationNone; @@ -45,9 +49,17 @@ NSString *const MPPasteBoardType = @"com.hicknhack.macpass.pasteboard"; - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id)info item:(id)item childIndex:(NSInteger)index { NSLog(@"Drag %@ to: %@ index: %ld", _draggedItem, [item representedObject], index); KdbGroup *target = [item representedObject]; - BOOL accepted = (target != _draggedItem.parent); + BOOL accepted = YES; + if( _draggedItem.parent == target ) { + accepted &= index != NSOutlineViewDropOnItemIndex; + accepted &= index != [_draggedItem.parent.groups indexOfObject:_draggedItem]; + } info.animatesToDestination = YES; - [_draggedItem moveToGroupUndoable:target]; + MPDocument *document = [[[outlineView window] windowController] document]; + accepted = [document group:_draggedItem isMoveableToGroup:target]; + if( accepted ) { + [document moveGroup:_draggedItem toGroup:target index:index]; + } return accepted; } @end diff --git a/MacPass/MacPass-Info.plist b/MacPass/MacPass-Info.plist index 03086f32..c4b10cc1 100644 --- a/MacPass/MacPass-Info.plist +++ b/MacPass/MacPass-Info.plist @@ -48,7 +48,7 @@ CFBundleSignature ???? CFBundleVersion - ABD + ACC LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSHumanReadableCopyright