shutdown after emptying the trashbin
preferencesAboutTextFull
Anatoly Mihalchenko 12 years ago
parent e441f2c2f8
commit 5816a17f57
  1. 310
      src/document/UBDocumentController.cpp
  2. 3
      src/document/UBDocumentController.h

@ -117,8 +117,11 @@ UBDocumentProxyTreeItem* UBDocumentController::findDocument(UBDocumentProxy* pro
void UBDocumentController::selectDocument(UBDocumentProxy* proxy, bool setAsCurrentDocument)
{
if (!proxy)
if (proxy==NULL)
{
setDocument(NULL);
return;
}
QTreeWidgetItemIterator it(mDocumentUI->documentTreeWidget);
@ -531,6 +534,153 @@ void UBDocumentController::duplicateSelectedItem()
}
}
void UBDocumentController::moveDocumentToTrash(UBDocumentGroupTreeItem* groupTi, UBDocumentProxyTreeItem *proxyTi)
{
int index = proxyTi->parent()->indexOfChild(proxyTi);
index --;
if (index >= 0)
{
if (proxyTi->proxy() == mBoardController->selectedDocument())
{
selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(index))->proxy(), true);
}
else
proxyTi->parent()->child(index)->setSelected(true);
}
else if (proxyTi->parent()->childCount() > 1)
{
if (proxyTi->proxy() == mBoardController->selectedDocument())
{
selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(1))->proxy(), true);
}
else
proxyTi->parent()->child(1)->setSelected(true);
}
else
{
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<UBDocumentGroupTreeItem*>(item);
if (!groupItem->isTrashFolder())
{
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(groupTi->groupName());
selectDocument(document, true);
}
}
else
proxyTi->parent()->setSelected(true);
}
QString oldGroupName = proxyTi->proxy()->metaData(UBSettings::documentGroupName).toString();
proxyTi->proxy()->setMetaData(UBSettings::documentGroupName, UBSettings::trashedDocumentGroupNamePrefix + oldGroupName);
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxyTi->proxy());
proxyTi->parent()->removeChild(proxyTi);
mTrashTi->addChild(proxyTi);
proxyTi->setFlags(proxyTi->flags() ^ Qt::ItemIsEditable);
}
void UBDocumentController::moveFolderToTrash(UBDocumentGroupTreeItem* groupTi)
{
bool changeCurrentDocument = false;
for (int i = 0; i < groupTi->childCount(); i++)
{
UBDocumentProxyTreeItem* proxyTi = dynamic_cast<UBDocumentProxyTreeItem*>(groupTi->child(i));
if (proxyTi && proxyTi->proxy() && proxyTi->proxy() == mBoardController->selectedDocument())
{
changeCurrentDocument = true;
break;
}
}
QList<UBDocumentProxyTreeItem*> toBeDeleted;
for (int i = 0; i < groupTi->childCount(); i++)
{
UBDocumentProxyTreeItem* proxyTi = dynamic_cast<UBDocumentProxyTreeItem*>(groupTi->child(i));
if (proxyTi && proxyTi->proxy())
toBeDeleted << proxyTi;
}
for (int i = 0; i < toBeDeleted.count(); i++)
{
UBDocumentProxyTreeItem* proxyTi = toBeDeleted.at(i);
showMessage(QString("Deleting %1").arg(proxyTi->proxy()->metaData(UBSettings::documentName).toString()));
// 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());
groupTi->removeChild(proxyTi);
mTrashTi->addChild(proxyTi);
proxyTi->setFlags(proxyTi->flags() ^ Qt::ItemIsEditable);
showMessage(QString("%1 deleted").arg(groupTi->groupName()));
}
// dont remove default group
if (!groupTi->isDefaultFolder())
{
int index = mDocumentUI->documentTreeWidget->indexOfTopLevelItem(groupTi);
if (index >= 0)
{
mDocumentUI->documentTreeWidget->takeTopLevelItem(index);
}
}
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();
}
void UBDocumentController::deleteSelectedItem()
{
@ -553,79 +703,19 @@ void UBDocumentController::deleteSelectedItem()
{
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 --;
if (index >= 0)
{
if (proxyTi->proxy() == mBoardController->selectedDocument())
{
selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(index))->proxy(), true);
}
else
proxyTi->parent()->child(index)->setSelected(true);
}
else if (proxyTi->parent()->childCount() > 1)
{
if (proxyTi->proxy() == mBoardController->selectedDocument())
{
selectDocument(((UBDocumentProxyTreeItem*)proxyTi->parent()->child(1))->proxy(), true);
}
else
proxyTi->parent()->child(1)->setSelected(true);
}
else
{
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<UBDocumentGroupTreeItem*>(item);
if (!groupItem->isTrashFolder())
{
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(groupTi->groupName());
selectDocument(document, true);
}
}
else
proxyTi->parent()->setSelected(true);
}
QString oldGroupName = proxyTi->proxy()->metaData(UBSettings::documentGroupName).toString();
proxyTi->proxy()->setMetaData(UBSettings::documentGroupName, UBSettings::trashedDocumentGroupNamePrefix + oldGroupName);
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxyTi->proxy());
proxyTi->parent()->removeChild(proxyTi);
mTrashTi->addChild(proxyTi);
proxyTi->setFlags(proxyTi->flags() ^ Qt::ItemIsEditable);
moveDocumentToTrash(groupTi, proxyTi);
}
else
{
// We have to physical delete document
// No action with selection required - document from Trash cant be selected in Board
// We have to physically delete document
proxyTi->parent()->removeChild(proxyTi);
UBPersistenceManager::persistenceManager()->deleteDocument(proxyTi->proxy());
if (mTrashTi->childCount()==0)
selectDocument(NULL);
else
selectDocument(((UBDocumentProxyTreeItem*)mTrashTi->child(0))->proxy());
reloadThumbnails();
}
}
}
@ -666,87 +756,7 @@ void UBDocumentController::deleteSelectedItem()
if(UBApplication::mainWindow->yesNoQuestion(tr("Remove Folder"), tr("Are you sure you want to remove the folder '%1' and all its content?").arg(groupTi->groupName())))
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
bool changeCurrentDocument = false;
for (int i = 0; i < groupTi->childCount(); i++)
{
UBDocumentProxyTreeItem* proxyTi = dynamic_cast<UBDocumentProxyTreeItem*>(groupTi->child(i));
if (proxyTi && proxyTi->proxy() && proxyTi->proxy() == mBoardController->selectedDocument())
{
changeCurrentDocument = true;
break;
}
}
QList<UBDocumentProxyTreeItem*> toBeDeleted;
for (int i = 0; i < groupTi->childCount(); i++)
{
UBDocumentProxyTreeItem* proxyTi = dynamic_cast<UBDocumentProxyTreeItem*>(groupTi->child(i));
if (proxyTi && proxyTi->proxy())
toBeDeleted << proxyTi;
}
for (int i = 0; i < toBeDeleted.count(); i++)
{
UBDocumentProxyTreeItem* proxyTi = toBeDeleted.at(i);
showMessage(QString("Deleting %1").arg(proxyTi->proxy()->metaData(UBSettings::documentName).toString()));
// 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());
groupTi->removeChild(proxyTi);
mTrashTi->addChild(proxyTi);
proxyTi->setFlags(proxyTi->flags() ^ Qt::ItemIsEditable);
showMessage(QString("%1 deleted").arg(groupTi->groupName()));
}
// dont remove default group
if (!groupTi->isDefaultFolder())
{
int index = mDocumentUI->documentTreeWidget->indexOfTopLevelItem(groupTi);
if (index >= 0)
{
mDocumentUI->documentTreeWidget->takeTopLevelItem(index);
}
}
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();
moveFolderToTrash(groupTi);
QApplication::restoreOverrideCursor();
}
}

@ -111,6 +111,9 @@ class UBDocumentController : public UBDocumentContainer
bool mToolsPalettePositionned;
UBDocumentGroupTreeItem* mTrashTi;
void moveDocumentToTrash(UBDocumentGroupTreeItem* groupTi, UBDocumentProxyTreeItem *proxyTi);
void moveFolderToTrash(UBDocumentGroupTreeItem* groupTi);
private slots:
void documentZoomSliderValueChanged (int value);
void loadDocumentProxies();

Loading…
Cancel
Save