From 5a6263c9f356a01b23e5f1636985a4b5c32967a3 Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Fri, 2 Dec 2022 10:49:31 +0800 Subject: [PATCH] FIX: [STUDIO-1525] not switch preset after cancel edit dialog Change-Id: I91810298da40250e3c5def72737b2be6df764a3b --- src/slic3r/GUI/ParamsDialog.cpp | 1 + src/slic3r/GUI/Plater.cpp | 16 ++++++++++------ src/slic3r/GUI/Plater.hpp | 1 + src/slic3r/GUI/PresetComboBoxes.cpp | 14 ++++++++++---- src/slic3r/GUI/PresetComboBoxes.hpp | 2 +- src/slic3r/GUI/Tab.cpp | 4 +++- src/slic3r/GUI/Tab.hpp | 2 +- src/slic3r/GUI/UnsavedChangesDialog.cpp | 3 ++- 8 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/slic3r/GUI/ParamsDialog.cpp b/src/slic3r/GUI/ParamsDialog.cpp index 6bf1fd16b..f6a5acfbf 100644 --- a/src/slic3r/GUI/ParamsDialog.cpp +++ b/src/slic3r/GUI/ParamsDialog.cpp @@ -54,6 +54,7 @@ ParamsDialog::ParamsDialog(wxWindow * parent) #else Hide(); #endif + wxGetApp().sidebar().finish_param_edit(); }); wxGetApp().UpdateDlgDarkUI(this); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index a02e4b52c..78dad6582 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -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 = 0; - combo_printer->switch_to_tab(); + p->editing_filament = -1; + if (combo_printer->switch_to_tab()) + p->editing_filament = 0; }); 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 = filament_idx; // sync with TabPresetComboxBox's m_filament_idx - combobox->switch_to_tab(); + p->editing_filament = -1; + if (combobox->switch_to_tab()) + p->editing_filament = filament_idx; // sync with TabPresetComboxBox's m_filament_idx }); 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& Sidebar::combos_filament() { return p->combos_filament; diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index dc91637fd..2d4df16bb 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -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); diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index eca6e7aeb..2164513a4 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -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); - wxGetApp().get_tab(m_type)->get_combo_box()->set_filament_idx(m_filament_idx); + 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() diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 4f074f50c..67aab0d65 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -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(); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 7c8a9d909..ac2407293 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -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. diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 8bd3a3923..b495d3f9b 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -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(); diff --git a/src/slic3r/GUI/UnsavedChangesDialog.cpp b/src/slic3r/GUI/UnsavedChangesDialog.cpp index a13b04968..6a4dfe06e 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.cpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.cpp @@ -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);