Commit eaf81aed authored by twanvl's avatar twanvl

escape key clears card filter box

parent 54de7cf9
...@@ -40,7 +40,8 @@ DECLARE_TYPEOF_COLLECTION(AddCardsScriptP); ...@@ -40,7 +40,8 @@ DECLARE_TYPEOF_COLLECTION(AddCardsScriptP);
class TextCtrlWithFocus : public wxTextCtrl { class TextCtrlWithFocus : public wxTextCtrl {
public: public:
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
void forwardEvent(wxFocusEvent&); void forwardFocusEvent(wxFocusEvent&);
void forwardKeyEvent(wxKeyEvent&);
}; };
/// A search/filter textbox /// A search/filter textbox
...@@ -49,7 +50,7 @@ class FilterCtrl : public wxControl { ...@@ -49,7 +50,7 @@ class FilterCtrl : public wxControl {
FilterCtrl(wxWindow* parent, int id); FilterCtrl(wxWindow* parent, int id);
/// Set the filter text /// Set the filter text
void setFilter(const String& filter, bool event = false); void setFilter(const String& filter, bool event = false);
void clearFilter() { setFilter(String()); } void clearFilter(bool event = false) { setFilter(String(),event); }
bool hasFilter() const { return !value.empty(); } bool hasFilter() const { return !value.empty(); }
String const& getFilter() const { return value; } String const& getFilter() const { return value; }
...@@ -68,6 +69,7 @@ class FilterCtrl : public wxControl { ...@@ -68,6 +69,7 @@ class FilterCtrl : public wxControl {
void onChangeEvent(wxCommandEvent&); void onChangeEvent(wxCommandEvent&);
void onClear(wxCommandEvent&); void onClear(wxCommandEvent&);
void onSizeEvent(wxSizeEvent&); void onSizeEvent(wxSizeEvent&);
void onChar(wxKeyEvent&);
void onSize(); void onSize();
public: public:
void onSetFocus(wxFocusEvent&); void onSetFocus(wxFocusEvent&);
...@@ -124,9 +126,17 @@ void FilterCtrl::onChangeEvent(wxCommandEvent&) { ...@@ -124,9 +126,17 @@ void FilterCtrl::onChangeEvent(wxCommandEvent&) {
setFilter(filter_ctrl->GetValue(),true); setFilter(filter_ctrl->GetValue(),true);
} }
} }
void FilterCtrl::onChar(wxKeyEvent& ev) {
if (ev.GetKeyCode() == WXK_ESCAPE) {
// escape clears the filter box
clearFilter(true);
} else {
ev.Skip();
}
}
void FilterCtrl::onClear(wxCommandEvent&) { void FilterCtrl::onClear(wxCommandEvent&) {
setFilter(String(),true); clearFilter(true);
} }
void FilterCtrl::onSizeEvent(wxSizeEvent&) { void FilterCtrl::onSizeEvent(wxSizeEvent&) {
...@@ -160,15 +170,20 @@ BEGIN_EVENT_TABLE(FilterCtrl, wxControl) ...@@ -160,15 +170,20 @@ BEGIN_EVENT_TABLE(FilterCtrl, wxControl)
EVT_SIZE (FilterCtrl::onSizeEvent) EVT_SIZE (FilterCtrl::onSizeEvent)
EVT_SET_FOCUS (FilterCtrl::onSetFocus) EVT_SET_FOCUS (FilterCtrl::onSetFocus)
EVT_KILL_FOCUS(FilterCtrl::onKillFocus) EVT_KILL_FOCUS(FilterCtrl::onKillFocus)
EVT_CHAR (FilterCtrl::onChar)
END_EVENT_TABLE() END_EVENT_TABLE()
void TextCtrlWithFocus::forwardEvent(wxFocusEvent& ev) { void TextCtrlWithFocus::forwardFocusEvent(wxFocusEvent& ev) {
GetParent()->HandleWindowEvent(ev);
}
void TextCtrlWithFocus::forwardKeyEvent(wxKeyEvent& ev) {
GetParent()->HandleWindowEvent(ev); GetParent()->HandleWindowEvent(ev);
} }
BEGIN_EVENT_TABLE(TextCtrlWithFocus, wxTextCtrl) BEGIN_EVENT_TABLE(TextCtrlWithFocus, wxTextCtrl)
EVT_SET_FOCUS (TextCtrlWithFocus::forwardEvent) EVT_SET_FOCUS (TextCtrlWithFocus::forwardFocusEvent)
EVT_KILL_FOCUS(TextCtrlWithFocus::forwardEvent) EVT_KILL_FOCUS(TextCtrlWithFocus::forwardFocusEvent)
EVT_CHAR (TextCtrlWithFocus::forwardKeyEvent)
END_EVENT_TABLE() END_EVENT_TABLE()
// ----------------------------------------------------------------------------- : CardsPanel // ----------------------------------------------------------------------------- : CardsPanel
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment