Add code to ensure unique preference pack names.
This commit is contained in:
@@ -94,6 +94,11 @@ void DlgCreateNewPreferencePackImp::setPreferencePackTemplates(const std::vector
|
||||
}
|
||||
}
|
||||
|
||||
void Gui::Dialog::DlgCreateNewPreferencePackImp::setPreferencePackNames(const std::vector<std::string>& usedNames)
|
||||
{
|
||||
_existingPackNames = usedNames;
|
||||
}
|
||||
|
||||
std::vector<Gui::PreferencePackManager::TemplateFile> DlgCreateNewPreferencePackImp::selectedTemplates() const
|
||||
{
|
||||
std::vector<Gui::PreferencePackManager::TemplateFile> results;
|
||||
@@ -149,5 +154,19 @@ void DlgCreateNewPreferencePackImp::on_lineEdit_textEdited(const QString& text)
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty());
|
||||
}
|
||||
|
||||
void Gui::Dialog::DlgCreateNewPreferencePackImp::accept()
|
||||
{
|
||||
// Ensure that the chosen name is either unique, or that the user actually wants to overwrite the old one
|
||||
if (auto chosenName = ui->lineEdit->text().toStdString();
|
||||
std::find(_existingPackNames.begin(), _existingPackNames.end(), chosenName) != _existingPackNames.end()) {
|
||||
auto result = QMessageBox::warning(this, tr("Pack already exists"),
|
||||
tr("A preference pack with that name already exists. Do you want to overwrite it?"),
|
||||
QMessageBox::Yes | QMessageBox::Cancel);
|
||||
if (result == QMessageBox::Cancel)
|
||||
return;
|
||||
}
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
|
||||
#include "moc_DlgCreateNewPreferencePackImp.cpp"
|
||||
|
||||
Reference in New Issue
Block a user