ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/tools/edi.git/commit/?id=1bcb2cbf95c76c33dd2a100f27857ac670c67fd4

commit 1bcb2cbf95c76c33dd2a100f27857ac670c67fd4
Author: Andy Williams <a...@andywilliams.me>
Date:   Mon May 18 16:32:46 2015 +0100

    editor: Remember open tabs and windows.
    
    Store per-project to open what you were last working on in the project
---
 src/bin/edi_config.c            | 67 ++++++++++++++++++++++++++++++++++++++++-
 src/bin/edi_config.h            | 24 +++++++++++++--
 src/bin/edi_main.c              | 16 ++++++++++
 src/bin/mainview/edi_mainview.c |  5 +++
 4 files changed, 109 insertions(+), 3 deletions(-)

diff --git a/src/bin/edi_config.c b/src/bin/edi_config.c
index 4b02c60..c0ea734 100644
--- a/src/bin/edi_config.c
+++ b/src/bin/edi_config.c
@@ -52,6 +52,7 @@ static Edi_Config_DD *_edi_cfg_proj_edd = NULL;
 static Edi_Config_DD *_edi_cfg_mime_edd = NULL;
 
 static Edi_Project_Config_DD *_edi_proj_cfg_edd = NULL;
+static Edi_Project_Config_DD *_edi_proj_cfg_tab_edd = NULL;
 
 /* external variables */
 Edi_Config *_edi_config = NULL;
@@ -120,6 +121,14 @@ _edi_config_cb_free(void)
 static void
 _edi_project_config_cb_free(void)
 {
+   Edi_Project_Config_Tab *tab;
+
+   EINA_LIST_FREE(_edi_project_config->tabs, tab)
+     {
+        if (tab->path) eina_stringshare_del(tab->path);
+        free(tab);
+     }
+
    free(_edi_project_config);
    _edi_project_config = NULL;
 }
@@ -209,6 +218,14 @@ _edi_config_init(void)
    EDI_CONFIG_LIST(D, T, projects, _edi_cfg_proj_edd);
    EDI_CONFIG_LIST(D, T, mime_assocs, _edi_cfg_mime_edd);
 
+   _edi_proj_cfg_tab_edd = EDI_CONFIG_DD_NEW("Project_Config_Tab", 
Edi_Project_Config_Tab);
+   #undef T
+   #undef D
+   #define T Edi_Project_Config_Tab
+   #define D _edi_proj_cfg_tab_edd
+   EDI_CONFIG_VAL(D, T, path, EET_T_STRING);
+   EDI_CONFIG_VAL(D, T, windowed, EET_T_UCHAR);
+
    _edi_proj_cfg_edd = EDI_CONFIG_DD_NEW("Project_Config", Edi_Project_Config);
    #undef T
    #undef D
@@ -228,6 +245,8 @@ _edi_config_init(void)
    EDI_CONFIG_VAL(D, T, gui.width_marker, EET_T_UINT);
    EDI_CONFIG_VAL(D, T, gui.tabstop, EET_T_UINT);
 
+   EDI_CONFIG_LIST(D, T, tabs, _edi_proj_cfg_tab_edd);
+
    _edi_config_load();
 
    return EINA_TRUE;
@@ -244,6 +263,7 @@ _edi_config_shutdown(void)
    EDI_CONFIG_DD_FREE(_edi_cfg_edd);
 
    EDI_CONFIG_DD_FREE(_edi_proj_cfg_edd);
+   EDI_CONFIG_DD_FREE(_edi_proj_cfg_tab_edd);
 
    efreet_shutdown();
 
@@ -420,6 +440,8 @@ _edi_project_config_load()
 
    _edi_project_config->gui.width_marker = 80;
    _edi_project_config->gui.tabstop = 8;
+
+   _edi_project_config->tabs = NULL;
    IFPCFGEND;
 
    /* limit config values so they are sane */
@@ -435,10 +457,53 @@ _edi_project_config_load()
    if (save) _edi_project_config_save();
 }
 
+static Eina_Bool
+_edi_project_config_save_no_notify()
+{
+   return _edi_config_domain_save(_edi_project_config_dir_get(), PACKAGE_NAME, 
_edi_proj_cfg_edd, _edi_project_config);
+}
+
 void 
 _edi_project_config_save()
 {
-   if (_edi_config_domain_save(_edi_project_config_dir_get(), PACKAGE_NAME, 
_edi_proj_cfg_edd, _edi_project_config))
+   if (_edi_project_config_save_no_notify())
      ecore_event_add(EDI_EVENT_CONFIG_CHANGED, NULL, NULL, NULL);
 }
 
+void
+_edi_project_config_tab_add(const char *path, Eina_Bool windowed)
+{
+   Edi_Project_Config_Tab *tab;
+   Eina_List *list, *next;
+
+   EINA_LIST_FOREACH_SAFE(_edi_project_config->tabs, list, next, tab)
+     {
+        if (!strncmp(tab->path, path, strlen(tab->path)))
+          _edi_project_config->tabs = 
eina_list_remove_list(_edi_project_config->tabs, list);
+     }
+
+   tab = malloc(sizeof(*tab));
+   tab->path = eina_stringshare_add(path);
+   tab->windowed = windowed;
+   _edi_project_config->tabs = eina_list_append(_edi_project_config->tabs, 
tab);
+   _edi_project_config_save_no_notify();
+}
+
+void
+_edi_project_config_tab_remove(const char *path)
+{
+   Edi_Project_Config_Tab *tab;
+   Eina_List *list, *next;
+
+   EINA_LIST_FOREACH_SAFE(_edi_project_config->tabs, list, next, tab)
+     {
+        if (!strncmp(tab->path, path, strlen(tab->path)))
+          break;
+     }
+
+   _edi_project_config->tabs = eina_list_remove(_edi_project_config->tabs, 
tab);
+   _edi_project_config_save_no_notify();
+
+   eina_stringshare_del(tab->path);
+   free(tab);
+}
diff --git a/src/bin/edi_config.h b/src/bin/edi_config.h
index fc7b022..7d07cce 100644
--- a/src/bin/edi_config.h
+++ b/src/bin/edi_config.h
@@ -16,6 +16,7 @@ typedef struct _Edi_Config_Mime_Association 
Edi_Config_Mime_Association;
 typedef struct _Edi_Config Edi_Config;
 
 typedef struct _Edi_Project_Config Edi_Project_Config;
+typedef struct _Edi_Project_Config_Tab Edi_Project_Config_Tab;
 
 struct _Edi_Config_Project
 {
@@ -39,6 +40,12 @@ struct _Edi_Config
    Eina_List *mime_assocs;
 };
 
+struct _Edi_Project_Config_Tab
+{
+   const char *path;
+   Eina_Bool windowed;
+};
+
 struct _Edi_Project_Config 
 {
    int version;
@@ -57,17 +64,22 @@ struct _Edi_Project_Config
         Eina_Bool show_whitespace;
         unsigned int width_marker, tabstop;
      } gui;
+
+   Eina_List *tabs;
 };
 
 extern Edi_Config *_edi_config;
 extern Edi_Project_Config *_edi_project_config;
 
+// General configuration management
+
 Eina_Bool _edi_config_init(void);
 Eina_Bool _edi_config_shutdown(void);
+
+// Global configuration handling
+
 void _edi_config_load(void);
 void _edi_config_save(void);
-void _edi_project_config_load();
-void _edi_project_config_save();
 
 void _edi_config_project_add(const char *path);
 void _edi_config_project_remove(const char *path);
@@ -75,6 +87,14 @@ void _edi_config_project_remove(const char *path);
 void _edi_config_mime_add(const char *mime, const char* id);
 const char* _edi_config_mime_search(const char *mime);
 
+// Project based configuration handling
+
+void _edi_project_config_load(void);
+void _edi_project_config_save(void);
+
+void _edi_project_config_tab_add(const char *path, Eina_Bool windowed);
+void _edi_project_config_tab_remove(const char *path);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/bin/edi_main.c b/src/bin/edi_main.c
index 3b8af7d..d012ee1 100644
--- a/src/bin/edi_main.c
+++ b/src/bin/edi_main.c
@@ -760,6 +760,21 @@ _edi_resize_cb(void *data EINA_UNUSED, Evas *e 
EINA_UNUSED, Evas_Object *obj,
    _edi_project_config_save();
 }
 
+void
+_edi_open_tabs()
+{
+   Edi_Project_Config_Tab *tab;
+   Eina_List *list, *next;
+
+   EINA_LIST_FOREACH_SAFE(_edi_project_config->tabs, list, next, tab)
+     {
+        if (tab->windowed)
+          edi_mainview_open_window_path(tab->path);
+        else
+          edi_mainview_open_path(tab->path);
+     }
+}
+
 Evas_Object *
 edi_open(const char *inputpath)
 {
@@ -807,6 +822,7 @@ edi_open(const char *inputpath)
    evas_object_show(win);
 
    _edi_config_project_add(path);
+   _edi_open_tabs();
 
    free(path);
    return win;
diff --git a/src/bin/mainview/edi_mainview.c b/src/bin/mainview/edi_mainview.c
index f2979b6..42a619f 100644
--- a/src/bin/mainview/edi_mainview.c
+++ b/src/bin/mainview/edi_mainview.c
@@ -196,6 +196,7 @@ _edi_mainview_item_tab_add(Edi_Path_Options *options, const 
char *mime)
 
    if (options->line)
      edi_mainview_goto(options->line);
+   _edi_project_config_tab_add(options->path, EINA_FALSE);
 }
 
 static void
@@ -207,6 +208,8 @@ _edi_mainview_win_exit(void *data EINA_UNUSED, Evas_Object 
*obj, void *event_inf
 
    it = evas_object_data_get(obj, "edi_mainview_item");
    _edi_mainview_items = eina_list_remove(_edi_mainview_items, it);
+
+   _edi_project_config_tab_remove(it->path);
    eina_stringshare_del(it->path);
    free(it);
 }
@@ -248,6 +251,7 @@ _edi_mainview_item_win_add(Edi_Path_Options *options, const 
char *mime)
 
    evas_object_resize(win, 380 * elm_config_scale_get(), 260 * 
elm_config_scale_get());
    evas_object_show(win);
+   _edi_project_config_tab_add(options->path, EINA_TRUE);
 }
 
 static void
@@ -507,6 +511,7 @@ edi_mainview_close()
    elm_object_item_del(elm_toolbar_selected_item_get(tb));
    _edi_mainview_items = eina_list_remove(_edi_mainview_items, item);
 
+   _edi_project_config_tab_remove(item->path);
    eina_stringshare_del(item->path);
    free(item);
 }

-- 


Reply via email to