From f99eb6c3c8b2f134d87456c3803062d4d8a1e09f Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sat, 3 Sep 2022 11:22:40 +0200 Subject: [PATCH] Set sensible default paths when browsing using FileSelection Previously FileSelection would default to the OBS run dir --- src/utils/file-selection.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/utils/file-selection.cpp b/src/utils/file-selection.cpp index 086ffcfe..ab79921f 100644 --- a/src/utils/file-selection.cpp +++ b/src/utils/file-selection.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include FileSelection::FileSelection(FileSelection::Type type, QWidget *parent) : QWidget(parent), _type(type) @@ -29,12 +31,22 @@ void FileSelection::SetPath(const QString &path) void FileSelection::BrowseButtonClicked() { + QString defaultPath; + if (std::filesystem::exists( + std::filesystem::path(_filePath->text().toStdString()))) { + defaultPath = _filePath->text(); + } else { + defaultPath = QStandardPaths::writableLocation( + QStandardPaths::DesktopLocation); + } + QString path; if (_type == FileSelection::Type::WRITE) { - path = QFileDialog::getSaveFileName(this); + path = QFileDialog::getSaveFileName(this, "", defaultPath); } else { - path = QFileDialog::getOpenFileName(this); + path = QFileDialog::getOpenFileName(this, "", defaultPath); } + if (path.isEmpty()) { return; }