GH-2050 fix cancel button in file browse dialogs filling text fields

This commit is contained in:
Petr Mrázek 2017-12-03 19:21:04 +01:00
parent 95e6f37d39
commit 4bae6fe491
7 changed files with 19 additions and 22 deletions

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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())

View File

@ -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())

View File

@ -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())
{

View File

@ -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);
}
}

View File

@ -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;
}