QoL: Enable Enter key to confirm Clone dialog and run cloning action (#11422)

Enter key confirms Clone dialog

Co-authored-by: yw4z <ywsyildiz@gmail.com>
This commit is contained in:
Kiss Lorand
2026-01-16 00:25:29 +02:00
committed by GitHub
parent 0c3055fd13
commit 304ea7867e

View File

@@ -28,6 +28,7 @@ CloneDialog::CloneDialog(wxWindow *parent)
arrange_label->Wrap(FromDIP(300)); arrange_label->Wrap(FromDIP(300));
m_arrange_cb = new ::CheckBox(this); m_arrange_cb = new ::CheckBox(this);
m_arrange_cb->SetValue(m_config->get("auto_arrange") == "true"); m_arrange_cb->SetValue(m_config->get("auto_arrange") == "true");
f_sizer->Add(arrange_label, 0, wxEXPAND | wxALIGN_CENTER_VERTICAL); f_sizer->Add(arrange_label, 0, wxEXPAND | wxALIGN_CENTER_VERTICAL);
f_sizer->Add(m_arrange_cb , 0, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM, FromDIP(5)); f_sizer->Add(m_arrange_cb , 0, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM, FromDIP(5));
@@ -44,6 +45,9 @@ CloneDialog::CloneDialog(wxWindow *parent)
auto dlg_btns = new DialogButtons(this, {"Fill", "OK", "Cancel"}, "", 1 /*left_aligned*/); auto dlg_btns = new DialogButtons(this, {"Fill", "OK", "Cancel"}, "", 1 /*left_aligned*/);
// Keep pointer to OK button so we can trigger it manually on Enter.
Button *ok_btn = dlg_btns->GetOK();
dlg_btns->GetFIRST()->SetToolTip(_L("Fill bed with copies")); dlg_btns->GetFIRST()->SetToolTip(_L("Fill bed with copies"));
dlg_btns->GetFIRST()->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { dlg_btns->GetFIRST()->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) {
m_plater->fill_bed_with_instances(); m_plater->fill_bed_with_instances();
@@ -73,10 +77,12 @@ CloneDialog::CloneDialog(wxWindow *parent)
for (int i = 0; i < m_count; i++) { // same method with Selection::clone() for (int i = 0; i < m_count; i++) { // same method with Selection::clone()
m_progress->SetValue(static_cast<int>(static_cast<double>(i) / m_count * 100)); // pass 0 / 100 m_progress->SetValue(static_cast<int>(static_cast<double>(i) / m_count * 100)); // pass 0 / 100
sel.paste_from_clipboard(); sel.paste_from_clipboard();
if (m_cancel_process) { if (m_cancel_process) {
m_plater->undo(); m_plater->undo();
return; return;
} }
wxYield(); // Allow event loop to process updates wxYield(); // Allow event loop to process updates
} }
@@ -90,7 +96,7 @@ CloneDialog::CloneDialog(wxWindow *parent)
} }
}); });
dlg_btns->GetCANCEL()->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { dlg_btns->GetCANCEL()->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
m_cancel_process = true; m_cancel_process = true;
if (m_plater->IsFrozen()) if (m_plater->IsFrozen())
m_plater->Thaw(); m_plater->Thaw();
@@ -104,7 +110,27 @@ CloneDialog::CloneDialog(wxWindow *parent)
this->SetSizer(v_sizer); this->SetSizer(v_sizer);
this->Layout(); this->Layout();
v_sizer->Fit(this); v_sizer->Fit(this);
wxGetApp().UpdateDlgDarkUI(this); wxGetApp().UpdateDlgDarkUI(this);
// ------------------ ENTER KEY OVERRIDE ------------------
// This makes Enter inside the spinbox behave EXACTLY like clicking OK.
Bind(wxEVT_CHAR_HOOK, [this, ok_btn](wxKeyEvent &e)
{
const int key = e.GetKeyCode();
if ((key == WXK_RETURN || key == WXK_NUMPAD_ENTER) &&
m_count_spin->GetTextCtrl()->HasFocus())
{
// Trigger OK button's handler manually
wxCommandEvent evt(wxEVT_BUTTON, ok_btn->GetId());
ok_btn->GetEventHandler()->ProcessEvent(evt);
} else {
// Not handled here, process normally
e.Skip();
}
});
// --------------------------------------------------------
} }
CloneDialog::~CloneDialog() {} CloneDialog::~CloneDialog() {}