config: Store relative paths for open files

Avoid problems with moving project
or having multiple copies of the same codebase!
This commit is contained in:
Andy Williams 2017-01-02 21:19:55 +00:00
parent 1b2ee9a372
commit 14498afdaa
5 changed files with 24 additions and 8 deletions

View File

@ -508,7 +508,13 @@ _edi_project_config_tab_add(const char *path, Eina_Bool windowed)
} }
tab = malloc(sizeof(*tab)); tab = malloc(sizeof(*tab));
tab->path = eina_stringshare_add(path);
// let's keep paths relative
if (!strncmp(path, edi_project_get(), strlen(edi_project_get())))
tab->path = eina_stringshare_add(path + strlen(edi_project_get()) + 1);
else
tab->path = eina_stringshare_add(path);
tab->windowed = windowed; tab->windowed = windowed;
_edi_project_config->tabs = eina_list_append(_edi_project_config->tabs, tab); _edi_project_config->tabs = eina_list_append(_edi_project_config->tabs, tab);
_edi_project_config_save_no_notify(); _edi_project_config_save_no_notify();
@ -524,6 +530,9 @@ _edi_project_config_tab_remove(const char *path)
{ {
if (!strncmp(tab->path, path, strlen(tab->path))) if (!strncmp(tab->path, path, strlen(tab->path)))
break; break;
if (!strncmp(path, edi_project_get(), strlen(edi_project_get())) &&
!strncmp(path + strlen(edi_project_get()) + 1, tab->path, strlen(tab->path)))
break;
} }
_edi_project_config->tabs = eina_list_remove(_edi_project_config->tabs, tab); _edi_project_config->tabs = eina_list_remove(_edi_project_config->tabs, tab);

View File

@ -1004,15 +1004,22 @@ _edi_open_tabs()
{ {
Edi_Project_Config_Tab *tab; Edi_Project_Config_Tab *tab;
Eina_List *tabs, *list; Eina_List *tabs, *list;
char *path;
tabs = _edi_project_config->tabs; tabs = _edi_project_config->tabs;
_edi_project_config->tabs = NULL; _edi_project_config->tabs = NULL;
EINA_LIST_FOREACH(tabs, list, tab) EINA_LIST_FOREACH(tabs, list, tab)
{ {
if (tab->windowed) if (!strncmp(tab->path, edi_project_get(), strlen(edi_project_get())))
edi_mainview_open_window_path(tab->path); path = strdup(tab->path);
else else
edi_mainview_open_path(tab->path); path = edi_path_append(edi_project_get(), tab->path);
if (tab->windowed)
edi_mainview_open_window_path(eina_stringshare_add(path));
else
edi_mainview_open_path(eina_stringshare_add(path));
free(path);
} }
EINA_LIST_FREE(tabs, tab) EINA_LIST_FREE(tabs, tab)

View File

@ -13,13 +13,13 @@
static Eina_Bool static Eina_Bool
_relative_path_exists(const char *base, const char *relative) _relative_path_exists(const char *base, const char *relative)
{ {
const char *path; char *path;
Eina_Bool ret; Eina_Bool ret;
path = edi_path_append(base, relative); path = edi_path_append(base, relative);
ret = ecore_file_exists(path); ret = ecore_file_exists(path);
free((void *)path); free(path);
return ret; return ret;
} }

View File

@ -43,7 +43,7 @@ edi_path_options_create(const char *input)
return ret; return ret;
} }
EAPI const char * EAPI char *
edi_path_append(const char *path, const char *file) edi_path_append(const char *path, const char *file)
{ {
char *concat; char *concat;

View File

@ -49,7 +49,7 @@ EAPI Edi_Path_Options *edi_path_options_create(const char *input);
* @return a newly allocated string that merges the items to a path using the * @return a newly allocated string that merges the items to a path using the
* correct separator for the current platform. * correct separator for the current platform.
*/ */
EAPI const char *edi_path_append(const char *path, const char *file); EAPI char *edi_path_append(const char *path, const char *file);
/** /**
* @} * @}