这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 42 additions & 29 deletions app/src/mainwindow2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ bool MainWindow2::saveAsNewDocument()

void MainWindow2::openStartupFile(const QString& filename)
{
if (tryRecoverUnsavedProject())
if (checkForRecoverableProjects())
{
return;
}
Expand Down Expand Up @@ -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();
Expand All @@ -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("<h4>%1</h4>%2").arg(caption, text));
msgBox->setInformativeText(QString("<b>%1</b>").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<QMessageBox*>(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("<h4>%1</h4>%2").arg(caption, text));
msgBox.setInformativeText(QString("<b>%1</b>").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())
Expand All @@ -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("<h4>%1</h4>%2").arg(title, text));
return;
return false;
}

Q_ASSERT(o);
Expand All @@ -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("<h4>%1</h4>%2").arg(title, text));

return true;
}

void MainWindow2::createToolbars()
Expand Down
5 changes: 3 additions & 2 deletions app/src/mainwindow2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading