From 12f2716f31e09d18d47ffdbb6c06dfb71c6ec8fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 28 Jul 2018 22:08:09 +0200 Subject: [PATCH] GH-2355 Do not allow instances to be created with whitespace prefix or suffix --- application/dialogs/CopyInstanceDialog.cpp | 14 ++++++++++++-- application/dialogs/NewInstanceDialog.cpp | 8 ++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/application/dialogs/CopyInstanceDialog.cpp b/application/dialogs/CopyInstanceDialog.cpp index c565510c..b16684c6 100644 --- a/application/dialogs/CopyInstanceDialog.cpp +++ b/application/dialogs/CopyInstanceDialog.cpp @@ -62,12 +62,22 @@ CopyInstanceDialog::~CopyInstanceDialog() void CopyInstanceDialog::updateDialogState() { - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!instName().isEmpty()); + auto allowOK = !instName().isEmpty(); + auto OkButton = ui->buttonBox->button(QDialogButtonBox::Ok); + if(OkButton->isEnabled() != allowOK) + { + OkButton->setEnabled(allowOK); + } } QString CopyInstanceDialog::instName() const { - return ui->instNameTextBox->text(); + auto result = ui->instNameTextBox->text().trimmed(); + if(result.size()) + { + return result; + } + return QString(); } QString CopyInstanceDialog::iconKey() const diff --git a/application/dialogs/NewInstanceDialog.cpp b/application/dialogs/NewInstanceDialog.cpp index f1247a50..c68d6537 100644 --- a/application/dialogs/NewInstanceDialog.cpp +++ b/application/dialogs/NewInstanceDialog.cpp @@ -165,15 +165,15 @@ void NewInstanceDialog::updateDialogState() QString NewInstanceDialog::instName() const { - auto result = ui->instNameTextBox->text(); + auto result = ui->instNameTextBox->text().trimmed(); if(result.size()) { - return result.trimmed(); + return result; } - result = ui->instNameTextBox->placeholderText(); + result = ui->instNameTextBox->placeholderText().trimmed(); if(result.size()) { - return result.trimmed(); + return result; } return QString(); }