From 452eb62f1102e0a59d0b3979fc1101a6421029a5 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 20 Mar 2019 16:22:01 +0100 Subject: [PATCH] Some code refactoring --- src/slic3r/GUI/GUI_App.cpp | 2 +- src/slic3r/GUI/Tab.cpp | 38 ++++++++++++++++++-------------------- src/slic3r/GUI/Tab.hpp | 4 +++- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 3b7ddd1d8..d68257a0a 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -530,7 +530,7 @@ void GUI_App::update_mode() sidebar().update_mode(); for (auto tab : tabs_list) - tab->update_visibility(); + tab->update_mode(); plater()->update_object_menu(); } diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index d54d01572..46a6de6ab 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -705,25 +705,28 @@ void Tab::reload_config() // Thaw(); } -void Tab::update_visibility() +void Tab::update_mode() { - const ConfigOptionMode mode = wxGetApp().get_mode(); -// Freeze(); - - for (auto page : m_pages) - page->update_visibility(mode); - update_page_tree_visibility(); + m_mode = wxGetApp().get_mode(); // update mode for ModeSizer - m_mode_sizer->SetMode(mode); + m_mode_sizer->SetMode(m_mode); + + update_visibility(); +} + +void Tab::update_visibility() +{ + Freeze(); // There is needed Freeze/Thaw to avoid a flashing after Show/Layout + + for (auto page : m_pages) + page->update_visibility(m_mode); + update_page_tree_visibility(); Layout(); -// Thaw(); + Thaw(); - // to update tree items color -// wxTheApp->CallAfter([this]() { - update_changed_tree_ui(); -// }); + update_changed_tree_ui(); } Field* Tab::get_field(const t_config_option_key& opt_key, int opt_index/* = -1*/) const @@ -2264,7 +2267,7 @@ void TabPrinter::update_pages() else m_pages_sla.empty() ? build_sla() : m_pages.swap(m_pages_sla); - rebuild_page_tree(true); + rebuild_page_tree(); } void TabPrinter::update() @@ -2470,10 +2473,8 @@ void Tab::load_current_preset() } //Regerenerate content of the page tree. -void Tab::rebuild_page_tree(bool tree_sel_change_event /*= false*/) +void Tab::rebuild_page_tree() { -// Freeze(); - // get label of the currently selected item const auto sel_item = m_treectrl->GetSelection(); const auto selected = sel_item ? m_treectrl->GetItemText(sel_item) : ""; @@ -2486,10 +2487,7 @@ void Tab::rebuild_page_tree(bool tree_sel_change_event /*= false*/) auto itemId = m_treectrl->AppendItem(rootItem, p->title(), p->iconID()); m_treectrl->SetItemTextColour(itemId, p->get_item_colour()); if (p->title() == selected) { -// if (!(p->title() == _(L("Machine limits")) || p->title() == _(L("Single extruder MM setup")))) // These Pages have to be updated inside OnTreeSelChange -// m_disable_tree_sel_changed_event = !tree_sel_change_event; m_treectrl->SelectItem(itemId); - m_disable_tree_sel_changed_event = false; have_selection = 1; } } diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 81a79c58c..15ae0443c 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -209,6 +209,7 @@ protected: int m_em_unit; // To avoid actions with no-completed Tab bool m_complited { false }; + ConfigOptionMode m_mode = comSimple; public: PresetBundle* m_preset_bundle; @@ -236,7 +237,7 @@ public: void create_preset_tab(); void load_current_preset(); - void rebuild_page_tree(bool tree_sel_change_event = false); + void rebuild_page_tree(); void update_page_tree_visibility(); void select_preset(std::string preset_name = ""); bool may_discard_current_dirty_preset(PresetCollection* presets = nullptr, const std::string& new_printer_name = ""); @@ -270,6 +271,7 @@ public: void update_tab_ui(); void load_config(const DynamicPrintConfig& config); virtual void reload_config(); + void update_mode(); void update_visibility(); Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const; bool set_value(const t_config_option_key& opt_key, const boost::any& value);