Merge remote-tracking branch 'remotes/origin/anatoly_dev' into develop

preferencesAboutTextFull
Anatoly Mihalchenko 12 years ago
commit 5273261870
  1. 91
      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(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); int index = proxyTi->parent()->indexOfChild(proxyTi);
index --; index --;
@ -560,7 +563,7 @@ void UBDocumentController::deleteSelectedItem()
{ {
if (proxyTi->proxy() == mBoardController->selectedDocument()) if (proxyTi->proxy() == mBoardController->selectedDocument())
{ {
selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(index))->proxy()); selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(index))->proxy(), true);
} }
else else
proxyTi->parent()->child(index)->setSelected(true); proxyTi->parent()->child(index)->setSelected(true);
@ -569,7 +572,7 @@ void UBDocumentController::deleteSelectedItem()
{ {
if (proxyTi->proxy() == mBoardController->selectedDocument()) if (proxyTi->proxy() == mBoardController->selectedDocument())
{ {
selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(1))->proxy()); selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(1))->proxy(), true);
} }
else else
proxyTi->parent()->child(1)->setSelected(true); proxyTi->parent()->child(1)->setSelected(true);
@ -578,30 +581,36 @@ void UBDocumentController::deleteSelectedItem()
{ {
if (proxyTi->proxy() == mBoardController->selectedDocument()) if (proxyTi->proxy() == mBoardController->selectedDocument())
{ {
bool documentFound = false;
for (int i = 0; i < mDocumentUI->documentTreeWidget->topLevelItemCount(); i++) for (int i = 0; i < mDocumentUI->documentTreeWidget->topLevelItemCount(); i++)
{ {
QTreeWidgetItem* item = mDocumentUI->documentTreeWidget->topLevelItem(i); QTreeWidgetItem* item = mDocumentUI->documentTreeWidget->topLevelItem(i);
UBDocumentGroupTreeItem* groupItem = dynamic_cast<UBDocumentGroupTreeItem*>(item); UBDocumentGroupTreeItem* groupItem = dynamic_cast<UBDocumentGroupTreeItem*>(item);
if (groupItem != selectedDocumentGroupTreeItem() && groupItem->childCount() > 0) if (!groupItem->isTrashFolder())
{ {
selectDocument(((UBDocumentProxyTreeItem*)groupItem->child(0))->proxy()); for(int j=0; j<groupItem->childCount(); j++)
break; {
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 else
proxyTi->parent()->setSelected(true); 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(); QString oldGroupName = proxyTi->proxy()->metaData(UBSettings::documentGroupName).toString();
proxyTi->proxy()->setMetaData(UBSettings::documentGroupName, UBSettings::trashedDocumentGroupNamePrefix + oldGroupName); proxyTi->proxy()->setMetaData(UBSettings::documentGroupName, UBSettings::trashedDocumentGroupNamePrefix + oldGroupName);
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxyTi->proxy()); UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxyTi->proxy());
@ -610,6 +619,14 @@ void UBDocumentController::deleteSelectedItem()
mTrashTi->addChild(proxyTi); mTrashTi->addChild(proxyTi);
proxyTi->setFlags(proxyTi->flags() ^ Qt::ItemIsEditable); 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) 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<UBDocumentGroupTreeItem*>(item);
if (groupItem != groupTi && groupItem->childCount() > 0)
{
selectDocument(((UBDocumentProxyTreeItem*)groupItem->child(0))->proxy());
break;
}
}
}
QList<UBDocumentProxyTreeItem*> toBeDeleted; QList<UBDocumentProxyTreeItem*> toBeDeleted;
for (int i = 0; i < groupTi->childCount(); i++) 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<UBDocumentGroupTreeItem*>(item);
if (!groupItem->isTrashFolder() && groupItem != groupTi)
{
for(int j=0; j<groupItem->childCount(); 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(); reloadThumbnails();
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();

Loading…
Cancel
Save