Commit 78c2ab5e authored by twanvl's avatar twanvl

Some more keyboard related tweaks.

parent edd8649d
......@@ -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) {
......
......@@ -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;
};
......
......@@ -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<FakeTextValue&>(*viewers.front()->getValue()).editable;
}
TextStyle& TextCtrl::getStyle() {
assert(!viewers.empty());
......
......@@ -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();
......
......@@ -53,6 +53,7 @@ NewSetWindow::NewSetWindow(Window* parent)
} catch (FileNotFoundError e) {
handle_error(e);
}
game_list->SetFocus();
UpdateWindowUI(wxUPDATE_UI_RECURSE);
}
......
......@@ -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);
......
......@@ -77,6 +77,7 @@ class CardsPanel : public SetWindowPanel {
ImageCardList* card_list;
TextCtrl* notes;
HoverButton* collapse_notes;
wxTextCtrl* filter;
// --------------------------------------------------- : Menus & tools
IconMenu* menuCard, *menuFormat;
......
......@@ -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);
......
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