From c745bdcb5ca4bde38324a52197d94deefd01a5c4 Mon Sep 17 00:00:00 2001 From: Marcel Hollerbach Date: Wed, 22 Nov 2017 12:18:30 +0100 Subject: [PATCH] elm_gengrid: jump back to the last selected item on gengrid focus jump this moves the item into selection and focus that was last focused or selected. --- src/lib/elementary/elm_gengrid.c | 35 +++++++++++++++++++++++++++++++ src/lib/elementary/elm_gengrid.eo | 1 + 2 files changed, 36 insertions(+) diff --git a/src/lib/elementary/elm_gengrid.c b/src/lib/elementary/elm_gengrid.c index 563ea77dd2..0aaabfdd11 100644 --- a/src/lib/elementary/elm_gengrid.c +++ b/src/lib/elementary/elm_gengrid.c @@ -4179,6 +4179,41 @@ elm_gengrid_add(Evas_Object *parent) return elm_legacy_add(MY_CLASS, parent); } +EOLIAN static void +_elm_gengrid_efl_ui_focus_manager_setup_on_first_touch(Eo *obj, Elm_Gengrid_Data *pd, Efl_Ui_Focus_Direction direction, Efl_Ui_Focus_Object *entry EINA_UNUSED) +{ + Elm_Object_Item *eo_it = NULL; + + if (direction == EFL_UI_FOCUS_DIRECTION_LAST && entry == NULL) return; + + if (pd->last_focused_item) + eo_it = pd->last_focused_item; + else if (pd->last_selected_item) + eo_it = pd->last_selected_item; + else if (_elm_config->first_item_focus_on_first_focus_in) + { + if (direction == EFL_UI_FOCUS_DIRECTION_NEXT) + { + eo_it = elm_gengrid_first_item_get(obj); + } + else if (direction == EFL_UI_FOCUS_DIRECTION_PREVIOUS) + { + eo_it = elm_gengrid_last_item_get(obj); + } + } + + eo_it = _elm_gengrid_nearest_visible_item_get(obj, eo_it); + + if (eo_it) + { + if (!_elm_config->item_select_on_focus_disable && + eo_it != pd->last_selected_item) + elm_gengrid_item_selected_set(eo_it, EINA_TRUE); + else + efl_ui_focus_manager_focus_set(obj, eo_it); + } +} + static void _gengrid_element_focused(void *data, const Efl_Event *ev) { diff --git a/src/lib/elementary/elm_gengrid.eo b/src/lib/elementary/elm_gengrid.eo index 6aa62aa964..133b20d51d 100644 --- a/src/lib/elementary/elm_gengrid.eo +++ b/src/lib/elementary/elm_gengrid.eo @@ -570,6 +570,7 @@ class Elm.Gengrid (Efl.Ui.Layout, Efl.Ui.Focus.Composition, Elm.Interface_Scroll Efl.Access.Selection.clear; Efl.Ui.Focus.Composition.prepare; Elm.Widget.focus_state_apply; + Efl.Ui.Focus.Manager.setup_on_first_touch; } events { realized; [[Called when gengrid realized]]