diff --git a/src/gui/control/card_editor.cpp b/src/gui/control/card_editor.cpp index 8242c685..04aec457 100644 --- a/src/gui/control/card_editor.cpp +++ b/src/gui/control/card_editor.cpp @@ -79,17 +79,23 @@ void DataEditor::selectFirst() { selectByTabPos(0); } bool DataEditor::selectNext() { - return selectByTabPos(currentTabPos() + 1); + return selectByTabPos(currentTabPos() + 1, true); } bool DataEditor::selectPrevious() { - return selectByTabPos(currentTabPos() - 1); + return selectByTabPos(currentTabPos() - 1, false); } -bool DataEditor::selectByTabPos(int tab_pos) { - if (tab_pos >= 0 && (size_t)tab_pos < by_tab_index.size()) { - select(by_tab_index[tab_pos]); - return true; - } else if (!by_tab_index.empty()) { +bool DataEditor::selectByTabPos(int tab_pos, bool forward) { + while (tab_pos >= 0 && (size_t)tab_pos < by_tab_index.size()) { + ValueViewer* v = by_tab_index[tab_pos]; + if (v->getField()->editable) { + select(v); + return true; + } + // not enabled, maybe the next one? + tab_pos += forward ? 1 : -1; + } + if (!by_tab_index.empty()) { // also select something! so when we regain focus the selected editor makes sense if (tab_pos < 0) select(by_tab_index.back()); else select(by_tab_index.front()); @@ -235,7 +241,7 @@ void DataEditor::onMotion(wxMouseEvent& ev) { if (!HasCapture()) { // find editor under mouse ValueViewer* new_hovered_viewer = nullptr; - FOR_EACH_EDITOR_REVERSE { // find high z index fields first + FOR_EACH_REVERSE(v,viewers) { // find high z index fields first if (v->containsPoint(pos) && v->getField()->editable) { new_hovered_viewer = v.get(); break; @@ -305,8 +311,6 @@ void DataEditor::selectFieldNoEvents(const RealPoint& p) { return; } } -//% current_viewer = nullptr; -//% current_editor = nullptr; } RealPoint DataEditor::mousePoint(const wxMouseEvent& ev) { diff --git a/src/gui/control/card_editor.hpp b/src/gui/control/card_editor.hpp index ae9bb7a5..de57c3eb 100644 --- a/src/gui/control/card_editor.hpp +++ b/src/gui/control/card_editor.hpp @@ -126,7 +126,7 @@ class DataEditor : public CardViewer { void createTabIndex(); /// Select the field with the given position in the by_tab_index list /** Returns success */ - bool selectByTabPos(int tab_pos); + bool selectByTabPos(int tab_pos, bool forward = true); /// Find the tab pos of the current viewer, returns -1 if not found int currentTabPos() const; }; diff --git a/src/gui/control/text_ctrl.cpp b/src/gui/control/text_ctrl.cpp index 0a057165..b837f327 100644 --- a/src/gui/control/text_ctrl.cpp +++ b/src/gui/control/text_ctrl.cpp @@ -18,7 +18,6 @@ DECLARE_TYPEOF_COLLECTION(ValueViewerP); TextCtrl::TextCtrl(Window* parent, int id, bool multi_line, long style) : DataEditor(parent, id, style) - , value(nullptr) , multi_line(multi_line) {} TextCtrl::~TextCtrl() {} @@ -36,6 +35,12 @@ void TextCtrl::draw(DC& dc) { } } +bool TextCtrl::AcceptsFocus() const { + return wxControl::AcceptsFocus() && + !viewers.empty() && + static_cast(*viewers.front()->getValue()).editable; +} + TextStyle& TextCtrl::getStyle() { assert(!viewers.empty()); diff --git a/src/gui/control/text_ctrl.hpp b/src/gui/control/text_ctrl.hpp index 06f8c639..83394d74 100644 --- a/src/gui/control/text_ctrl.hpp +++ b/src/gui/control/text_ctrl.hpp @@ -55,6 +55,8 @@ class TextCtrl : public DataEditor { virtual void draw(DC& dc); + virtual bool AcceptsFocus() const; + virtual void onChangeSet(); protected: @@ -62,7 +64,6 @@ class TextCtrl : public DataEditor { virtual wxSize DoGetBestSize() const; private: - String* value; ///< Value to edit bool multi_line; ///< Multi line text control? DECLARE_EVENT_TABLE(); diff --git a/src/gui/new_window.cpp b/src/gui/new_window.cpp index 83f096c5..03a47d04 100644 --- a/src/gui/new_window.cpp +++ b/src/gui/new_window.cpp @@ -53,6 +53,7 @@ NewSetWindow::NewSetWindow(Window* parent) } catch (FileNotFoundError e) { handle_error(e); } + game_list->SetFocus(); UpdateWindowUI(wxUPDATE_UI_RECURSE); } diff --git a/src/gui/set/cards_panel.cpp b/src/gui/set/cards_panel.cpp index 9ed75ffb..b59e5d00 100644 --- a/src/gui/set/cards_panel.cpp +++ b/src/gui/set/cards_panel.cpp @@ -37,6 +37,7 @@ CardsPanel::CardsPanel(Window* parent, int id) notes = new TextCtrl(notesP, ID_NOTES, true); collapse_notes = new HoverButton(notesP, ID_COLLAPSE_NOTES, _("btn_collapse"), wxNullColour, false); collapse_notes->SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES); + filter = nullptr; // init sizer for notes panel wxSizer* sn = new wxBoxSizer(wxVERTICAL); wxSizer* sc = new wxBoxSizer(wxHORIZONTAL); @@ -124,6 +125,9 @@ void CardsPanel::initUI(wxToolBar* tb, wxMenuBar* mb) { tb->AddTool(ID_CARD_REMOVE, _(""), load_resource_tool_image(_("card_del")), wxNullBitmap, wxITEM_NORMAL,_TOOLTIP_("remove card"), _HELP_("remove card")); tb->AddSeparator(); tb->AddTool(ID_CARD_ROTATE, _(""), load_resource_tool_image(_("card_rotate")), wxNullBitmap,wxITEM_NORMAL, _TOOLTIP_("rotate card"), _HELP_("rotate card")); +//% tb->AddSeparator(); +//% if (!filter) filter = new wxTextCtrl(tb, wxID_ANY, _(""), wxDefaultPosition, wxDefaultSize, wxSTATIC_BORDER); +//% tb->AddControl(filter); tb->Realize(); // Menus mb->Insert(2, menuCard, _MENU_("cards")); @@ -139,9 +143,11 @@ void CardsPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) { tb->DeleteTool(ID_CARD_ADD); tb->DeleteTool(ID_CARD_REMOVE); tb->DeleteTool(ID_CARD_ROTATE); +//% tb->DeleteTool(filter->GetId()); filter = nullptr; // HACK: hardcoded size of rest of toolbar tb->DeleteToolByPos(12); // delete separator tb->DeleteToolByPos(12); // delete separator +//% tb->DeleteToolByPos(12); // delete separator // Menus mb->Remove(3); mb->Remove(2); diff --git a/src/gui/set/cards_panel.hpp b/src/gui/set/cards_panel.hpp index 82f276f4..964224a3 100644 --- a/src/gui/set/cards_panel.hpp +++ b/src/gui/set/cards_panel.hpp @@ -77,6 +77,7 @@ class CardsPanel : public SetWindowPanel { ImageCardList* card_list; TextCtrl* notes; HoverButton* collapse_notes; + wxTextCtrl* filter; // --------------------------------------------------- : Menus & tools IconMenu* menuCard, *menuFormat; diff --git a/src/gui/set/keywords_panel.cpp b/src/gui/set/keywords_panel.cpp index 283205b1..9bdec106 100644 --- a/src/gui/set/keywords_panel.cpp +++ b/src/gui/set/keywords_panel.cpp @@ -39,8 +39,8 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id) mode = new wxChoice(panel, ID_KEYWORD_MODE, wxDefaultPosition, wxDefaultSize, 0, nullptr); match = new TextCtrl(panel, ID_MATCH, false); add_param = new wxButton(panel, ID_KEYWORD_ADD_PARAM, _BUTTON_("insert parameter")); - ref_param = new wxButton(panel, ID_KEYWORD_REF_PARAM, _BUTTON_("refer parameter")); reminder = new TextCtrl(panel, ID_REMINDER, true); // allow multiline for wordwrap + ref_param = new wxButton(panel, ID_KEYWORD_REF_PARAM, _BUTTON_("refer parameter")); rules = new TextCtrl(panel, ID_RULES, true); errors = new wxStaticText(panel, wxID_ANY, _("")); errors->SetForegroundColour(*wxRED);