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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2019-08-12 10:00:48 -07:00 committed by Lubomir I. Ivanov
parent 25db28b905
commit 5ffca686c2

View file

@ -1457,8 +1457,20 @@ void MainWindow::loadRecentFiles()
if (!key.startsWith("File_")) if (!key.startsWith("File_"))
continue; continue;
QString file = s.value(key).toString(); 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); recentFiles.append(file);
}
if (recentFiles.count() > NUM_RECENT_FILES) if (recentFiles.count() > NUM_RECENT_FILES)
break; break;
} }
@ -1484,6 +1496,9 @@ void MainWindow::updateRecentFilesMenu()
void MainWindow::addRecentFile(const QString &file, bool update) 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); QString localFile = QDir::toNativeSeparators(file);
int index = recentFiles.indexOf(localFile); int index = recentFiles.indexOf(localFile);
if (index >= 0) if (index >= 0)