diff --git a/MacPass/KdbGroup+MPTreeTools.h b/MacPass/KdbGroup+MPTreeTools.h index 9f9581ec..51920cdb 100644 --- a/MacPass/KdbGroup+MPTreeTools.h +++ b/MacPass/KdbGroup+MPTreeTools.h @@ -20,4 +20,6 @@ /* Returns the group with the UUID */ - (KdbGroup *)groupForUUID:(UUID *)uuid; +- (BOOL)isAnchestorOfGroup:(KdbGroup *)group; + @end \ No newline at end of file diff --git a/MacPass/KdbGroup+MPTreeTools.m b/MacPass/KdbGroup+MPTreeTools.m index 4853e5e1..4412fa68 100644 --- a/MacPass/KdbGroup+MPTreeTools.m +++ b/MacPass/KdbGroup+MPTreeTools.m @@ -49,4 +49,18 @@ return [filteredGroups lastObject]; } +- (BOOL)isAnchestorOfGroup:(KdbGroup *)group { + if(group == nil) { + return NO; + } + KdbGroup *ancestor = self.parent; + while(ancestor.parent) { + if(group == self) { + return YES; + } + ancestor = ancestor.parent; + } + return NO; +} + @end \ No newline at end of file diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index ca75ea97..13331844 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -83,7 +83,6 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey; /* All non-setter undoable actions */ -- (BOOL)group:(KdbGroup *)group isMoveableToGroup:(KdbGroup *)target; /* TODO in UNDO auslagen */ - (void)addStringField:(StringField *)field toEntry:(Kdb4Entry *)entry atIndex:(NSUInteger)index; diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 9d11e1f4..e9ec7069 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -347,6 +347,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; if(!parent) { return nil; // No parent } + if(parent == self.trash) { + return nil; // no new Groups in trash + } KdbEntry *newEntry = [self.tree createEntry:parent]; newEntry.title = NSLocalizedString(@"DEFAULT_ENTRY_TITLE", @"Title for a newly created entry"); if(self.treeV4 && ([self.treeV4.defaultUserName length] > 0)) { @@ -362,6 +365,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; if(!parent) { return nil; // no parent! } + if(parent == self.trash) { + return nil; // no new Groups in trash + } KdbGroup *newGroup = [self.tree createGroup:parent]; newGroup.name = NSLocalizedString(@"DEFAULT_GROUP_NAME", @"Title for a newly created group"); newGroup.image = MPIconFolder; @@ -385,42 +391,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; 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) { - return; // No changes - } - [[[self undoManager] prepareWithInvocationTarget:self] moveGroup:group toGroup:group.parent index:oldIndex]; - if(self.trash == target) { - [[self undoManager] setActionName:@"UNDO_DELETE_GROUP"]; - } - else { - [[self undoManager] setActionName:@"MOVE_GROUP"]; - } - [group.parent removeObjectFromGroupsAtIndex:oldIndex]; - if(index < 0 || index > [target.groups count] ) { - index = [target.groups count]; - } - [target insertObject:group inGroupsAtIndex:index]; -} - -- (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; -} - - (void)deleteEntry:(KdbEntry *)entry { if(self.useTrash) { if(!self.trash) { diff --git a/MacPass/MPOutlineDataSource.m b/MacPass/MPOutlineDataSource.m index 32bf232f..9660c9a9 100644 --- a/MacPass/MPOutlineDataSource.m +++ b/MacPass/MPOutlineDataSource.m @@ -77,8 +77,7 @@ accepted &= index != NSOutlineViewDropOnItemIndex; accepted &= index != [_draggedItem.parent.groups indexOfObject:_draggedItem]; } - MPDocument *document = [[[outlineView window] windowController] document]; - accepted = [document group:_draggedItem isMoveableToGroup:target]; + accepted = ![_draggedItem isAnchestorOfGroup:target]; if( accepted ) { [_draggedItem moveToGroupUndoable:target atIndex:index]; }