Some code refactoring

This commit is contained in:
YuSanka 2019-03-20 16:22:01 +01:00
parent e2349bdd2e
commit 452eb62f11
3 changed files with 22 additions and 22 deletions

View file

@ -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();
}

View file

@ -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;
}
}

View file

@ -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);