From 424fd961850997f5f0afdc4505cd578296cd05ea Mon Sep 17 00:00:00 2001 From: Twan van Laarhoven Date: Sat, 16 May 2020 14:16:32 +0200 Subject: [PATCH] Add help text to the card/keyword filter boxes --- data/en.mse-locale/locale | 3 +++ src/gui/control/filter_ctrl.cpp | 22 +++++++++++++++++++--- src/gui/control/filter_ctrl.hpp | 7 +++++-- src/gui/set/cards_panel.cpp | 2 +- src/gui/set/keywords_panel.cpp | 2 +- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/data/en.mse-locale/locale b/data/en.mse-locale/locale index bdbc64d5..a4ec5ebd 100644 --- a/data/en.mse-locale/locale +++ b/data/en.mse-locale/locale @@ -215,6 +215,9 @@ help: # Cards panel collapse notes: Hide the card notes box expand notes: Show the card notes box + search cards control: Filter the card list. Use - to exclude cards. Use field: to search in a specific field. Use quotes for literal search. Separate multiple queries with a space. + # Keywords panel + search keywords control: Filter the keyword list. Use - to exclude keywords. Use field: to search in a specific field. Use quotes for literal search. Separate multiple queries with a space. # Random pack panel random seed: Different packs will be generated each time. fixed seed: Using the same seed number gives the same 'random' packs. diff --git a/src/gui/control/filter_ctrl.cpp b/src/gui/control/filter_ctrl.cpp index 6406f77a..081430e3 100644 --- a/src/gui/control/filter_ctrl.cpp +++ b/src/gui/control/filter_ctrl.cpp @@ -32,14 +32,13 @@ protected: // ----------------------------------------------------------------------------- : FilterControl -FilterCtrl::FilterCtrl(wxWindow* parent, int id, String const& placeholder) +FilterCtrl::FilterCtrl(wxWindow* parent, int id, String const& placeholder, String const& help_text) : wxTextCtrl(parent, id, _(""), wxDefaultPosition, wxSize(160, -1), wxBORDER_THEME) , changing(false) , placeholder(placeholder) + , help_text(help_text) { wxColour bg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); - SetBackgroundColour(bg); - SetCursor(wxCURSOR_IBEAM); clear_button = new HoverButton(this, wxID_ANY, _("btn_clear_filter"), bg, false); clear_button->SetCursor(*wxSTANDARD_CURSOR); onSize(); @@ -63,6 +62,7 @@ void FilterCtrl::focusAndSelect() { if (!value.empty()) { SetSelection(-1,-1); } + showHelp(); } void FilterCtrl::update() { @@ -125,16 +125,32 @@ void FilterCtrl::onKillFocus(wxFocusEvent& ev) { ev.Skip(); } +void FilterCtrl::onMouseEnter(wxMouseEvent& ev) { + showHelp(); +} +void FilterCtrl::onMouseLeave(wxMouseEvent& ev) { + showHelp(false); +} + bool FilterCtrl::hasFocus() { wxWindow* focus = wxWindow::FindFocus(); return focus == this || focus == clear_button; } +void FilterCtrl::showHelp(bool show) { + wxFrame* frame = dynamic_cast(wxGetTopLevelParent(this)); + if (frame) { + frame->DoGiveHelp(help_text, show); + } +} + BEGIN_EVENT_TABLE(FilterCtrl, wxControl) EVT_BUTTON (wxID_ANY, FilterCtrl::onClear) EVT_TEXT (wxID_ANY, FilterCtrl::onChangeEvent) EVT_SIZE (FilterCtrl::onSizeEvent) EVT_SET_FOCUS (FilterCtrl::onSetFocus) EVT_KILL_FOCUS(FilterCtrl::onKillFocus) + EVT_ENTER_WINDOW(FilterCtrl::onMouseEnter) + EVT_LEAVE_WINDOW(FilterCtrl::onMouseLeave) EVT_CHAR (FilterCtrl::onChar) END_EVENT_TABLE() diff --git a/src/gui/control/filter_ctrl.hpp b/src/gui/control/filter_ctrl.hpp index acc4b1a5..c2617dfa 100644 --- a/src/gui/control/filter_ctrl.hpp +++ b/src/gui/control/filter_ctrl.hpp @@ -18,7 +18,7 @@ class HoverButton; /// A search/filter textbox class FilterCtrl : public wxTextCtrl { public: - FilterCtrl(wxWindow* parent, int id, String const& placeholder); + FilterCtrl(wxWindow* parent, int id, String const& placeholder, String const& help_text); /// Set the filter text void setFilter(const String& filter, bool send_event = false); @@ -41,10 +41,12 @@ private: bool changing; String value; String placeholder; + String help_text; HoverButton* clear_button; void update(); bool hasFocus(); + void showHelp(bool show = true); // wxWidgets appears to have developed an overload allergy void onChangeEvent(wxCommandEvent&); void onClear(wxCommandEvent&); @@ -53,6 +55,7 @@ private: void onSize(); void onSetFocus(wxFocusEvent&); void onKillFocus(wxFocusEvent&); - void onPaint(wxPaintEvent&); + void onMouseEnter(wxMouseEvent&); + void onMouseLeave(wxMouseEvent&); }; diff --git a/src/gui/set/cards_panel.cpp b/src/gui/set/cards_panel.cpp index b573b809..3cf1a4b5 100644 --- a/src/gui/set/cards_panel.cpp +++ b/src/gui/set/cards_panel.cpp @@ -200,7 +200,7 @@ void CardsPanel::initUI(wxToolBar* tb, wxMenuBar* mb) { // Filter/search textbox tb->AddSeparator(); assert(!filter); - filter = new FilterCtrl(tb, ID_CARD_FILTER, _LABEL_("search cards")); + filter = new FilterCtrl(tb, ID_CARD_FILTER, _LABEL_("search cards"), _HELP_("search_cards_control")); filter->setFilter(filter_value); tb->AddControl(filter); tb->Realize(); diff --git a/src/gui/set/keywords_panel.cpp b/src/gui/set/keywords_panel.cpp index 2e9f95f0..de1b56be 100644 --- a/src/gui/set/keywords_panel.cpp +++ b/src/gui/set/keywords_panel.cpp @@ -132,7 +132,7 @@ void KeywordsPanel::initUI(wxToolBar* tb, wxMenuBar* mb) { // Filter/search textbox tb->AddSeparator(); assert(!filter); - filter = new FilterCtrl(tb, ID_KEYWORD_FILTER, _LABEL_("search keywords")); + filter = new FilterCtrl(tb, ID_KEYWORD_FILTER, _LABEL_("search keywords"), _HELP_("search_keywords_control")); filter->setFilter(filter_value); tb->AddControl(filter); tb->Realize();