From 5ffca686c21bbe4cf6e2cf370e1bf2c7c50de1ef Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 12 Aug 2019 10:00:48 -0700 Subject: Desktop: show local git repos in recent files But don't show our cloud storage entry (as that is already in the File menu, anyway). This is extremely useful because while you can manually enter a file name to save to (and therefore can use the 'magic' git repo syntax), on most OSs there is no way to enter that non-existing 'file name' (which is the git branch in square brackets) in the file open dialog. Fixes: #2236 Signed-off-by: Dirk Hohndel --- desktop-widgets/mainwindow.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index d25ffe3af..b19062612 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -1457,8 +1457,20 @@ void MainWindow::loadRecentFiles() if (!key.startsWith("File_")) continue; QString file = s.value(key).toString(); - if (QFile::exists(file)) + + // never add our cloud URL to the recent files + if (!same_string(prefs.cloud_git_url, "") && file.startsWith(prefs.cloud_git_url)) + continue; + // but allow local git repos + QRegularExpression gitrepo("(.*)\\[[^]]+]"); + QRegularExpressionMatch match = gitrepo.match(file); + if (match.hasMatch()) { + const QFileInfo gitDirectory(match.captured(1) + "/.git"); + if ((gitDirectory.exists()) && (gitDirectory.isDir())) + recentFiles.append(file); + } else if (QFile::exists(file)) { recentFiles.append(file); + } if (recentFiles.count() > NUM_RECENT_FILES) break; } @@ -1484,6 +1496,9 @@ void MainWindow::updateRecentFilesMenu() void MainWindow::addRecentFile(const QString &file, bool update) { + // never add Subsurface cloud file to the recent files - it has its own menu entry + if (!same_string(prefs.cloud_git_url, "") && file.startsWith(prefs.cloud_git_url)) + return; QString localFile = QDir::toNativeSeparators(file); int index = recentFiles.indexOf(localFile); if (index >= 0) -- cgit v1.2.3-70-g09d2