diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index b00ee4a4..bc8b0fdf 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -756,7 +756,7 @@ void UBDocumentController::deleteTreeItem(QTreeWidgetItem * item, bool showConfi tr("Are you sure you want to remove the document '%1'?").arg(document->proxy()->metaData(UBSettings::documentName).toString()))) return; - if (!isDocumentInTrash(document)) + if (!document->isInTrash()) moveDocumentToTrash(dynamic_cast(document->parent()), document); else { @@ -1157,11 +1157,6 @@ void UBDocumentController::pageSelectionChanged() selectionChanged(); } -bool UBDocumentController::isDocumentInTrash(UBDocumentProxyTreeItem * document) -{ - return dynamic_cast(document->parent())->isTrashFolder(); -} - bool UBDocumentController::isCurrentSelectionInTrash() { bool selectionIsInTrash = false; @@ -1169,7 +1164,7 @@ bool UBDocumentController::isCurrentSelectionInTrash() // Find the first valid element; no need to check all of them UBDocumentProxyTreeItem * document = dynamic_cast(item); if (document) { - selectionIsInTrash = isDocumentInTrash(document); + selectionIsInTrash = document->isInTrash(); break; } } @@ -1220,7 +1215,7 @@ void UBDocumentController::updateCurrentSelection() UBDocumentProxyTreeItem * document = dynamic_cast(item); if (document) { // No mix between trashed and non-trashed items - if (isDocumentInTrash(document) != selectionIsInTrash) + if (document->isInTrash() != selectionIsInTrash) addToSelection = false; } @@ -1234,9 +1229,15 @@ void UBDocumentController::updateCurrentSelection() if (selectionIsInTrash) addToSelection = false; } + if (!folder && !document) + addToSelection = false; - if (addToSelection) - mCurrentSelection.append(item); + if (addToSelection) { + if (!mCurrentSelection.contains(item)) { + // the .subtract() above doesn't seem to work all the time... + mCurrentSelection.append(item); + } + } else item->setSelected(false); } diff --git a/src/gui/UBDocumentTreeWidget.cpp b/src/gui/UBDocumentTreeWidget.cpp index 7fc34e8f..ea660133 100644 --- a/src/gui/UBDocumentTreeWidget.cpp +++ b/src/gui/UBDocumentTreeWidget.cpp @@ -419,6 +419,17 @@ UBDocumentProxyTreeItem::UBDocumentProxyTreeItem(QTreeWidgetItem * parent, UBDoc parent->insertChild(i, this); } +bool UBDocumentProxyTreeItem::isInTrash() +{ + UBDocumentGroupTreeItem * parentFolder = dynamic_cast(this->parent()); + if (parentFolder) + return parentFolder->isTrashFolder(); + else { + qWarning() << "UBDocumentProxyTreeItem::isInTrash: document has no parent folder. Assuming it is in trash."; + return true; + } +} + UBDocumentGroupTreeItem::UBDocumentGroupTreeItem(QTreeWidgetItem *parent, bool isEditable) : QTreeWidgetItem(parent) diff --git a/src/gui/UBDocumentTreeWidget.h b/src/gui/UBDocumentTreeWidget.h index af78fe56..4856b06c 100644 --- a/src/gui/UBDocumentTreeWidget.h +++ b/src/gui/UBDocumentTreeWidget.h @@ -77,6 +77,8 @@ class UBDocumentProxyTreeItem : public QTreeWidgetItem return mProxy; } + bool isInTrash(); + QPointer mProxy; };