From f9a5d718961955eab8bbde4dff61bb697a004038 Mon Sep 17 00:00:00 2001 From: Mykyta Biliavskyi Date: Mon, 28 Dec 2015 17:10:13 +0900 Subject: [PATCH] Ctxpopup: reload the image content for preview. The mouse wheel Up/Down to show preview of the previous/next image. Previously the new ctxpopup widget was created for each image inside the set. Now the preview content is reloaded without creating new ctxpopup widget. fix T2974 --- src/lib/ctxpopup.c | 10 ++++++++++ src/lib/edc_editor.c | 35 +++++++++++++++++------------------ src/lib/enventor_private.h | 2 +- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/lib/ctxpopup.c b/src/lib/ctxpopup.c index 72acad0..7a86065 100644 --- a/src/lib/ctxpopup.c +++ b/src/lib/ctxpopup.c @@ -581,6 +581,16 @@ ctxpopup_key_down_cb(void *data, Evas *e EINA_UNUSED, /* Externally accessible calls */ /*****************************************************************************/ +void +ctxpopup_img_preview_reload(Evas_Object *ctxpopup, const char *imgpath) +{ + if (!ctxpopup) return; + + Evas_Object *layout = elm_object_content_get(ctxpopup); + Evas_Object *img = elm_object_part_content_get(layout, "elm.swallow.img"); + evas_object_image_file_set(img, imgpath, NULL); +} + Evas_Object * ctxpopup_img_preview_create(edit_data *ed, const char *imgpath, diff --git a/src/lib/edc_editor.c b/src/lib/edc_editor.c index 805e3cc..449bf2d 100644 --- a/src/lib/edc_editor.c +++ b/src/lib/edc_editor.c @@ -401,10 +401,8 @@ ctxpopup_preview_dismiss_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) { edit_data *ed = data; - int skip_focus = (int)(uintptr_t) evas_object_data_get(obj, "continue"); //Since the ctxpopup will be shown again, Don't revert the focus. - if (skip_focus) return; elm_object_tree_focus_allow_set(ed->layout, EINA_TRUE); elm_object_focus_set(ed->en_edit, EINA_TRUE); evas_object_smart_callback_call(ed->enventor, SIG_CTXPOPUP_DISMISSED, NULL); @@ -448,12 +446,6 @@ preview_img_relay_show(edit_data *ed, Evas_Object *ctxpopup, Eina_Bool next) if (image_preview_show(ed, text, x, y)) { - /* Since the ctxpopup will be shown again, - Don't revert the focus in the dismiss cb. */ - evas_object_data_set(ctxpopup, "continue", (void *) 1); - evas_object_event_callback_del(ctxpopup, EVAS_CALLBACK_DEL, - ctxpopup_del_cb); - //Set the entry selection region to next image. const char *colon = parser_colon_pos_get(NULL, text); if (!colon) goto end; @@ -471,6 +463,7 @@ preview_img_relay_show(edit_data *ed, Evas_Object *ctxpopup, Eina_Bool next) int cursor_pos = elm_entry_cursor_pos_get(ed->en_edit); elm_entry_select_region_set(ed->en_edit, (cursor_pos - select_len), cursor_pos); + return; } end: elm_ctxpopup_dismiss(ctxpopup); @@ -519,21 +512,27 @@ image_preview_show(edit_data *ed, char *cur, Evas_Coord x, Evas_Coord y) //Create Ctxpopup with the image pathes. if (found) { - Evas_Object *ctxpopup = - ctxpopup_img_preview_create(ed, fullpath, - ctxpopup_preview_dismiss_cb, - ctxpopup_preview_relay_cb); - if (!ctxpopup) + /*In case if ctxpopup already created, then just reload image. */ + if (ed->ctxpopup) + ctxpopup_img_preview_reload(ed->ctxpopup, fullpath); + else + { + ed->ctxpopup = + ctxpopup_img_preview_create(ed, fullpath, + ctxpopup_preview_dismiss_cb, + ctxpopup_preview_relay_cb); + evas_object_event_callback_add(ed->ctxpopup, EVAS_CALLBACK_DEL, + ctxpopup_del_cb, ed); + } + + if (!ed->ctxpopup) { free(filename); return EINA_FALSE; } - evas_object_move(ctxpopup, x, y); - evas_object_show(ctxpopup); - evas_object_event_callback_add(ctxpopup, EVAS_CALLBACK_DEL, - ctxpopup_del_cb, ed); - ed->ctxpopup = ctxpopup; + evas_object_move(ed->ctxpopup, x, y); + evas_object_show(ed->ctxpopup); elm_object_tree_focus_allow_set(ed->layout, EINA_FALSE); succeed = EINA_TRUE; } diff --git a/src/lib/enventor_private.h b/src/lib/enventor_private.h index 30cc449..0e65d61 100644 --- a/src/lib/enventor_private.h +++ b/src/lib/enventor_private.h @@ -229,7 +229,7 @@ Eina_Bool template_insert(edit_data *ed, Enventor_Template_Insert_Type insert_ty /* ctxpopup */ Evas_Object *ctxpopup_candidate_list_create(edit_data *ed, attr_value *attr, Evas_Smart_Cb ctxpopup_dismiss_cb, Evas_Smart_Cb ctxpopup_changed_cb); Evas_Object *ctxpopup_img_preview_create(edit_data*ed, const char *imgpath, Evas_Smart_Cb ctxpopup_dismiss_cb, Evas_Smart_Cb ctxpopup_relay_cb); - +void ctxpopup_img_preview_reload(Evas_Object *ctxpopup, const char *imgpath); /* edc_editor */ edit_data *edit_init(Evas_Object *enventor);