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.
This commit is contained in:
Kimmo Varis 2011-05-12 13:30:22 +03:00
parent 15820b87a4
commit 97eff37f28
2 changed files with 43 additions and 1 deletions

View File

@ -948,7 +948,34 @@ void MainWindow::OpenRecentProject()
{
QAction *action = qobject_cast<QAction *>(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();
}

View File

@ -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
*