Validate folder drop to make sure no folders with the same name are already in the target account
This commit is contained in:
parent
e7c339fb09
commit
beacad1aeb
|
@ -262,10 +262,22 @@ private extension SidebarOutlineDataSource {
|
|||
return accounts
|
||||
}
|
||||
|
||||
func accountHasFolderRepresentingAnyDraggedFolders(_ account: Account, _ draggedFolders: Set<PasteboardFolder>) -> Bool {
|
||||
for draggedFolder in draggedFolders {
|
||||
if account.existingFolder(with: draggedFolder.name) != nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func validateLocalFolderDrop(_ outlineView: NSOutlineView, _ draggedFolder: PasteboardFolder, _ parentNode: Node, _ index: Int) -> NSDragOperation {
|
||||
guard let dropAccount = parentNode.representedObject as? Account, dropAccount.accountID != draggedFolder.accountID else {
|
||||
return SidebarOutlineDataSource.dragOperationNone
|
||||
}
|
||||
if accountHasFolderRepresentingAnyDraggedFolders(dropAccount, Set([draggedFolder])) {
|
||||
return SidebarOutlineDataSource.dragOperationNone
|
||||
}
|
||||
let updatedIndex = indexWhereDraggedFolderWouldAppear(parentNode, draggedFolder)
|
||||
if index != updatedIndex {
|
||||
outlineView.setDropItem(parentNode, dropChildIndex: updatedIndex)
|
||||
|
@ -277,6 +289,9 @@ private extension SidebarOutlineDataSource {
|
|||
guard let dropAccount = parentNode.representedObject as? Account else {
|
||||
return SidebarOutlineDataSource.dragOperationNone
|
||||
}
|
||||
if accountHasFolderRepresentingAnyDraggedFolders(dropAccount, draggedFolders) {
|
||||
return SidebarOutlineDataSource.dragOperationNone
|
||||
}
|
||||
for draggedFolder in draggedFolders {
|
||||
if dropAccount.accountID == draggedFolder.accountID {
|
||||
return SidebarOutlineDataSource.dragOperationNone
|
||||
|
|
Loading…
Reference in New Issue