diff --git a/src/Gui/DlgCreateNewPreferencePackImp.cpp b/src/Gui/DlgCreateNewPreferencePackImp.cpp index 498199f7b6..94af8a73f7 100644 --- a/src/Gui/DlgCreateNewPreferencePackImp.cpp +++ b/src/Gui/DlgCreateNewPreferencePackImp.cpp @@ -94,6 +94,11 @@ void DlgCreateNewPreferencePackImp::setPreferencePackTemplates(const std::vector } } +void Gui::Dialog::DlgCreateNewPreferencePackImp::setPreferencePackNames(const std::vector& usedNames) +{ + _existingPackNames = usedNames; +} + std::vector DlgCreateNewPreferencePackImp::selectedTemplates() const { std::vector 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" diff --git a/src/Gui/DlgCreateNewPreferencePackImp.h b/src/Gui/DlgCreateNewPreferencePackImp.h index 6e4f75058b..b6d0caf705 100644 --- a/src/Gui/DlgCreateNewPreferencePackImp.h +++ b/src/Gui/DlgCreateNewPreferencePackImp.h @@ -55,6 +55,7 @@ public: ~DlgCreateNewPreferencePackImp(); void setPreferencePackTemplates(const std::vector &availableTemplates); + void setPreferencePackNames(const std::vector& usedNames); std::vector 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; std::map _groups; std::vector _templates; QRegExpValidator _nameValidator; + std::vector _existingPackNames; }; } // namespace Dialog diff --git a/src/Gui/DlgGeneralImp.cpp b/src/Gui/DlgGeneralImp.cpp index b4bd12ebea..6f7fc277b9 100644 --- a/src/Gui/DlgGeneralImp.cpp +++ b/src/Gui/DlgGeneralImp.cpp @@ -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(this); newPreferencePackDialog->setPreferencePackTemplates(Application::Instance->prefPackManager()->templateFiles()); + newPreferencePackDialog->setPreferencePackNames(allPacks); connect(newPreferencePackDialog.get(), &DlgCreateNewPreferencePackImp::accepted, this, &DlgGeneralImp::newPreferencePackDialogAccepted); newPreferencePackDialog->open(); }