Skip to content

Commit

Permalink
Attempt to get the services panel in preferences to actually work
Browse files Browse the repository at this point in the history
  • Loading branch information
dkulp committed Feb 9, 2025
1 parent c8b2796 commit 4694baf
Showing 1 changed file with 37 additions and 24 deletions.
61 changes: 37 additions & 24 deletions xLights/preferences/ServicesPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -56,49 +56,59 @@ 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 {
event.Skip();
}
}

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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -185,4 +198,4 @@ void ServicesPanel::OnButtonTestClick(wxCommandEvent& event) {
}
}
}
}
}

2 comments on commit 4694baf

@derwin12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the mac side need some permissions stuff to allow it to call out to the api?

@cybercop23
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't enter my api key in Secret 1. Won't allow any data entry in any of the fields. Works fine on Windows (been using it there)

Image

Please sign in to comment.