From 23e500090491732786389b7dc9dfb6756ca295b0 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 25 Apr 2024 15:22:11 +0200 Subject: [PATCH] UnsavedChangesDialog: Unselect custom G-codes by default (SPE-2238) --- src/slic3r/GUI/UnsavedChangesDialog.cpp | 55 ++++++++++++++++++++++--- src/slic3r/GUI/UnsavedChangesDialog.hpp | 2 + 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/UnsavedChangesDialog.cpp b/src/slic3r/GUI/UnsavedChangesDialog.cpp index 0fae8a3eb4..9c23ca5b6a 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.cpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.cpp @@ -598,6 +598,29 @@ static std::string get_pure_opt_key(std::string opt_key) return opt_key; } +wxDataViewItem DiffModel::GetItemByName(wxString name) +{ + // add items + for (std::unique_ptr& preset : m_preset_nodes) { + for (std::unique_ptr& category : preset->GetChildren()) { + if (category->text().Contains(name)) + return wxDataViewItem((void*)category.get()); + + for (std::unique_ptr& group : category->GetChildren()) { + if (group->text().Contains(name)) + return wxDataViewItem((void*)group.get()); + + for (std::unique_ptr& option : group->GetChildren()) + if (option->text().Contains(name)) + return wxDataViewItem((void*)option.get()); + } + } + } + + return wxDataViewItem(nullptr); +} + + // ---------------------------------------------------------------------------- // DiffViewCtrl // ---------------------------------------------------------------------------- @@ -742,12 +765,7 @@ void DiffViewCtrl::item_value_changed(wxDataViewEvent& event) return; wxDataViewItem item = event.GetItem(); - - model->UpdateItemEnabling(item); - Refresh(); - - // update an enabling of the "save/move" buttons - m_empty_selection = selected_options().empty(); + update_item_enabling(item); } bool DiffViewCtrl::has_unselected_options() @@ -759,6 +777,16 @@ bool DiffViewCtrl::has_unselected_options() return false; } +void DiffViewCtrl::update_item_enabling(wxDataViewItem item) +{ + + model->UpdateItemEnabling(item); + Refresh(); + + // update an enabling of the "save/move" buttons + m_empty_selection = selected_options().empty(); +} + std::vector DiffViewCtrl::options(Preset::Type type, bool selected) { std::vector ret; @@ -1299,6 +1327,8 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres m_tree->Append("extruders_count", type, _L("General"), _L("Capabilities"), local_label, old_val, mod_val, new_val, category_icon_map.at("General")); } + wxString custom_gcode_local_name = wxEmptyString; + for (const std::string& opt_key : dirty_options) { const Search::Option& option = searcher.get_option(opt_key, type); if (option.opt_key() != opt_key) { @@ -1308,10 +1338,23 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres continue; } + if (custom_gcode_local_name.IsEmpty() && boost::nowide::narrow(option.category) == "Custom G-code") + custom_gcode_local_name = option.category_local; + m_tree->Append(opt_key, type, option.category_local, option.group_local, option.label_local, get_string_value(opt_key, old_config), get_string_value(opt_key, mod_config), m_tree->has_new_value_column() ? get_string_value(opt_key, new_config) : "", category_icon_map.at(option.category)); } + + // Unselect all Custom-Gcodes + if (!custom_gcode_local_name.IsEmpty()) { + wxDataViewItem item = m_tree->model->GetItemByName(custom_gcode_local_name); + if (item.IsOk()) { + wxVariant variant = false; + m_tree->model->SetValue(variant, item, DiffModel::colToggle); + m_tree->update_item_enabling(item); + } + } } // Revert sort of searcher back diff --git a/src/slic3r/GUI/UnsavedChangesDialog.hpp b/src/slic3r/GUI/UnsavedChangesDialog.hpp index d2866dbbcc..5c0740d70e 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.hpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.hpp @@ -175,6 +175,7 @@ public: wxDataViewItem Delete(const wxDataViewItem& item); void Clear(); + wxDataViewItem GetItemByName(wxString name); wxDataViewItem GetParent(const wxDataViewItem& item) const override; unsigned int GetChildren(const wxDataViewItem& parent, wxDataViewItemArray& array) const override; @@ -241,6 +242,7 @@ public: bool has_unselected_options(); bool has_long_strings() { return m_has_long_strings; } bool has_new_value_column() { return this->GetColumnCount() == DiffModel::colMax; } + void update_item_enabling(wxDataViewItem item); std::vector options(Preset::Type type, bool selected); std::vector selected_options();