fix(gui): stop Reset Fields wiping the search history, gate the history UI - #709
Merged
got3nks merged 1 commit intoJul 30, 2026
Merged
Conversation
…ry UI
Four things, all around the IDC_SEARCHNAME field.
"Reset Fields" wiped the whole search history instead of just the Name field.
The call was already casting to wxTextEntry to avoid exactly that, with a
comment saying so, but the cast does not help: wxTextEntry::Clear() is
virtual and wxComboBoxBase overrides it as { wxItemContainer::Clear();
wxTextEntry::Clear(); }, so the call dispatched to the override and emptied
the dropdown's item list too. Use SetValue("") instead, which only touches
the text. This also explains the second half of the report -- the last term
still being offered as a completion after the list looked empty -- since the
item list was cleared while the autocomplete set was left armed.
Fixes a null dereference in SearchListCtrl's "search related files" action.
The field became a wxComboBox in amule-project#643, and wxComboBox does not derive from
wxTextCtrl -- it is wxWindowWithItems<wxControl, wxComboBoxBase> -- so the
CastByID dynamic_cast to wxTextCtrl there had been yielding nullptr, which
the following SetValue() dereferenced. Cast to wxTextEntry, the common base
of both control types.
Adds a visible "Clear search history" button after the search-type choice.
The action already existed in the field's right-click menu, but that menu is
unreachable on Windows: wxComboBox's editable part is a native child EDIT
window, and wx forwards only key, focus and clipboard messages from it
(ShouldForwardFromEditToCombo in src/msw/combobox.cpp) -- WM_CONTEXTMENU is
not among them, so the native menu appears instead and our handler never
runs. Built in SearchDlg.cpp rather than muuli_wdr so the existing msgid
keeps its catalog position; adding the same string to muuli_wdr.cpp would
move the pot entry, since xgettext orders entries by file scan order.
Gates the whole history UI on "Remember search history", which previously
only stopped new terms being recorded: existing terms stayed visible in the
dropdown and kept being offered as completions, and the field kept its
dropdown either way. Now the Name field is a plain wxTextCtrl when the
preference is off, the Clear button is hidden, and no stored terms are
loaded. searchhistory.dat is deliberately left on disk, so re-enabling
restores the previous history rather than starting over. Applied live from
PrefsUnifiedDlg::OnOk, so no restart is needed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #697. Four fixes around the search Name field, addressing all three of @ghysler's proposals plus a crash found while auditing the call sites.
1. "Reset Fields" wiped the whole search history
The reported bug, and the cause is a subtle one. The call already cast to
wxTextEntryspecifically to avoid this, with a comment saying so — but the cast doesn't help:wxTextEntry::Clear()is virtual, so calling it through awxTextEntry*dispatches to the combo override and empties the item list too. Now usesSetValue(""), which only touches the text.This also explains the second half of the report — the last term still being offered as a completion after the pull-down looked empty. The item list was being cleared while the autocomplete set stayed armed, so proposal (3) resolves with the same fix rather than needing its own.
2. Crash in "search related files"
SearchListCtrl.cppdidCastByID(IDC_SEARCHNAME, …, wxTextCtrl)->SetValue(keyword). The field became awxComboBoxin #643, andwxComboBoxdoesn't derive fromwxTextCtrl— it'swxWindowWithItems<wxControl, wxComboBoxBase>.CastByIDis adynamic_cast, so that yieldednullptrand theSetValue()dereferenced it. Reachable whenever you're connected to an ed2k server. Cast towxTextEntry, the common base.3. "Clear search history" as a visible button
Proposal (2). The action already existed in the field's right-click menu, but that menu is unreachable on Windows: the editable part of a
wxComboBoxis a native childEDITwindow, and perShouldForwardFromEditToCombo()insrc/msw/combobox.cppwx forwards onlyWM_KEYUP/KEYDOWN/CHAR/SYSCHAR/SYSKEYDOWN/SYSKEYUP/SETFOCUS/KILLFOCUS/CUT/COPY/PASTEfrom it.WM_CONTEXTMENUisn't among them, so the native menu appears and our handler never runs — matching @ghysler's screenshot exactly.The button sits after the search-type choice and greys out when there's nothing stored. Built in
SearchDlg.cpprather thanmuuli_wdr.cppso the existing msgid keeps its catalog position — adding the same string tomuuli_wdr.cppwould move the pot entry, since xgettext orders entries by file scan order, and that trips pot-sync. No catalog changes in this PR.4. The preference now gates the whole history UI
"Remember search history" previously only stopped new terms being recorded: existing terms stayed in the dropdown, kept being offered as completions, and the field kept its dropdown regardless. Now, with it off, the Name field is a plain
wxTextCtrl, the Clear button is hidden, and no stored terms are loaded.searchhistory.datis deliberately left on disk, so re-enabling restores the previous history rather than starting over.Applied live from
PrefsUnifiedDlg::OnOkviaCfgChanged(IDC_SEARCHHISTORYENABLED), following the same idiom as the existingIDC_EXTCATINFO/IDC_SLIDERbranches, so no restart is needed. The swap useswxSizer::Replace, carries the typed value across, keepswxTE_PROCESS_ENTERso Enter still searches, and re-binds the context menu when a combo is created.Testing
Built monolithic + amulegui clean on macOS ARM64, Ubuntu ARM64 (wxGTK3) and Windows ARM64.
git clang-format origin/masterclean; diff-scoped Tier-2 clang-tidy clean. Verified on the Windows portable: the crash is gone, Reset Fields keeps the dropdown, and the preference toggle swaps the field and the button live in both directions.