summaryrefslogtreecommitdiff
path: root/src/lib/edje/edje_edit.c
diff options
context:
space:
mode:
authorVorobiov Vitalii <vi.vorobiov@samsung.com>2013-12-19 15:15:34 +0900
committerCedric BAIL <cedric.bail@samsung.com>2013-12-19 15:52:51 +0900
commit12c91a88527d9a9615559fc2d7d8583b0ef1e879 (patch)
tree6ee79b1a522d25e97b3b6cea42ae1eb0a4c60357 /src/lib/edje/edje_edit.c
parentf4d24e962dba33bef8f990ce3359c06eed8771d0 (diff)
edje: edje_edit - adding edje_edit_group_copy.
This new function will copy the whole group into same file but with another group name/id. Copying whole group data field by field require some huge code. Alternatively we found another solution for copying whole group as you can see it in this commit. This function will copy group and all it's data (like scripts etc) and it will be totally independent. Reviewers: cedric, seoz, raster CC: reutskiy.v.v, cedric Differential Revision: https://phab.enlightenment.org/D385 Signed-off-by: Cedric BAIL <cedric.bail@samsung.com>
Diffstat (limited to '')
-rw-r--r--src/lib/edje/edje_edit.c146
1 files changed, 143 insertions, 3 deletions
diff --git a/src/lib/edje/edje_edit.c b/src/lib/edje/edje_edit.c
index 21030ca832..e016acc218 100644
--- a/src/lib/edje/edje_edit.c
+++ b/src/lib/edje/edje_edit.c
@@ -913,6 +913,148 @@ edje_edit_compiler_get(Evas_Object *obj)
913/****************/ 913/****************/
914 914
915EAPI Eina_Bool 915EAPI Eina_Bool
916edje_edit_group_copy(Evas_Object *obj, const char *group_name, const char *copy_name)
917{
918 Edje_Part_Collection_Directory_Entry *e;
919 Edje_Part_Collection_Directory_Entry *de;
920 Edje_Part_Collection_Directory_Entry *d;
921 Edje_Part_Collection *epc;
922 int id;
923 int search;
924 Eet_File *eetf;
925 char buf[64];
926 int count, script_count;
927 void *data;
928 char **keys, **c;
929
930 GET_ED_OR_RETURN(EINA_FALSE);
931 if (!ed->file || !ed->file->collection)
932 return EINA_FALSE;
933
934 e = eina_hash_find(ed->file->collection, group_name);
935 if (!e) return EINA_FALSE;
936 if (eina_hash_find(ed->file->collection, copy_name))
937 return EINA_FALSE;
938
939 eetf = eet_open(ed->file->path, EET_FILE_MODE_READ_WRITE);
940 if (!eetf)
941 {
942 ERR("Edje_Edit: Error. unable to open \"%s\" "
943 "for writing output", ed->file->path);
944 return EINA_FALSE;
945 }
946 snprintf(buf, sizeof(buf), "edje/collections/%d", e->id);
947 epc = eet_data_read(eetf, _edje_edd_edje_part_collection, buf);
948
949 /* Search first free id */
950 id = -1;
951 search = 0;
952 while (id == -1)
953 {
954 Eina_Iterator *i;
955 Eina_Bool found = 0;
956
957 i = eina_hash_iterator_data_new(ed->file->collection);
958
959 EINA_ITERATOR_FOREACH(i, d)
960 {
961 if (search == d->id)
962 {
963 found = 1;
964 break;
965 }
966 }
967
968 eina_iterator_free(i);
969
970 if (!found) id = search;
971 else search++;
972 }
973
974 /* Create structs */
975 de = _alloc(sizeof(Edje_Part_Collection_Directory_Entry));
976 if (!de) return EINA_FALSE;
977
978 /* Init Edje_Part_Collection_Directory_Entry */
979 de->id = id;
980 de->entry = eina_stringshare_add(copy_name);
981 memcpy(&de->count, &e->count, sizeof (de->count));
982
983#define EDIT_EMN(Tp, Sz, Ce) \
984 Ce->mp.Tp = eina_mempool_add("chained_mempool", #Tp, NULL, sizeof (Sz), 8);
985#define EDIT_EMNP(Tp, Sz, Ce) \
986 Ce->mp_rtl.Tp = eina_mempool_add("chained_mempool", #Tp, NULL, sizeof (Sz), 8);
987
988 eina_hash_direct_add(ed->file->collection, de->entry, de);
989
990 EDIT_EMN(RECTANGLE, Edje_Part_Description_Common, de);
991 EDIT_EMN(TEXT, Edje_Part_Description_Text, de);
992 EDIT_EMN(IMAGE, Edje_Part_Description_Image, de);
993 EDIT_EMN(PROXY, Edje_Part_Description_Proxy, de);
994 EDIT_EMN(SWALLOW, Edje_Part_Description_Common, de);
995 EDIT_EMN(TEXTBLOCK, Edje_Part_Description_Text, de);
996 EDIT_EMN(GROUP, Edje_Part_Description_Common, de);
997 EDIT_EMN(BOX, Edje_Part_Description_Box, de);
998 EDIT_EMN(TABLE, Edje_Part_Description_Table, de);
999 EDIT_EMN(EXTERNAL, Edje_Part_Description_External, de);
1000 EDIT_EMN(SPACER, Edje_Part_Description_Common, de);
1001 EDIT_EMN(part, Edje_Part, de);
1002
1003 EDIT_EMNP(RECTANGLE, Edje_Part_Description_Common, de);
1004 EDIT_EMNP(TEXT, Edje_Part_Description_Text, de);
1005 EDIT_EMNP(IMAGE, Edje_Part_Description_Image, de);
1006 EDIT_EMNP(PROXY, Edje_Part_Description_Proxy, de);
1007 EDIT_EMNP(SWALLOW, Edje_Part_Description_Common, de);
1008 EDIT_EMNP(TEXTBLOCK, Edje_Part_Description_Text, de);
1009 EDIT_EMNP(GROUP, Edje_Part_Description_Common, de);
1010 EDIT_EMNP(BOX, Edje_Part_Description_Box, de);
1011 EDIT_EMNP(TABLE, Edje_Part_Description_Table, de);
1012 EDIT_EMNP(EXTERNAL, Edje_Part_Description_External, de);
1013 EDIT_EMNP(SPACER, Edje_Part_Description_Common, de);
1014
1015 epc->id = id;
1016 epc->part = eina_stringshare_add(copy_name);
1017 ed->file->collection_cache = eina_list_prepend(ed->file->collection_cache, epc);
1018
1019 /* Copying Scripts */
1020 snprintf(buf, sizeof(buf), "edje/scripts/embryo/compiled/%d", e->id);
1021 data = eet_read(eetf, buf, &count);
1022 snprintf(buf, sizeof(buf), "edje/scripts/embryo/compiled/%d", epc->id);
1023 eet_write(eetf, buf, data, count, 1);
1024
1025 snprintf(buf, sizeof(buf), "edje/scripts/embryo/source/%d", e->id);
1026 data = eet_read(eetf, buf, &count);
1027 snprintf(buf, sizeof(buf), "edje/scripts/embryo/source/%d", epc->id);
1028 eet_write(eetf, buf, data, count, 0);
1029
1030 snprintf(buf, sizeof(buf), "edje/scripts/embryo/source/%d/*", e->id);
1031 keys = eet_list(eetf, buf, &count);
1032 if (keys)
1033 {
1034 while(count)
1035 {
1036 count--;
1037 data = eet_read(eetf, keys[count], &script_count);
1038 /* we need to save id of every script we are going to copy. */
1039 c = eina_str_split(keys[count], "/", 6);
1040 snprintf(buf, sizeof(buf), "edje/scripts/embryo/source/%d/%s", epc->id, c[5]);
1041 eet_write(eetf, buf, data, script_count, 0);
1042 }
1043 free(keys);
1044 free(c[0]);
1045 free(c);
1046 }
1047
1048 eet_close(eetf);
1049
1050 /* we need to save everything to make sure the file won't have broken
1051 * references the next time is loaded */
1052 edje_edit_save_all(obj);
1053
1054 return EINA_TRUE;
1055}
1056
1057EAPI Eina_Bool
916edje_edit_group_add(Evas_Object *obj, const char *name) 1058edje_edit_group_add(Evas_Object *obj, const char *name)
917{ 1059{
918 Edje_Part_Collection_Directory_Entry *de; 1060 Edje_Part_Collection_Directory_Entry *de;
@@ -984,8 +1126,6 @@ edje_edit_group_add(Evas_Object *obj, const char *name)
984 1126
985 //cd = _alloc(sizeof(Code)); 1127 //cd = _alloc(sizeof(Code));
986 //codes = eina_list_append(codes, cd); 1128 //codes = eina_list_append(codes, cd);
987#define EDIT_EMN(Tp, Sz, Ce) \
988 Ce->mp.Tp = eina_mempool_add("chained_mempool", #Tp, NULL, sizeof (Sz), 8);
989 1129
990 EDIT_EMN(RECTANGLE, Edje_Part_Description_Common, de); 1130 EDIT_EMN(RECTANGLE, Edje_Part_Description_Common, de);
991 EDIT_EMN(TEXT, Edje_Part_Description_Text, de); 1131 EDIT_EMN(TEXT, Edje_Part_Description_Text, de);
@@ -7585,7 +7725,7 @@ _edje_edit_internal_save(Evas_Object *obj, int current_only)
7585 snprintf(buf, sizeof(buf), "edje/scripts/embryo/source/%i", 7725 snprintf(buf, sizeof(buf), "edje/scripts/embryo/source/%i",
7586 ed->collection->id); 7726 ed->collection->id);
7587 eet_write(eetf, buf, eed->embryo_source, 7727 eet_write(eetf, buf, eed->embryo_source,
7588 strlen(eed->embryo_source) +1, 1); 7728 strlen(eed->embryo_source) + 1, 1);
7589 eed->embryo_source_dirty = EINA_FALSE; 7729 eed->embryo_source_dirty = EINA_FALSE;
7590 } 7730 }
7591 7731