Qt: Pay down some technical debt in the shader selector

This commit is contained in:
Vicki Pfau 2020-12-03 23:55:46 -08:00
parent a8a7372083
commit d44a26d962
3 changed files with 13 additions and 15 deletions

View File

@ -184,12 +184,12 @@ QString GBAApp::getSaveFileName(QWidget* owner, const QString& title, const QStr
return filename;
}
QString GBAApp::getOpenDirectoryName(QWidget* owner, const QString& title) {
QString GBAApp::getOpenDirectoryName(QWidget* owner, const QString& title, const QString& path) {
QList<Window*> paused;
pauseAll(&paused);
QString filename = QFileDialog::getExistingDirectory(owner, title, m_configController->getOption("lastDirectory"));
QString filename = QFileDialog::getExistingDirectory(owner, title, !path.isNull() ? path : m_configController->getOption("lastDirectory"));
continueAll(paused);
if (!filename.isEmpty()) {
if (path.isNull() && !filename.isEmpty()) {
m_configController->setOption("lastDirectory", QFileInfo(filename).dir().canonicalPath());
}
return filename;

View File

@ -58,10 +58,10 @@ public:
Window* newWindow();
QString getOpenFileName(QWidget* owner, const QString& title, const QString& filter = QString());
QStringList getOpenFileNames(QWidget* owner, const QString& title, const QString& filter = QString());
QString getSaveFileName(QWidget* owner, const QString& title, const QString& filter = QString());
QString getOpenDirectoryName(QWidget* owner, const QString& title);
QString getOpenFileName(QWidget* owner, const QString& title, const QString& filter = {});
QStringList getOpenFileNames(QWidget* owner, const QString& title, const QString& filter = {});
QString getSaveFileName(QWidget* owner, const QString& title, const QString& filter = {});
QString getOpenDirectoryName(QWidget* owner, const QString& title, const QString& path = {});
const NoIntroDB* gameDB() const { return m_db; }
bool reloadGameDB();

View File

@ -11,6 +11,7 @@
#include "VFileDevice.h"
#include <QCheckBox>
#include <QDir>
#include <QDoubleSpinBox>
#include <QFileDialog>
#include <QFormLayout>
@ -60,14 +61,11 @@ void ShaderSelector::clear() {
}
void ShaderSelector::selectShader() {
QString path(GBAApp::dataDir());
path += QLatin1String("/shaders");
QFileDialog dialog(nullptr, tr("Load shader"), path);
dialog.setFileMode(QFileDialog::Directory);
dialog.exec();
QStringList names = dialog.selectedFiles();
if (names.count() == 1) {
loadShader(names[0]);
QDir path(GBAApp::dataDir());
path.cd(QLatin1String("shaders"));
QString name = GBAApp::app()->getOpenDirectoryName(this, tr("Load shader"), path.absolutePath());
if (!name.isNull()) {
loadShader(name);
refreshShaders();
}
}