diff --git a/src/slic3r/GUI/SelectMachine.cpp b/src/slic3r/GUI/SelectMachine.cpp index c63e66f77..95de716c0 100644 --- a/src/slic3r/GUI/SelectMachine.cpp +++ b/src/slic3r/GUI/SelectMachine.cpp @@ -997,10 +997,7 @@ SelectMachineDialog::SelectMachineDialog(Plater *plater) m_rename_edit_panel->Layout(); rename_edit_sizer_v->Fit(m_rename_edit_panel); - m_rename_input->Bind(wxEVT_TEXT_ENTER, &SelectMachineDialog::on_rename_enter, this); m_rename_button->Bind(wxEVT_BUTTON, &SelectMachineDialog::on_rename_click, this); - - m_rename_switch_panel->AddPage(m_rename_normal_panel, wxEmptyString, true); m_rename_switch_panel->AddPage(m_rename_edit_panel, wxEmptyString, false); @@ -1218,6 +1215,21 @@ SelectMachineDialog::SelectMachineDialog(Plater *plater) Bind(EVT_PRINT_JOB_CANCEL, &SelectMachineDialog::on_print_job_cancel, this); Bind(EVT_SET_FINISH_MAPPING, &SelectMachineDialog::on_set_finish_mapping, this); + m_panel_prepare->Bind(wxEVT_LEFT_DOWN, [this](auto& e) { + check_fcous_state(this); + e.Skip(); + }); + + m_scrollable_region->Bind(wxEVT_LEFT_DOWN, [this](auto& e) { + check_fcous_state(this); + e.Skip(); + }); + + Bind(wxEVT_LEFT_DOWN, [this](auto& e) { + check_fcous_state(this); + e.Skip(); + }); + m_sizer_scrollable_region->Add(m_rename_switch_panel, 0, wxALIGN_CENTER_HORIZONTAL, 0); m_sizer_scrollable_region->Add(0, 0, 0, wxTOP, FromDIP(8)); m_sizer_scrollable_region->Add(m_panel_image, 0, wxALIGN_CENTER_HORIZONTAL, 0); @@ -1264,6 +1276,21 @@ SelectMachineDialog::SelectMachineDialog(Plater *plater) Centre(wxBOTH); wxGetApp().UpdateDlgDarkUI(this); } +void SelectMachineDialog::check_focus(wxWindow* window) +{ + if (window == m_rename_input || window == m_rename_input->GetTextCtrl()) { + on_rename_enter(); + } +} + +void SelectMachineDialog::check_fcous_state(wxWindow* window) +{ + check_focus(window); + auto children = window->GetChildren(); + for (auto child : children) { + check_fcous_state(child); + } +} wxWindow *SelectMachineDialog::create_ams_checkbox(wxString title, wxWindow *parent, wxString tooltip) { @@ -2270,12 +2297,22 @@ void SelectMachineDialog::update_user_printer() void SelectMachineDialog::on_rename_click(wxCommandEvent& event) { + m_is_rename_mode = true; m_rename_input->GetTextCtrl()->SetValue(m_current_project_name); m_rename_switch_panel->SetSelection(1); + m_rename_input->GetTextCtrl()->SetFocus(); + m_rename_input->GetTextCtrl()->SetInsertionPointEnd(); } -void SelectMachineDialog::on_rename_enter(wxCommandEvent& event) +void SelectMachineDialog::on_rename_enter() { + if (m_is_rename_mode == false){ + return; + } + else { + m_is_rename_mode = false; + } + auto new_file_name = m_rename_input->GetTextCtrl()->GetValue(); auto m_valid_type = Valid; wxString info_line; @@ -2317,7 +2354,7 @@ void SelectMachineDialog::on_rename_enter(wxCommandEvent& event) m_rename_switch_panel->SetSelection(0); m_rename_text->SetLabel(m_current_project_name); m_rename_normal_panel->Layout(); - return; + return; } } diff --git a/src/slic3r/GUI/SelectMachine.hpp b/src/slic3r/GUI/SelectMachine.hpp index 6b4a6d10c..a98208c4e 100644 --- a/src/slic3r/GUI/SelectMachine.hpp +++ b/src/slic3r/GUI/SelectMachine.hpp @@ -355,7 +355,9 @@ protected: public: SelectMachineDialog(Plater *plater = nullptr); - wxWindow *create_ams_checkbox(wxString title, wxWindow *parent, wxString tooltip); + void check_focus(wxWindow* window); + void check_fcous_state(wxWindow* window); + wxWindow* create_ams_checkbox(wxString title, wxWindow* parent, wxString tooltip); ~SelectMachineDialog(); wxWindow *create_item_checkbox(wxString title, wxWindow *parent, wxString tooltip, std::string param); @@ -396,6 +398,7 @@ protected: wxString m_current_project_name; std::string m_print_info; int timeout_count = 0; + bool m_is_rename_mode{false}; bool is_timeout(); void reset_timeout(); void update_user_printer(); @@ -410,7 +413,7 @@ protected: // Virtual event handlers, overide them in your derived class void on_rename_click(wxCommandEvent &event); - void on_rename_enter(wxCommandEvent &event); + void on_rename_enter(); void update_printer_combobox(wxCommandEvent &event); void on_cancel(wxCloseEvent &event); diff --git a/src/slic3r/GUI/SendToPrinter.cpp b/src/slic3r/GUI/SendToPrinter.cpp index 5bd5590df..865f8e5e8 100644 --- a/src/slic3r/GUI/SendToPrinter.cpp +++ b/src/slic3r/GUI/SendToPrinter.cpp @@ -71,26 +71,40 @@ wxString SendToPrinterDialog::format_text(wxString &m_msg) return out_txt; } -void SendToPrinterDialog::on_kill_focus(wxFocusEvent& event) +void SendToPrinterDialog::check_focus(wxWindow* window) { - if (m_rename_switch_panel->GetSelection() == 1) { - m_rename_switch_panel->SetSelection(0); - m_rename_text->SetLabel(m_current_project_name); - m_rename_normal_panel->Layout(); - + if (window == m_rename_input || window == m_rename_input->GetTextCtrl()) { + on_rename_enter(); + } +} + +void SendToPrinterDialog::check_fcous_state(wxWindow* window) +{ + check_focus(window); + auto children = window->GetChildren(); + for (auto child : children) { + check_fcous_state(child); } - event.Skip(); } void SendToPrinterDialog::on_rename_click(wxCommandEvent& event) { + m_is_rename_mode = true; m_rename_input->GetTextCtrl()->SetValue(m_current_project_name); m_rename_switch_panel->SetSelection(1); m_rename_input->GetTextCtrl()->SetFocus(); + m_rename_input->GetTextCtrl()->SetInsertionPointEnd(); } -void SendToPrinterDialog::on_rename_enter(wxCommandEvent& event) +void SendToPrinterDialog::on_rename_enter() { + if (m_is_rename_mode == false) { + return; + } + else { + m_is_rename_mode = false; + } + auto new_file_name = m_rename_input->GetTextCtrl()->GetValue(); auto m_valid_type = Valid; wxString info_line; @@ -352,11 +366,7 @@ SendToPrinterDialog::SendToPrinterDialog(Plater *plater) m_rename_edit_panel->Layout(); rename_edit_sizer_v->Fit(m_rename_edit_panel); - m_rename_input->GetTextCtrl()->Bind(wxEVT_KILL_FOCUS, &SendToPrinterDialog::on_kill_focus, this); - m_rename_input->Bind(wxEVT_TEXT_ENTER, &SendToPrinterDialog::on_rename_enter, this); m_rename_button->Bind(wxEVT_BUTTON, &SendToPrinterDialog::on_rename_click, this); - - m_rename_switch_panel->AddPage(m_rename_normal_panel, wxEmptyString, true); m_rename_switch_panel->AddPage(m_rename_edit_panel, wxEmptyString, false); @@ -376,6 +386,20 @@ SendToPrinterDialog::SendToPrinterDialog(Plater *plater) } }); + m_panel_prepare->Bind(wxEVT_LEFT_DOWN, [this](auto& e) { + check_fcous_state(this); + e.Skip(); + }); + + m_scrollable_region->Bind(wxEVT_LEFT_DOWN, [this](auto& e) { + check_fcous_state(this); + e.Skip(); + }); + + Bind(wxEVT_LEFT_DOWN, [this](auto& e) { + check_fcous_state(this); + e.Skip(); + }); m_sizer_main->Add(m_line_top, 0, wxEXPAND, 0); m_sizer_main->Add(0, 0, 0, wxTOP, FromDIP(22)); diff --git a/src/slic3r/GUI/SendToPrinter.hpp b/src/slic3r/GUI/SendToPrinter.hpp index 50371ed9d..4be2898ce 100644 --- a/src/slic3r/GUI/SendToPrinter.hpp +++ b/src/slic3r/GUI/SendToPrinter.hpp @@ -101,17 +101,19 @@ protected: wxBoxSizer* m_sizer_main; wxBoxSizer* m_sizer_bottom; + bool m_is_rename_mode{false}; bool enable_prepare_mode{true}; bool m_need_adaptation_screen{ false }; wxPanel* m_scrollable_region; wxBoxSizer* m_sizer_scrollable_region; - void on_kill_focus(wxFocusEvent& event); void on_rename_click(wxCommandEvent& event); - void on_rename_enter(wxCommandEvent& event); + void on_rename_enter(); void stripWhiteSpace(std::string& str); wxString format_text(wxString& m_msg); + void check_focus(wxWindow* window); + void check_fcous_state(wxWindow* window); void update_priner_status_msg(wxString msg, bool is_warning = false); void update_print_status_msg(wxString msg, bool is_warning = false, bool is_printer = true);