From 4bae6fe491c8c92286c4ac9f39e9d4ac846d4f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 3 Dec 2017 19:21:04 +0100 Subject: [PATCH] GH-2050 fix cancel button in file browse dialogs filling text fields --- application/dialogs/ExportInstanceDialog.cpp | 2 +- application/dialogs/SkinUploadDialog.cpp | 4 ++-- application/pages/InstanceSettingsPage.cpp | 4 ++-- .../pages/global/ExternalToolsPage.cpp | 4 ++-- application/pages/global/JavaPage.cpp | 4 ++-- application/pages/global/MultiMCPage.cpp | 21 ++++++++----------- application/setupwizard/JavaWizardPage.cpp | 2 +- 7 files changed, 19 insertions(+), 22 deletions(-) diff --git a/application/dialogs/ExportInstanceDialog.cpp b/application/dialogs/ExportInstanceDialog.cpp index caa15c48..7f3fd937 100644 --- a/application/dialogs/ExportInstanceDialog.cpp +++ b/application/dialogs/ExportInstanceDialog.cpp @@ -388,7 +388,7 @@ bool ExportInstanceDialog::doExport() const QString output = QFileDialog::getSaveFileName( this, tr("Export %1").arg(m_instance->name()), FS::PathCombine(QDir::homePath(), name + ".zip"), "Zip (*.zip)", nullptr, QFileDialog::DontConfirmOverwrite); - if (output.isNull()) + if (output.isEmpty()) { return false; } diff --git a/application/dialogs/SkinUploadDialog.cpp b/application/dialogs/SkinUploadDialog.cpp index ebbab785..287aaf7e 100644 --- a/application/dialogs/SkinUploadDialog.cpp +++ b/application/dialogs/SkinUploadDialog.cpp @@ -54,11 +54,11 @@ void SkinUploadDialog::on_buttonBox_accepted() void SkinUploadDialog::on_skinBrowseBtn_clicked() { QString raw_path = QFileDialog::getOpenFileName(this, tr("Select Skin Texture"), QString(), "*.png"); - QString cooked_path = FS::NormalizePath(raw_path); - if (cooked_path.isEmpty() || !QFileInfo::exists(cooked_path)) + if (raw_path.isEmpty() || !QFileInfo::exists(raw_path)) { return; } + QString cooked_path = FS::NormalizePath(raw_path); ui->skinPathTextBox->setText(cooked_path); } diff --git a/application/pages/InstanceSettingsPage.cpp b/application/pages/InstanceSettingsPage.cpp index 90c2e92e..b146ffd8 100644 --- a/application/pages/InstanceSettingsPage.cpp +++ b/application/pages/InstanceSettingsPage.cpp @@ -212,13 +212,13 @@ void InstanceSettingsPage::on_javaDetectBtn_clicked() void InstanceSettingsPage::on_javaBrowseBtn_clicked() { QString raw_path = QFileDialog::getOpenFileName(this, tr("Find Java executable")); - QString cooked_path = FS::NormalizePath(raw_path); // do not allow current dir - it's dirty. Do not allow dirs that don't exist - if(cooked_path.isEmpty()) + if(raw_path.isEmpty()) { return; } + QString cooked_path = FS::NormalizePath(raw_path); QFileInfo javaInfo(cooked_path);; if(!javaInfo.exists() || !javaInfo.isExecutable()) diff --git a/application/pages/global/ExternalToolsPage.cpp b/application/pages/global/ExternalToolsPage.cpp index b446fc06..a1a029ff 100644 --- a/application/pages/global/ExternalToolsPage.cpp +++ b/application/pages/global/ExternalToolsPage.cpp @@ -206,12 +206,12 @@ void ExternalToolsPage::on_jsonEditorBrowseBtn_clicked() ? QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation).first() #endif : ui->jsonEditorTextBox->text()); - QString cooked_file = FS::NormalizePath(raw_file); - if (cooked_file.isEmpty()) + if (raw_file.isEmpty()) { return; } + QString cooked_file = FS::NormalizePath(raw_file); // it has to exist and be an executable if (QFileInfo(cooked_file).exists() && QFileInfo(cooked_file).isExecutable()) diff --git a/application/pages/global/JavaPage.cpp b/application/pages/global/JavaPage.cpp index 81c6f7a7..1c1e7658 100644 --- a/application/pages/global/JavaPage.cpp +++ b/application/pages/global/JavaPage.cpp @@ -131,14 +131,14 @@ void JavaPage::on_javaDetectBtn_clicked() void JavaPage::on_javaBrowseBtn_clicked() { QString raw_path = QFileDialog::getOpenFileName(this, tr("Find Java executable")); - QString cooked_path = FS::NormalizePath(raw_path); // do not allow current dir - it's dirty. Do not allow dirs that don't exist - if(cooked_path.isEmpty()) + if(raw_path.isEmpty()) { return; } + QString cooked_path = FS::NormalizePath(raw_path); QFileInfo javaInfo(cooked_path);; if(!javaInfo.exists() || !javaInfo.isExecutable()) { diff --git a/application/pages/global/MultiMCPage.cpp b/application/pages/global/MultiMCPage.cpp index d945de94..88c3a3b1 100644 --- a/application/pages/global/MultiMCPage.cpp +++ b/application/pages/global/MultiMCPage.cpp @@ -94,13 +94,12 @@ bool MultiMCPage::apply() void MultiMCPage::on_instDirBrowseBtn_clicked() { - QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Instance Folder"), - ui->instDirTextBox->text()); - QString cooked_dir = FS::NormalizePath(raw_dir); + QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Instance Folder"), ui->instDirTextBox->text()); // do not allow current dir - it's dirty. Do not allow dirs that don't exist - if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) + if (!raw_dir.isEmpty() && QDir(raw_dir).exists()) { + QString cooked_dir = FS::NormalizePath(raw_dir); if (FS::checkProblemticPathJava(QDir(cooked_dir))) { QMessageBox warning; @@ -127,25 +126,23 @@ void MultiMCPage::on_instDirBrowseBtn_clicked() void MultiMCPage::on_iconsDirBrowseBtn_clicked() { - QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Icons Folder"), - ui->iconsDirTextBox->text()); - QString cooked_dir = FS::NormalizePath(raw_dir); + QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Icons Folder"), ui->iconsDirTextBox->text()); // do not allow current dir - it's dirty. Do not allow dirs that don't exist - if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) + if (!raw_dir.isEmpty() && QDir(raw_dir).exists()) { + QString cooked_dir = FS::NormalizePath(raw_dir); ui->iconsDirTextBox->setText(cooked_dir); } } void MultiMCPage::on_modsDirBrowseBtn_clicked() { - QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Mods Folder"), - ui->modsDirTextBox->text()); - QString cooked_dir = FS::NormalizePath(raw_dir); + QString raw_dir = QFileDialog::getExistingDirectory(this, tr("Mods Folder"), ui->modsDirTextBox->text()); // do not allow current dir - it's dirty. Do not allow dirs that don't exist - if (!cooked_dir.isEmpty() && QDir(cooked_dir).exists()) + if (!raw_dir.isEmpty() && QDir(raw_dir).exists()) { + QString cooked_dir = FS::NormalizePath(raw_dir); ui->modsDirTextBox->setText(cooked_dir); } } diff --git a/application/setupwizard/JavaWizardPage.cpp b/application/setupwizard/JavaWizardPage.cpp index 50f61681..deeb5ffe 100644 --- a/application/setupwizard/JavaWizardPage.cpp +++ b/application/setupwizard/JavaWizardPage.cpp @@ -263,7 +263,7 @@ void JavaWizardPage::on_javaBrowseBtn_clicked() filter = "Java (java)"; #endif QString raw_path = QFileDialog::getOpenFileName(this, tr("Find Java executable"), QString(), filter); - if(raw_path.isNull()) + if(raw_path.isEmpty()) { return; }