mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 05:36:59 -04:00
Fixed tab key behaviour the first time of viewing a card. Also fixed which editor gets the focus with Tab or Shift+Tab
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@966 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -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) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
|||||||
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() {
|
|||||||
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) {
|
|||||||
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
|
||||||
@@ -388,7 +394,11 @@ void DataEditor::onFocus(wxFocusEvent& ev) {
|
|||||||
current_editor->onFocus();
|
current_editor->onFocus();
|
||||||
onChange();
|
onChange();
|
||||||
} else {
|
} else {
|
||||||
selectFirst();
|
if (ev.GetWindow() && ev.GetWindow() == next_in_tab_order) {
|
||||||
|
selectLast();
|
||||||
|
} else {
|
||||||
|
selectFirst();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void DataEditor::onLoseFocus(wxFocusEvent& ev) {
|
void DataEditor::onLoseFocus(wxFocusEvent& ev) {
|
||||||
|
|||||||
@@ -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 {
|
|||||||
|
|
||||||
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)
|
|||||||
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user