FIX: [STUDIO-1525] not switch preset after cancel edit dialog

Change-Id: I91810298da40250e3c5def72737b2be6df764a3b
This commit is contained in:
chunmao.guo 2022-12-02 10:49:31 +08:00 committed by Lane.Wei
parent 50a5f8bddf
commit 5a6263c9f3
8 changed files with 29 additions and 14 deletions

View File

@ -54,6 +54,7 @@ ParamsDialog::ParamsDialog(wxWindow * parent)
#else
Hide();
#endif
wxGetApp().sidebar().finish_param_edit();
});
wxGetApp().UpdateDlgDarkUI(this);

View File

@ -523,8 +523,9 @@ Sidebar::Sidebar(Plater *parent)
edit_btn->SetToolTip(_L("Click to edit preset"));
edit_btn->Bind(wxEVT_BUTTON, [this, combo_printer](wxCommandEvent)
{
p->editing_filament = -1;
if (combo_printer->switch_to_tab())
p->editing_filament = 0;
combo_printer->switch_to_tab();
});
combo_printer->edit_btn = edit_btn;
p->combo_printer = combo_printer;
@ -741,7 +742,7 @@ Sidebar::Sidebar(Plater *parent)
}
if (p->editing_filament >= filament_count) {
p->editing_filament = 0;
p->editing_filament = -1;
}
wxGetApp().preset_bundle->set_num_filaments(filament_count);
@ -768,7 +769,7 @@ Sidebar::Sidebar(Plater *parent)
ScalableButton* set_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "settings");
set_btn->SetToolTip(_L("Set filaments to use"));
set_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) {
// p->editing_filament = -1;
p->editing_filament = -1;
// wxGetApp().params_dialog()->Popup();
// wxGetApp().get_tab(Preset::TYPE_FILAMENT)->restore_last_select_item();
wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_FILAMENTS);
@ -905,8 +906,9 @@ void Sidebar::init_filament_combo(PlaterPresetComboBox **combo, const int filame
PlaterPresetComboBox* combobox = (*combo);
edit_btn->Bind(wxEVT_BUTTON, [this, combobox, filament_idx](wxCommandEvent)
{
p->editing_filament = -1;
if (combobox->switch_to_tab())
p->editing_filament = filament_idx; // sync with TabPresetComboxBox's m_filament_idx
combobox->switch_to_tab();
});
combobox->edit_btn = edit_btn;
@ -1496,6 +1498,8 @@ bool Sidebar::show_object_list(bool show) const
return true;
}
void Sidebar::finish_param_edit() { p->editing_filament = -1; }
std::vector<PlaterPresetComboBox*>& Sidebar::combos_filament()
{
return p->combos_filament;

View File

@ -149,6 +149,7 @@ public:
void update_searcher();
void update_ui_from_settings();
bool show_object_list(bool show) const;
void finish_param_edit();
#ifdef _MSW_DARK_MODE
void show_mode_sizer(bool show);

View File

@ -773,11 +773,11 @@ void PlaterPresetComboBox::OnSelect(wxCommandEvent &evt)
evt.Skip();
}
void PlaterPresetComboBox::switch_to_tab()
bool PlaterPresetComboBox::switch_to_tab()
{
Tab* tab = wxGetApp().get_tab(m_type);
if (!tab)
return;
return false;
//BBS Select NoteBook Tab params
if (tab->GetParent() == wxGetApp().params_panel())
@ -793,8 +793,12 @@ void PlaterPresetComboBox::switch_to_tab()
if (!boost::algorithm::starts_with(selected_preset, Preset::suffix_modified()))
{
const std::string& preset_name = wxGetApp().preset_bundle->filaments.get_preset_name_by_alias(selected_preset);
wxGetApp().get_tab(m_type)->select_preset(preset_name);
if (wxGetApp().get_tab(m_type)->select_preset(preset_name))
wxGetApp().get_tab(m_type)->get_combo_box()->set_filament_idx(m_filament_idx);
else {
wxGetApp().params_dialog()->Hide();
return false;
}
}
}
@ -819,6 +823,8 @@ void PlaterPresetComboBox::switch_to_tab()
}
}
*/
return true;
}
void PlaterPresetComboBox::change_extruder_color()

View File

@ -170,7 +170,7 @@ public:
wxColor get_color() { return m_color; }
void switch_to_tab();
bool switch_to_tab();
void change_extruder_color();
void show_add_menu();
void show_edit_menu();

View File

@ -3728,7 +3728,7 @@ void Tab::update_preset_choice()
// Called by the UI combo box when the user switches profiles, and also to delete the current profile.
// Select a preset by a name.If !defined(name), then the default preset is selected.
// If the current profile is modified, user is asked to save the changes.
void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/, const std::string& last_selected_ph_printer_name/* =""*/, bool force_select)
bool Tab::select_preset(std::string preset_name, bool delete_current /*=false*/, const std::string& last_selected_ph_printer_name/* =""*/, bool force_select)
{
BOOST_LOG_TRIVIAL(info) << boost::format("select preset, name %1%, delete_current %2%")
%preset_name %delete_current;
@ -3956,6 +3956,8 @@ void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/,
if (technology_changed)
wxGetApp().mainframe->technology_changed();
BOOST_LOG_TRIVIAL(info) << boost::format("select preset, exit");
return !canceled;
}
// If the current preset is dirty, the user is asked whether the changes may be discarded.

View File

@ -322,7 +322,7 @@ public:
void update_btns_enabling();
void update_preset_choice();
// Select a new preset, possibly delete the current one.
void select_preset(std::string preset_name = "", bool delete_current = false, const std::string& last_selected_ph_printer_name = "", bool force_select = false);
bool select_preset(std::string preset_name = "", bool delete_current = false, const std::string& last_selected_ph_printer_name = "", bool force_select = false);
bool may_discard_current_dirty_preset(PresetCollection* presets = nullptr, const std::string& new_printer_name = "", bool no_transfer = false);
virtual void clear_pages();

View File

@ -1383,7 +1383,8 @@ void UnsavedChangesDialog::update(Preset::Type type, PresetCollection* dependent
}
wxString action_msg;
action_msg = format_wxstr(_L("You have changed some preset settings. \nWould you like to keep these changed settings (new value) after switching preset?"));
action_msg = format_wxstr(_L("You have changed some settings of preset \"%1%\". \nWould you like to keep these changed settings (new value) after switching preset?"),
dependent_presets->get_edited_preset().name);
m_action_line->SetLabel(action_msg);
update_tree(type, presets);