mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +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;
|
QStringList files;
|
||||||
QSettings s;
|
QSettings s;
|
||||||
|
|
||||||
if (newFiles.isEmpty()) {
|
if (newFiles.isEmpty())
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
s.beginGroup("Recent_Files");
|
s.beginGroup("Recent_Files");
|
||||||
|
|
||||||
|
@ -792,11 +791,11 @@ void MainWindow::addRecentFile(const QStringList &newFiles)
|
||||||
files.removeLast();
|
files.removeLast();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int c = 0; c < 4; c++) {
|
for (int c = 1; c <= 4; c++) {
|
||||||
QString key = QString("File_%1").arg(c + 1);
|
QString key = QString("File_%1").arg(c);
|
||||||
|
|
||||||
if (files.count() > c) {
|
if (files.count() >= c) {
|
||||||
s.setValue(key, files.at(c));
|
s.setValue(key, files.at(c - 1));
|
||||||
} else {
|
} else {
|
||||||
if (s.contains(key)) {
|
if (s.contains(key)) {
|
||||||
s.remove(key);
|
s.remove(key);
|
||||||
|
@ -809,6 +808,47 @@ void MainWindow::addRecentFile(const QStringList &newFiles)
|
||||||
loadRecentFiles(&s);
|
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)
|
void MainWindow::recentFileTriggered(bool checked)
|
||||||
{
|
{
|
||||||
Q_UNUSED(checked);
|
Q_UNUSED(checked);
|
||||||
|
@ -925,6 +965,7 @@ void MainWindow::loadFiles(const QStringList fileNames)
|
||||||
|
|
||||||
char *error = NULL;
|
char *error = NULL;
|
||||||
QByteArray fileNamePtr;
|
QByteArray fileNamePtr;
|
||||||
|
QStringList failedParses;
|
||||||
|
|
||||||
for (int i = 0; i < fileNames.size(); ++i) {
|
for (int i = 0; i < fileNames.size(); ++i) {
|
||||||
fileNamePtr = QFile::encodeName(fileNames.at(i));
|
fileNamePtr = QFile::encodeName(fileNames.at(i));
|
||||||
|
@ -933,6 +974,7 @@ void MainWindow::loadFiles(const QStringList fileNames)
|
||||||
setTitle(MWTF_FILENAME);
|
setTitle(MWTF_FILENAME);
|
||||||
|
|
||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
|
failedParses.append(fileNames.at(i));
|
||||||
showError(error);
|
showError(error);
|
||||||
free(error);
|
free(error);
|
||||||
}
|
}
|
||||||
|
@ -940,6 +982,7 @@ void MainWindow::loadFiles(const QStringList fileNames)
|
||||||
|
|
||||||
process_dives(false, false);
|
process_dives(false, false);
|
||||||
addRecentFile(fileNames);
|
addRecentFile(fileNames);
|
||||||
|
removeRecentFile(failedParses);
|
||||||
|
|
||||||
refreshDisplay();
|
refreshDisplay();
|
||||||
ui.actionAutoGroup->setChecked(autogroup);
|
ui.actionAutoGroup->setChecked(autogroup);
|
||||||
|
|
|
@ -64,6 +64,7 @@ public:
|
||||||
MainTab *information();
|
MainTab *information();
|
||||||
void loadRecentFiles(QSettings *s);
|
void loadRecentFiles(QSettings *s);
|
||||||
void addRecentFile(const QStringList &newFiles);
|
void addRecentFile(const QStringList &newFiles);
|
||||||
|
void removeRecentFile(QStringList failedFiles);
|
||||||
DiveListView *dive_list();
|
DiveListView *dive_list();
|
||||||
GlobeGPS *globe();
|
GlobeGPS *globe();
|
||||||
void showError(QString message);
|
void showError(QString message);
|
||||||
|
|
Loading…
Add table
Reference in a new issue