From 4694bafce7586eb3b74503cd4cf93ebad826a3f7 Mon Sep 17 00:00:00 2001 From: Daniel Kulp Date: Sat, 8 Feb 2025 19:58:02 -0500 Subject: [PATCH] Attempt to get the services panel in preferences to actually work --- xLights/preferences/ServicesPanel.cpp | 61 ++++++++++++++++----------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/xLights/preferences/ServicesPanel.cpp b/xLights/preferences/ServicesPanel.cpp index 61149af76..d95f33eb8 100644 --- a/xLights/preferences/ServicesPanel.cpp +++ b/xLights/preferences/ServicesPanel.cpp @@ -46,8 +46,8 @@ bool IsServiceValid(const std::string& service, const std::string& id, const std class EditableListCtrl : public wxListCtrl { public: - EditableListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) : - wxListCtrl(parent, id, pos, size, style, validator, name) { + EditableListCtrl(ServicesPanel* p, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) : + wxListCtrl(p, id, pos, size, style, validator, name), parent(p) { Bind(wxEVT_LEFT_DOWN, &EditableListCtrl::OnLeftDown, this); Bind(wxEVT_TEXT_ENTER, &EditableListCtrl::OnTextEnter, this); } @@ -56,21 +56,15 @@ class EditableListCtrl : public wxListCtrl { wxTextCtrl* m_textCtrl = nullptr; int m_editingRow = -1; int m_editingCol = -1; + ServicesPanel *parent; void OnLeftDown(wxMouseEvent& event) { - long col; int flags; - int row = HitTest(event.GetPosition(), flags, &col); + int row = HitTest(event.GetPosition(), flags, nullptr); - if (row != wxNOT_FOUND && col >= 1 && col <= 3) { + if (row != wxNOT_FOUND) { // check this cell is editable - std::string service = GetItemText(row, 0); - const SERVICE_DEFINITION& svc = FindService(service); - if ((col == 1 && svc.idName != "") || - (col == 2 && svc.secretName1 != "") || - (col == 3 && svc.secretName2 != "")) { - EditCell(row, col); - } else { + if (EditCell(row, event.GetX())) { event.Skip(); } } else { @@ -78,27 +72,43 @@ class EditableListCtrl : public wxListCtrl { } } - void EditCell(long item, int col) { + bool EditCell(long item, int xpos) { if (m_textCtrl) { m_textCtrl->Destroy(); } - wxRect rect; - GetSubItemRect(item, col, rect); - - m_textCtrl = new wxTextCtrl(this, wxID_ANY, GetItemText(item, col), - wxPoint(rect.x, rect.y), wxSize(rect.width, rect.height), - wxTE_PROCESS_ENTER); - m_textCtrl->SetFocus(); - m_textCtrl->SetSelection(-1, -1); + std::string service = GetItemText(item, 0); + const SERVICE_DEFINITION& svc = FindService(service); + for (int col = 0; col <= 3; col++) { + wxRect rect; + GetSubItemRect(item, col, rect); + if (xpos >= rect.x && xpos < (rect.x + rect.width)) { + if ((col == 1 && svc.idName != "") || + (col == 2 && svc.secretName1 != "") || + (col == 3 && svc.secretName2 != "")) { + m_textCtrl = new wxTextCtrl(this, wxID_ANY, GetItemText(item, col), + wxPoint(rect.x, rect.y), wxSize(rect.width, rect.height), + wxTE_PROCESS_ENTER); + m_textCtrl->SetFocus(); + m_textCtrl->SetSelection(-1, -1); + + m_editingRow = item; + m_editingCol = col; + return false; + } + return true; + } + } + return true; - m_editingRow = item; - m_editingCol = col; } void OnTextEnter(wxCommandEvent& event) { if (m_textCtrl) { SetItem(m_editingRow, m_editingCol, m_textCtrl->GetValue()); + if (wxPreferencesEditor::ShouldApplyChangesImmediately()) { + parent->TransferDataFromWindow(); + } m_textCtrl->Destroy(); m_textCtrl = nullptr; } @@ -107,6 +117,9 @@ class EditableListCtrl : public wxListCtrl { void OnKillFocus(wxFocusEvent& event) { if (m_textCtrl) { SetItem(m_editingRow, m_editingCol, m_textCtrl->GetValue()); + if (wxPreferencesEditor::ShouldApplyChangesImmediately()) { + parent->TransferDataFromWindow(); + } m_textCtrl->Destroy(); m_textCtrl = nullptr; } @@ -185,4 +198,4 @@ void ServicesPanel::OnButtonTestClick(wxCommandEvent& event) { } } } -} \ No newline at end of file +}