Commit 31006b6c authored by twanvl's avatar twanvl

Fixed tab key behaviour the first time of viewing a card. Also fixed which...

Fixed tab key behaviour the first time of viewing a card. Also fixed which editor gets the focus with Tab or Shift+Tab
parent a72371df
...@@ -24,6 +24,7 @@ DECLARE_TYPEOF_COLLECTION(ValueViewer*); ...@@ -24,6 +24,7 @@ DECLARE_TYPEOF_COLLECTION(ValueViewer*);
DataEditor::DataEditor(Window* parent, int id, long style) DataEditor::DataEditor(Window* parent, int id, long style)
: CardViewer(parent, id, style | wxWANTS_CHARS) : CardViewer(parent, id, style | wxWANTS_CHARS)
, next_in_tab_order(nullptr)
, current_viewer(nullptr) , current_viewer(nullptr)
, current_editor(nullptr) , current_editor(nullptr)
, hovered_viewer(nullptr) , hovered_viewer(nullptr)
...@@ -78,7 +79,10 @@ void DataEditor::select(ValueViewer* v) { ...@@ -78,7 +79,10 @@ void DataEditor::select(ValueViewer* v) {
} }
void DataEditor::selectFirst() { void DataEditor::selectFirst() {
selectByTabPos(0); selectByTabPos(0, true);
}
void DataEditor::selectLast() {
selectByTabPos((int)by_tab_index.size() - 1, false);
} }
bool DataEditor::selectNext() { bool DataEditor::selectNext() {
return selectByTabPos(currentTabPos() + 1, true); return selectByTabPos(currentTabPos() + 1, true);
...@@ -90,18 +94,20 @@ bool DataEditor::selectPrevious() { ...@@ -90,18 +94,20 @@ bool DataEditor::selectPrevious() {
bool DataEditor::selectByTabPos(int tab_pos, bool forward) { bool DataEditor::selectByTabPos(int tab_pos, bool forward) {
while (tab_pos >= 0 && (size_t)tab_pos < by_tab_index.size()) { while (tab_pos >= 0 && (size_t)tab_pos < by_tab_index.size()) {
ValueViewer* v = by_tab_index[tab_pos]; ValueViewer* v = by_tab_index[tab_pos];
if (v->getField()->editable) { if (v->getField()->editable && v->getStyle()->isVisible()) {
select(v); select(v);
return true; return true;
} }
// not enabled, maybe the next one? // not enabled, maybe the next one?
tab_pos += forward ? 1 : -1; tab_pos += forward ? 1 : -1;
} }
if (!by_tab_index.empty()) { // deselect
// also select something! so when we regain focus the selected editor makes sense if (current_editor) {
if (tab_pos < 0) select(by_tab_index.back()); current_editor->onLoseFocus();
else select(by_tab_index.front()); onChange();
} }
current_viewer = nullptr;
current_editor = nullptr;
return false; return false;
} }
int DataEditor::currentTabPos() const { int DataEditor::currentTabPos() const {
...@@ -138,7 +144,7 @@ void DataEditor::createTabIndex() { ...@@ -138,7 +144,7 @@ void DataEditor::createTabIndex() {
by_tab_index.clear(); by_tab_index.clear();
FOR_EACH(v, viewers) { FOR_EACH(v, viewers) {
ValueEditor* e = v->getEditor(); ValueEditor* e = v->getEditor();
if (e && v->getField()->editable && v->getStyle()->isVisible()) { if (e) {
by_tab_index.push_back(v.get()); by_tab_index.push_back(v.get());
} }
} }
...@@ -160,7 +166,7 @@ bool DataEditor::search(FindInfo& find, bool from_start) { ...@@ -160,7 +166,7 @@ bool DataEditor::search(FindInfo& find, bool from_start) {
for (size_t i = 0 ; i < by_tab_index.size() ; ++i) { for (size_t i = 0 ; i < by_tab_index.size() ; ++i) {
ValueViewer& viewer = *by_tab_index[find.forward() ? i : by_tab_index.size() - i - 1]; ValueViewer& viewer = *by_tab_index[find.forward() ? i : by_tab_index.size() - i - 1];
if (&viewer == current_viewer) include = true; if (&viewer == current_viewer) include = true;
if (include) { if (include && viewer.getField()->editable && viewer.getStyle()->isVisible()) {
ValueEditor* editor = viewer.getEditor(); ValueEditor* editor = viewer.getEditor();
if (editor && editor->search(find, from_start || &viewer != current_viewer)) { if (editor && editor->search(find, from_start || &viewer != current_viewer)) {
return true; // done return true; // done
...@@ -387,9 +393,13 @@ void DataEditor::onFocus(wxFocusEvent& ev) { ...@@ -387,9 +393,13 @@ void DataEditor::onFocus(wxFocusEvent& ev) {
if (current_editor) { if (current_editor) {
current_editor->onFocus(); current_editor->onFocus();
onChange(); onChange();
} else {
if (ev.GetWindow() && ev.GetWindow() == next_in_tab_order) {
selectLast();
} else { } else {
selectFirst(); selectFirst();
} }
}
} }
void DataEditor::onLoseFocus(wxFocusEvent& ev) { void DataEditor::onLoseFocus(wxFocusEvent& ev) {
if (current_editor) { if (current_editor) {
......
...@@ -36,6 +36,8 @@ class DataEditor : public CardViewer { ...@@ -36,6 +36,8 @@ class DataEditor : public CardViewer {
void select(ValueViewer* v); void select(ValueViewer* v);
/// Select the first editable and visible editor (by tab index) /// Select the first editable and visible editor (by tab index)
void selectFirst(); void selectFirst();
/// Select the last editable and visible editor (by tab index)
void selectLast();
/// Select the next editable editor, returns false if the current editor is the last one /// Select the next editable editor, returns false if the current editor is the last one
bool selectNext(); bool selectNext();
/// Select the previous editable editor, returns false if the current editor is the first one /// Select the previous editable editor, returns false if the current editor is the first one
...@@ -43,6 +45,9 @@ class DataEditor : public CardViewer { ...@@ -43,6 +45,9 @@ class DataEditor : public CardViewer {
virtual bool AcceptsFocus() const; virtual bool AcceptsFocus() const;
/// The next window in the tab order (optional)
const wxWindow* next_in_tab_order;
// --------------------------------------------------- : Clipboard // --------------------------------------------------- : Clipboard
bool canCut() const; bool canCut() const;
......
...@@ -39,6 +39,7 @@ CardsPanel::CardsPanel(Window* parent, int id) ...@@ -39,6 +39,7 @@ CardsPanel::CardsPanel(Window* parent, int id)
collapse_notes = new HoverButton(notesP, ID_COLLAPSE_NOTES, _("btn_collapse"), wxNullColour, false); collapse_notes = new HoverButton(notesP, ID_COLLAPSE_NOTES, _("btn_collapse"), wxNullColour, false);
collapse_notes->SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES); collapse_notes->SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES);
filter = nullptr; filter = nullptr;
editor->next_in_tab_order = card_list;
// init sizer for notes panel // init sizer for notes panel
wxSizer* sn = new wxBoxSizer(wxVERTICAL); wxSizer* sn = new wxBoxSizer(wxVERTICAL);
wxSizer* sc = new wxBoxSizer(wxHORIZONTAL); wxSizer* sc = new wxBoxSizer(wxHORIZONTAL);
......
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