Skip to content

Commit

Permalink
Lazy init DiffPresetDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Noisyfox committed Nov 28, 2024
1 parent 03fa545 commit e4747c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/slic3r/GUI/UnsavedChangesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2056,16 +2056,19 @@ DiffPresetDialog::DiffPresetDialog(MainFrame* mainframe)
// From the very beginning set dialog font to the wxSYS_DEFAULT_GUI_FONT
this->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
#endif // __WXMSW__
}

// Init bundles

assert(wxGetApp().preset_bundle);
void DiffPresetDialog::ensure_inited()
{
if (inited) {
return;
}
inited = true;

m_preset_bundle_left = std::make_unique<PresetBundle>(*wxGetApp().preset_bundle);
m_preset_bundle_right = std::make_unique<PresetBundle>(*wxGetApp().preset_bundle);
assert(m_preset_bundle_left.get());
assert(m_preset_bundle_right.get());

// Create UI items

SetBackgroundColour(*wxWHITE);

create_info_lines();
Expand All @@ -2083,6 +2086,7 @@ DiffPresetDialog::DiffPresetDialog(MainFrame* mainframe)

void DiffPresetDialog::update_controls_visibility(Preset::Type type /* = Preset::TYPE_INVALID*/)
{
ensure_inited();
for (auto preset_combos : m_preset_combos) {
Preset::Type cb_type = preset_combos.presets_left->get_type();
bool show = type != Preset::TYPE_INVALID ? type == cb_type :
Expand All @@ -2104,8 +2108,16 @@ void DiffPresetDialog::update_controls_visibility(Preset::Type type /* = Preset:

void DiffPresetDialog::update_bundles_from_app()
{
*m_preset_bundle_left = *wxGetApp().preset_bundle;
*m_preset_bundle_right = *wxGetApp().preset_bundle;
if (m_preset_bundle_left.get()) {
*m_preset_bundle_left = *wxGetApp().preset_bundle;
} else {
m_preset_bundle_left = std::make_unique<PresetBundle>(*wxGetApp().preset_bundle);
}
if (m_preset_bundle_right.get()) {
*m_preset_bundle_right = *wxGetApp().preset_bundle;
} else {
m_preset_bundle_right = std::make_unique<PresetBundle>(*wxGetApp().preset_bundle);
}

m_pr_technology = m_preset_bundle_left.get()->printers.get_edited_preset().printer_technology();
}
Expand Down
3 changes: 3 additions & 0 deletions src/slic3r/GUI/UnsavedChangesDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ class DiffPresetDialog : public DPIDialog
std::unique_ptr<PresetBundle> m_preset_bundle_left;
std::unique_ptr<PresetBundle> m_preset_bundle_right;

bool inited{false};
void ensure_inited();

void create_buttons();
void create_edit_sizer();
void complete_dialog_creation();
Expand Down

0 comments on commit e4747c8

Please sign in to comment.