mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Remove failed parses from recent files menu
This patch will remove all files that fail to parse from the recent files menu. Signed-off-by: Joshua Wambua <joshua@megvel.me.ke> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
76e6420f6b
commit
9cd3d61c11
2 changed files with 50 additions and 6 deletions
|
@ -757,9 +757,8 @@ void MainWindow::addRecentFile(const QStringList &newFiles)
|
|||
QStringList files;
|
||||
QSettings s;
|
||||
|
||||
if (newFiles.isEmpty()) {
|
||||
if (newFiles.isEmpty())
|
||||
return;
|
||||
}
|
||||
|
||||
s.beginGroup("Recent_Files");
|
||||
|
||||
|
@ -792,11 +791,11 @@ void MainWindow::addRecentFile(const QStringList &newFiles)
|
|||
files.removeLast();
|
||||
}
|
||||
|
||||
for (int c = 0; c < 4; c++) {
|
||||
QString key = QString("File_%1").arg(c + 1);
|
||||
for (int c = 1; c <= 4; c++) {
|
||||
QString key = QString("File_%1").arg(c);
|
||||
|
||||
if (files.count() > c) {
|
||||
s.setValue(key, files.at(c));
|
||||
if (files.count() >= c) {
|
||||
s.setValue(key, files.at(c - 1));
|
||||
} else {
|
||||
if (s.contains(key)) {
|
||||
s.remove(key);
|
||||
|
@ -809,6 +808,47 @@ void MainWindow::addRecentFile(const QStringList &newFiles)
|
|||
loadRecentFiles(&s);
|
||||
}
|
||||
|
||||
void MainWindow::removeRecentFile(QStringList failedFiles)
|
||||
{
|
||||
QStringList files;
|
||||
QSettings s;
|
||||
|
||||
if (failedFiles.isEmpty())
|
||||
return;
|
||||
|
||||
s.beginGroup("Recent_Files");
|
||||
|
||||
for (int c = 1; c <= 4; c++) {
|
||||
QString key = QString("File_%1").arg(c);
|
||||
|
||||
if (s.contains(key)) {
|
||||
QString file = s.value(key).toString();
|
||||
files.append(file);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (QString file, failedFiles)
|
||||
files.removeAll(file);
|
||||
|
||||
for (int c = 1; c <= 4; c++) {
|
||||
QString key = QString("File_%1").arg(c);
|
||||
|
||||
if (files.count() >= c) {
|
||||
s.setValue(key, files.at(c - 1));
|
||||
} else {
|
||||
if (s.contains(key))
|
||||
s.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
s.endGroup();
|
||||
s.sync();
|
||||
|
||||
loadRecentFiles(&s);
|
||||
}
|
||||
|
||||
void MainWindow::recentFileTriggered(bool checked)
|
||||
{
|
||||
Q_UNUSED(checked);
|
||||
|
@ -925,6 +965,7 @@ void MainWindow::loadFiles(const QStringList fileNames)
|
|||
|
||||
char *error = NULL;
|
||||
QByteArray fileNamePtr;
|
||||
QStringList failedParses;
|
||||
|
||||
for (int i = 0; i < fileNames.size(); ++i) {
|
||||
fileNamePtr = QFile::encodeName(fileNames.at(i));
|
||||
|
@ -933,6 +974,7 @@ void MainWindow::loadFiles(const QStringList fileNames)
|
|||
setTitle(MWTF_FILENAME);
|
||||
|
||||
if (error != NULL) {
|
||||
failedParses.append(fileNames.at(i));
|
||||
showError(error);
|
||||
free(error);
|
||||
}
|
||||
|
@ -940,6 +982,7 @@ void MainWindow::loadFiles(const QStringList fileNames)
|
|||
|
||||
process_dives(false, false);
|
||||
addRecentFile(fileNames);
|
||||
removeRecentFile(failedParses);
|
||||
|
||||
refreshDisplay();
|
||||
ui.actionAutoGroup->setChecked(autogroup);
|
||||
|
|
|
@ -64,6 +64,7 @@ public:
|
|||
MainTab *information();
|
||||
void loadRecentFiles(QSettings *s);
|
||||
void addRecentFile(const QStringList &newFiles);
|
||||
void removeRecentFile(QStringList failedFiles);
|
||||
DiveListView *dive_list();
|
||||
GlobeGPS *globe();
|
||||
void showError(QString message);
|
||||
|
|
Loading…
Reference in a new issue