From 4561b55464f10efb9f4511f640c1d05863e9bef7 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 15 Jun 2018 12:10:23 +0100 Subject: [PATCH] Persist a default browse directory for file dialogs, if none is provided * This provides a slightly more sensible default than the application working directory. * The default is shared across all dialogs and open/save. --- .../Code/Interface/PersistantConfig.cpp | 4 +++ qrenderdoc/Code/Interface/PersistantConfig.h | 8 +++++ qrenderdoc/Code/QRDUtils.cpp | 29 +++++++++++++++++-- qrenderdoc/Code/QRDUtils.h | 2 ++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/qrenderdoc/Code/Interface/PersistantConfig.cpp b/qrenderdoc/Code/Interface/PersistantConfig.cpp index 897d3efd1..87d7bc958 100644 --- a/qrenderdoc/Code/Interface/PersistantConfig.cpp +++ b/qrenderdoc/Code/Interface/PersistantConfig.cpp @@ -287,6 +287,8 @@ bool PersistantConfig::Load(const rdcstr &filename) RENDERDOC_SetConfigSetting("Disassembly_FriendlyNaming", ShaderViewer_FriendlyNaming ? "1" : "0"); + RDDialog::DefaultBrowsePath = LastFileBrowsePath; + // localhost should always be available as a remote host bool foundLocalhost = false; @@ -396,6 +398,8 @@ bool PersistantConfig::Save() RENDERDOC_SetConfigSetting("Disassembly_FriendlyNaming", ShaderViewer_FriendlyNaming ? "1" : "0"); + LastFileBrowsePath = RDDialog::DefaultBrowsePath; + return Serialize(m_Filename); } diff --git a/qrenderdoc/Code/Interface/PersistantConfig.h b/qrenderdoc/Code/Interface/PersistantConfig.h index 33541c8ac..e3d5d1269 100644 --- a/qrenderdoc/Code/Interface/PersistantConfig.h +++ b/qrenderdoc/Code/Interface/PersistantConfig.h @@ -167,6 +167,8 @@ DECLARE_REFLECTION_STRUCT(BugReport); \ CONFIG_SETTING_VAL(public, QString, rdcstr, LastCaptureFilePath, "") \ \ + CONFIG_SETTING_VAL(public, QString, rdcstr, LastFileBrowsePath, "") \ + \ CONFIG_SETTING(public, QVariantList, rdcarray, RecentCaptureFiles) \ \ CONFIG_SETTING_VAL(public, QString, rdcstr, LastCapturePath, "") \ @@ -332,6 +334,12 @@ For more information about some of these settings that are user-facing see The path to the last capture to be opened, which is useful as a default location for browsing. +.. data:: LastFileBrowsePath + + The path to the last file browsed to in any dialog. Used as a default location for all file + browsers without another explicit default directory (such as opening capture files - see + :data:`LastCaptureFilePath`). + .. data:: RecentCaptureFiles A ``list`` of ``str`` with the recently opened capture files. diff --git a/qrenderdoc/Code/QRDUtils.cpp b/qrenderdoc/Code/QRDUtils.cpp index c54b8200b..973ee25ba 100644 --- a/qrenderdoc/Code/QRDUtils.cpp +++ b/qrenderdoc/Code/QRDUtils.cpp @@ -859,6 +859,8 @@ bool GUIInvoke::onUIThread() return qApp->thread() == QThread::currentThread(); } +QString RDDialog::DefaultBrowsePath; + const QMessageBox::StandardButtons RDDialog::YesNoCancel = QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); @@ -978,7 +980,11 @@ QString RDDialog::getOpenFileName(QWidget *parent, const QString &caption, const const QString &filter, QString *selectedFilter, QFileDialog::Options options) { - QFileDialog fd(parent, caption, dir, filter); + QString d = dir; + if(d.isEmpty()) + d = DefaultBrowsePath; + + QFileDialog fd(parent, caption, d, filter); fd.setFileMode(QFileDialog::ExistingFile); fd.setAcceptMode(QFileDialog::AcceptOpen); fd.setOptions(options); @@ -991,7 +997,10 @@ QString RDDialog::getOpenFileName(QWidget *parent, const QString &caption, const QStringList files = fd.selectedFiles(); if(!files.isEmpty()) + { + DefaultBrowsePath = QFileInfo(files[0]).dir().absolutePath(); return files[0]; + } } return QString(); @@ -1000,6 +1009,10 @@ QString RDDialog::getOpenFileName(QWidget *parent, const QString &caption, const QString RDDialog::getExecutableFileName(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options) { + QString d = dir; + if(d.isEmpty()) + d = DefaultBrowsePath; + QString filter; #if defined(Q_OS_WIN32) @@ -1007,7 +1020,7 @@ QString RDDialog::getExecutableFileName(QWidget *parent, const QString &caption, filter = QApplication::translate("RDDialog", "Executables (*.exe);;All Files (*)"); #endif - QFileDialog fd(parent, caption, dir, filter); + QFileDialog fd(parent, caption, d, filter); fd.setOptions(options); fd.setAcceptMode(QFileDialog::AcceptOpen); fd.setFileMode(QFileDialog::ExistingFile); @@ -1022,7 +1035,10 @@ QString RDDialog::getExecutableFileName(QWidget *parent, const QString &caption, { QStringList files = fd.selectedFiles(); if(!files.isEmpty()) + { + DefaultBrowsePath = QFileInfo(files[0]).dir().absolutePath(); return files[0]; + } } return QString(); @@ -1045,7 +1061,11 @@ QString RDDialog::getSaveFileName(QWidget *parent, const QString &caption, const const QString &filter, QString *selectedFilter, QFileDialog::Options options) { - QFileDialog fd(parent, caption, dir, filter); + QString d = dir; + if(d.isEmpty()) + d = DefaultBrowsePath; + + QFileDialog fd(parent, caption, d, filter); fd.setAcceptMode(QFileDialog::AcceptSave); fd.setOptions(options); const QStringList &defaultSuffixes = getDefaultSuffixesFromFilter(filter); @@ -1064,7 +1084,10 @@ QString RDDialog::getSaveFileName(QWidget *parent, const QString &caption, const QStringList files = fd.selectedFiles(); if(!files.isEmpty()) + { + DefaultBrowsePath = QFileInfo(files[0]).dir().absolutePath(); return files[0]; + } } return QString(); diff --git a/qrenderdoc/Code/QRDUtils.h b/qrenderdoc/Code/QRDUtils.h index eefd7aa95..6a6dd6238 100644 --- a/qrenderdoc/Code/QRDUtils.h +++ b/qrenderdoc/Code/QRDUtils.h @@ -442,6 +442,8 @@ struct RDDialog { static const QMessageBox::StandardButtons YesNoCancel; + static QString DefaultBrowsePath; + static void show(QMenu *menu, QPoint pos); static int show(QDialog *dialog); static QMessageBox::StandardButton messageBox(