From 19dd4d1fc7684ce0539ac51a8fba6ef583153824 Mon Sep 17 00:00:00 2001 From: Craig Watson Date: Tue, 23 Feb 2016 12:35:25 +0100 Subject: [PATCH] Fixed documents being accidentally permanently deleted in some cases When both a folder and items it contained were selected, and trashed, the documents could sometimes be deleted twice and thus, permanently deleted when one just intended to move them to the trash. --- src/document/UBDocumentController.cpp | 25 +++++++++++++++++++++++++ src/document/UBDocumentController.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index ef6f3ede..b00ee4a4 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -803,7 +803,19 @@ void UBDocumentController::deleteSelectedItem() tr("Are you sure you want to remove all selected documents?"))) return; + QList foldersToDelete; + foreach (QTreeWidgetItem * item, mCurrentSelection) { + LastSelectedElementType type = itemType(item); + if (type == Document) + deleteTreeItem(item, false); + + else if (type == Folder) + // Delete folders later, to avoid deleting a document twice + foldersToDelete << item; + } + + foreach (QTreeWidgetItem * item, foldersToDelete) { deleteTreeItem(item, false); } } @@ -1824,3 +1836,16 @@ bool UBDocumentController::multipleSelection() QList items = mDocumentUI->documentTreeWidget->selectedItems(); return (items.size() > 1); } + +UBDocumentController::LastSelectedElementType UBDocumentController::itemType(QTreeWidgetItem * item) +{ + UBDocumentProxyTreeItem * document = dynamic_cast(item); + if (document) + return Document; + + UBDocumentGroupTreeItem * folder = dynamic_cast(item); + if (folder) + return Folder; + + return None; +} diff --git a/src/document/UBDocumentController.h b/src/document/UBDocumentController.h index a946f0fe..fc28af0c 100644 --- a/src/document/UBDocumentController.h +++ b/src/document/UBDocumentController.h @@ -135,6 +135,7 @@ class UBDocumentController : public UBDocumentContainer bool multipleSelection(); bool isDocumentInTrash(UBDocumentProxyTreeItem * document); bool isCurrentSelectionInTrash(); + LastSelectedElementType itemType(QTreeWidgetItem * item); private slots: void documentZoomSliderValueChanged (int value);