hermet pushed a commit to branch master. http://git.enlightenment.org/tools/enventor.git/commit/?id=6303afd975ccde4883187affa6bdd3f87155e602
commit 6303afd975ccde4883187affa6bdd3f87155e602 Author: Hermet Park <[email protected]> Date: Sun Jul 3 08:50:47 2016 +0900 multi-file: ++implementation. + line deletion and file saving. --- src/bin/file_browser.c | 5 +-- src/bin/file_mgr.c | 38 +++++++++++++++- src/bin/goto.c | 1 - src/bin/live_edit.c | 4 +- src/bin/main.c | 19 ++++---- src/bin/menu.c | 42 ++++++++++++------ src/bin/search.c | 1 - src/bin/tools.c | 4 +- src/include/file_mgr.h | 2 + src/lib/Enventor_Legacy.h | 18 ++++---- src/lib/enventor_object.eo | 8 ---- src/lib/enventor_smart.c | 105 +++++++++++++++++++++++++++------------------ 12 files changed, 156 insertions(+), 91 deletions(-) diff --git a/src/bin/file_browser.c b/src/bin/file_browser.c index 2134975..8d261d1 100644 --- a/src/bin/file_browser.c +++ b/src/bin/file_browser.c @@ -84,10 +84,7 @@ gl_clicked_double_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *it_file_path; //Case 1. main file. - - //FIXME: Probably file browser item may have boolean info for a collection - //data. and just check it is enough. - eit = enventor_object_main_item_get(base_enventor_get()); + eit = file_mgr_main_item_get(); if (!eit) { EINA_LOG_ERR("No main item??"); diff --git a/src/bin/file_mgr.c b/src/bin/file_mgr.c index a056ecc..cda4a93 100644 --- a/src/bin/file_mgr.c +++ b/src/bin/file_mgr.c @@ -158,8 +158,8 @@ file_mgr_edc_save(void) { char buf[PATH_MAX]; - Eina_Bool save_success = enventor_object_save(base_enventor_get(), - config_input_path_get()); + Enventor_Item *it = file_mgr_focused_item_get(); + Eina_Bool save_success = enventor_item_file_save(it, NULL); if (!config_stats_bar_get()) return; if (save_success) @@ -268,3 +268,37 @@ file_mgr_focused_item_get(void) { return enventor_object_focused_item_get(base_enventor_get()); } + +Eina_Bool +file_mgr_save_all(void) +{ + file_mgr_data *fmd = g_fmd; + EINA_SAFETY_ON_NULL_RETURN_VAL(fmd, EINA_FALSE); + + if (!fmd->edc_modified) return EINA_TRUE; + + Enventor_Item *it; + Eina_Bool ret = EINA_TRUE; + + //Main file. + it = file_mgr_main_item_get(); + if (!enventor_item_file_save(it, NULL)) ret = EINA_FALSE; + + Eina_List *l; + Eina_List *sub_its = + (Eina_List *) enventor_object_sub_items_get(base_enventor_get()); + EINA_LIST_FOREACH(sub_its, l, it) + { + if (!enventor_item_file_save(it, NULL)) ret = EINA_FALSE; + } + + fmd->edc_modified = EINA_FALSE; + + return ret; +} + +Enventor_Item * +file_mgr_main_item_get(void) +{ + return enventor_object_main_item_get(base_enventor_get()); +} diff --git a/src/bin/goto.c b/src/bin/goto.c index 413ac18..9e3344a 100644 --- a/src/bin/goto.c +++ b/src/bin/goto.c @@ -140,7 +140,6 @@ goto_open(void) search_close(); Enventor_Item *it = file_mgr_focused_item_get(); - EINA_SAFETY_ON_NULL_RETURN(it); gd = calloc(1, sizeof(goto_data)); if (!gd) diff --git a/src/bin/live_edit.c b/src/bin/live_edit.c index 71e2d57..75990f1 100644 --- a/src/bin/live_edit.c +++ b/src/bin/live_edit.c @@ -414,6 +414,8 @@ live_edit_insert(live_data *ld) calc_relative_info(ld); + Enventor_Item *it = file_mgr_focused_item_get(); + enventor_object_template_part_insert(base_enventor_get(), type, ENVENTOR_TEMPLATE_INSERT_LIVE_EDIT, @@ -432,7 +434,7 @@ live_edit_insert(live_data *ld) ld->rel_to_info.rel2_x, ld->rel_to_info.rel2_y, NULL, 0); - enventor_object_save(base_enventor_get(), config_input_path_get()); + enventor_item_file_save(it, NULL); free(ld->rel_to_info.rel1_x_part); free(ld->rel_to_info.rel1_y_part); diff --git a/src/bin/main.c b/src/bin/main.c index 5e77f16..cea85c3 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -84,7 +84,7 @@ syntax_color_update(Enventor_Object *enventor) Enventor_Item *it; - it = enventor_object_main_item_get(enventor); + it = file_mgr_main_item_get(); enventor_item_syntax_color_full_apply(it, EINA_TRUE); Eina_List *l; @@ -172,12 +172,6 @@ main_mouse_wheel_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *ev) //Font Size Enventor_Item *it = file_mgr_focused_item_get(); - if (!it) - { - EINA_LOG_ERR("No focused enventor item??"); - return ECORE_CALLBACK_PASS_ON; - } - evas_object_geometry_get(enventor_item_editor_get(it), &x, &y, &w, &h); if ((event->x >= x) && (event->x <= (x + w)) && @@ -494,6 +488,9 @@ enventor_ctxpopup_changed_cb(void *data, Enventor_Object *obj, void *event_info EINA_UNUSED) { app_data *ad = data; + + Enventor_Item *it = file_mgr_focused_item_get(); + if (!enventor_object_modified_get(obj)) return; if (ad->on_saving) { @@ -501,7 +498,7 @@ enventor_ctxpopup_changed_cb(void *data, Enventor_Object *obj, return; } ad->on_saving = EINA_TRUE; - enventor_object_save(obj, config_input_path_get()); + enventor_item_file_save(it, NULL); } static void @@ -509,9 +506,11 @@ enventor_live_view_updated_cb(void *data, Enventor_Object *obj, void *event_info EINA_UNUSED) { app_data *ad = data; + + Enventor_Item *it = file_mgr_focused_item_get(); if (ad->lazy_save && enventor_object_modified_get(obj)) { - enventor_object_save(obj, config_input_path_get()); + enventor_item_file_save(it, NULL); ad->lazy_save = EINA_FALSE; } else @@ -638,7 +637,7 @@ ctrl_func(Evas_Event_Key_Down *event) //Delete Line if (!strcmp(event->key, "d") || !strcmp(event->key, "D")) { - enventor_object_line_delete(base_enventor_get()); + enventor_item_line_delete(file_mgr_focused_item_get()); return EINA_TRUE; } //Find/Replace diff --git a/src/bin/menu.c b/src/bin/menu.c index 636de44..9762c3f 100644 --- a/src/bin/menu.c +++ b/src/bin/menu.c @@ -246,7 +246,7 @@ static void exit_save_btn_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { - enventor_object_save(base_enventor_get(), config_input_path_get()); + file_mgr_save_all(); elm_exit(); } @@ -285,7 +285,7 @@ new_save_btn_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { menu_data *md = data; - enventor_object_save(base_enventor_get(), config_input_path_get()); + file_mgr_save_all(); newfile_open(md); warning_close(md); menu_close(md); @@ -341,15 +341,25 @@ fileselector_save_done_cb(void *data, Evas_Object *obj, void *event_info) } Enventor_Object *enventor = base_enventor_get(); + Enventor_Item *it = file_mgr_focused_item_get(); if (is_edc) { - config_input_path_set(selected); - Eina_List *list = eina_list_append(NULL, config_output_path_get()); - enventor_object_path_set(enventor, ENVENTOR_PATH_TYPE_EDJ, - list); - eina_list_free(list); - if (!enventor_object_save(enventor, selected)) + Eina_Bool main_file; + if (file_mgr_main_item_get() == it) main_file = EINA_TRUE; + else main_file = EINA_TRUE; + + //Update config path if main file. + if (main_file) + { + config_input_path_set(selected); + Eina_List *list = eina_list_append(NULL, config_output_path_get()); + enventor_object_path_set(enventor, ENVENTOR_PATH_TYPE_EDJ, + list); + eina_list_free(list); + } + + if (!enventor_item_file_save(it, selected)) { char buf[PATH_MAX]; snprintf(buf, sizeof(buf), _("Failed to save: %s."), selected); @@ -360,7 +370,8 @@ fileselector_save_done_cb(void *data, Evas_Object *obj, void *event_info) eina_stringshare_del(selected); return; } - file_mgr_main_file_set(selected); + + if (main_file) file_mgr_main_file_set(selected); } else if (is_edj) { @@ -369,7 +380,7 @@ fileselector_save_done_cb(void *data, Evas_Object *obj, void *event_info) enventor_object_path_set(enventor, ENVENTOR_PATH_TYPE_EDJ, edj_pathes); enventor_object_modified_set(enventor, EINA_TRUE); - enventor_object_save(enventor, config_input_path_get()); + enventor_item_file_save(it, NULL); eina_list_free(edj_pathes); } @@ -528,7 +539,7 @@ load_save_btn_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { menu_data *md = data; - enventor_object_save(base_enventor_get(), config_input_path_get()); + file_mgr_save_all(); edc_file_load(md); warning_close(md); } @@ -636,7 +647,7 @@ menu_edc_new(Eina_Bool template_new) { menu_data *md = g_md; md->template_new = template_new; - if (enventor_object_modified_get(base_enventor_get())) + if (file_mgr_edc_modified_get()) warning_open(md, new_yes_btn_cb, new_save_btn_cb); else newfile_open(md); @@ -718,12 +729,15 @@ enventor_ctxpopup_dismissed_cb(void *data, Evas_Object *obj EINA_UNUSED, void menu_exit(void) { + //Quit Enventor Application. + menu_data *md = g_md; EINA_SAFETY_ON_NULL_RETURN(md); - Enventor_Object *enventor = base_enventor_get(); - if (enventor_object_modified_get(enventor)) + if (file_mgr_edc_modified_get()) { + Enventor_Object *enventor = base_enventor_get(); + search_close(); if (enventor_object_ctxpopup_visible_get(enventor)) { diff --git a/src/bin/search.c b/src/bin/search.c index 977cf0d..20e3b54 100644 --- a/src/bin/search.c +++ b/src/bin/search.c @@ -345,7 +345,6 @@ search_open(void) goto_close(); Enventor_Item *it = file_mgr_focused_item_get(); - EINA_SAFETY_ON_NULL_RETURN(it); sd = calloc(1, sizeof(search_data)); if (!sd) diff --git a/src/bin/tools.c b/src/bin/tools.c index 9698dff..3346914 100644 --- a/src/bin/tools.c +++ b/src/bin/tools.c @@ -625,6 +625,8 @@ tools_template_insert(void) return; } + Enventor_Item *it = file_mgr_focused_item_get(); + char syntax[12]; if (enventor_object_template_insert(base_enventor_get(), syntax, sizeof(syntax))) @@ -632,7 +634,7 @@ tools_template_insert(void) char msg[64]; snprintf(msg, sizeof(msg), _("Template code inserted, (%s)"), syntax); stats_info_msg_update(msg); - enventor_object_save(base_enventor_get(), config_input_path_get()); + enventor_item_file_save(it, NULL); } else { diff --git a/src/include/file_mgr.h b/src/include/file_mgr.h index af51771..76f7ded 100644 --- a/src/include/file_mgr.h +++ b/src/include/file_mgr.h @@ -10,3 +10,5 @@ Enventor_Item *file_mgr_main_file_set(const char *path); Enventor_Item *file_mgr_sub_file_add(const char *path); Enventor_Item *file_mgr_focused_item_get(void); void file_mgr_file_focus(Enventor_Item *it); +Eina_Bool file_mgr_save_all(void); +Enventor_Item *file_mgr_main_item_get(void); diff --git a/src/lib/Enventor_Legacy.h b/src/lib/Enventor_Legacy.h index 3a71ec3..26bf9a2 100644 --- a/src/lib/Enventor_Legacy.h +++ b/src/lib/Enventor_Legacy.h @@ -2,7 +2,7 @@ typedef struct _Enventor_Item_Data Enventor_Item; EAPI Evas_Object *enventor_object_add(Evas_Object *parent); -//FIXME: Should be eofied. +//FIXME: Eofy. EAPI Enventor_Item *enventor_object_main_item_set(Evas_Object *obj, const char *file); EAPI Enventor_Item *enventor_object_sub_item_add(Evas_Object *obj, const char *file); EAPI Enventor_Item *enventor_object_main_item_get(const Evas_Object *obj); @@ -12,15 +12,17 @@ EAPI const char *enventor_item_file_get(const Enventor_Item *it); EAPI Enventor_Item *enventor_object_focused_item_get(const Evas_Object *obj); EAPI Eina_Bool enventor_item_focus_set(Enventor_Item *it); EAPI int enventor_item_max_line_get(const Enventor_Item *it); -EAPI void enventor_item_line_goto(Enventor_Item *it, int line); -EAPI void enventor_item_syntax_color_full_apply(Enventor_Item *it, Eina_Bool force); -EAPI void enventor_item_syntax_color_partial_apply(Enventor_Item *it, double interval); -EAPI void enventor_item_select_region_set(Enventor_Item *it, int start, int end); -EAPI void enventor_item_select_none(Enventor_Item *it); -EAPI void enventor_item_cursor_pos_set(Enventor_Item *it, int position); +EAPI Eina_Bool enventor_item_line_goto(Enventor_Item *it, int line); +EAPI Eina_Bool enventor_item_syntax_color_full_apply(Enventor_Item *it, Eina_Bool force); +EAPI Eina_Bool enventor_item_syntax_color_partial_apply(Enventor_Item *it, double interval); +EAPI Eina_Bool enventor_item_select_region_set(Enventor_Item *it, int start, int end); +EAPI Eina_Bool enventor_item_select_none(Enventor_Item *it); +EAPI Eina_Bool enventor_item_cursor_pos_set(Enventor_Item *it, int position); EAPI int enventor_item_cursor_pos_get(const Enventor_Item *it); EAPI const char *enventor_item_selection_get(const Enventor_Item *it); -EAPI void enventor_item_text_insert(Enventor_Item *it, const char *text); +EAPI Eina_Bool enventor_item_text_insert(Enventor_Item *it, const char *text); EAPI const char * enventor_item_text_get(const Enventor_Item *it); +EAPI Eina_Bool enventor_item_line_delete(Enventor_Item *it); +EAPI Eina_Bool enventor_item_file_save(Enventor_Item *it, const char *file); #include "enventor_object.eo.legacy.h" diff --git a/src/lib/enventor_object.eo b/src/lib/enventor_object.eo index 9cf96a6..277c32f 100644 --- a/src/lib/enventor_object.eo +++ b/src/lib/enventor_object.eo @@ -149,14 +149,6 @@ class Enventor.Object (Elm.Widget, Efl.File) { parts_list_get { return: list<char *>; } - line_delete { - } - save { - return: bool; - params { - @in file: const(char) *; - } - } live_view_get { return: Efl.Canvas.Object; } diff --git a/src/lib/enventor_smart.c b/src/lib/enventor_smart.c index a773697..93d7ee0 100644 --- a/src/lib/enventor_smart.c +++ b/src/lib/enventor_smart.c @@ -30,7 +30,7 @@ typedef struct _Enventor_Item_Data Enventor_Item_Data; struct _Enventor_Item_Data { edit_data *ed; - Enventor_Object *enventor; + Enventor_Object_Data *pd; }; struct _Enventor_Object_Data @@ -734,29 +734,6 @@ _enventor_object_syntax_color_get(Eo *obj EINA_UNUSED, return edit_syntax_color_get(pd->main_it.ed, color_type); } -//TODO: Might need for items -EOLIAN static Eina_Bool -_enventor_object_save(Eo *obj EINA_UNUSED, Enventor_Object_Data *pd, - const char *file) -{ - //Update edc file and try to save if the edc path is different. - if (build_edc_path_get() != file) - edit_changed_set(pd->main_it.ed, EINA_TRUE); - - Eina_Bool saved = edit_save(pd->main_it.ed, file); - if (saved) build_edc(); - return saved; -} - -//TODO: Itemize -EOLIAN static void -_enventor_object_line_delete(Eo *obj EINA_UNUSED, Enventor_Object_Data *pd) -{ - edit_line_delete(pd->main_it.ed); - //Close auto-completion popup if it's shown. - autocomp_reset(); -} - EOLIAN static Eo * _enventor_object_live_view_get(Eo *obj EINA_UNUSED, Enventor_Object_Data *pd EINA_UNUSED) @@ -889,8 +866,8 @@ enventor_object_sub_item_add(Enventor_Object *obj, const char *file) pd->sub_its = eina_list_append(pd->sub_its, it); - it->enventor = obj; it->ed = edit_init(obj, EINA_FALSE); + it->pd = pd; autocomp_target_set(it->ed); edit_load(it->ed, file); @@ -909,7 +886,7 @@ enventor_object_main_item_set(Enventor_Object *obj, const char *file) _enventor_main_item_free(pd); - pd->main_it.enventor = obj; + pd->main_it.pd = pd; pd->main_it.ed = edit_init(obj, EINA_TRUE); edit_view_sync_cb_set(pd->main_it.ed, edit_view_sync_cb, pd); pd->focused_it = &pd->main_it; @@ -949,7 +926,7 @@ enventor_item_focus_set(Enventor_Item *it) { EINA_SAFETY_ON_NULL_RETURN_VAL(it, EINA_FALSE); - Enventor_Object *obj = it->enventor; + Enventor_Object *obj = it->pd->obj; Enventor_Object_Data *pd = eo_data_scope_get(obj, ENVENTOR_OBJECT_CLASS); edit_view_sync_cb_set(it->ed, edit_view_sync_cb, pd); @@ -992,53 +969,65 @@ enventor_item_max_line_get(const Enventor_Item *it) return edit_max_line_get(it->ed); } -EAPI void +EAPI Eina_Bool enventor_item_line_goto(Enventor_Item *it, int line) { - EINA_SAFETY_ON_NULL_RETURN(it); + EINA_SAFETY_ON_NULL_RETURN_VAL(it, EINA_FALSE); edit_goto(it->ed, line); + + return EINA_TRUE; } -EAPI void +EAPI Eina_Bool enventor_item_syntax_color_full_apply(Enventor_Item *it, Eina_Bool force) { - EINA_SAFETY_ON_NULL_RETURN(it); + EINA_SAFETY_ON_NULL_RETURN_VAL(it, EINA_FALSE); edit_syntax_color_full_apply(it->ed, force); + + return EINA_TRUE; } -EAPI void +EAPI Eina_Bool enventor_item_syntax_color_partial_apply(Enventor_Item *it, double interval) { - EINA_SAFETY_ON_NULL_RETURN(it); + EINA_SAFETY_ON_NULL_RETURN_VAL(it, EINA_FALSE); edit_syntax_color_partial_apply(it->ed, interval); + + return EINA_TRUE; } -EAPI void +EAPI Eina_Bool enventor_item_select_region_set(Enventor_Item *it, int start, int end) { - EINA_SAFETY_ON_NULL_RETURN(it); + EINA_SAFETY_ON_NULL_RETURN_VAL(it, EINA_FALSE); edit_selection_clear(it->ed); edit_selection_region_center_set(it->ed, start, end); + + return EINA_TRUE; } -EAPI void +EAPI Eina_Bool enventor_item_select_none(Enventor_Item *it) { - EINA_SAFETY_ON_NULL_RETURN(it); + EINA_SAFETY_ON_NULL_RETURN_VAL(it, EINA_FALSE); edit_select_none(it->ed); + + return EINA_TRUE; } -EAPI void +EAPI Eina_Bool enventor_item_cursor_pos_set(Enventor_Item *it, int position) { - EINA_SAFETY_ON_NULL_RETURN(it); + EINA_SAFETY_ON_NULL_RETURN_VAL(it, EINA_FALSE); edit_cursor_pos_set(it->ed, position); + + return EINA_TRUE; } EAPI int @@ -1057,12 +1046,14 @@ enventor_item_selection_get(const Enventor_Item *it) return edit_selection_get(it->ed); } -EAPI void +EAPI Eina_Bool enventor_item_text_insert(Enventor_Item *it, const char *text) { - EINA_SAFETY_ON_NULL_RETURN(it); + EINA_SAFETY_ON_NULL_RETURN_VAL(it, EINA_FALSE); edit_text_insert(it->ed, text); + + return EINA_TRUE; } EAPI const char * @@ -1072,4 +1063,36 @@ enventor_item_text_get(const Enventor_Item *it) return edit_text_get(it->ed); } + +EAPI Eina_Bool +enventor_item_line_delete(Enventor_Item *it) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(it, EINA_FALSE); + + edit_line_delete(it->ed); + //Close auto-completion popup if it's shown. + autocomp_reset(); + + return EINA_TRUE; +} + +EAPI Eina_Bool +enventor_item_file_save(Enventor_Item *it, const char *file) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(it, EINA_FALSE); + + if (!file) file = edit_file_get(it->ed); + + //Update edc file and try to save if the edc path is different. + if (&it->pd->main_it == it) + { + if (build_edc_path_get() != file) + edit_changed_set(it->ed, EINA_TRUE); + } + + Eina_Bool saved = edit_save(it->ed, file); + if (saved) build_edc(); + return saved; +} + #include "enventor_object.eo.c" --
