From 6f21bacd82b107b03db829c96567e638b94ada81 Mon Sep 17 00:00:00 2001 From: Cory Bloor Date: Sun, 8 Oct 2017 19:18:27 -0600 Subject: [PATCH] Set default extensions for most save files In most of these cases, the open file dialog won't even display a file without the proper extension, so this helps ensure the user doesn't accidentally misplace their files. The one exception is *.rdc, which could be found without the extension, but could not be opened. --- qrenderdoc/Code/QRDUtils.cpp | 5 +++-- qrenderdoc/Code/QRDUtils.h | 1 + qrenderdoc/Windows/Dialogs/CaptureDialog.cpp | 2 +- qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.cpp | 5 +++-- qrenderdoc/Windows/Dialogs/TextureSaveDialog.cpp | 4 ++-- qrenderdoc/Windows/MainWindow.cpp | 4 ++-- qrenderdoc/Windows/PythonShell.cpp | 2 +- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/qrenderdoc/Code/QRDUtils.cpp b/qrenderdoc/Code/QRDUtils.cpp index 43791add8..e2e11606d 100644 --- a/qrenderdoc/Code/QRDUtils.cpp +++ b/qrenderdoc/Code/QRDUtils.cpp @@ -537,11 +537,12 @@ QString RDDialog::getExecutableFileName(QWidget *parent, const QString &caption, } QString RDDialog::getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, - const QString &filter, QString *selectedFilter, - QFileDialog::Options options) + const QString &filter, const QString &defaultExt, + QString *selectedFilter, QFileDialog::Options options) { QFileDialog fd(parent, caption, dir, filter); fd.setAcceptMode(QFileDialog::AcceptSave); + fd.setDefaultSuffix(defaultExt); fd.setOptions(options); show(&fd); diff --git a/qrenderdoc/Code/QRDUtils.h b/qrenderdoc/Code/QRDUtils.h index d4808fbc0..ecfd91b03 100644 --- a/qrenderdoc/Code/QRDUtils.h +++ b/qrenderdoc/Code/QRDUtils.h @@ -877,6 +877,7 @@ struct RDDialog static QString getSaveFileName(QWidget *parent = NULL, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), + const QString &defaultExt = QString(), QString *selectedFilter = NULL, QFileDialog::Options options = QFileDialog::Options()); }; diff --git a/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp b/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp index 0671d2d79..36967e6b2 100644 --- a/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp +++ b/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp @@ -856,7 +856,7 @@ void CaptureDialog::on_toggleGlobal_clicked() void CaptureDialog::on_saveSettings_clicked() { QString filename = RDDialog::getSaveFileName(this, tr("Save Settings As"), QString(), - tr("Capture settings (*.cap)")); + tr("Capture settings (*.cap)"), lit("cap")); if(!filename.isEmpty()) { diff --git a/qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.cpp b/qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.cpp index 85dd0c78a..2a8501f7a 100644 --- a/qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.cpp +++ b/qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.cpp @@ -353,8 +353,9 @@ void PerformanceCounterSelection::SetSelectedCounters(const QList &c void PerformanceCounterSelection::Save() { - QString filename = RDDialog::getSaveFileName(this, tr("Save File"), QDir::homePath(), - tr("Performance Counter Settings (*.json)")); + QString filename = + RDDialog::getSaveFileName(this, tr("Save File"), QDir::homePath(), + tr("Performance Counter Settings (*.json)"), lit("json")); if(filename.isEmpty()) return; diff --git a/qrenderdoc/Windows/Dialogs/TextureSaveDialog.cpp b/qrenderdoc/Windows/Dialogs/TextureSaveDialog.cpp index 716abb84d..211b2b1ff 100644 --- a/qrenderdoc/Windows/Dialogs/TextureSaveDialog.cpp +++ b/qrenderdoc/Windows/Dialogs/TextureSaveDialog.cpp @@ -526,8 +526,8 @@ void TextureSaveDialog::on_browse_clicked() QString *selectedFilter = NULL; - QString filename = - RDDialog::getSaveFileName(this, tr("Save Texture As"), QString(), filter, selectedFilter); + QString filename = RDDialog::getSaveFileName(this, tr("Save Texture As"), QString(), filter, + QString(), selectedFilter); QFileInfo checkFile(filename); if(!filename.isEmpty()) diff --git a/qrenderdoc/Windows/MainWindow.cpp b/qrenderdoc/Windows/MainWindow.cpp index 2f0f8525b..2cac6c64e 100644 --- a/qrenderdoc/Windows/MainWindow.cpp +++ b/qrenderdoc/Windows/MainWindow.cpp @@ -566,8 +566,8 @@ QString MainWindow::GetSavePath() dir = m_LastSaveCapturePath; } - QString filename = - RDDialog::getSaveFileName(this, tr("Save Capture As"), dir, tr("Capture Files (*.rdc)")); + QString filename = RDDialog::getSaveFileName(this, tr("Save Capture As"), dir, + tr("Capture Files (*.rdc)"), lit("rdc")); if(!filename.isEmpty()) { diff --git a/qrenderdoc/Windows/PythonShell.cpp b/qrenderdoc/Windows/PythonShell.cpp index 2dd990604..27ed350d3 100644 --- a/qrenderdoc/Windows/PythonShell.cpp +++ b/qrenderdoc/Windows/PythonShell.cpp @@ -511,7 +511,7 @@ void PythonShell::on_openScript_clicked() void PythonShell::on_saveScript_clicked() { QString filename = RDDialog::getSaveFileName(this, tr("Save Python Script"), QString(), - tr("Python scripts (*.py)")); + tr("Python scripts (*.py)"), lit("py")); if(!filename.isEmpty()) {