Fix missing carret in card filter box

Add Ctrl+K as a shortcut for card/keyword filter
This commit is contained in:
Twan van Laarhoven
2020-05-15 01:57:45 +02:00
parent c9698573c9
commit 3ea5ea9573
7 changed files with 51 additions and 56 deletions
+1
View File
@@ -11,6 +11,7 @@ Features:
for example `type:Wizard` searches for cards with Wizard in the type. for example `type:Wizard` searches for cards with Wizard in the type.
* Added "Select All" to menu (#19) * Added "Select All" to menu (#19)
* Added "Save as Directory" to menu * Added "Save as Directory" to menu
* Added a keyboard shortcut for the search box (Ctrl+K)
Bug fixes: Bug fixes:
* card variable in console panel now refers to the selected card * card variable in console panel now refers to the selected card
+14 -10
View File
@@ -1,7 +1,7 @@
mse version: 2.0.2 mse version: 2.0.2
installer group: translations/English installer group: translations/English
full name: English full name: English
version: 2029-05-09 version: 2020-05-15
icon: usgb.png icon: usgb.png
############################################################## Menu items ############################################################## Menu items
@@ -47,6 +47,7 @@ menu:
cards: &Cards cards: &Cards
previous card: Select &Previous Card PgUp previous card: Select &Previous Card PgUp
next card: Select &Next Card PgDn next card: Select &Next Card PgDn
search cards: &Search Cards Ctrl+K
add card: &Add Card Ctrl+Enter add card: &Add Card Ctrl+Enter
add cards: Add &Multiple Cards... add cards: Add &Multiple Cards...
remove card: &Delete Selected Card remove card: &Delete Selected Card
@@ -60,6 +61,7 @@ menu:
keywords: &Keywords keywords: &Keywords
previous keyword: Select &Previous Keyword PgUp previous keyword: Select &Previous Keyword PgUp
next keyword: Select &Next Keyword PgDn next keyword: Select &Next Keyword PgDn
search keywords: &Search Keywords Ctrl+K
add keyword: &Add Keyword Ctrl+Enter add keyword: &Add Keyword Ctrl+Enter
remove keyword: &Remove Select Keyword Del remove keyword: &Remove Select Keyword Del
@@ -81,13 +83,13 @@ menu:
window: &Window window: &Window
new window: &New Window new window: &New Window
cards tab: &Cards (Alt+1) cards tab: &Cards Alt+1
set info tab: &Set Information (Alt+2) set info tab: &Set Information Alt+2
style tab: St&yle (Alt+3) style tab: St&yle Alt+3
keywords tab: &Keywords (Alt+4) keywords tab: &Keywords Alt+4
stats tab: S&tatistics (Alt+5) stats tab: S&tatistics Alt+5
random pack tab: &Random Packs (Alt+6) random pack tab: &Random Packs Alt+6
console tab: &Console (Alt+7) console tab: &Console Alt+7
help: &Help help: &Help
index: &Index... F1 index: &Index... F1
@@ -161,6 +163,7 @@ help:
#cards: #cards:
previous card: Selects the previous card in the list previous card: Selects the previous card in the list
next card: Selects the next card in the list next card: Selects the next card in the list
search cards: Filter the card list using search terms
add card: Add a new, blank, card to this set add card: Add a new, blank, card to this set
add cards: Add multiple cards to the set add cards: Add multiple cards to the set
remove card: Delete the selected card from this set remove card: Delete the selected card from this set
@@ -175,6 +178,7 @@ help:
#keywords: #keywords:
previous keyword: Selects the previous keyword in the list previous keyword: Selects the previous keyword in the list
next keyword: Selects the next keyword in the list next keyword: Selects the next keyword in the list
search keywords: Filter the keyword list using search terms
add keyword: Add a new keyword to this set add keyword: Add a new keyword to this set
remove keyword: Delete the selected keyword from this set remove keyword: Delete the selected keyword from this set
@@ -421,10 +425,10 @@ tooltip:
label: label:
# Cards tab # Cards tab
card notes: Card notes: card notes: Card notes:
search cards: Search for cards... search cards: Search cards (Ctrl+K)
# Keywords tab # Keywords tab
search keywords: Search for keywords... search keywords: Search keywords (Ctrl+K)
keyword: Keyword keyword: Keyword
match: Matches match: Matches
mode: Mode mode: Mode
+22 -42
View File
@@ -32,24 +32,14 @@ protected:
// ----------------------------------------------------------------------------- : FilterControl // ----------------------------------------------------------------------------- : FilterControl
/// Text control that forwards focus events to the parent
class TextCtrlWithFocus : public wxTextCtrl {
public:
DECLARE_EVENT_TABLE();
void forwardFocusEvent(wxFocusEvent&);
void forwardKeyEvent(wxKeyEvent&);
};
FilterCtrl::FilterCtrl(wxWindow* parent, int id, String const& placeholder) FilterCtrl::FilterCtrl(wxWindow* parent, int id, String const& placeholder)
: wxControl(parent, id, wxDefaultPosition, wxSize(160,-1), wxSTATIC_BORDER) : wxTextCtrl(parent, id, _(""), wxDefaultPosition, wxSize(160, -1), wxBORDER_THEME)
, changing(false) , changing(false)
, placeholder(placeholder) , placeholder(placeholder)
{ {
wxColour bg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); wxColour bg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
SetBackgroundColour(bg); SetBackgroundColour(bg);
SetCursor(wxCURSOR_IBEAM); SetCursor(wxCURSOR_IBEAM);
filter_ctrl = new TextCtrlWithFocus();
filter_ctrl->Create(this, wxID_ANY, _(""), wxDefaultPosition, wxSize(130,-1), wxNO_BORDER);
clear_button = new HoverButton(this, wxID_ANY, _("btn_clear_filter"), bg, false); clear_button = new HoverButton(this, wxID_ANY, _("btn_clear_filter"), bg, false);
clear_button->SetCursor(*wxSTANDARD_CURSOR); clear_button->SetCursor(*wxSTANDARD_CURSOR);
onSize(); onSize();
@@ -68,24 +58,31 @@ void FilterCtrl::setFilter(const String& new_value, bool event) {
} }
} }
void FilterCtrl::focusAndSelect() {
SetFocus();
if (!value.empty()) {
SetSelection(-1,-1);
}
}
void FilterCtrl::update() { void FilterCtrl::update() {
changing = true; changing = true;
if (!value.empty() || hasFocus()) { if (!value.empty() || hasFocus()) {
filter_ctrl->SetValue(value); SetValue(value);
wxColour fg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); wxColour fg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
filter_ctrl->SetDefaultStyle(wxTextAttr(fg)); SetDefaultStyle(wxTextAttr(fg));
filter_ctrl->SetForegroundColour(fg); SetForegroundColour(fg);
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
filter_ctrl->SetFont(font); SetFont(font);
} else { } else {
filter_ctrl->SetValue(placeholder); SetValue(placeholder);
wxColour fg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); wxColour fg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
wxColour bg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); wxColour bg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
filter_ctrl->SetDefaultStyle(wxTextAttr(lerp(fg,bg,0.5))); SetDefaultStyle(wxTextAttr(lerp(fg,bg,0.5)));
filter_ctrl->SetForegroundColour(lerp(fg,bg,0.5)); SetForegroundColour(lerp(fg,bg,0.5));
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
font.SetStyle(wxFONTSTYLE_ITALIC); font.SetStyle(wxFONTSTYLE_ITALIC);
filter_ctrl->SetFont(font); SetFont(font);
} }
clear_button->Show(!value.empty()); clear_button->Show(!value.empty());
changing = false; changing = false;
@@ -93,7 +90,7 @@ void FilterCtrl::update() {
void FilterCtrl::onChangeEvent(wxCommandEvent&) { void FilterCtrl::onChangeEvent(wxCommandEvent&) {
if (!changing) { if (!changing) {
setFilter(filter_ctrl->GetValue(),true); setFilter(GetValue(),true);
} }
} }
void FilterCtrl::onChar(wxKeyEvent& ev) { void FilterCtrl::onChar(wxKeyEvent& ev) {
@@ -114,24 +111,23 @@ void FilterCtrl::onSizeEvent(wxSizeEvent&) {
} }
void FilterCtrl::onSize() { void FilterCtrl::onSize() {
wxSize s = GetClientSize(); wxSize s = GetClientSize();
wxSize fs = filter_ctrl->GetBestSize();
wxSize cs = clear_button->GetBestSize(); wxSize cs = clear_button->GetBestSize();
int margin = 2; int margin = 2;
filter_ctrl ->SetSize(margin, max(margin,(s.y-fs.y)/2), s.x - cs.x - 3*margin, fs.y);
clear_button->SetSize(s.x - cs.x - margin, (s.y-cs.y)/2, cs.x, cs.y); clear_button->SetSize(s.x - cs.x - margin, (s.y-cs.y)/2, cs.x, cs.y);
} }
void FilterCtrl::onSetFocus(wxFocusEvent&) { void FilterCtrl::onSetFocus(wxFocusEvent& ev) {
filter_ctrl->SetFocus();
update(); update();
ev.Skip();
} }
void FilterCtrl::onKillFocus(wxFocusEvent&) { void FilterCtrl::onKillFocus(wxFocusEvent& ev) {
update(); update();
ev.Skip();
} }
bool FilterCtrl::hasFocus() { bool FilterCtrl::hasFocus() {
wxWindow* focus = wxWindow::FindFocus(); wxWindow* focus = wxWindow::FindFocus();
return focus == this || focus == filter_ctrl || focus == clear_button; return focus == this || focus == clear_button;
} }
BEGIN_EVENT_TABLE(FilterCtrl, wxControl) BEGIN_EVENT_TABLE(FilterCtrl, wxControl)
@@ -142,19 +138,3 @@ BEGIN_EVENT_TABLE(FilterCtrl, wxControl)
EVT_KILL_FOCUS(FilterCtrl::onKillFocus) EVT_KILL_FOCUS(FilterCtrl::onKillFocus)
EVT_CHAR (FilterCtrl::onChar) EVT_CHAR (FilterCtrl::onChar)
END_EVENT_TABLE() END_EVENT_TABLE()
// ----------------------------------------------------------------------------- : TextCtrlWithFocus
void TextCtrlWithFocus::forwardFocusEvent(wxFocusEvent& ev) {
GetParent()->HandleWindowEvent(ev);
}
void TextCtrlWithFocus::forwardKeyEvent(wxKeyEvent& ev) {
GetParent()->HandleWindowEvent(ev);
}
BEGIN_EVENT_TABLE(TextCtrlWithFocus, wxTextCtrl)
EVT_SET_FOCUS (TextCtrlWithFocus::forwardFocusEvent)
EVT_KILL_FOCUS(TextCtrlWithFocus::forwardFocusEvent)
EVT_CHAR (TextCtrlWithFocus::forwardKeyEvent)
END_EVENT_TABLE()
+4 -4
View File
@@ -12,12 +12,11 @@
#include <data/filter.hpp> #include <data/filter.hpp>
class HoverButton; class HoverButton;
class TextCtrlWithFocus;
// ----------------------------------------------------------------------------- : FilterCtrl // ----------------------------------------------------------------------------- : FilterCtrl
/// A search/filter textbox /// A search/filter textbox
class FilterCtrl : public wxControl { class FilterCtrl : public wxTextCtrl {
public: public:
FilterCtrl(wxWindow* parent, int id, String const& placeholder); FilterCtrl(wxWindow* parent, int id, String const& placeholder);
@@ -26,9 +25,10 @@ public:
void clearFilter(bool send_event = false) { setFilter(String(),send_event); } void clearFilter(bool send_event = false) { setFilter(String(),send_event); }
bool hasFilter() const { return !value.empty(); } bool hasFilter() const { return !value.empty(); }
String const& getFilterString() const { return value; } String const& getFilterString() const { return value; }
void focusAndSelect();
template <typename T> template <typename T>
intrusive_ptr<Filter<T> > getFilter() const { intrusive_ptr<Filter<T>> getFilter() const {
if (hasFilter()) { if (hasFilter()) {
return make_intrusive<QuickFilter<T>>(getFilterString()); return make_intrusive<QuickFilter<T>>(getFilterString());
} else { } else {
@@ -41,7 +41,6 @@ private:
bool changing; bool changing;
String value; String value;
String placeholder; String placeholder;
TextCtrlWithFocus* filter_ctrl;
HoverButton* clear_button; HoverButton* clear_button;
void update(); void update();
@@ -54,5 +53,6 @@ private:
void onSize(); void onSize();
void onSetFocus(wxFocusEvent&); void onSetFocus(wxFocusEvent&);
void onKillFocus(wxFocusEvent&); void onKillFocus(wxFocusEvent&);
void onPaint(wxPaintEvent&);
}; };
+4
View File
@@ -67,6 +67,7 @@ CardsPanel::CardsPanel(Window* parent, int id)
menuCard = new wxMenu(); menuCard = new wxMenu();
add_menu_item_tr(menuCard, ID_CARD_PREV, nullptr, "previous card"); add_menu_item_tr(menuCard, ID_CARD_PREV, nullptr, "previous card");
add_menu_item_tr(menuCard, ID_CARD_NEXT, nullptr, "next card"); add_menu_item_tr(menuCard, ID_CARD_NEXT, nullptr, "next card");
add_menu_item_tr(menuCard, ID_CARD_SEARCH, nullptr, "search cards");
menuCard->AppendSeparator(); menuCard->AppendSeparator();
add_menu_item_tr(menuCard, ID_CARD_ADD, "card_add", "add_card"); add_menu_item_tr(menuCard, ID_CARD_ADD, "card_add", "add_card");
insertManyCardsMenu = add_menu_item_tr(menuCard, ID_CARD_ADD_MULT, "card_add_multiple", "add cards"); insertManyCardsMenu = add_menu_item_tr(menuCard, ID_CARD_ADD_MULT, "card_add_multiple", "add cards");
@@ -303,6 +304,9 @@ void CardsPanel::onCommand(int id) {
// Note: Forwarded events may cause this to occur even at the bottom. // Note: Forwarded events may cause this to occur even at the bottom.
if (card_list->canSelectNext()) card_list->selectNext(); if (card_list->canSelectNext()) card_list->selectNext();
break; break;
case ID_CARD_SEARCH:
filter->focusAndSelect();
break;
case ID_CARD_ADD: case ID_CARD_ADD:
set->actions.addAction(make_unique<AddCardAction>(*set)); set->actions.addAction(make_unique<AddCardAction>(*set));
break; break;
+4
View File
@@ -104,6 +104,7 @@ void KeywordsPanel::initControls() {
menuKeyword = new wxMenu(); menuKeyword = new wxMenu();
add_menu_item_tr(menuKeyword, ID_KEYWORD_PREV, nullptr, "previous_keyword"); add_menu_item_tr(menuKeyword, ID_KEYWORD_PREV, nullptr, "previous_keyword");
add_menu_item_tr(menuKeyword, ID_KEYWORD_NEXT, nullptr, "next_keyword"); add_menu_item_tr(menuKeyword, ID_KEYWORD_NEXT, nullptr, "next_keyword");
add_menu_item_tr(menuKeyword, ID_KEYWORD_SEARCH, nullptr, "search keywords");
menuKeyword->AppendSeparator(); menuKeyword->AppendSeparator();
add_menu_item_tr(menuKeyword, ID_KEYWORD_ADD, "keyword_add", "add_keyword"); add_menu_item_tr(menuKeyword, ID_KEYWORD_ADD, "keyword_add", "add_keyword");
// NOTE: space after "Del" prevents wx from making del an accellerator // NOTE: space after "Del" prevents wx from making del an accellerator
@@ -174,6 +175,9 @@ void KeywordsPanel::onCommand(int id) {
case ID_KEYWORD_NEXT: case ID_KEYWORD_NEXT:
list->selectNext(); list->selectNext();
break; break;
case ID_KEYWORD_SEARCH:
filter->focusAndSelect();
break;
case ID_KEYWORD_ADD: case ID_KEYWORD_ADD:
set->actions.addAction(make_unique<AddKeywordAction>(*set)); set->actions.addAction(make_unique<AddKeywordAction>(*set));
break; break;
+2
View File
@@ -97,6 +97,7 @@ enum ChildMenuID {
ID_CARD_REMOVE, ID_CARD_REMOVE,
ID_CARD_PREV, ID_CARD_PREV,
ID_CARD_NEXT, ID_CARD_NEXT,
ID_CARD_SEARCH,
ID_CARD_ROTATE, ID_CARD_ROTATE,
ID_CARD_ROTATE_0, ID_CARD_ROTATE_0,
ID_CARD_ROTATE_90, ID_CARD_ROTATE_90,
@@ -110,6 +111,7 @@ enum ChildMenuID {
ID_KEYWORD_REMOVE, ID_KEYWORD_REMOVE,
ID_KEYWORD_PREV, ID_KEYWORD_PREV,
ID_KEYWORD_NEXT, ID_KEYWORD_NEXT,
ID_KEYWORD_SEARCH,
// Format menu // Format menu
ID_FORMAT_BOLD = 6201, ID_FORMAT_BOLD = 6201,