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"
|
||||
|
||||
@@ -55,6 +55,7 @@ public:
|
||||
~DlgCreateNewPreferencePackImp();
|
||||
|
||||
void setPreferencePackTemplates(const std::vector<PreferencePackManager::TemplateFile> &availableTemplates);
|
||||
void setPreferencePackNames(const std::vector<std::string>& usedNames);
|
||||
|
||||
std::vector<PreferencePackManager::TemplateFile> selectedTemplates() const;
|
||||
std::string preferencePackName() const;
|
||||
@@ -65,11 +66,14 @@ protected Q_SLOTS:
|
||||
|
||||
void on_lineEdit_textEdited(const QString &text);
|
||||
|
||||
void accept() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui_DlgCreateNewPreferencePack> ui;
|
||||
std::map<std::string, QTreeWidgetItem*> _groups;
|
||||
std::vector<PreferencePackManager::TemplateFile> _templates;
|
||||
QRegExpValidator _nameValidator;
|
||||
std::vector<std::string> _existingPackNames;
|
||||
};
|
||||
|
||||
} // namespace Dialog
|
||||
|
||||
@@ -359,8 +359,15 @@ void DlgGeneralImp::preferencePackSelectionChanged()
|
||||
void DlgGeneralImp::saveAsNewPreferencePack()
|
||||
{
|
||||
// Create and run a modal New PreferencePack dialog box
|
||||
auto appearancePacks = Application::Instance->prefPackManager()->preferencePackNames(PreferencePack::Type::Appearance);
|
||||
auto behaviorPacks = Application::Instance->prefPackManager()->preferencePackNames(PreferencePack::Type::Behavior);
|
||||
auto combinationPacks = Application::Instance->prefPackManager()->preferencePackNames(PreferencePack::Type::Combination);
|
||||
auto allPacks = appearancePacks;
|
||||
allPacks.insert(allPacks.end(), behaviorPacks.begin(), behaviorPacks.end());
|
||||
allPacks.insert(allPacks.end(), combinationPacks.begin(), combinationPacks.end());
|
||||
newPreferencePackDialog = std::make_unique<DlgCreateNewPreferencePackImp>(this);
|
||||
newPreferencePackDialog->setPreferencePackTemplates(Application::Instance->prefPackManager()->templateFiles());
|
||||
newPreferencePackDialog->setPreferencePackNames(allPacks);
|
||||
connect(newPreferencePackDialog.get(), &DlgCreateNewPreferencePackImp::accepted, this, &DlgGeneralImp::newPreferencePackDialogAccepted);
|
||||
newPreferencePackDialog->open();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user