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
This commit is contained in:
Andrii Kroitor 2014-07-03 19:23:11 +09:00 committed by Carsten Haitzler (Rasterman)
parent f0f5c393d0
commit d8316bcc07
2 changed files with 96 additions and 0 deletions

View File

@ -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

View File

@ -10941,6 +10941,87 @@ _edje_edit_internal_save(Evas_Object *obj, int current_only, Eina_Bool generate_
return EINA_TRUE;
}
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)
{