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.
This commit is contained in:
baldurk
2018-06-15 12:10:23 +01:00
parent efd11bb7f2
commit 4561b55464
4 changed files with 40 additions and 3 deletions
@@ -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);
}
@@ -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<rdcstr>, 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.
+26 -3
View File
@@ -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();
+2
View File
@@ -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(