From 78208620c0a044fb0b1d602df29846e8af3c1a93 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 22 Mar 2018 09:37:42 +0100 Subject: [PATCH] Correct updating of "Undo"-buttons according to the option changes --- xs/src/slic3r/GUI/Tab.cpp | 35 ++++++++++++++++++++++++++++++----- xs/src/slic3r/GUI/Tab.hpp | 7 +++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index 926679664..52b7ea94e 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -293,7 +293,7 @@ void Tab::update_changed_ui() Field* field = get_field(opt_key); if (field == nullptr) continue; std::string icon = wxMSW ? "sys_lock.png" : "lock.png"; - wxColor& color = *get_sys_label_clr(); + wxColour& color = *get_sys_label_clr(); if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) != m_sys_options.end()) { field->m_is_nonsys_value = false; } @@ -302,6 +302,8 @@ void Tab::update_changed_ui() icon = m_nonsys_btn_icon; if(find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end()) color = wxSYS_COLOUR_WINDOWTEXT; + else + color = *get_modified_label_clr(); } field->m_Undo_to_sys_btn->SetBitmap(wxBitmap(from_u8(var(icon)), wxBITMAP_TYPE_PNG)); if (field->m_Label != nullptr){ @@ -379,6 +381,7 @@ void Tab::update_sys_ui_after_sel_preset() void Tab::update_changed_tree_ui() { auto cur_item = m_treectrl->GetFirstVisibleItem(); + auto selection = m_treectrl->GetItemText(m_treectrl->GetSelection()); while (cur_item){ auto title = m_treectrl->GetItemText(cur_item); int i=0; @@ -406,19 +409,37 @@ void Tab::update_changed_tree_ui() if (!sys_page && modified_page) break; } - if (sys_page){ + if (sys_page) m_treectrl->SetItemTextColour(cur_item, *get_sys_label_clr()); - } - else if (modified_page){ + else if (modified_page) m_treectrl->SetItemTextColour(cur_item, *get_modified_label_clr()); - } else m_treectrl->SetItemTextColour(cur_item, wxSYS_COLOUR_WINDOWTEXT); + + page->m_is_nonsys_values = !sys_page; + page->m_is_modified_values = modified_page; + + if (selection == title){ + m_is_nonsys_values = page->m_is_nonsys_values; + m_is_modified_values = page->m_is_modified_values; + } break; } auto next_item = m_treectrl->GetNextVisible(cur_item); cur_item = next_item; } + update_undo_buttons(); +} + +void Tab::update_undo_buttons() +{ + const std::string& undo_icon = !m_is_modified_values ? "bullet_white.png" : + wxMSW ? "action_undo.png" : "arrow_undo.png"; + const std::string& undo_to_sys_icon = m_is_nonsys_values ? m_nonsys_btn_icon : + wxMSW ? "sys_lock.png" : "lock.png"; + + m_undo_btn->SetBitmap(wxBitmap(from_u8(var(undo_icon)), wxBITMAP_TYPE_PNG)); + m_undo_to_sys_btn->SetBitmap(wxBitmap(from_u8(var(undo_to_sys_icon)), wxBITMAP_TYPE_PNG)); } // Update the combo box label of the selected preset based on its "dirty" state, @@ -1796,6 +1817,8 @@ void Tab::OnTreeSelChange(wxTreeEvent& event) if (p->title() == selection) { page = p.get(); + m_is_nonsys_values = page->m_is_nonsys_values; + m_is_modified_values = page->m_is_modified_values; break; } if (page == nullptr) return; @@ -1805,6 +1828,8 @@ void Tab::OnTreeSelChange(wxTreeEvent& event) page->Show(); m_hsizer->Layout(); Refresh(); + + update_undo_buttons(); } void Tab::OnKeyDown(wxKeyEvent& event) diff --git a/xs/src/slic3r/GUI/Tab.hpp b/xs/src/slic3r/GUI/Tab.hpp index 8dd667bd1..fbc65745c 100644 --- a/xs/src/slic3r/GUI/Tab.hpp +++ b/xs/src/slic3r/GUI/Tab.hpp @@ -54,6 +54,9 @@ public: } ~Page(){} + bool m_is_modified_values{ false }; + bool m_is_nonsys_values{ true }; + public: std::vector m_optgroups; DynamicPrintConfig* m_config; @@ -109,6 +112,9 @@ protected: wxEventType m_event_value_change = 0; wxEventType m_event_presets_changed = 0; + bool m_is_modified_values{ false }; + bool m_is_nonsys_values{ true }; + public: PresetBundle* m_preset_bundle; bool m_show_btn_incompatible_presets = false; @@ -155,6 +161,7 @@ public: void update_full_options_list(); void update_sys_ui_after_sel_preset(); void update_changed_tree_ui(); + void update_undo_buttons(); PageShp add_options_page(wxString title, std::string icon, bool is_extruder_pages = false);