diff --git a/src/slic3r/GUI/BindDialog.cpp b/src/slic3r/GUI/BindDialog.cpp index 6678cde76..d2240280d 100644 --- a/src/slic3r/GUI/BindDialog.cpp +++ b/src/slic3r/GUI/BindDialog.cpp @@ -127,6 +127,7 @@ PingCodeBindDialog::PingCodeBindDialog(Plater* plater /*= nullptr*/) m_text_input_single_code[i]->GetTextCtrl()->SetMaxLength(1); m_text_input_single_code[i]->GetTextCtrl()->Bind(wxEVT_TEXT, &PingCodeBindDialog::on_text_changed, this); m_text_input_single_code[i]->GetTextCtrl()->Bind(wxEVT_KEY_DOWN, &PingCodeBindDialog::on_key_backspace, this); + m_text_input_single_code[i]->GetTextCtrl()->Bind(wxEVT_CHAR, &PingCodeBindDialog::on_key_input, this); ping_code_input->Add(m_text_input_single_code[i], 0, wxALL, FromDIP(5)); } @@ -194,7 +195,7 @@ PingCodeBindDialog::PingCodeBindDialog(Plater* plater /*= nullptr*/) wxBoxSizer* m_sizer_binding_button = new wxBoxSizer(wxHORIZONTAL); m_sizer_binding_button->Add(0, 0, 1, wxEXPAND, 5); - auto m_button_close = new Button(binding_panel, _L("Close")); + m_button_close = new Button(binding_panel, _L("Close")); m_button_close->SetBackgroundColor(btn_bg_white); m_button_close->SetBorderColor(BIND_DIALOG_GREY900); m_button_close->SetSize(BIND_DIALOG_BUTTON_SIZE); @@ -227,10 +228,26 @@ PingCodeBindDialog::PingCodeBindDialog(Plater* plater /*= nullptr*/) m_button_bind->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(PingCodeBindDialog::on_bind_printer), NULL, this); m_button_cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(PingCodeBindDialog::on_cancel), NULL, this); + m_button_close->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(PingCodeBindDialog::on_cancel), NULL, this); m_simplebook->SetSelection(0); } +void PingCodeBindDialog::on_key_input(wxKeyEvent& evt) +{ + int keyCode = evt.GetKeyCode(); + + if (keyCode == WXK_BACK || (keyCode >= '0' && keyCode <= '9') || (keyCode >= 'a' && keyCode <= 'z') || (keyCode >= 'A' && keyCode <= 'Z')) + { + evt.Skip(); + } + else + { + wxBell(); + return; + } +} + void PingCodeBindDialog::on_text_changed(wxCommandEvent& event) { //switch focus to the text text input wxTextCtrl* text_input = static_cast(event.GetEventObject()); @@ -246,9 +263,24 @@ void PingCodeBindDialog::on_text_changed(wxCommandEvent& event) { if (idx < PING_CODE_LENGTH-1) { m_text_input_single_code[idx + 1]->SetFocus(); } - else if (idx == PING_CODE_LENGTH - 1) { + + auto has_empty = false; + for (int i = 0; i < PING_CODE_LENGTH; i++) { + if (m_text_input_single_code[i]->GetTextCtrl()->GetValue().ToStdString().empty()) { + has_empty = true; + } + } + + if (has_empty) { + m_button_bind->Enable(false); + } + else { m_button_bind->Enable(true); } + + /*if (idx == PING_CODE_LENGTH - 1) { + m_button_bind->Enable(true); + }*/ } } @@ -264,9 +296,11 @@ void PingCodeBindDialog::on_key_backspace(wxKeyEvent& event) } } - if (event.GetKeyCode() == WXK_BACK && idx > 0) { - m_text_input_single_code[idx - 1]->SetFocus(); - m_button_bind->Enable(false); + if (event.GetKeyCode() == WXK_BACK && idx >= 0) { + CallAfter([this, idx]() { + m_text_input_single_code[idx - 1]->SetFocus(); + m_button_bind->Enable(false); + }); } event.Skip(); } @@ -308,6 +342,7 @@ void PingCodeBindDialog::on_dpi_changed(const wxRect& suggested_rect) PingCodeBindDialog::~PingCodeBindDialog() { m_button_bind->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(PingCodeBindDialog::on_bind_printer), NULL, this); m_button_cancel->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(PingCodeBindDialog::on_cancel), NULL, this); + m_button_close->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(PingCodeBindDialog::on_cancel), NULL, this); } BindMachineDialog::BindMachineDialog(Plater *plater /*= nullptr*/) diff --git a/src/slic3r/GUI/BindDialog.hpp b/src/slic3r/GUI/BindDialog.hpp index e7d7a9d97..11f31b2c2 100644 --- a/src/slic3r/GUI/BindDialog.hpp +++ b/src/slic3r/GUI/BindDialog.hpp @@ -55,6 +55,7 @@ private: TextInput* m_text_input_single_code[PING_CODE_LENGTH]; Button* m_button_bind; Button* m_button_cancel; + Button* m_button_close; wxSimplebook* m_simplebook; wxPanel* request_bind_panel; wxPanel* binding_panel; @@ -77,6 +78,7 @@ public: PingCodeBindDialog(Plater* plater = nullptr); ~PingCodeBindDialog(); + void on_key_input(wxKeyEvent& evt); void on_text_changed(wxCommandEvent& event); void on_key_backspace(wxKeyEvent& event); void on_cancel(wxCommandEvent& event);