fileselector: Make fileselector focusable. Ok on Enter key and Cancel on Escape key.

Now fileselector accepts the key event on Enter and Escape.
This commit is contained in:
Daniel Juyung Seo 2014-01-22 15:53:49 +09:00
parent 0ddb97b377
commit 8298782bdc
3 changed files with 37 additions and 2 deletions

View File

@ -38,10 +38,15 @@ ELM_PRIV_FILESELECTOR_SIGNALS(ELM_PRIV_STATIC_VARIABLE_DECLARE);
static const Evas_Smart_Cb_Description _smart_callbacks[] = {
ELM_PRIV_FILESELECTOR_SIGNALS(ELM_PRIV_SMART_CALLBACKS_DESC)
{"focused", ""}, /**< handled by elm_widget */
{"unfocused", ""}, /**< handled by elm_widget */
{NULL, NULL}
};
#undef ELM_PRIV_FILESELECTOR_SIGNALS
static void _ok(void *data, Evas_Object *obj, void *event_info);
static void _canc(void *data, Evas_Object *obj, void *event_info);
/* final routine on deletion */
static void
_elm_fileselector_smart_del_do(Elm_Fileselector_Smart_Data *sd)
@ -137,6 +142,33 @@ _elm_fileselector_smart_theme(Eo *obj, void *_pd, va_list *list)
if (ret) *ret = EINA_TRUE;
}
static void
_elm_fileselector_smart_event(Eo *obj, void *_pd EINA_UNUSED, va_list *list)
{
Evas_Object *src = va_arg(*list, Evas_Object *);
Evas_Callback_Type type = va_arg(*list, Evas_Callback_Type);
Evas_Event_Key_Down *ev = va_arg(*list, void *);
Eina_Bool *ret = va_arg(*list, Eina_Bool *);
if (ret) *ret = EINA_FALSE;
(void) src;
if (elm_widget_disabled_get(obj)) return;
if (type != EVAS_CALLBACK_KEY_DOWN) return;
if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
if ((!strcmp(ev->key, "Return")) ||
(!strcmp(ev->key, "KP_Enter")))
_ok(obj, NULL, NULL);
else if (!strcmp(ev->key, "Escape"))
_canc(obj, NULL, NULL);
else
return;
ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
if (ret) *ret = EINA_TRUE;
}
/*** GENLIST/GENGRID "MODEL" ***/
static char *
_itc_text_get(void *data,
@ -1306,7 +1338,7 @@ _elm_fileselector_smart_add(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
eo_do_super(obj, MY_CLASS, evas_obj_smart_add());
elm_widget_sub_object_parent_add(obj);
elm_widget_can_focus_set(obj, EINA_FALSE);
elm_widget_can_focus_set(obj, EINA_TRUE);
priv->expand = !!_elm_config->fileselector_expand_enable;
priv->double_tap_navigation = !!_elm_config->fileselector_double_tap_navigation_enable;
@ -2280,6 +2312,7 @@ _class_constructor(Eo_Class *klass)
EO_OP_FUNC(EVAS_OBJ_SMART_ID(EVAS_OBJ_SMART_SUB_ID_DEL), _elm_fileselector_smart_del),
EO_OP_FUNC(ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_THEME_APPLY), _elm_fileselector_smart_theme),
EO_OP_FUNC(ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_EVENT), _elm_fileselector_smart_event),
EO_OP_FUNC(ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_FOCUS_NEXT_MANAGER_IS), _elm_fileselector_smart_focus_next_manager_is),
EO_OP_FUNC(ELM_WIDGET_ID(ELM_WIDGET_SUB_ID_FOCUS_DIRECTION_MANAGER_IS), _elm_fileselector_smart_focus_direction_manager_is),

View File

@ -52,6 +52,8 @@
* - @c "done" - the user has clicked on the "ok" or "cancel"
* buttons (@c event_info is a pointer to the selection's
* path, a @b stringshared string)
* - @c "focused" - When the fileselector has received focus. (since 1.9)
* - @c "unfocused" - When the fileselector has lost focus. (since 1.9)
*
* For text, elm_layout_text_set() will work here on:
* @li @c "ok" - OK button label if the ok button is set. @since 1.8

View File

@ -387,7 +387,7 @@ _elm_fileselector_entry_smart_add(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
elm_layout_content_set(obj, "elm.swallow.entry", priv->entry);
}
elm_widget_can_focus_set(obj, EINA_FALSE);
elm_widget_can_focus_set(obj, EINA_TRUE);
elm_layout_sizing_eval(obj);
}