From 509b9bd6283bebc56beb11e2e485b19cd6c3f09f Mon Sep 17 00:00:00 2001 From: Jaehyun Cho Date: Mon, 29 Feb 2016 20:02:39 +0900 Subject: [PATCH] edc_editor: Support auto save to update preview. auto save function saves edc file and updates preview by using timer. auto save timer is applied when entry is changed or redo/undo is done. auto save timer is cancelled when candidate list or auto complete list appears. --- src/lib/auto_comp.c | 4 ++++ src/lib/edc_editor.c | 37 +++++++++++++++++++++++++++++++++++++ src/lib/enventor_private.h | 2 ++ 3 files changed, 43 insertions(+) diff --git a/src/lib/auto_comp.c b/src/lib/auto_comp.c index 664db9e..9754e62 100644 --- a/src/lib/auto_comp.c +++ b/src/lib/auto_comp.c @@ -506,6 +506,8 @@ list_del_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, { autocomp_data *ad = data; ad->list = NULL; + + edit_auto_save_timer_apply(ad->ed); } @@ -579,6 +581,8 @@ entry_tooltip_content_cb(void *data, Evas_Object *obj EINA_UNUSED, elm_list_go(ad->list); evas_object_show(ad->list); + edit_auto_save_timer_cancel(ad->ed); + return ad->list; } diff --git a/src/lib/edc_editor.c b/src/lib/edc_editor.c index 931b190..65809aa 100644 --- a/src/lib/edc_editor.c +++ b/src/lib/edc_editor.c @@ -13,6 +13,7 @@ const int MAX_LINE_DIGIT_CNT = 10; const int SYNTAX_COLOR_SPARE_LINES = 42; const double SYNTAX_COLOR_DEFAULT_TIME = 0.25; const double SYNTAX_COLOR_SHORT_TIME = 0.025; +const double AUTO_SAVE_TIME = 2.0; typedef struct syntax_color_thread_data_s { @@ -48,6 +49,7 @@ struct editor_s int right; } bracket; + Ecore_Timer *auto_save_timer; Ecore_Timer *syntax_color_timer; Ecore_Thread *syntax_color_thread; @@ -457,6 +459,8 @@ edit_changed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info) syntax_color_partial_update(ed, SYNTAX_COLOR_DEFAULT_TIME); parser_bracket_cancel(ed->pd); + + edit_auto_save_timer_apply(ed); } static void @@ -547,6 +551,8 @@ ctxpopup_del_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, { edit_data *ed = data; ed->ctxpopup = NULL; + + edit_auto_save_timer_apply(ed); } //This function is called when user press up/down key or mouse wheel up/down @@ -708,6 +714,8 @@ candidate_list_show(edit_data *ed, char *text, char *cur, char *selected) evas_object_event_callback_add(ctxpopup, EVAS_CALLBACK_DEL, ctxpopup_del_cb, ed); ed->ctxpopup = ctxpopup; elm_object_tree_focus_allow_set(ed->layout, EINA_FALSE); + + edit_auto_save_timer_cancel(ed); } static void @@ -1106,6 +1114,16 @@ edit_focused_cb(void *data, Evas_Object *obj EINA_UNUSED, evas_object_smart_callback_call(ed->enventor, SIG_FOCUSED, NULL); } +static Eina_Bool +auto_save_timer_cb(void *data) +{ + edit_data *ed = data; + edit_save(ed, build_edc_path_get()); + build_edc(); + ed->auto_save_timer = NULL; + return ECORE_CALLBACK_CANCEL; +} + /*****************************************************************************/ /* Externally accessible calls */ /*****************************************************************************/ @@ -1858,5 +1876,24 @@ edit_redoundo(edit_data *ed, Eina_Bool undo) edit_changed_set(ed, EINA_TRUE); syntax_color_full_update(ed, EINA_TRUE); + edit_auto_save_timer_apply(ed); + return EINA_TRUE; } + +void +edit_auto_save_timer_apply(edit_data *ed) +{ + if (ed->auto_save_timer) + ecore_timer_del(ed->auto_save_timer); + ed->auto_save_timer = ecore_timer_add(AUTO_SAVE_TIME, auto_save_timer_cb, + ed); +} + +void +edit_auto_save_timer_cancel(edit_data *ed) +{ + if (ed->auto_save_timer) + ecore_timer_del(ed->auto_save_timer); + ed->auto_save_timer = NULL; +} diff --git a/src/lib/enventor_private.h b/src/lib/enventor_private.h index c16e5e9..e1df42f 100644 --- a/src/lib/enventor_private.h +++ b/src/lib/enventor_private.h @@ -296,5 +296,7 @@ void edit_disabled_set(edit_data *ed, Eina_Bool disabled); void edit_error_set(edit_data *ed, int line, const char *target); void edit_text_insert(edit_data *ed, const char *text); void edit_part_cursor_set(edit_data *ed, const char *group_name, const char *part_name); +void edit_auto_save_timer_apply(edit_data *ed); +void edit_auto_save_timer_cancel(edit_data *ed); #endif