ajwillia-ms pushed a commit to branch master. http://git.enlightenment.org/tools/edi.git/commit/?id=cb872785f44d440d84cdc76dedb5d657002377e5
commit cb872785f44d440d84cdc76dedb5d657002377e5 Author: Kelly Wilson <wils...@cpsc.ucalgary.ca> Date: Sat Feb 7 01:13:40 2015 -0700 Config: remember file types We now associate the mime type of a file with the type of file to open. So open a .py file as text once and then you won't be prompted any more. --- src/bin/edi_config.c | 48 +++++++++++++++++++++++++++++++++++++++++ src/bin/edi_config.h | 11 ++++++++++ src/bin/edi_content_provider.c | 9 ++++++-- src/bin/mainview/edi_mainview.c | 3 +++ 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/bin/edi_config.c b/src/bin/edi_config.c index 29d5d9e..344d0df 100644 --- a/src/bin/edi_config.c +++ b/src/bin/edi_config.c @@ -43,6 +43,7 @@ typedef Eet_Data_Descriptor Edi_Config_DD; /* local variables */ static Edi_Config_DD *_edi_cfg_edd = NULL; static Edi_Config_DD *_edi_cfg_proj_edd = NULL; +static Edi_Config_DD *_edi_cfg_mime_edd = NULL; /* external variables */ Edi_Config *_edi_cfg = NULL; @@ -75,6 +76,7 @@ static void _edi_config_cb_free(void) { Edi_Config_Project *proj; + Edi_Config_Mime_Associations *mimes; EINA_LIST_FREE(_edi_cfg->projects, proj) { @@ -83,6 +85,13 @@ _edi_config_cb_free(void) free(proj); } + EINA_LIST_FREE(_edi_cfg->mime_assocs, mimes) + { + if (mimes->id) eina_stringshare_del(mimes->id); + if (mimes->mime) eina_stringshare_del(mimes->mime); + free(mimes); + } + free(_edi_cfg); _edi_cfg = NULL; } @@ -154,6 +163,14 @@ _edi_config_init(void) EDI_CONFIG_VAL(D, T, name, EET_T_STRING); EDI_CONFIG_VAL(D, T, path, EET_T_STRING); + _edi_cfg_mime_edd = EDI_CONFIG_DD_NEW("Config_Mime", Edi_Config_Mime_Associations); + #undef T + #undef D + #define T Edi_Config_Mime_Associations + #define D _edi_cfg_mime_edd + EDI_CONFIG_VAL(D, T, id, EET_T_STRING); + EDI_CONFIG_VAL(D, T, mime, EET_T_STRING); + _edi_cfg_edd = EDI_CONFIG_DD_NEW("Config", Edi_Config); #undef T #undef D @@ -170,6 +187,7 @@ _edi_config_init(void) EDI_CONFIG_VAL(D, T, gui.bottomopen, EET_T_UCHAR); EDI_CONFIG_VAL(D, T, gui.bottomtab, EET_T_INT); EDI_CONFIG_LIST(D, T, projects, _edi_cfg_proj_edd); + EDI_CONFIG_LIST(D, T, mime_assocs, _edi_cfg_mime_edd); _edi_config_load(); @@ -182,6 +200,7 @@ _edi_config_shutdown(void) _edi_config_cb_free(); EDI_CONFIG_DD_FREE(_edi_cfg_proj_edd); + EDI_CONFIG_DD_FREE(_edi_cfg_mime_edd); EDI_CONFIG_DD_FREE(_edi_cfg_edd); efreet_shutdown(); @@ -238,6 +257,7 @@ _edi_config_load(void) _edi_cfg->gui.bottomopen = EINA_FALSE; _edi_cfg->gui.bottomtab = 0; _edi_cfg->projects = NULL; + _edi_cfg->mime_assocs = NULL; IFCFGEND; /* limit config values so they are sane */ @@ -297,3 +317,31 @@ _edi_config_project_remove(const char *path) _edi_cfg->projects = eina_list_remove(_edi_cfg->projects, project); _edi_config_save(); } + +void +_edi_config_mime_add(const char *mime, const char *id) +{ + Edi_Config_Mime_Associations *mime_assoc; + + mime_assoc = malloc(sizeof(*mime_assoc)); + mime_assoc->id = eina_stringshare_add(id); + mime_assoc->mime = eina_stringshare_add(mime); + _edi_cfg->mime_assocs = eina_list_prepend(_edi_cfg->mime_assocs, mime_assoc); + _edi_config_save(); +} + +const char* +_edi_config_mime_search(const char *mime) +{ + Edi_Config_Mime_Associations *mime_assoc; + Eina_List *list, *next; + + EINA_LIST_FOREACH_SAFE(_edi_cfg->mime_assocs, list, next, mime_assoc) + { + if (!strncmp(mime_assoc->mime, mime, strlen(mime_assoc->mime))) + { + return mime_assoc->id; + } + } + return ""; +} diff --git a/src/bin/edi_config.h b/src/bin/edi_config.h index 28aaed7..0b3e337 100644 --- a/src/bin/edi_config.h +++ b/src/bin/edi_config.h @@ -8,6 +8,7 @@ extern "C" { #endif typedef struct _Edi_Config_Project Edi_Config_Project; +typedef struct _Edi_Config_Mime_Associations Edi_Config_Mime_Associations; typedef struct _Edi_Config Edi_Config; struct _Edi_Config_Project @@ -16,6 +17,12 @@ struct _Edi_Config_Project const char *path; }; +struct _Edi_Config_Mime_Associations +{ + const char *id; + const char *mime; +}; + struct _Edi_Config { int version; @@ -34,6 +41,7 @@ struct _Edi_Config } gui; Eina_List *projects; + Eina_List *mime_assocs; }; extern Edi_Config *_edi_cfg; @@ -46,6 +54,9 @@ void _edi_config_save(void); void _edi_config_project_add(const char *path); 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); + #ifdef __cplusplus } #endif diff --git a/src/bin/edi_content_provider.c b/src/bin/edi_content_provider.c index 0472d5b..8a9e411 100644 --- a/src/bin/edi_content_provider.c +++ b/src/bin/edi_content_provider.c @@ -9,6 +9,7 @@ #include "editor/edi_editor.h" #include "edi_private.h" +#include "edi_config.h" // TODO move out to edi_content.c ot similar just like the editor type // (and the Evas include) @@ -57,7 +58,7 @@ static Edi_Content_Provider _edi_content_provider_registry[] = Edi_Content_Provider *edi_content_provider_for_mime_get(const char *mime) { - char *id; + char *id = NULL; if (!mime) return NULL; @@ -74,7 +75,11 @@ Edi_Content_Provider *edi_content_provider_for_mime_get(const char *mime) else if (!strcasecmp(mime, "text/x-diff") || !strcasecmp(mime, "text/x-patch")) id = "diff"; else - return NULL; + { + id = (char *)_edi_config_mime_search(mime); + if (!strcasecmp(id, "")) + return NULL; + } return edi_content_provider_for_id_get(id); } diff --git a/src/bin/mainview/edi_mainview.c b/src/bin/mainview/edi_mainview.c index 53fd087..5f0bacb 100644 --- a/src/bin/mainview/edi_mainview.c +++ b/src/bin/mainview/edi_mainview.c @@ -15,6 +15,7 @@ #include "edi_content_provider.h" #include "edi_private.h" +#include "edi_config.h" static Evas_Object *nf, *tb, *_main_win; static Evas_Object *_edi_mainview_choose_popup; @@ -244,6 +245,7 @@ _edi_mainview_choose_type_tab_cb(void *data, evas_object_del(_edi_mainview_choose_popup); _edi_mainview_choose_options->type = (const char *) data; + _edi_config_mime_add(efreet_mime_type_get(_edi_mainview_choose_options->path), _edi_mainview_choose_options->type); edi_mainview_open(_edi_mainview_choose_options); } @@ -255,6 +257,7 @@ _edi_mainview_choose_type_win_cb(void *data, evas_object_del(_edi_mainview_choose_popup); _edi_mainview_choose_options->type = (const char *) data; + _edi_config_mime_add(efreet_mime_type_get(_edi_mainview_choose_options->path), _edi_mainview_choose_options->type); edi_mainview_open_window(_edi_mainview_choose_options); } --