summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/edje/Edje_Edit.h22
-rw-r--r--src/lib/edje/edje_edit.c146
2 files changed, 164 insertions, 4 deletions
diff --git a/src/lib/edje/Edje_Edit.h b/src/lib/edje/Edje_Edit.h
index 099dce7c3c..d216ec237d 100644
--- a/src/lib/edje/Edje_Edit.h
+++ b/src/lib/edje/Edje_Edit.h
@@ -187,7 +187,7 @@ EAPI void edje_edit_print_internal_status(Evas_Object *obj);
187 * @param obj The pointer to edje object. 187 * @param obj The pointer to edje object.
188 * @param name The name of the group. 188 * @param name The name of the group.
189 * 189 *
190 * @return 1 If it could allocate memory to the part group added 190 * @return EINA_TRUE If it could allocate memory to the part group added
191 * or zero if not. 191 * or zero if not.
192 * 192 *
193 * This function adds, at run time, one more group, which will reside 193 * This function adds, at run time, one more group, which will reside
@@ -201,6 +201,26 @@ EAPI void edje_edit_print_internal_status(Evas_Object *obj);
201EAPI Eina_Bool edje_edit_group_add(Evas_Object *obj, const char *name); 201EAPI Eina_Bool edje_edit_group_add(Evas_Object *obj, const char *name);
202 202
203/** 203/**
204 * @brief Copy whole group and all it's data into separate group.
205 *
206 * @param obj The pointer to edje object.
207 * @param group_name The name of the group.
208 * @param copy_name The name of the new group that is a copy.
209 *
210 * @return @c EINA_TRUE on success, @c EINA_FALSE on failure.
211 *
212 * This function copy, at run time, a whole group, which will reside
213 * in memory, to the group set found in the .edj file which @a obj was
214 * loaded with. This group can be manipulated by other API functions,
215 * like @c edje_edit_part_add(), for example.
216 *
217 * @attention This group will copy the whole group and this operation can't be undone as all references to the group will be added to the file.
218 * (for example all scripts will be written to the file directly)
219 *
220 */
221EAPI Eina_Bool edje_edit_group_copy(Evas_Object *obj, const char *group_name, const char *copy_name);
222
223/**
204 * @brief Delete the specified group from the edje file. 224 * @brief Delete the specified group from the edje file.
205 * 225 *
206 * @param obj The pointer to the edje object. 226 * @param obj The pointer to the edje object.
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