From d9be3652f5b1eebb46a7c90590ecfa41bc027849 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Tue, 28 Aug 2012 17:08:18 +0300 Subject: [PATCH] SANKORE-985 shutdown after emptying the trashbin --- src/document/UBDocumentController.cpp | 91 ++++++++++++++++++--------- 1 file changed, 62 insertions(+), 29 deletions(-) diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index dbe0707b..4be9ee0f 100755 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -551,8 +551,11 @@ void UBDocumentController::deleteSelectedItem() { if(UBApplication::mainWindow->yesNoQuestion(tr("Remove Document"), tr("Are you sure you want to remove the document '%1'?").arg(proxyTi->proxy()->metaData(UBSettings::documentName).toString()))) { - if (proxyTi->parent() == mTrashTi) + if (proxyTi->parent() != mTrashTi) { + // We have to move document into Trash + // Select another document for processing + // This is for Board, where this document can be selected int index = proxyTi->parent()->indexOfChild(proxyTi); index --; @@ -560,7 +563,7 @@ void UBDocumentController::deleteSelectedItem() { if (proxyTi->proxy() == mBoardController->selectedDocument()) { - selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(index))->proxy()); + selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(index))->proxy(), true); } else proxyTi->parent()->child(index)->setSelected(true); @@ -569,7 +572,7 @@ void UBDocumentController::deleteSelectedItem() { if (proxyTi->proxy() == mBoardController->selectedDocument()) { - selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(1))->proxy()); + selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(1))->proxy(), true); } else proxyTi->parent()->child(1)->setSelected(true); @@ -578,30 +581,36 @@ void UBDocumentController::deleteSelectedItem() { if (proxyTi->proxy() == mBoardController->selectedDocument()) { + bool documentFound = false; for (int i = 0; i < mDocumentUI->documentTreeWidget->topLevelItemCount(); i++) { QTreeWidgetItem* item = mDocumentUI->documentTreeWidget->topLevelItem(i); UBDocumentGroupTreeItem* groupItem = dynamic_cast(item); - if (groupItem != selectedDocumentGroupTreeItem() && groupItem->childCount() > 0) + if (!groupItem->isTrashFolder()) { - selectDocument(((UBDocumentProxyTreeItem*)groupItem->child(0))->proxy()); - break; + for(int j=0; jchildCount(); j++) + { + if (((UBDocumentProxyTreeItem*)groupItem->child(j))->proxy() != mBoardController->selectedDocument()) + { + selectDocument(((UBDocumentProxyTreeItem*)groupItem->child(0))->proxy(), true); + documentFound = true; + break; + } + } } + if (documentFound) + break; + } + if (!documentFound) + { + UBDocumentProxy *document = UBPersistenceManager::persistenceManager()->createDocument(groupTi->groupName()); + selectDocument(document, true); } } else proxyTi->parent()->setSelected(true); } - proxyTi->parent()->removeChild(proxyTi); - - UBPersistenceManager::persistenceManager()->deleteDocument(proxyTi->proxy()); - - reloadThumbnails(); - } - else - { - // Move document to trash QString oldGroupName = proxyTi->proxy()->metaData(UBSettings::documentGroupName).toString(); proxyTi->proxy()->setMetaData(UBSettings::documentGroupName, UBSettings::trashedDocumentGroupNamePrefix + oldGroupName); UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxyTi->proxy()); @@ -610,6 +619,14 @@ void UBDocumentController::deleteSelectedItem() mTrashTi->addChild(proxyTi); proxyTi->setFlags(proxyTi->flags() ^ Qt::ItemIsEditable); } + else + { + // We have to physical delete document + // No action with selection required - document from Trash cant be selected in Board + + proxyTi->parent()->removeChild(proxyTi); + UBPersistenceManager::persistenceManager()->deleteDocument(proxyTi->proxy()); + } } } else if (groupTi) @@ -661,20 +678,6 @@ void UBDocumentController::deleteSelectedItem() } } - if (changeCurrentDocument) - { - for (int i = 0; i < mDocumentUI->documentTreeWidget->topLevelItemCount(); i++) - { - QTreeWidgetItem* item = mDocumentUI->documentTreeWidget->topLevelItem(i); - UBDocumentGroupTreeItem* groupItem = dynamic_cast(item); - if (groupItem != groupTi && groupItem->childCount() > 0) - { - selectDocument(((UBDocumentProxyTreeItem*)groupItem->child(0))->proxy()); - break; - } - } - } - QList toBeDeleted; for (int i = 0; i < groupTi->childCount(); i++) @@ -712,6 +715,36 @@ void UBDocumentController::deleteSelectedItem() } } + if (changeCurrentDocument) + { + bool documentFound = false; + for (int i = 0; i < mDocumentUI->documentTreeWidget->topLevelItemCount(); i++) + { + QTreeWidgetItem* item = mDocumentUI->documentTreeWidget->topLevelItem(i); + UBDocumentGroupTreeItem* groupItem = dynamic_cast(item); + if (!groupItem->isTrashFolder() && groupItem != groupTi) + { + for(int j=0; jchildCount(); j++) + { + if (((UBDocumentProxyTreeItem*)groupItem->child(j))->proxy() != mBoardController->selectedDocument()) + { + selectDocument(((UBDocumentProxyTreeItem*)groupItem->child(0))->proxy(), true); + documentFound = true; + break; + } + } + } + if (documentFound) + break; + } + if (!documentFound) + { + UBDocumentProxy *document = UBPersistenceManager::persistenceManager()->createDocument( UBSettings::defaultDocumentGroupName ); + selectDocument(document, true); + } + } + + reloadThumbnails(); QApplication::restoreOverrideCursor();