From 97eff37f286092d90c5ba36c7612e79c160e6124 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Thu, 12 May 2011 13:30:22 +0300 Subject: [PATCH] GUI: Handle non-existing projects in MRU list. If the project file in MRU list does not exist ask user if one wants to remove the file from the list. If user agrees then the file is removed from the list. Otherwise the file is left to the list but not tried to open. User may have accidentally moved or renamed the file so we give a possibility to add it back and not just blindly removing it from the list. --- gui/mainwindow.cpp | 38 +++++++++++++++++++++++++++++++++++++- gui/mainwindow.h | 6 ++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 7bbd793ec..885e6feb4 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -948,7 +948,34 @@ void MainWindow::OpenRecentProject() { QAction *action = qobject_cast(sender()); if (action) - LoadProjectFile(action->data().toString()); + { + const QString project = action->data().toString(); + QFileInfo inf(project); + if (inf.exists()) + { + LoadProjectFile(project); + } + else + { + QString text(tr("The project file\n\n%1\n\n could not be found!\n\n" + "Do you want to remove the file from the recently " + "used projects -list?").arg(project)); + + QMessageBox msg(QMessageBox::Warning, + tr("Cppcheck"), + text, + QMessageBox::Yes | QMessageBox::No, + this); + + msg.setDefaultButton(QMessageBox::No); + int rv = msg.exec(); + if (rv == QMessageBox::Yes) + { + RemoveProjectMRU(project); + } + + } + } } void MainWindow::UpdateMRUMenuItems() @@ -986,3 +1013,12 @@ void MainWindow::AddProjectMRU(const QString &project) mSettings->setValue(SETTINGS_MRU_PROJECTS, files); UpdateMRUMenuItems(); } + +void MainWindow::RemoveProjectMRU(const QString &project) +{ + QStringList files = mSettings->value(SETTINGS_MRU_PROJECTS).toStringList(); + files.removeAll(project); + + mSettings->setValue(SETTINGS_MRU_PROJECTS, files); + UpdateMRUMenuItems(); +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 7d9f6272f..62ed4d807 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -405,6 +405,12 @@ protected: */ void AddProjectMRU(const QString &project); + /** + * @brief Remove project file (path) from the MRU list. + * @param project Full path of the project file to remove. + */ + void RemoveProjectMRU(const QString &project); + /** * @brief Program settings *