Skip to content

Commit 4b9b6d7

Browse files
authored
issue: Better Cont composer dialog work. (#386)
Dialog wasn't as fluid as it could be. This should improve the interaction.
1 parent 14048f3 commit 4b9b6d7

File tree

2 files changed

+61
-9
lines changed

2 files changed

+61
-9
lines changed

src/ContinuityBrowserPanel.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ void ContinuityBrowserPanel::OnNewEntry(int cell)
106106

107107
void ContinuityBrowserPanel::OnEditEntry(int cell)
108108
{
109-
if (!mView) {
110-
return;
111-
}
112-
113109
ContinuityComposerDialog dialog(mCont.GetParsedContinuity().at(cell)->clone(), this);
114110

115111
if (dialog.ShowModal() != wxID_OK) {

src/ContinuityComposerDialog.cpp

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class ContinuityComposerPanel : public wxPanel {
7979
// Event Handlers
8080
void OnDrawableContClick(CalChart::DrawableCont const& c);
8181
void OnCmdTextEnterKeyPressed(wxCommandEvent const& event);
82+
void OnComboPressed(wxCommandEvent const& event);
83+
void OnComboText(wxCommandEvent const& event);
8284

8385
std::unique_ptr<CalChart::ContProcedure> mCont;
8486
CalChart::DrawableCont mDrawableCont;
@@ -89,6 +91,7 @@ class ContinuityComposerPanel : public wxPanel {
8991
std::function<void(CalChart::DrawableCont const& c)> const mAction;
9092
CalChartConfiguration& mConfig;
9193
std::function<void(bool)> mOnUpdateIsValid{};
94+
std::string mLastValue;
9295
};
9396

9497
IMPLEMENT_CLASS(ContinuityComposerPanel, wxPanel)
@@ -141,7 +144,10 @@ void ContinuityComposerPanel::CreateControls()
141144
this->OnCmdTextEnterKeyPressed(event);
142145
});
143146
mComboSelection->Bind(wxEVT_COMBOBOX, [this](auto const& event) {
144-
this->OnCmdTextEnterKeyPressed(event);
147+
this->OnComboPressed(event);
148+
});
149+
mComboSelection->Bind(wxEVT_TEXT, [this](auto const& event) {
150+
this->OnComboText(event);
145151
});
146152
}));
147153

@@ -551,18 +557,54 @@ void ContinuityComposerPanel::OnCmdTextEnterKeyPressed(wxCommandEvent const& eve
551557
if (changed) {
552558
mDrawableCont = mCont->GetDrawableCont();
553559
std::tie(mCurrentSelected, mCurrentParent) = first_unset(mDrawableCont);
560+
// clear out the text
561+
mComboSelection->SetValue("");
554562
}
555563
}
556564
OnUpdate();
557565
}
558566

567+
// how this works: Go through each char of input str and find the in order matches of the
568+
// input list given.
569+
// We do this by keeping a tally of the match points, and prune off the strings that don't match
570+
auto findStringsThatMatchString(std::string const& str, std::vector<std::string> const& input)
571+
{
572+
auto listOfStrings = std::vector<std::pair<std::string, size_t>>{};
573+
std::transform(input.begin(), input.end(), std::back_inserter(listOfStrings), [](auto&& i) -> std::pair<std::string, size_t> {
574+
return { i, 0 };
575+
});
576+
for (auto&& l : str) {
577+
std::transform(listOfStrings.begin(), listOfStrings.end(), listOfStrings.begin(), [l](auto&& i) -> std::pair<std::string, size_t> {
578+
auto result = std::min(i.first.find(tolower(l), i.second), i.first.find(toupper(l), i.second));
579+
return { i.first, result };
580+
});
581+
listOfStrings.erase(std::remove_copy_if(listOfStrings.begin(), listOfStrings.end(), listOfStrings.begin(), [](auto&& i) {
582+
return i.second == std::string::npos; }), listOfStrings.cend());
583+
}
584+
auto result = std::vector<std::string>{};
585+
std::transform(listOfStrings.cbegin(), listOfStrings.cend(), std::back_inserter(result), [](auto&& i) { return i.first; });
586+
587+
return result;
588+
}
589+
590+
// we take the list of strings, filter them based on the char.
559591
void ContinuityComposerPanel::OnUpdate()
560592
{
561-
// save off what's in the list.
593+
// Get the master list.
562594
auto list_of_strings = GetCurrentList(mCurrentSelected);
563-
// this is where we would filter things out.
564-
std::vector<wxString> wxStringsCont(list_of_strings.begin(), list_of_strings.end());
565-
mComboSelection->Set(wxStringsCont.size(), wxStringsCont.data());
595+
596+
// filter out the selected
597+
auto filteredStrings = findStringsThatMatchString(mComboSelection->GetValue(), std::vector(list_of_strings.begin(), list_of_strings.end()));
598+
auto stringsCont = std::vector<wxString>(filteredStrings.begin(), filteredStrings.end());
599+
// if we *not* in the middle of browsing the list, or there's currently no strings, put in the culled list.
600+
if (wxNOT_FOUND == mComboSelection->GetSelection() || mComboSelection->GetCount() == 0) {
601+
while (mComboSelection->GetCount()) {
602+
mComboSelection->Delete(0);
603+
}
604+
if (!stringsCont.empty()) {
605+
mComboSelection->Insert(stringsCont, 0);
606+
}
607+
}
566608

567609
mCanvas->DoSetContinuity(mDrawableCont, mAction);
568610
// is it valid?
@@ -576,6 +618,20 @@ void ContinuityComposerPanel::OnUpdate()
576618
Refresh();
577619
}
578620

621+
// currently unused
622+
void ContinuityComposerPanel::OnComboPressed(wxCommandEvent const& /*event*/)
623+
{
624+
}
625+
626+
void ContinuityComposerPanel::OnComboText(wxCommandEvent const& /*event*/)
627+
{
628+
// we only do updates when the text changes
629+
if (mLastValue != mComboSelection->GetValue()) {
630+
mLastValue = mComboSelection->GetValue();
631+
OnUpdate();
632+
}
633+
}
634+
579635
void ContinuityComposerPanel::OnDrawableContClick(CalChart::DrawableCont const& c)
580636
{
581637
mCurrentSelected = c.self_ptr;

0 commit comments

Comments
 (0)