Skip to content

Commit

Permalink
Add support for rearranging the frequency list.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Jul 5, 2023
1 parent 450e39e commit 273fb7c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/dlg_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c
m_txtCtrlNewFrequency->Connect(wxEVT_TEXT, wxCommandEventHandler(OptionsDlg::OnReportingFreqTextChange), NULL, this);
m_freqListAdd->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(OptionsDlg::OnReportingFreqAdd), NULL, this);
m_freqListRemove->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(OptionsDlg::OnReportingFreqRemove), NULL, this);
m_freqListMoveUp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(OptionsDlg::OnReportingFreqMoveUp), NULL, this);
m_freqListMoveDown->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(OptionsDlg::OnReportingFreqMoveDown), NULL, this);

event_in_serial = 0;
event_out_serial = 0;
Expand Down Expand Up @@ -666,6 +668,8 @@ OptionsDlg::~OptionsDlg()
m_txtCtrlNewFrequency->Disconnect(wxEVT_TEXT, wxCommandEventHandler(OptionsDlg::OnReportingFreqTextChange), NULL, this);
m_freqListAdd->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(OptionsDlg::OnReportingFreqAdd), NULL, this);
m_freqListRemove->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(OptionsDlg::OnReportingFreqRemove), NULL, this);
m_freqListMoveUp->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(OptionsDlg::OnReportingFreqMoveUp), NULL, this);
m_freqListMoveDown->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(OptionsDlg::OnReportingFreqMoveDown), NULL, this);
}


Expand Down Expand Up @@ -1215,11 +1219,36 @@ void OptionsDlg::OnReportingFreqTextChange(wxCommandEvent& event)
{
m_freqListAdd->Enable(false);
m_freqListRemove->Enable(true);

if (idx == 0)
{
m_freqListMoveUp->Enable(false);
m_freqListMoveDown->Enable(true);
}
else if (idx == m_freqList->GetCount() - 1)
{
m_freqListMoveUp->Enable(true);
m_freqListMoveDown->Enable(false);
}
else
{
m_freqListMoveUp->Enable(true);
m_freqListMoveDown->Enable(true);
}
}
else if (rgx.Matches(m_txtCtrlNewFrequency->GetValue()))
{
m_freqListAdd->Enable(true);
m_freqListRemove->Enable(false);
m_freqListMoveUp->Enable(false);
m_freqListMoveDown->Enable(false);
}
else
{
m_freqListAdd->Enable(false);
m_freqListRemove->Enable(false);
m_freqListMoveUp->Enable(false);
m_freqListMoveDown->Enable(false);
}
}

Expand All @@ -1238,4 +1267,34 @@ void OptionsDlg::OnReportingFreqRemove(wxCommandEvent& event)
m_freqList->Delete(idx);
}
m_txtCtrlNewFrequency->SetValue("");
}

void OptionsDlg::OnReportingFreqMoveUp(wxCommandEvent& event)
{
auto prevStr = m_txtCtrlNewFrequency->GetValue();
auto idx = m_freqList->FindString(m_txtCtrlNewFrequency->GetValue());
if (idx > 0)
{
m_freqList->Delete(idx);
m_freqList->Insert(prevStr, idx - 1);
m_freqList->SetSelection(idx - 1);
}

// Refresh button status
m_txtCtrlNewFrequency->SetValue(prevStr);
}

void OptionsDlg::OnReportingFreqMoveDown(wxCommandEvent& event)
{
auto prevStr = m_txtCtrlNewFrequency->GetValue();
auto idx = m_freqList->FindString(m_txtCtrlNewFrequency->GetValue());
if (idx < m_freqList->GetCount() - 1)
{
m_freqList->Delete(idx);
m_freqList->Insert(prevStr, idx + 1);
m_freqList->SetSelection(idx + 1);
}

// Refresh button status
m_txtCtrlNewFrequency->SetValue(prevStr);
}
2 changes: 2 additions & 0 deletions src/dlg_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ class OptionsDlg : public wxDialog
void OnReportingFreqTextChange(wxCommandEvent& event);
void OnReportingFreqAdd(wxCommandEvent& event);
void OnReportingFreqRemove(wxCommandEvent& event);
void OnReportingFreqMoveUp(wxCommandEvent& event);
void OnReportingFreqMoveDown(wxCommandEvent& event);

private:
void updateReportingState();
Expand Down

0 comments on commit 273fb7c

Please sign in to comment.