diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index ea75a1a24..535d71261 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -652,7 +652,7 @@ bool MainWindow2::saveAsNewDocument() void MainWindow2::openStartupFile(const QString& filename) { - if (tryRecoverUnsavedProject()) + if (checkForRecoverableProjects()) { return; } @@ -1568,7 +1568,7 @@ void MainWindow2::displayMessageBoxNoTitle(const QString& body) QMessageBox::information(this, nullptr, tr(qPrintable(body)), QMessageBox::Ok); } -bool MainWindow2::tryRecoverUnsavedProject() +bool MainWindow2::checkForRecoverableProjects() { FileManager fm; QStringList recoverables = fm.searchForUnsavedProjects(); @@ -1578,41 +1578,52 @@ bool MainWindow2::tryRecoverUnsavedProject() return false; } - QString caption = tr("Restore Project?"); - QString text = tr("Pencil2D didn't close correctly. Would you like to restore the project?"); + foreach (const QString path, recoverables) + { + if (tryRecoverProject(path)) + { + return true; + } + } - QString recoverPath = recoverables[0]; - - QMessageBox* msgBox = new QMessageBox(this); - msgBox->setWindowTitle(tr("Restore project")); - msgBox->setWindowModality(Qt::ApplicationModal); - msgBox->setAttribute(Qt::WA_DeleteOnClose); - msgBox->setIconPixmap(QPixmap(":/icons/logo.png")); - msgBox->setText(QString("

%1

%2").arg(caption, text)); - msgBox->setInformativeText(QString("%1").arg(retrieveProjectNameFromTempPath(recoverPath))); - msgBox->setStandardButtons(QMessageBox::Open | QMessageBox::Discard); - msgBox->setProperty("RecoverPath", recoverPath); - hideQuestionMark(*msgBox); - - connect(msgBox, &QMessageBox::finished, this, &MainWindow2::startProjectRecovery); - msgBox->open(); - return true; + return false; } -void MainWindow2::startProjectRecovery(int result) +bool MainWindow2::tryRecoverProject(const QString recoverPath) { - const QMessageBox* msgBox = dynamic_cast(QObject::sender()); - const QString recoverPath = msgBox->property("RecoverPath").toString(); + QString caption = tr("Restore Project?"); + QString text = tr("Pencil2D didn't close correctly. Would you like to restore the project?"); - if (result == QMessageBox::Discard) + QMessageBox msgBox(this); + hideQuestionMark(msgBox); // Must be before setDefaultButton + msgBox.setWindowTitle(tr("Restore project")); + msgBox.setWindowModality(Qt::ApplicationModal); + msgBox.setIconPixmap(QPixmap(":/icons/logo.png")); + msgBox.setText(QString("

%1

%2").arg(caption, text)); + msgBox.setInformativeText(QString("%1").arg(retrieveProjectNameFromTempPath(recoverPath))); + msgBox.setStandardButtons(QMessageBox::Open | QMessageBox::Discard | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Cancel); + + int result = msgBox.exec(); + + switch (result) { - // The user presses discard + case QMessageBox::Discard: QDir(recoverPath).removeRecursively(); - tryLoadPreset(); - return; + return false; + case QMessageBox::Cancel: + return false; + case QMessageBox::Open: + return startProjectRecovery(recoverPath); + default: + Q_ASSERT(false); } - Q_ASSERT(result == QMessageBox::Open); + return false; +} + +bool MainWindow2::startProjectRecovery(const QString recoverPath) +{ FileManager fm; Object* o = fm.recoverUnsavedProject(recoverPath); if (!fm.error().ok()) @@ -1621,7 +1632,7 @@ void MainWindow2::startProjectRecovery(int result) const QString title = tr("Recovery Failed."); const QString text = tr("Sorry! Pencil2D is unable to restore your project"); QMessageBox::information(this, title, QString("

%1

%2").arg(title, text)); - return; + return false; } Q_ASSERT(o); @@ -1632,6 +1643,8 @@ void MainWindow2::startProjectRecovery(int result) const QString title = tr("Recovery Succeeded!"); const QString text = tr("Please save your work immediately to prevent loss of data"); QMessageBox::information(this, title, QString("

%1

%2").arg(title, text)); + + return true; } void MainWindow2::createToolbars() diff --git a/app/src/mainwindow2.h b/app/src/mainwindow2.h index 0aa9cdccd..2025eaff9 100644 --- a/app/src/mainwindow2.h +++ b/app/src/mainwindow2.h @@ -149,8 +149,9 @@ private slots: void makeConnections(Editor*, OnionSkinWidget*); void makeConnections(Editor*, StatusBar*); - bool tryRecoverUnsavedProject(); - void startProjectRecovery(int result); + bool checkForRecoverableProjects(); + bool tryRecoverProject(const QString recoverPath); + bool startProjectRecovery(const QString recoverPath); // UI: Dock widgets ColorBox* mColorBox = nullptr;