mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Fix missing carret in card filter box
Add Ctrl+K as a shortcut for card/keyword filter
This commit is contained in:
@@ -32,24 +32,14 @@ protected:
|
||||
|
||||
// ----------------------------------------------------------------------------- : 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)
|
||||
: wxControl(parent, id, wxDefaultPosition, wxSize(160,-1), wxSTATIC_BORDER)
|
||||
: wxTextCtrl(parent, id, _(""), wxDefaultPosition, wxSize(160, -1), wxBORDER_THEME)
|
||||
, changing(false)
|
||||
, placeholder(placeholder)
|
||||
{
|
||||
wxColour bg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
|
||||
SetBackgroundColour(bg);
|
||||
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->SetCursor(*wxSTANDARD_CURSOR);
|
||||
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() {
|
||||
changing = true;
|
||||
if (!value.empty() || hasFocus()) {
|
||||
filter_ctrl->SetValue(value);
|
||||
SetValue(value);
|
||||
wxColour fg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
|
||||
filter_ctrl->SetDefaultStyle(wxTextAttr(fg));
|
||||
filter_ctrl->SetForegroundColour(fg);
|
||||
SetDefaultStyle(wxTextAttr(fg));
|
||||
SetForegroundColour(fg);
|
||||
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
||||
filter_ctrl->SetFont(font);
|
||||
SetFont(font);
|
||||
} else {
|
||||
filter_ctrl->SetValue(placeholder);
|
||||
SetValue(placeholder);
|
||||
wxColour fg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
|
||||
wxColour bg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
|
||||
filter_ctrl->SetDefaultStyle(wxTextAttr(lerp(fg,bg,0.5)));
|
||||
filter_ctrl->SetForegroundColour(lerp(fg,bg,0.5));
|
||||
SetDefaultStyle(wxTextAttr(lerp(fg,bg,0.5)));
|
||||
SetForegroundColour(lerp(fg,bg,0.5));
|
||||
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
||||
font.SetStyle(wxFONTSTYLE_ITALIC);
|
||||
filter_ctrl->SetFont(font);
|
||||
SetFont(font);
|
||||
}
|
||||
clear_button->Show(!value.empty());
|
||||
changing = false;
|
||||
@@ -93,7 +90,7 @@ void FilterCtrl::update() {
|
||||
|
||||
void FilterCtrl::onChangeEvent(wxCommandEvent&) {
|
||||
if (!changing) {
|
||||
setFilter(filter_ctrl->GetValue(),true);
|
||||
setFilter(GetValue(),true);
|
||||
}
|
||||
}
|
||||
void FilterCtrl::onChar(wxKeyEvent& ev) {
|
||||
@@ -114,24 +111,23 @@ void FilterCtrl::onSizeEvent(wxSizeEvent&) {
|
||||
}
|
||||
void FilterCtrl::onSize() {
|
||||
wxSize s = GetClientSize();
|
||||
wxSize fs = filter_ctrl->GetBestSize();
|
||||
wxSize cs = clear_button->GetBestSize();
|
||||
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);
|
||||
}
|
||||
|
||||
void FilterCtrl::onSetFocus(wxFocusEvent&) {
|
||||
filter_ctrl->SetFocus();
|
||||
void FilterCtrl::onSetFocus(wxFocusEvent& ev) {
|
||||
update();
|
||||
ev.Skip();
|
||||
}
|
||||
void FilterCtrl::onKillFocus(wxFocusEvent&) {
|
||||
void FilterCtrl::onKillFocus(wxFocusEvent& ev) {
|
||||
update();
|
||||
ev.Skip();
|
||||
}
|
||||
|
||||
bool FilterCtrl::hasFocus() {
|
||||
wxWindow* focus = wxWindow::FindFocus();
|
||||
return focus == this || focus == filter_ctrl || focus == clear_button;
|
||||
return focus == this || focus == clear_button;
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(FilterCtrl, wxControl)
|
||||
@@ -142,19 +138,3 @@ BEGIN_EVENT_TABLE(FilterCtrl, wxControl)
|
||||
EVT_KILL_FOCUS(FilterCtrl::onKillFocus)
|
||||
EVT_CHAR (FilterCtrl::onChar)
|
||||
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()
|
||||
|
||||
|
||||
@@ -12,12 +12,11 @@
|
||||
#include <data/filter.hpp>
|
||||
|
||||
class HoverButton;
|
||||
class TextCtrlWithFocus;
|
||||
|
||||
// ----------------------------------------------------------------------------- : FilterCtrl
|
||||
|
||||
/// A search/filter textbox
|
||||
class FilterCtrl : public wxControl {
|
||||
class FilterCtrl : public wxTextCtrl {
|
||||
public:
|
||||
FilterCtrl(wxWindow* parent, int id, String const& placeholder);
|
||||
|
||||
@@ -26,9 +25,10 @@ public:
|
||||
void clearFilter(bool send_event = false) { setFilter(String(),send_event); }
|
||||
bool hasFilter() const { return !value.empty(); }
|
||||
String const& getFilterString() const { return value; }
|
||||
void focusAndSelect();
|
||||
|
||||
template <typename T>
|
||||
intrusive_ptr<Filter<T> > getFilter() const {
|
||||
intrusive_ptr<Filter<T>> getFilter() const {
|
||||
if (hasFilter()) {
|
||||
return make_intrusive<QuickFilter<T>>(getFilterString());
|
||||
} else {
|
||||
@@ -41,7 +41,6 @@ private:
|
||||
bool changing;
|
||||
String value;
|
||||
String placeholder;
|
||||
TextCtrlWithFocus* filter_ctrl;
|
||||
HoverButton* clear_button;
|
||||
|
||||
void update();
|
||||
@@ -54,5 +53,6 @@ private:
|
||||
void onSize();
|
||||
void onSetFocus(wxFocusEvent&);
|
||||
void onKillFocus(wxFocusEvent&);
|
||||
void onPaint(wxPaintEvent&);
|
||||
};
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ CardsPanel::CardsPanel(Window* parent, int id)
|
||||
menuCard = new wxMenu();
|
||||
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_SEARCH, nullptr, "search cards");
|
||||
menuCard->AppendSeparator();
|
||||
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");
|
||||
@@ -303,6 +304,9 @@ void CardsPanel::onCommand(int id) {
|
||||
// Note: Forwarded events may cause this to occur even at the bottom.
|
||||
if (card_list->canSelectNext()) card_list->selectNext();
|
||||
break;
|
||||
case ID_CARD_SEARCH:
|
||||
filter->focusAndSelect();
|
||||
break;
|
||||
case ID_CARD_ADD:
|
||||
set->actions.addAction(make_unique<AddCardAction>(*set));
|
||||
break;
|
||||
|
||||
@@ -104,6 +104,7 @@ void KeywordsPanel::initControls() {
|
||||
menuKeyword = new wxMenu();
|
||||
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_SEARCH, nullptr, "search keywords");
|
||||
menuKeyword->AppendSeparator();
|
||||
add_menu_item_tr(menuKeyword, ID_KEYWORD_ADD, "keyword_add", "add_keyword");
|
||||
// NOTE: space after "Del" prevents wx from making del an accellerator
|
||||
@@ -174,6 +175,9 @@ void KeywordsPanel::onCommand(int id) {
|
||||
case ID_KEYWORD_NEXT:
|
||||
list->selectNext();
|
||||
break;
|
||||
case ID_KEYWORD_SEARCH:
|
||||
filter->focusAndSelect();
|
||||
break;
|
||||
case ID_KEYWORD_ADD:
|
||||
set->actions.addAction(make_unique<AddKeywordAction>(*set));
|
||||
break;
|
||||
|
||||
@@ -97,6 +97,7 @@ enum ChildMenuID {
|
||||
ID_CARD_REMOVE,
|
||||
ID_CARD_PREV,
|
||||
ID_CARD_NEXT,
|
||||
ID_CARD_SEARCH,
|
||||
ID_CARD_ROTATE,
|
||||
ID_CARD_ROTATE_0,
|
||||
ID_CARD_ROTATE_90,
|
||||
@@ -110,6 +111,7 @@ enum ChildMenuID {
|
||||
ID_KEYWORD_REMOVE,
|
||||
ID_KEYWORD_PREV,
|
||||
ID_KEYWORD_NEXT,
|
||||
ID_KEYWORD_SEARCH,
|
||||
|
||||
// Format menu
|
||||
ID_FORMAT_BOLD = 6201,
|
||||
|
||||
Reference in New Issue
Block a user