diff --git a/Common/UI/PopupScreens.cpp b/Common/UI/PopupScreens.cpp index 39748192d4..a4a2ad6395 100644 --- a/Common/UI/PopupScreens.cpp +++ b/Common/UI/PopupScreens.cpp @@ -762,9 +762,10 @@ void PopupTextInputChoice::HandleClick(EventParams &e) { // Choose method depending on platform capabilities. if (System_GetPropertyBool(SYSPROP_HAS_TEXT_INPUT_DIALOG)) { - System_InputBoxGetString(token_, text_, *value_, passwordMasking_, [=](const std::string &enteredValue, int) { + System_InputBoxGetString(token_, text_, *value_, passwordMasking_, [this](const std::string &enteredValue, int) { *value_ = SanitizeString(StripSpaces(enteredValue), restriction_, minLen_, maxLen_); EventParams params{}; + params.v = this; OnChange.Trigger(params); }); return; @@ -775,7 +776,15 @@ void PopupTextInputChoice::HandleClick(EventParams &e) { if (System_GetPropertyBool(SYSPROP_KEYBOARD_IS_SOFT)) { popupScreen->SetAlignTop(true); } - popupScreen->OnChange.Handle(this, &PopupTextInputChoice::HandleChange); + popupScreen->OnChange.Add([this](EventParams &e) { + *value_ = StripSpaces(SanitizeString(*value_, restriction_, minLen_, maxLen_)); + EventParams params{}; + params.v = this; + OnChange.Trigger(params); + if (restoreFocus_) { + SetFocusedView(this); + } + }); if (e.v) popupScreen->SetPopupOrigin(e.v); screenManager_->push(popupScreen); @@ -785,16 +794,6 @@ std::string PopupTextInputChoice::ValueText() const { return *value_; } -void PopupTextInputChoice::HandleChange(EventParams &e) { - *value_ = StripSpaces(SanitizeString(*value_, restriction_, minLen_, maxLen_)); - e.v = this; - OnChange.Trigger(e); - - if (restoreFocus_) { - SetFocusedView(this); - } -} - void TextEditPopupScreen::CreatePopupContents(UI::ViewGroup *parent) { using namespace UI; UIContext &dc = *screenManager()->getUIContext(); diff --git a/Common/UI/PopupScreens.h b/Common/UI/PopupScreens.h index 5a96d14135..f9651baf9d 100644 --- a/Common/UI/PopupScreens.h +++ b/Common/UI/PopupScreens.h @@ -506,7 +506,6 @@ protected: private: void HandleClick(EventParams &e); - void HandleChange(EventParams &e); RequesterToken token_; ScreenManager *screenManager_; std::string *value_; diff --git a/UI/TabbedDialogScreen.cpp b/UI/TabbedDialogScreen.cpp index a5b1e0774a..e9f425100d 100644 --- a/UI/TabbedDialogScreen.cpp +++ b/UI/TabbedDialogScreen.cpp @@ -114,12 +114,12 @@ void UITabbedBaseDialogScreen::CreateViews() { auto se = GetI18NCategory(I18NCat::SEARCH); searchSettings->Add(new ItemHeader(se->T("Find settings"))); - searchSettings->Add(new PopupTextInputChoice(GetRequesterToken(), &searchFilter_, se->T("Filter"), "", 64, screenManager()))->OnChange.Add([=](UI::EventParams &e) { + searchSettings->Add(new PopupTextInputChoice(GetRequesterToken(), &searchFilter_, se->T("Filter"), "", 64, screenManager()))->OnChange.Add([this](UI::EventParams &e) { System_PostUIMessage(UIMessage::GAMESETTINGS_SEARCH, StripSpaces(searchFilter_)); }); clearSearchChoice_ = searchSettings->Add(new Choice(se->T("Clear filter"))); - clearSearchChoice_->OnClick.Add([=](UI::EventParams &e) { + clearSearchChoice_->OnClick.Add([](UI::EventParams &e) { System_PostUIMessage(UIMessage::GAMESETTINGS_SEARCH, ""); }); clearSearchChoice_->SetVisibility(searchFilter_.empty() ? UI::V_GONE : UI::V_VISIBLE); @@ -128,6 +128,11 @@ void UITabbedBaseDialogScreen::CreateViews() { }); } } + + // Need to handle recreates, both important and accidental ones. + if (!searchFilter_.empty()) { + ApplySearchFilter(); + } } void UITabbedBaseDialogScreen::sendMessage(UIMessage message, const char *value) { @@ -205,7 +210,7 @@ void UITabbedBaseDialogScreen::ApplySearchFilter() { if (match && lastHeading) lastHeading->SetVisibility(UI::V_VISIBLE); - v->SetVisibility(searchFilter_.empty() || match ? UI::V_VISIBLE : UI::V_GONE); + v->SetVisibility((searchFilter_.empty() || match) ? UI::V_VISIBLE : UI::V_GONE); } tabHolder_->EnableTab(t, tabMatches); matches = matches || tabMatches;