Check input profile name for duplicates in New/Rename (#4779)
* Check input profile name for duplicates in New/Rename * DRY + separation of concerns * simplify return branching * make readonly function const
This commit is contained in:
parent
5727e1b43d
commit
186ffc235f
|
@ -437,6 +437,11 @@ void ConfigureInput::NewProfile() {
|
|||
if (name.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (IsProfileNameDuplicate(name)) {
|
||||
WarnProposedProfileNameIsDuplicate();
|
||||
return;
|
||||
}
|
||||
|
||||
applyConfiguration();
|
||||
Settings::SaveProfile(ui->profile->currentIndex());
|
||||
Settings::CreateProfile(name.toStdString());
|
||||
|
@ -465,6 +470,20 @@ void ConfigureInput::RenameProfile() {
|
|||
if (new_name.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (IsProfileNameDuplicate(new_name)) {
|
||||
WarnProposedProfileNameIsDuplicate();
|
||||
return;
|
||||
}
|
||||
|
||||
ui->profile->setItemText(ui->profile->currentIndex(), new_name);
|
||||
Settings::RenameCurrentProfile(new_name.toStdString());
|
||||
}
|
||||
|
||||
bool ConfigureInput::IsProfileNameDuplicate(const QString& name) const {
|
||||
return ui->profile->findText(name, Qt::MatchFixedString | Qt::MatchCaseSensitive) != -1;
|
||||
}
|
||||
|
||||
void ConfigureInput::WarnProposedProfileNameIsDuplicate() {
|
||||
QMessageBox::warning(this, tr("Duplicate profile name"),
|
||||
tr("Profile name already exists. Please choose a different name."));
|
||||
}
|
||||
|
|
|
@ -119,4 +119,7 @@ private:
|
|||
void NewProfile();
|
||||
void DeleteProfile();
|
||||
void RenameProfile();
|
||||
|
||||
bool IsProfileNameDuplicate(const QString& name) const;
|
||||
void WarnProposedProfileNameIsDuplicate();
|
||||
};
|
||||
|
|
Reference in New Issue