hermet pushed a commit to branch master.

http://git.enlightenment.org/tools/enventor.git/commit/?id=b3afcc4810b69fcaff3f9b8b6b3b4b1dacfa9b92

commit b3afcc4810b69fcaff3f9b8b6b3b4b1dacfa9b92
Author: Hermet Park <[email protected]>
Date:   Mon Aug 8 23:58:08 2016 +0900

    file_browser: stabilizing switching main edc file function.
---
 src/bin/file_browser.c   | 11 ++++++++
 src/bin/file_mgr.c       | 66 +++++++++++++++++++++++++++++++++++++++++++-----
 src/bin/file_tab.c       | 24 ++++++++++++++++--
 src/include/file_mgr.h   |  1 +
 src/include/file_tab.h   |  1 +
 src/lib/edc_editor.c     |  3 ++-
 src/lib/enventor_smart.c | 14 +++++++---
 7 files changed, 108 insertions(+), 12 deletions(-)

diff --git a/src/bin/file_browser.c b/src/bin/file_browser.c
index 0edc71f..0522bf3 100644
--- a/src/bin/file_browser.c
+++ b/src/bin/file_browser.c
@@ -859,6 +859,17 @@ file_browser_selected_file_main_set(void)
         return;
      }
 
+   //Same to previous item
+   if (it == bd->main_it)
+     {
+        char buf[1024];
+        brows_file *file = elm_object_item_data_get(it);
+        if (!file) return;
+        snprintf(buf, sizeof(buf), "\"%s\" is already set to main", 
file->name);
+        stats_info_msg_update(buf);
+        return;
+     }
+
    brows_file *file = elm_object_item_data_get(it);
    if (!file)
      {
diff --git a/src/bin/file_mgr.c b/src/bin/file_mgr.c
index 0e9ab1b..5102579 100644
--- a/src/bin/file_mgr.c
+++ b/src/bin/file_mgr.c
@@ -233,6 +233,14 @@ file_mgr_term(void)
    free(fmd);
 }
 
+void
+file_mgr_file_del(Enventor_Item *it)
+{
+   if (!it) return;
+   file_tab_it_remove(it);
+   enventor_item_del(it);
+}
+
 Enventor_Item *
 file_mgr_sub_file_add(const char *path)
 {
@@ -249,15 +257,61 @@ file_mgr_sub_file_add(const char *path)
 Enventor_Item *
 file_mgr_main_file_set(const char *path)
 {
-   Enventor_Item *it = enventor_object_main_item_set(base_enventor_get(), 
path);
-   EINA_SAFETY_ON_NULL_RETURN_VAL(it, NULL);
+   if (!path)
+     {
+        EINA_LOG_ERR("No path??");
+        return NULL;
+     }
 
-   file_tab_clear();
-   file_tab_it_add(it);
-   file_mgr_file_focus(it);
+   char *realpath = ecore_file_realpath(path);
+
+   //Same with previous?
+   Enventor_Item *main_it = file_mgr_main_item_get();
+   if (main_it)
+     {
+        const char *prev_path = enventor_item_file_get(main_it);
+        if (prev_path)
+          {
+             if (!strcmp(prev_path, realpath)) return main_it;
+          }
+     }
+
+   Eina_List *list;
+   Enventor_Item *it;
+
+   //If this file is already openend with sub file, remove it.
+   Eina_List *sub_its =
+      (Eina_List *) enventor_object_sub_items_get(base_enventor_get());
+   Eina_List *l;
+   EINA_LIST_FOREACH(sub_its, l, it)
+     {
+        const char *path2 = enventor_item_file_get(it);
+        if (!path2) continue;
+        if (strcmp(realpath, path2)) continue;
+        file_tab_it_remove(it);
+        enventor_item_del(it);
+        break;
+     }
+
+   //If main file is already openend, set it sub file first.
+   if (main_it)
+     {
+        const char *file_path = NULL;
+        file_path = enventor_item_file_get(main_it);
+        file_mgr_sub_file_add(file_path);
+        file_mgr_file_del(main_it);
+     }
+
+   main_it = enventor_object_main_item_set(base_enventor_get(), realpath);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(main_it, NULL);
+
+   file_tab_it_add(main_it);
+   file_mgr_file_focus(main_it);
    base_console_reset();
 
-   return it;
+   free(realpath);
+
+   return main_it;
 }
 
 void
diff --git a/src/bin/file_tab.c b/src/bin/file_tab.c
index 67e12a4..9dcf113 100644
--- a/src/bin/file_tab.c
+++ b/src/bin/file_tab.c
@@ -108,6 +108,27 @@ close_btn_clicked_cb(void *data, Evas_Object *obj 
EINA_UNUSED,
 /*****************************************************************************/
 /* Externally accessible calls                                               */
 /*****************************************************************************/
+void
+file_tab_it_remove(Enventor_Item *enventor_it)
+{
+   file_data *fd = g_fd;
+   EINA_SAFETY_ON_NULL_RETURN(fd);
+
+   Eina_List *list = (Eina_List*) elm_list_items_get(fd->list);
+   Eina_List *l;
+   Elm_Object_Item *it;
+
+   EINA_LIST_FOREACH(list, l, it)
+     {
+        file_tab_it *fti = elm_object_item_data_get(it);
+        if (fti->enventor_it == enventor_it)
+          {
+             elm_object_item_del(it);
+             break;
+          }
+     }
+}
+
 Eina_Bool
 file_tab_it_select(Enventor_Item *enventor_it)
 {
@@ -206,8 +227,6 @@ file_tab_it_add(Enventor_Item *enventor_it)
 
    evas_object_smart_callback_add(btn, "clicked", close_btn_clicked_cb, fti);
 
-   free(filename);
-
    return EINA_TRUE;
 
 err:
@@ -319,3 +338,4 @@ file_tab_term(void)
    free(fd);
    g_fd = NULL;
 }
+
diff --git a/src/include/file_mgr.h b/src/include/file_mgr.h
index 629306b..34be535 100644
--- a/src/include/file_mgr.h
+++ b/src/include/file_mgr.h
@@ -14,4 +14,5 @@ Eina_Bool file_mgr_save_all(void);
 Enventor_Item *file_mgr_main_item_get(void);
 Eina_Bool file_mgr_modified_get(void);
 Eina_Bool file_mgr_file_open(const char *file_path);
+void file_mgr_file_del(Enventor_Item *it);
 
diff --git a/src/include/file_tab.h b/src/include/file_tab.h
index e4d24b2..c1733b0 100644
--- a/src/include/file_tab.h
+++ b/src/include/file_tab.h
@@ -1,6 +1,7 @@
 Evas_Object *file_tab_init(Evas_Object *parent);
 void file_tab_term(void);
 Eina_Bool file_tab_it_add(Enventor_Item *it);
+void file_tab_it_remove(Enventor_Item *enventor_it);
 Eina_Bool file_tab_it_select(Enventor_Item *enventor_it);
 void file_tab_disabled_set(Eina_Bool disabled);
 void file_tab_clear(void);
diff --git a/src/lib/edc_editor.c b/src/lib/edc_editor.c
index 8835f80..943ae37 100644
--- a/src/lib/edc_editor.c
+++ b/src/lib/edc_editor.c
@@ -1791,13 +1791,14 @@ edit_error_set(edit_data *ed, int line, const char 
*target)
 Eina_Bool
 edit_ctxpopup_visible_get(edit_data *ed)
 {
+   if (!ed) return EINA_FALSE;
    return (ed->ctxpopup ? EINA_TRUE : EINA_FALSE);
 }
 
 void
 edit_ctxpopup_dismiss(edit_data *ed)
 {
-   if (ed->ctxpopup) elm_ctxpopup_dismiss(ed->ctxpopup);
+   if (ed && ed->ctxpopup) elm_ctxpopup_dismiss(ed->ctxpopup);
 }
 
 Eina_Bool
diff --git a/src/lib/enventor_smart.c b/src/lib/enventor_smart.c
index 50d13d7..8cdf2fc 100644
--- a/src/lib/enventor_smart.c
+++ b/src/lib/enventor_smart.c
@@ -104,6 +104,8 @@ key_up_cb(void *data, int type EINA_UNUSED, void *ev)
    Enventor_Object_Data *pd = data;
    Ecore_Event_Key *event = ev;
 
+   if (!pd->focused_it) return ECORE_CALLBACK_PASS_ON;
+
    edit_key_up_event_dispatch(pd->focused_it->ed, event->key);
 
    return ECORE_CALLBACK_DONE;
@@ -114,6 +116,9 @@ key_down_cb(void *data, int type EINA_UNUSED, void *ev)
 {
    Enventor_Object_Data *pd = data;
    Ecore_Event_Key *event = ev;
+
+   if (!pd->focused_it) return ECORE_CALLBACK_PASS_ON;
+
    Eina_Bool ret = edit_focus_get(pd->focused_it->ed);
    if (!ret) return ECORE_CALLBACK_PASS_ON;
 
@@ -594,14 +599,16 @@ EOLIAN static Eina_Bool
 _enventor_object_ctxpopup_visible_get(Eo *obj EINA_UNUSED,
                                       Enventor_Object_Data *pd)
 {
-   return edit_ctxpopup_visible_get(pd->main_it->ed);
+   if (!pd->focused_it) return;
+   return edit_ctxpopup_visible_get(pd->focused_it->ed);
 }
 
 EOLIAN static void
 _enventor_object_ctxpopup_dismiss(Eo *obj EINA_UNUSED,
                                   Enventor_Object_Data *pd)
 {
-   edit_ctxpopup_dismiss(pd->main_it->ed);
+   if (!pd->focused_it) return;
+   edit_ctxpopup_dismiss(pd->focused_it->ed);
 }
 
 EOLIAN static Eina_Bool
@@ -742,7 +749,8 @@ _enventor_object_syntax_color_set(Eo *obj EINA_UNUSED,
    pd->text_color_val[color_type] = eina_stringshare_add(val);
 
    //Main Item
-   edit_syntax_color_set(pd->main_it->ed, color_type, val);
+   if (pd->main_it)
+     edit_syntax_color_set(pd->main_it->ed, color_type, val);
 
    //Sub Items
    Eina_List *l;

-- 


Reply via email to