rimmed pushed a commit to branch master. http://git.enlightenment.org/tools/eflete.git/commit/?id=88f98ef47de8a3e83477398865bdc260c382cf03
commit 88f98ef47de8a3e83477398865bdc260c382cf03 Author: Andrii Kroitor <[email protected]> Date: Tue Jul 5 17:22:38 2016 +0300 shortcuts: add handler API --- src/bin/ui/shortcuts/shortcuts.c | 38 +++++++++++++++++++++++++++++++++++--- src/bin/ui/shortcuts/shortcuts.h | 27 +++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/bin/ui/shortcuts/shortcuts.c b/src/bin/ui/shortcuts/shortcuts.c index ec25ea8..16f3c59 100644 --- a/src/bin/ui/shortcuts/shortcuts.c +++ b/src/bin/ui/shortcuts/shortcuts.c @@ -19,6 +19,8 @@ #include "shortcuts.h" +static Eina_List *handlers_stack = NULL; + static inline unsigned int _keycode_convert(unsigned int keycode) { @@ -131,23 +133,34 @@ static void _shortcut_handle(Shortcut_Type type) { int num; + Evas_Object *handler; #define SHORTCUT(NAME) \ case SHORTCUT_TYPE_##NAME: \ + evas_object_smart_callback_call(handler, SIGNAL_SHORTCUT_##NAME, NULL); \ + break; + +#define SHORTCUT_GLOBAL_ONLY(NAME) \ + case SHORTCUT_TYPE_##NAME: \ evas_object_smart_callback_call(ap.win, SIGNAL_SHORTCUT_##NAME, NULL); \ break; #define SHORTCUT_NUM(NAME, SIGNAL, NUM) \ case SHORTCUT_TYPE_##NAME: \ num = NUM; \ - evas_object_smart_callback_call(ap.win, SIGNAL, &num); \ + evas_object_smart_callback_call(handler, SIGNAL, &num); \ break; + if (handlers_stack) + handler = eina_list_data_get(handlers_stack); + else + handler = ap.win; + switch (type) { - SHORTCUT(QUIT); + SHORTCUT_GLOBAL_ONLY(QUIT); + SHORTCUT_GLOBAL_ONLY(SAVE); SHORTCUT(REDO); SHORTCUT(UNDO); - SHORTCUT(SAVE); SHORTCUT(ADD_GROUP); SHORTCUT(ADD_PART); SHORTCUT(ADD_STATE); @@ -541,3 +554,22 @@ shortcuts_shutdown(void) return true; } + + +void +shortcuts_object_push(Evas_Object *obj) +{ + assert(obj != NULL); + + handlers_stack = eina_list_prepend(handlers_stack, obj); +} + +void +shortcuts_object_check_pop(Evas_Object *obj) +{ + assert(obj != NULL); + assert(handlers_stack != NULL); + assert(obj == eina_list_data_get(handlers_stack)); + + handlers_stack = eina_list_remove_list(handlers_stack, handlers_stack); +} diff --git a/src/bin/ui/shortcuts/shortcuts.h b/src/bin/ui/shortcuts/shortcuts.h index 28c02dd..4314384 100644 --- a/src/bin/ui/shortcuts/shortcuts.h +++ b/src/bin/ui/shortcuts/shortcuts.h @@ -126,7 +126,7 @@ shortcuts_profile_load(Profile *profile); * @ingroup Shortcuts */ Eina_Bool -shortcuts_init(); +shortcuts_init(void); /** * Initialize shortcut module. @@ -140,6 +140,29 @@ shortcuts_init(); * @ingroup Shortcuts */ Eina_Bool -shortcuts_shutdown(); +shortcuts_shutdown(void); + +/** + * Push an object on stack of shortcut handlers. + * This object will recieve all shortcuts except SAVE and QUIT as long as it will + * be on top of handlers stack. + * + * @param obj New handler object + * + * @ingroup Shortcuts + */ +void +shortcuts_object_push(Evas_Object *obj); + +/** + * Pop an object from stack of shortcut handlers. + * + * @param obj Handler object. This object should be on top of stack, otherwise + * program will be terminated to avoid undefined behaviour. + * + * @ingroup Shortcuts + */ +void +shortcuts_object_check_pop(Evas_Object *obj); #endif /* SHORTCUTS_H */ --
