diff options
author | Andrii Kroitor <an.kroitor@samsung.com> | 2014-07-03 19:23:11 +0900 |
---|---|---|
committer | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2014-07-03 19:23:11 +0900 |
commit | d8316bcc0757f604ede2af0891345d702d0442c4 (patch) | |
tree | 6e45f0f1c3c2282a6b1dd7ee44dd78ea1e0ba253 | |
parent | f0f5c393d0144e75862524765c4004aa02cbee75 (diff) | |
download | efl-d8316bcc0757f604ede2af0891345d702d0442c4.tar.gz |
Edje_Edit: added clean save function
Summary:
This save function removes all unnecessary string from internal eet
distionary in .edj file. Needed after removing some objects from edje_object
e.g. groups, parts, limits etc.
Reviewers: cedric, seoz, raster, Hermet
CC: reutskiy.v.v, cedric
Differential Revision: https://phab.enlightenment.org/D1090
-rw-r--r-- | src/lib/edje/Edje_Edit.h | 15 | ||||
-rw-r--r-- | src/lib/edje/edje_edit.c | 81 |
2 files changed, 96 insertions, 0 deletions
diff --git a/src/lib/edje/Edje_Edit.h b/src/lib/edje/Edje_Edit.h index 0214b3ae3f..0740e2934b 100644 --- a/src/lib/edje/Edje_Edit.h +++ b/src/lib/edje/Edje_Edit.h @@ -205,6 +205,21 @@ EAPI Eina_Bool edje_edit_save(Evas_Object *obj); */ EAPI Eina_Bool edje_edit_save_all(Evas_Object *obj); +/** Save every group into new file. + * + * Use this function when you need clean eet dictionary in .edj file from + * unnecessary text entries (e.g. names of deleted groups etc.). + * + * @param obj Object to save. + * @param new_file_name Where to save object. File should not exist, otherwise + * EINA_FALSE will be returned. + * + * @return EINA_TRUE if successful, EINA_FALSE otherwise. + * + * @see edje_edit_save() + */ +EAPI Eina_Bool edje_edit_clean_save_as(Evas_Object *obj, const char* new_file_name); + /** Save the group(s) back to the file, without generation source code. * * This function saves changes in group(s) back into the edj file. Process of diff --git a/src/lib/edje/edje_edit.c b/src/lib/edje/edje_edit.c index bb7f93b754..7f9f17db57 100644 --- a/src/lib/edje/edje_edit.c +++ b/src/lib/edje/edje_edit.c @@ -10942,6 +10942,87 @@ _edje_edit_internal_save(Evas_Object *obj, int current_only, Eina_Bool generate_ } EAPI Eina_Bool +edje_edit_clean_save_as(Evas_Object *obj, const char* new_file_name) +{ + Eet_File *ef, *ef_out; + GET_ED_OR_RETURN(EINA_FALSE); + GET_EED_OR_RETURN(EINA_FALSE); + + if (!ed->file) return EINA_FALSE; + + if (ecore_file_exists(new_file_name)) + { + ERR("Error. file \"%s\" allready exists", + new_file_name); + return EINA_FALSE; + } + ef = eet_open(ed->file->path, EET_FILE_MODE_READ); + if (!ef) + { + ERR("Error. unable to open \"%s\" for reading", + ed->file->path); + return EINA_FALSE; + } + ef_out = eet_open(new_file_name, EET_FILE_MODE_WRITE); + if (!ef_out) + { + ERR("Error. unable to open \"%s\" for writing output", + new_file_name); + eet_close(ef); + return EINA_FALSE; + } + + /* copying file structure */ + _edje_edit_edje_file_save(ef_out, ed->file); + + int count = 0; + char **ent = eet_list(ef, "*", &count); + int i; + int size = 0; + const void * data; + + /* copying data */ + for (i = 0; i < count; i++) + { + /* Skiping entries that need special saving */ + if (!strcmp(ent[i], "edje/file")) continue; + if (!strcmp(ent[i], "edje_sources")) continue; + if (strstr(ent[i], "collection")) continue; + + data = eet_read_direct(ef, ent[i], &size); + if (data) eet_write(ef_out, ent[i], data, size, 0); + else + { + data = eet_read(ef, ent[i], &size); + eet_write(ef_out, ent[i], data, size, 1); + } + } + free(ent); + + /* copying groups */ + Edje_Part_Collection_Directory_Entry *ce; + Evas_Object *part_obj; + part_obj = edje_edit_object_add(ed->base->evas); + Eina_Iterator *it = eina_hash_iterator_data_new(ed->file->collection); + EINA_ITERATOR_FOREACH(it, ce) + { + /* forcing collection load into memory */ + edje_object_file_set(part_obj, ed->file->path, ce->entry); + + _edje_edit_collection_save(ef_out, ce->ref); + } + eina_iterator_free(it); + + /* generating source code */ + _edje_edit_source_save(ef_out, obj); + + eet_close(ef); + eet_close(ef_out); + + return EINA_TRUE; +} + +EAPI Eina_Bool edje_edit_save(Evas_Object *obj) { return _edje_edit_internal_save(obj, 1, EINA_TRUE); |