summaryrefslogtreecommitdiff
path: root/src/bin/egui_gui/propview.c
blob: 10392ab567d339804a65889da3b30f73ffbc5582 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719

#include <Elementary.h>
#include <Eolian.h>
#include "ffi_glue.h"
#include "egui_log.h"
#include "props_helper.h"
#include "propview.h"
#include "itemview.h"
#include "egui_logic_private.h"

#include "elm_widget_container.h"

static Elm_Genlist_Item_Class *_itc_class = NULL;
static Elm_Genlist_Item_Class *_itc_prop = NULL;
static Elm_Genlist_Item_Class *_itc_notfound = NULL;
static Elm_Genlist_Item_Class *_itc_cb = NULL;
static Elm_Genlist_Item_Class *_itc_desc = NULL;
static Elm_Genlist_Item_Class *_itc_ctn = NULL;

static Eo *propview_table = NULL;
static Eo *prop_list = NULL;
static Eo *cb_list = NULL;
static Eo *desc_list = NULL;
static Eo *ctn_list = NULL;

extern Gui_Context *
_active_context_get();

static PropViewCbs *_view_cbs = NULL;
static It_Data_Type _propsview_toolbar_selected_item_type = DESCRIPTION_TYPE;
static It_Data_Type _new_type = DESCRIPTION_TYPE;

void
_it_data_free(void *data)
{
   It_Data *it_data = data;

   if (!it_data) return;

   /* If property wasn't assigned to any widget, this is property with default values.
    * Delete it. */
   if ((it_data->type == PROPERTY_TYPE) && (it_data->prop) && !prop_wdg_get(it_data->prop))
     {
        prop_ref((Gui_Widget_Property *) it_data->prop);
        prop_unref((Gui_Widget_Property *) it_data->prop);
        it_data->prop = NULL;
     }

   free(it_data);
   it_data = NULL;
}

#define _PATH_ICON_UP_ARROW PACKAGE_DATA_DIR"/images/icon_up_arrow.png"
#define _PATH_ICON_DOWN_ARROW PACKAGE_DATA_DIR"/images/icon_down_arrow.png"

/*
 * Hash table to map op to proplist's item.
 * In order to quickly find item in list, when prop name is known.
 * [Op_Desc]->[Item] */
static Eina_Hash *op_item_table = NULL;

/* Hash table to keep the list of expanded classes */
static Eina_Hash *expanded_classes = NULL;

static Eina_Hash *mempool_cache = NULL;

static void
_mempool_hash_del(void* data)
{
   Eo* obj = NULL;
   Eina_List *list = data;
   EINA_LIST_FREE(list, obj)
     eo_unref(obj);
}

static void
_mempool_cache_init()
{
   mempool_cache = eina_hash_string_superfast_new(_mempool_hash_del);
}

static void
_mempool_cache_free()
{
   if (mempool_cache) eina_hash_free(mempool_cache);
}

static void*
_mempool_cache_data_get(const char *key)
{
   Eina_List *l = eina_hash_find(mempool_cache, key);

   if (!l) return NULL;

   void *ptr = eina_list_data_get(l);
   l = eina_list_remove_list(l, l);
   eina_hash_set(mempool_cache, key, l);

   return ptr;
}

static void
_mempool_cache_data_put(const char *key, void *ptr)
{
   Eina_List *l = eina_hash_find(mempool_cache, key);

   l = eina_list_append(l, ptr);
   eina_hash_set(mempool_cache, key, l);
}

static Evas_Object *
_item_content_get(It_Data *it_data);

static Eina_Bool
_content_item_content_get(It_Data *it_data)
{
   Eo *box = it_data->box;
   const Gui_Widget *wdg = it_data->wdg;
   const Gui_Context *ctx = wdg_context_get(wdg);

   unsigned int count, i;
   count = db_op_desc_param_number_get(it_data->op_desc);

   for (i = 0; i < count; i++)
     {
        /* Get value, for which we want to build field.
         * If it is NULL, field will be build, for nth value in Op_Desc */
        Gui_Value *val = ((it_data->prop) ? prop_value_nth_get(it_data->prop, i) : NULL);
        Eo *obj = props_value_add(box, ctx, wdg, val, it_data->op_desc, i);
        if (obj)
          {
             Par_Field_Data *pfd = calloc (1, sizeof(Par_Field_Data));
             pfd->it_data = it_data;
             pfd->par_idx = i;

             eo_do(obj, eo_key_data_set(_STR_EDITOR, pfd, free));

             if (eo_isa(obj, ELM_HOVERSEL_CLASS))
               {
                  eo_do(obj, eo_event_callback_add(EVAS_SELECTABLE_INTERFACE_EVENT_SELECTED,
                                                   _view_cbs->content_change_cb_func, NULL));
                  eo_do(obj, evas_obj_size_hint_weight_set(0, EVAS_HINT_EXPAND),
                             evas_obj_size_hint_align_set(0, EVAS_HINT_FILL));
               }
             else
               {
                  eo_do(obj, eo_event_callback_add(ELM_ENTRY_EVENT_ACTIVATED, _view_cbs->content_change_cb_func, NULL));
               }
          }
        else
          {
             ERR("Can't create field for %dnth parameter in \"%s\", \
                 probably this parameter is NULL pointer", i + 1, db_op_desc_op_name_get(it_data->op_desc));
          }
     }
   return EINA_TRUE;
}

static Eina_Bool
_default_hover_selected_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
{
   const char *choosen_value = elm_object_item_part_text_get(event_info, NULL);
   Eo *entry = data;
   Par_Field_Data *pfd = NULL;
   eo_do(entry, pfd = eo_key_data_get(_STR_EDITOR));
   const Op_Desc *op = pfd->it_data->op_desc;
   Eina_List *def_vals = (Eina_List *) op_params_desc_default_values_list_get(db_op_desc_nth_param_desc_get(op, pfd->par_idx));
   if (def_vals)
     {
        Param_Default_Value *def_val;
        Eina_List *itr;
        EINA_LIST_FOREACH(def_vals, itr, def_val)
          {
             if (!strcmp(choosen_value, param_default_value_name_get(def_val)))
               {
                  eo_do(entry, elm_obj_widget_part_text_set(NULL, param_default_value_get(def_val)));
                  break;
               }
          }
     }
   _view_cbs->property_update_cb_func(NULL, entry, NULL, NULL);
   return EO_CALLBACK_CONTINUE;
}

static Eina_Bool
_property_item_content_get(It_Data *it_data)
{
   Eo *box = it_data->box;
   const Op_Desc *op = it_data->op_desc;
   const Gui_Widget_Property *prop = it_data->prop;
   /* Add label with op name. */

   const char *label = db_op_desc_prop_display_name_get(op);
   if (!label) label = db_op_desc_op_name_get(op);
   props_label_add(box, label);

   unsigned int count, i;
   count = db_op_desc_param_number_get(op);

   for (i = 0; i < count; i++)
     {
        /* Get value, for which we want to build field.
         * If it is NULL, field will be build, for nth value in Op_Desc*/
        Gui_Value *value = ((prop && prop_value_get(prop)) ? prop_value_nth_get(prop, i) : NULL);
        Eo *obj = props_value_add(box, wdg_context_get(it_data->wdg), it_data->wdg, value, op, i);
        if (obj)
          {
             Par_Field_Data *pfd = calloc (1, sizeof(Par_Field_Data));
             pfd->it_data = it_data;
             pfd->par_idx = i;

             eo_do(obj, eo_key_data_set(_STR_EDITOR, pfd, free));

             if (eo_isa(obj, ELM_HOVERSEL_CLASS))
               {
                  /* pass box as a data, in order to change its color then value changed from default. */
                  eo_do(obj, eo_event_callback_add(EVAS_SELECTABLE_INTERFACE_EVENT_SELECTED, _view_cbs->property_update_cb_func, NULL));
               }
             else if (eo_isa(obj, ELM_CHECK_CLASS))
               {
                  /* pass box as a data, in order to change its color then value changed from default. */
                  eo_do(obj, eo_event_callback_add(ELM_CHECK_EVENT_CHANGED, _view_cbs->property_update_cb_func, NULL));
               }
             else if (eo_isa(obj, ELM_ENTRY_CLASS))
               {
                  /*FIXME: decide how to handle CHANGE ON ACTIVATE*/
                  /* pass box as a data, in order to change its color then value changed from default. */
                  eo_do(obj, eo_event_callback_add(ELM_ENTRY_EVENT_CHANGED_USER, _view_cbs->property_update_cb_func, NULL));

                  /* If there are default values, add Hoversel. */
                  Eina_List *def_vals = (Eina_List *) op_params_desc_default_values_list_get(db_op_desc_nth_param_desc_get(op, i));
                  if (def_vals)
                    {
                       Eo *hover = props_hoversel_enums_add(box, elm_widget_top_get(box), "...", NULL);
                       eo_do(hover, eo_event_callback_add(EVAS_SELECTABLE_INTERFACE_EVENT_SELECTED, _default_hover_selected_cb, obj));
                       Param_Default_Value *def_val;
                       Eina_List *itr;
                       EINA_LIST_FOREACH(def_vals, itr, def_val)
                         {
                            const char *def_val_name = param_default_value_name_get(def_val);
                            eo_do(hover, elm_obj_hoversel_item_add(def_val_name, NULL, ELM_ICON_NONE, NULL, NULL));
                         }
                    }
               }
          }
        else
          {
             /*
             ERR("Can't create field for %dnth parameter in \"%s\", \
                 probably this parameter is NULL pointer", i + 1, db_op_desc_op_name_get(op));
                 */
          }
     }

   return EINA_TRUE;
}

static void
_callback_item_box_reassign(It_Data *it_data, Eo *box);

static void
_select_callback_item(Dep_Id *cb_dep_id)
{
    Elm_Object_Item *it = elm_genlist_first_item_get(cb_list);
    for (; it; it = elm_genlist_item_next_get(it))
      {
          if (elm_genlist_item_item_class_get(it) != _itc_cb)
            continue;

          It_Data *it_data = elm_object_item_data_get(it);
          if (cb_dep_id_get(it_data->cb) == cb_dep_id)
            {
               /* In case of Undo/Redo can happen, that Callback in Dep_data was changed,
                * but It_Data still holds the old one. So need to change CB in It_Data and update the box. */
               if (it_data->cb != cb_get(cb_dep_id))
                 {
                    it_data->cb = cb_get(cb_dep_id);
                    _callback_item_box_reassign(it_data, it_data->box);
                 }
               elm_genlist_item_selected_set(it, EINA_TRUE);
               elm_genlist_item_bring_in(it, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
               break;
            }
      }
}

void
cbview_item_selected_set(Dep_Id *cb_dep_id)
{
   _select_callback_item(cb_dep_id);
}

static Eina_Bool
_cb_sequence_modify(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
{
   It_Data *it_data = data;
   Gui_Widget_Callback *cb_old = it_data->cb, *new_cb;
   Gui_Widget *wdg = (Gui_Widget *) it_data->wdg;
   Gui_Context *ctx = (Gui_Context *) wdg_context_get(wdg);
   Dep_Id *prevseq = cb_sequence_id_get(cb_old);
   const char *seq_name = elm_object_item_part_text_get(event_info, NULL);
   Dep_Id *new_seq_id = gui_context_dep_id_by_name_get(_active_context_get(), seq_name);
   if (prevseq == new_seq_id) return EO_CALLBACK_CONTINUE;
   elm_object_text_set(obj, seq_name);

   Gui_Memento *memento;
   /* if !prevseq - cb is default field, so there is no real callback behind, so create new. */
   if (!prevseq)
     {
        new_cb = cb_new_full(ctx, cb_type_get(cb_old), new_seq_id);
        Callback_Container *cc_new = NULL, *cc_old = NULL;
        cc_old = (Callback_Container *) wdg_cb_container_get(wdg);
        if (!cc_old)
          {
             cc_new = cb_container_new();
          }
        else
          {
             cc_new = cb_container_copy(cc_old);
          }
        /* Add callback to container. */
        cb_container_cb_add(cc_new, new_cb);
        /* Save containers into memento*/
        memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_CALLBACK_ADD_DEL, cc_old, cc_new);
        /* Unset old container from widget */
        wdg_cb_container_unset(wdg);
        wdg_cb_container_set(wdg, cc_new);
     }
   else
     {
        /* When changing existing callback need to copy old one, in order to have the same old Dep_Id. */
        new_cb = cb_copy(cb_old);
        cb_modify(new_cb, cb_type_get(new_cb), new_seq_id);
        memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_CALLBACK, cb_old, new_cb);
        Dep_Data *dep_data = gui_context_dep_data_get(cb_dep_id_get(new_cb));
        dep_data_cb_set(dep_data, new_cb);
     }
   gui_context_memento_add(ctx, memento);
   Egui_Layout_Widgets *g = egui_layout_gui_get();
   elm_object_item_disabled_set(g->main_win->toolbar_redo_it, EINA_TRUE);
   elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE);

   propview_build(it_data->wdg);
   _select_callback_item(cb_dep_id_get(new_cb));

   return EO_CALLBACK_CONTINUE;
}

static Eina_Bool
_callback_item_content_get(It_Data *it_data)
{
   Eo *box = it_data->box;
   Gui_Widget_Callback *cb = it_data->cb;

   Eo *label = props_label_add(box, cb_type_get(cb));
   eo_do(label, evas_obj_size_hint_align_set(0, 0.5));
   eo_do(label, evas_obj_size_hint_weight_set(1, 0));

   Dep_Id *dep_id = cb_sequence_id_get(cb);
   const char *default_str = NULL;
   if (dep_id)

   default_str = dep_name_get(dep_id);
   Eo *seqs_list = props_hoversel_seqs_add(box, elm_widget_top_get(propview_table), wdg_context_get(it_data->wdg), default_str, EINA_FALSE);

   eo_do(seqs_list, evas_obj_size_hint_align_set(1, 0));
   eo_do(seqs_list, evas_obj_size_hint_weight_set(1, 0));
   eo_do(seqs_list, eo_event_callback_add(EVAS_SELECTABLE_INTERFACE_EVENT_SELECTED,
                                          _cb_sequence_modify, it_data));

   /* Add callbacks from resources. */
   Eina_List *res_lst = (Eina_List *) gui_context_resource_list_get(wdg_context_get(it_data->wdg), RESOURCE_EO_CALLBACK);
   Eina_List *itr;
   Dep_Id *res_id;
   EINA_LIST_FOREACH(res_lst, itr, res_id)
     {
        const Gui_Resource *res = gui_context_resource_get(res_id);
        if (res) elm_hoversel_item_add(seqs_list, resource_name_get(res), NULL, ELM_ICON_NONE, NULL, NULL);
     }

   return EINA_TRUE;
}

static void
_callback_item_box_reassign(It_Data *it_data, Eo *box)
{
   Dep_Id *res_id, *seq_id;
   const Eina_List *itr, *list;

   it_data->box = box;
   const Gui_Context *ctx = wdg_context_get(it_data->wdg);

   Eina_List *contents = elm_box_children_get(box);

   Eo *label = eina_list_nth(contents, 0);
   Eo *seqs_list = eina_list_nth(contents, 1);

   eo_do(label, elm_obj_widget_part_text_set(NULL, cb_type_get(it_data->cb)));

   eo_do(seqs_list, eo_event_callback_add(EVAS_SELECTABLE_INTERFACE_EVENT_SELECTED,
                                          _cb_sequence_modify, it_data));

   eo_do(seqs_list, elm_obj_hoversel_clear());

   list = gui_context_seq_list_get(ctx);
   EINA_LIST_FOREACH(list, itr, seq_id)
     {
        Gui_Sequence *seq = sequence_get(seq_id);
        if (seq) eo_do(seqs_list, elm_obj_hoversel_item_add(sequence_name_get(seq), NULL, ELM_ICON_NONE, NULL, NULL));
     }

   list = gui_context_resource_list_get(ctx, RESOURCE_EO_CALLBACK);
   EINA_LIST_FOREACH(list, itr, res_id)
     {
        const Gui_Resource *res = gui_context_resource_get(res_id);
        if (res) eo_do(seqs_list, elm_obj_hoversel_item_add(resource_name_get(res), NULL, ELM_ICON_NONE, NULL, NULL));
     }

   Dep_Id *seqid = cb_sequence_id_get(it_data->cb);
   const char *txt = (seqid) ? dep_name_get(seqid) : PROP_HOVERSEL_NONE_VALUE;

   eo_do(seqs_list, elm_obj_widget_part_text_set(NULL, txt));

   eina_list_free(contents);
}

static Eina_Bool
_wdg_public_change_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Eina_Bool state;
   eo_do(obj, state = elm_obj_check_state_get());
   wdg_public_set(data, state);

   return EO_CALLBACK_CONTINUE;
}

static Eina_Bool
_wdg_name_change_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Gui_Widget *wdg = data;
   const char *str = NULL;
   eo_do(obj, str = elm_obj_widget_part_text_get(NULL));
   widget_name_change(wdg, str);

   return EO_CALLBACK_CONTINUE;
}

// Updates property visual box according to the specified propertiy.
// if it_data is given, also reassigns it to all of the fields
static void
_prop_field_update(const Gui_Widget_Property *prop, Eo *item_box, It_Data *it_data)
{
   Eina_List *box_list, *box_list_itr, *par_list, *l;
   Gui_Value *val;
   int i = 0;

   /* Need to free box_list in the end*/
   eo_do(item_box, box_list = elm_obj_box_children_get());
   box_list_itr = box_list;
   par_list = prop_value_get(prop);

   EINA_LIST_FOREACH(par_list, l, val)
     {
        Eo *o = NULL;
        Par_Field_Data *pfd = NULL;

        // Only fields that have a Par_Field_Data attached to them interest us.
        // Iterate over the next elements of the box until such element is found
        // and reassign it_data to it if needed.
        while (box_list_itr)
          {
             o = eina_list_data_get(box_list_itr);
             eo_do(o, pfd = (Par_Field_Data *) eo_key_data_get(_STR_EDITOR));
             box_list_itr = eina_list_next(box_list_itr);
             if (pfd)
               {
                  if (it_data) pfd->it_data = it_data;
                  break;
               }
          }

        if (!(box_list_itr || pfd)) break;

        Gui_Type t = gui_value_type_get(val);

        /* Create edit field for each parameter. */
        switch (t)
          {
           case GUI_TYPE_SINT:
                {
                   char str[15];
                   int int_v = INT_GET(prop_value_nth_get(prop, i));
                   sprintf(str, "%d", int_v);
                   /* Add this callback in order to avoid _prop_update_from_propview cb to be called. */
                   elm_entry_entry_set(o, str);
                   break;
                }
           case GUI_TYPE_STRING:
                {
                   char *str = STRING_GET(prop_value_nth_get(prop, i));
                   elm_entry_entry_set(o, str);
                   break;
                }
           case GUI_TYPE_FILE:
                {
                   eo_do(o, elm_obj_hoversel_clear());
                   props_hoversel_resource_files_add(NULL, o, NULL, NULL, wdg_context_get(it_data->wdg));

                   Dep_Id *dep_id = DEP_ID_GET(prop_value_nth_get(prop, i));
                   const char *default_str = PROP_HOVERSEL_NONE_VALUE;
                   if (dep_id)
                     default_str = dep_name_get(dep_id);
                   eo_do(o, elm_obj_widget_part_text_set(NULL, default_str));
                   break;
                }
           case GUI_TYPE_OBJECT:
                {
                   eo_do(o, elm_obj_hoversel_clear());
                   props_hoversel_objects_add(NULL, o, NULL, NULL, gui_context_wdg_list_get(wdg_context_get(it_data->wdg)), it_data->wdg);
                   Dep_Id *dep_id = DEP_ID_GET(prop_value_nth_get(prop, i));
                   const char *default_str = PROP_HOVERSEL_NONE_VALUE;
                   if (dep_id)
                     default_str = dep_name_get(dep_id);
                   eo_do(o, elm_obj_widget_part_text_set(NULL, default_str));
                   break;
                }
           case GUI_TYPE_DOUBLE:
                {
                   char str[30];
                   double d = DOUBLE_GET(prop_value_nth_get(prop, i));
                   sprintf(str, "%f", d);
                   elm_entry_entry_set(o, str);
                   break;
                }
           case GUI_TYPE_BOOL:
                {
                   Eina_Bool state = BOOL_GET(prop_value_nth_get(prop, i));
                   elm_check_state_set(o, state);
                   break;
                }
           case GUI_TYPE_ENUM:
                {
                   char *default_str = STRING_GET(prop_value_nth_get(prop, i));
                   elm_object_text_set(o, default_str);
                   break;
                }
           default:
              ERR("switch default for type: %s of property %s", db_gui_type_name_get(t), prop_name_get(prop));
          }
        i++; /*Because first item in box list is label*/
     }
   eina_list_free(box_list);
}

static Eina_Bool
_description_item_content_get(It_Data *it_data)
{
   Eo *box = it_data->box;
   Eo *label = eo_add(ELM_LABEL_CLASS, box);
   eo_do(label, evas_obj_visibility_set(EINA_TRUE),
                elm_obj_widget_part_text_set(NULL, it_data->desc));
   eo_do(box, elm_obj_box_pack_end(label));

   if (!strcmp(it_data->desc, DB_DEF_PUBLIC))
     {
        Eo *ck = props_check_add(box, wdg_public_get(it_data->wdg));
        eo_do (ck, eo_event_callback_add(ELM_ENTRY_EVENT_CHANGED, _wdg_public_change_cb, it_data->wdg));
     }
   else if (!strcmp(it_data->desc, DB_DEF_NAME))
     {
        Eo *entry = props_entry_add(box, wdg_name_get(it_data->wdg), GUI_TYPE_STRING);
        eo_do (entry, eo_event_callback_add(ELM_ENTRY_EVENT_ACTIVATED, _wdg_name_change_cb, it_data->wdg));
     }
   else if (!strcmp(it_data->desc, DB_DEF_CLASS))
     {
        Eo *entry = props_entry_add(box, wdg_class_name_get(it_data->wdg), GUI_TYPE_STRING);
        elm_object_disabled_set(entry, EINA_TRUE);
     }
   return EINA_TRUE;
}

/* Content set for property view.
 * Used to show properties and actions
 */
static Evas_Object *
_item_content_get(It_Data *it_data)
{
   Eo *box = NULL;

   box = eo_add(ELM_BOX_CLASS, propview_table);
   eo_do(box, evas_obj_visibility_set(EINA_TRUE),
         elm_obj_box_horizontal_set(EINA_TRUE),
         elm_obj_box_padding_set(5, 0),
         evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, 0),
         evas_obj_size_hint_align_set(EVAS_HINT_FILL, 0)
//         evas_obj_size_hint_min_set(32 * elm_config_scale_get(),
//                                    18 * elm_config_scale_get())
        );

   it_data->box = box;
   switch (it_data->type)
     {
      case PROPERTY_TYPE:
         _property_item_content_get(it_data);
         break;
      case CALLBACK_TYPE:
         _callback_item_content_get(it_data);
         break;
      case DESCRIPTION_TYPE:
         _description_item_content_get(it_data);
         break;
         /* Currently ITEM_TYPE cannot appear here.
          * This case is only to shut compiler up. */
      case ITEM_TYPE:
      case CONTENT_TYPE:
         _content_item_content_get(it_data);
         break;
     }

   return box;
}

PropViewCbs *propview_cbs_get()
{
   if (!_view_cbs) _view_cbs = calloc(1, sizeof(*_view_cbs));
   return _view_cbs;
}

static const char*
_filter_string_get()
{
   Egui_Layout_Widgets *g = egui_layout_gui_get();
   const char *str = elm_entry_entry_get(g->main_win->propsview_filter_entry);
   //Trim from left
   while (*str == ' ') str++;

   return strlen(str) ? str : NULL;
}

// Case insensitive test for a prefix in a string
static Eina_Bool
_str_nocase_prefix(const char *str, const char *prefix)
{
   if (!(str && prefix)) return EINA_FALSE;

   while (*prefix)
     {
        if ((*str == '\0') ||
            (tolower(*prefix) != tolower(*str)))
          return EINA_FALSE;
        prefix++;
        str++;
     }
   return EINA_TRUE;
}

static char *
_class_item_label_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
{
   Classname_Data *cl = data;
   return strdup(cl->classname);
}

static char *
_notfound_item_text_get(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
{
   return strdup("No search results");
}

static Evas_Object *
_prop_item_content_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
{
   It_Data *it_data = data;

   if (it_data->box) return it_data->box;

   const char *fullname = db_op_desc_op_name_full_get(it_data->op_desc);

   if (!it_data->prop)
     {
        it_data->prop = prop_create_for_op(it_data->op_desc);
        const Gui_Context *ctx = _active_context_get();
        Gui_Session *session = (Gui_Session *) gui_context_editor_session_get(ctx);
        manager_widget_property_get(session, it_data->wdg, it_data->prop);
     }

   Evas_Object * it_box = _mempool_cache_data_get(fullname);

   if (!it_box)
     {
        it_box = _item_content_get(it_data);

        Eo *prop_menu_button = props_button_add(it_box, NULL);
        eo_do(prop_menu_button, evas_obj_size_hint_align_set(1, 0));
        eo_do(prop_menu_button, evas_obj_size_hint_weight_set(0.01, 0));
        eo_do(prop_menu_button, eo_key_data_set(_STR_EDITOR, it_data, NULL));
        eo_do(prop_menu_button, eo_event_callback_add(EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _view_cbs->property_ctx_menu_cb_func, NULL));

        Eo *ic = eo_add(ELM_ICON_CLASS, it_box);
        eo_do(ic, efl_file_set(PACKAGE_DATA_DIR"/images/icon_prop_menu2.png", NULL));
        eo_do(prop_menu_button, elm_obj_container_content_set("icon", ic));

        eo_ref(it_box);
     }
   else
     {
        Eina_List *last = eina_list_last(eo_do(it_box, elm_obj_box_children_get()));
        Eo *prop_menu_button  = eina_list_data_get(last);
        eo_do(prop_menu_button, eo_key_data_set(_STR_EDITOR, it_data, NULL));

        it_data->box = it_box;
        _prop_field_update(it_data->prop, it_box, it_data);
     }

   if (!prop_wdg_get(it_data->prop))
     eo_do(it_box, evas_obj_color_set(150, 150, 150, 255));
   else
     eo_do(it_box, evas_obj_color_set(255, 255, 255, 255));

   return it_box;
}

static void
_class_item_del(void *data, Evas_Object *obj EINA_UNUSED)
{
   Classname_Data *cl = data;
   free(cl->classname);
   free(cl);
}

static void
_prop_item_del(void *data, Evas_Object *obj EINA_UNUSED)
{
   It_Data *it_data = data;
   const char *fullname = db_op_desc_op_name_full_get(it_data->op_desc);

   eina_hash_del(op_item_table, NULL, it_data);
   _mempool_cache_data_put(fullname, it_data->box);
   _it_data_free(it_data);
}

static void
_expand_request_cb(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *event_info)
{
   Elm_Object_Item *glit = event_info;
   Classname_Data *cl = elm_object_item_data_get(glit);
   eina_hash_set(expanded_classes, cl->classname, (void *)1);
   elm_genlist_item_expanded_set(glit, EINA_TRUE);
}

static void
_contract_request_cb(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *event_info)
{
   Elm_Object_Item *glit = event_info;
   Classname_Data *cl = elm_object_item_data_get(glit);
   eina_hash_del_by_key(expanded_classes, cl->classname);
   elm_genlist_item_expanded_set(glit, EINA_FALSE);
}

// Expand a specific class name for its properties children.
static void
_props_classname_table_expand(const Gui_Widget *wdg, const char *classname, Elm_Object_Item *parent)
{
   Eina_List *l1 = NULL;
   Eina_List *l2 = NULL;
   Op_Desc *op;

   const char *filter = _filter_string_get();

   /* iterate over each operation of class. */
   Eina_List *llst = db_class_op_desc_list_get(classname);

   EINA_LIST_FOREACH(llst, l1, op)
     {
        Gui_Widget_Property *prop;
        It_Data *it_data;

        if (db_op_desc_is_container(op)) continue;

        const char *op_display_name = db_op_desc_prop_display_name_get(op);

        // If filter is on and no match, dont add to property list
        if (filter && !_str_nocase_prefix(op_display_name, filter))
          continue;

        Eina_List *pitems = NULL;
        Eina_List *wdg_prop_lst = wdg_prop_list_get(wdg);

        // Find which class properties are in widget. Can be more than one.
        EINA_LIST_FOREACH(wdg_prop_lst, l2, prop)
          if (prop_op_desc_get(prop) == op) pitems = eina_list_append(pitems, prop);

        // If none found, its a default one
        if (!eina_list_count(pitems)) pitems = eina_list_append(pitems, NULL);

        EINA_LIST_FREE(pitems, prop)
          {
             it_data = IT_DATA_BUILD(PROPERTY_TYPE, wdg);
             it_data->op_desc = op;
             it_data->prop = prop;
             elm_genlist_item_append(prop_list, _itc_prop, it_data, parent,
                                      ELM_GENLIST_ITEM_NONE, NULL, NULL);
             /* map current item with its prop name. */
             eina_hash_add(op_item_table, db_op_desc_op_name_full_get(op), it_data);
          }
     }
}

static void
_props_expanded_cb(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *event_info)
{
   Elm_Object_Item *glit = event_info;
   Classname_Data *cl = elm_object_item_data_get(glit);
   _props_classname_table_expand(cl->wdg, cl->classname, glit);
}

static void
_props_contracted_cb(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *event_info)
{
   Elm_Object_Item *glit = event_info;
   elm_genlist_item_subitems_clear(glit);
}

static void
_properties_build(const Gui_Widget *wdg)
{
   op_item_table = eina_hash_string_superfast_new(NULL);
   Eina_List *kl_list = NULL;

   if (wdg)
     {
        /* FIXME: this will be fixed, when Eolian will be used for MRO.
         * Eo will not be needed for MRO. */
        const Gui_Session *session = gui_context_editor_session_get(_active_context_get());
        kl_list = eo_class_mro_get(eo_class_name_get(session_eo_get(session, wdg)));
     }
   const char *kl;

   const char *filter = _filter_string_get();

   EINA_LIST_FREE(kl_list, kl)
     {
        Op_Desc *op;
        Eina_List *llst = db_class_op_desc_list_get(kl);
        Eina_List *l = NULL;

        EINA_LIST_FOREACH(llst, l, op)
          {
             // We dont show container properties. So class with at least one non-container
             // property is good to show.
             if (!db_op_desc_is_container(op))
               {
                  if (filter)
                    {
                       _props_classname_table_expand(wdg, kl, NULL);
                    }
                  else
                    {
                       Classname_Data *cldata = calloc(1, sizeof(Classname_Data));
                       cldata->classname = strdup(kl);
                       cldata->wdg = wdg;

                       Elm_Object_Item *glit = elm_genlist_item_append(prop_list, _itc_class,
                                                                       cldata, NULL,
                                                                       ELM_GENLIST_ITEM_TREE,
                                                                       NULL, NULL);
                       if (eina_hash_find(expanded_classes, kl))
                          elm_genlist_item_expanded_set(glit, EINA_TRUE);
                    }
                  break;
               }
          }
     }

     //if filter search found nothing, yield an appropriate message to properties list
     if (filter)
       {
          if (!elm_genlist_items_count(prop_list))
              elm_genlist_item_append(prop_list, _itc_notfound, NULL, NULL,
                                      ELM_GENLIST_ITEM_NONE, NULL, NULL);
       }
     // Automatically expand the class
     else
       {
          Elm_Object_Item *glit = elm_genlist_first_item_get(prop_list);
          if (glit) elm_genlist_item_expanded_set(glit, EINA_TRUE);
       }
}

static void
_content_build(const Gui_Widget *wdg)
{
   Eina_List *ctn_items = NULL;
   Eina_List *l;
   int i = 0;
   Object_Container_Item *ci;
   It_Data *it_data;

   const char *wdg_name = wdg_obj_container_class_name_get(wdg);
   Eina_Bool isbox = (wdg_name &&
                      (!strcmp(wdg_name, DB_DEF_BOX_CLASS) ||
                       !strcmp(wdg_name, DB_DEF_WIN_CLASS)));

   Egui_Layout_Widgets *g = egui_layout_gui_get();
   elm_object_disabled_set(g->main_win->contentview_down_btn, !isbox);
   elm_object_disabled_set(g->main_win->contentview_up_btn, !isbox);

   Eina_List *items_lst = wdg_obj_container_contents_list_get(wdg);

   EINA_LIST_FOREACH(items_lst, l, ci)
     {
        Dep_Id *item_id = obj_container_item_dep_id_get(ci);
        if (item_id && !wdg_get(item_id)) continue;

        Gui_Widget_Property *prop = obj_container_item_prop_get(ci);
        it_data = IT_DATA_BUILD(CONTENT_TYPE, wdg);
        it_data->idx = i;
        it_data->prop = prop;
        it_data->op_desc = (Op_Desc *) prop_op_desc_get(prop);
        i++;

        ctn_items = eina_list_append(ctn_items, it_data);
     }

   /*  Add empty fields. */
   const char *wdg_class_name = wdg_class_name_get(wdg);
   const char *name;
   /* Add empty field for each type of container. */
   EINA_LIST_FOREACH(db_class_inherit_containers_list_get(wdg_class_name), l, name)
     {
        const Op_Desc *op_desc = db_container_desc_op_desc_get(db_container_desc_get(name), CONTAINER_PACK);
        it_data = IT_DATA_BUILD(CONTENT_TYPE, wdg);
        it_data->idx = i;
        it_data->op_desc = op_desc;
        it_data->prop = NULL;

        ctn_items = eina_list_append(ctn_items, it_data);
     }

   EINA_LIST_FREE(ctn_items, it_data)
     elm_genlist_item_append(ctn_list, _itc_ctn, it_data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
}

static void
_content_select_item(const Gui_Widget_Property *prop)
{
    Elm_Object_Item *it = elm_genlist_first_item_get(ctn_list);
    for (; it; it = elm_genlist_item_next_get(it))
      {
         It_Data *it_data = elm_object_item_data_get(it);
         if (it_data->prop == prop)
           {
              elm_genlist_item_selected_set(it, EINA_TRUE);
              break;
           }
      }
}

Eina_Bool
_contentview_del_btn_clicked(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc, void *event_info)
{
   const Gui_Widget_Property *prev_prop = NULL;

   Elm_Object_Item *glit = elm_genlist_selected_item_get(ctn_list);
   if (!glit) return EO_CALLBACK_CONTINUE;

   It_Data *it_data = elm_object_item_data_get(glit);
   intptr_t idx = (intptr_t) it_data->idx;

   it_data = elm_object_item_data_get(elm_genlist_item_next_get(glit));
   if (it_data) prev_prop = it_data->prop;
   if (!prev_prop)
     {
        it_data = elm_object_item_data_get(elm_genlist_item_prev_get(glit));
        if (it_data) prev_prop = it_data->prop;
     }

   Eina_Bool ret = _view_cbs->content_delete_cb_func((void *)idx, obj, desc, event_info);
   if (prev_prop) _content_select_item(prev_prop);

   return ret;
}

Eina_Bool
_contentview_up_btn_clicked(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc, void *event_info EINA_UNUSED)
{
   Elm_Object_Item *glit = elm_genlist_selected_item_get(ctn_list);
   if (!glit) return EO_CALLBACK_CONTINUE;

   It_Data *it_data = elm_object_item_data_get(glit);
   const Gui_Widget_Property *prev_prop = it_data->prop;
   intptr_t idx = it_data->idx;

   Eina_Bool ret = _view_cbs->content_reorder_cb_func((void *)idx, obj, desc, (void *)(intptr_t)UP);
   _content_select_item(prev_prop);

   return ret;
}

Eina_Bool
_contentview_down_btn_clicked(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc, void *event_info EINA_UNUSED)
{
    Elm_Object_Item *glit = elm_genlist_selected_item_get(ctn_list);
   if (!glit) return EO_CALLBACK_CONTINUE;

   It_Data *it_data = elm_object_item_data_get(glit);
   const Gui_Widget_Property *prev_prop = it_data->prop;
   intptr_t idx = it_data->idx;

   Eina_Bool ret = _view_cbs->content_reorder_cb_func((void *)idx, obj, desc, (void *)(intptr_t)DOWN);
   _content_select_item(prev_prop);

   return ret;
}

/* This function now is called for meny only */
static void
_item_build(const Gui_Widget *wdg)
{
   itemview_build(wdg);
}

static void
_desc_item_del(void *data, Evas_Object *obj EINA_UNUSED)
{
   It_Data *it_data = data;
   _it_data_free(it_data);
}

static Evas_Object *
_desc_item_content_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
{
   return _item_content_get(data);
}

static void
_contents_item_del(void *data, Evas_Object *obj EINA_UNUSED)
{
   It_Data *it_data = data;

   if (it_data->prop)
     {
        const char *fullname = db_op_desc_op_name_full_get(it_data->op_desc);
        _mempool_cache_data_put(fullname, it_data->box);
     }

   _it_data_free(it_data);
}

static Evas_Object *
_contents_item_content_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
{
   It_Data *it_data = data;

   if (!it_data->prop) return _item_content_get(it_data);

   if (it_data->box) return it_data->box;

   const char *fullname = db_op_desc_op_name_full_get(it_data->op_desc);

   Evas_Object * it_box = _mempool_cache_data_get(fullname);

   if (!it_box)
     {
        it_box = _item_content_get(it_data);
        eo_ref(it_box);
     }
   else
     {
        it_data->box = it_box;
        _prop_field_update(it_data->prop, it_box, it_data);
     }

   return it_box;
}

// Used to loop in _description_build function
static char *descs[] = { DB_DEF_NAME, DB_DEF_CLASS, DB_DEF_PUBLIC, NULL };

static void
_description_build(const Gui_Widget *wdg)
{
   int i;
   for (i = 0; descs[i]; i++)
     {
        It_Data *it_data = IT_DATA_BUILD(DESCRIPTION_TYPE, wdg);
        it_data->desc = descs[i];
        elm_genlist_item_append(desc_list, _itc_desc, it_data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
     }
}

static void
_callbacks_classname_table_expand(const Gui_Widget *wdg, const char *classname, Elm_Object_Item *parent)
{
   const Eolian_Class *class = eolian_class_get_by_name(classname);
   Eina_Iterator *events = eolian_class_events_get(class);
   Eolian_Event *event;

   const char *filter = _filter_string_get();

   EINA_ITERATOR_FOREACH(events, event)
     {
        const char *event_name = eolian_event_name_get(event);

        // If filter is on and no match, dont add to property list
        if (filter && !_str_nocase_prefix(event_name, filter))
          continue;

        Eina_List *wgdcbs = wdg_cb_list_get(wdg);
        Eina_List *items = NULL;
        Eina_List *l = NULL;
        Gui_Widget_Callback *cb;

        Dep_Id *dep_id;
        EINA_LIST_FOREACH(wgdcbs, l, dep_id)
          {
             cb = cb_get(dep_id);
             if (!strcmp(event_name, cb_type_get(cb)))
               items = eina_list_append(items, cb);
          }

        cb = cb_new(event_name, 0);
        items = eina_list_append(items, cb);

        EINA_LIST_FOREACH(items, l, cb)
          {
             It_Data *it_data = IT_DATA_BUILD(CALLBACK_TYPE, wdg);
             cb_ref(cb);
             it_data->cb = cb;
             elm_genlist_item_append(cb_list, _itc_cb, it_data, parent,
                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
          }
        eina_list_free(items);
     }
   eina_iterator_free(events);
}

static void
_callbacks_expanded_cb(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *event_info)
{
   Elm_Object_Item *glit = event_info;
   Classname_Data *cl = elm_object_item_data_get(glit);
   eina_hash_set(expanded_classes, cl->classname, (void *)1);
   _callbacks_classname_table_expand(cl->wdg, cl->classname, glit);
}

static void
_callbacks_contracted_cb(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *event_info)
{
   Elm_Object_Item *glit = event_info;
   Classname_Data *cl = elm_object_item_data_get(glit);
   eina_hash_del_by_key(expanded_classes, cl->classname);
   elm_genlist_item_subitems_clear(glit);
}

static void
_callbacks_item_del(void *data, Evas_Object *obj EINA_UNUSED)
{
   It_Data *it_data = data;
   cb_unref(it_data->cb);

   // Make box cache ready. Remove the callback event.
   Eina_List *contents = elm_box_children_get(it_data->box);
   Eo *hoversel = eina_list_nth(contents, 1);
   eo_do(hoversel, eo_event_callback_del(EVAS_SELECTABLE_INTERFACE_EVENT_SELECTED,
                                         _cb_sequence_modify, it_data));
   eina_list_free(contents);

   _mempool_cache_data_put(CACHE_CALLBACKS, it_data->box);
   _it_data_free(it_data);
}

static Evas_Object *
_callbacks_item_content_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
{
   It_Data *it_data = data;

   // Genlist can call content get without calling delete first
   // so in that case just return what it already has.
   if (it_data->box) return it_data->box;

   Dep_Id *dep_id = cb_sequence_id_get(it_data->cb);

   Eo *it_box = _mempool_cache_data_get(CACHE_CALLBACKS);

   if (it_box)
     {
        _callback_item_box_reassign(it_data, it_box);
     }
   else
     {
        it_box = _item_content_get(it_data);
        eo_ref(it_box);
     }

   if (dep_id)
     eo_do(it_box, evas_obj_color_set(255, 255, 255, 255));
   else
     eo_do(it_box, evas_obj_color_set(150, 150, 150, 255));

   return it_box;
}

static void
_callbacks_build(const Gui_Widget *wdg)
{
   Eina_List *classes = eo_class_mro_get(wdg_class_name_get(wdg));
   const char *classname;
   Elm_Object_Item *glit = NULL;

   const char *filter = _filter_string_get();

   EINA_LIST_FREE(classes, classname)
     {
        const Eolian_Class *class = eolian_class_get_by_name(classname);
        Eina_Iterator *events = eolian_class_events_get(class);
        if (events)
          {
             if (filter)
               {
                  _callbacks_classname_table_expand(wdg, classname, NULL);
               }
             else
               {
                  Classname_Data *cl = calloc(1, sizeof(Classname_Data));
                  cl->classname = strdup(classname);
                  cl->wdg = wdg;
                  glit = elm_genlist_item_append(cb_list, _itc_class, cl,
                                                 NULL, ELM_GENLIST_ITEM_TREE, NULL,
                                                 NULL);
                  if (eina_hash_find(expanded_classes, classname))
                    elm_genlist_item_expanded_set(glit, EINA_TRUE);
               }
          }
        eina_iterator_free(events);
     }
   //if filter search found nothing, yield an appropriate message to callbacks list
   if (filter && !elm_genlist_items_count(cb_list))
     elm_genlist_item_append(cb_list, _itc_notfound, NULL, NULL,
                             ELM_GENLIST_ITEM_NONE, NULL, NULL);
}

/* This callback is called in the end of propview_build()
 * in order to switch between scrollbox for properties
 * and genlist for items. */
static void
_propview_build_post_cb(const Gui_Widget *wdg, It_Data_Type new_type)
{
   Egui_Layout_Widgets *g = egui_layout_gui_get();
   /* Unsetting view according to old selected toolbar's item. */
   switch (_propsview_toolbar_selected_item_type)
     {
      case DESCRIPTION_TYPE:
           {
              break;
           }
      case PROPERTY_TYPE:
           {
              break;
           }
      case CALLBACK_TYPE:
           {
              break;
           }
      case CONTENT_TYPE:
           {
              break;
           }
      case ITEM_TYPE:
           {
              eo_do(g->main_win->contentview_box, evas_obj_visibility_set(EINA_TRUE));
              eo_do(g->main_win->itemview_box, evas_obj_visibility_set(EINA_FALSE));
              break;
           }
     }

   _propsview_toolbar_selected_item_type = new_type;

   /* Setting view according to new selected toolbar's item. */
   eo_do(g->main_win->contentview_box, evas_obj_visibility_set(EINA_FALSE));
   eo_do(g->main_win->properties_list, evas_obj_visibility_set(EINA_FALSE));
   eo_do(g->main_win->itemview_box, evas_obj_visibility_set(EINA_FALSE));
   eo_do(g->main_win->callbacksview_box, evas_obj_visibility_set(EINA_FALSE));
   eo_do(g->main_win->description_list, evas_obj_visibility_set(EINA_FALSE));

   switch (new_type)
     {
      case DESCRIPTION_TYPE:
           {
              eo_do(g->main_win->description_list, evas_obj_visibility_set(EINA_TRUE));
              break;
           }
      case PROPERTY_TYPE:
           {
              eo_do(g->main_win->properties_list, evas_obj_visibility_set(EINA_TRUE));
              break;
           }
      case CALLBACK_TYPE:
           {
              eo_do(g->main_win->callbacksview_box, evas_obj_visibility_set(EINA_TRUE));
              break;
           }
      case CONTENT_TYPE:
           {
              eo_do(g->main_win->contentview_box, evas_obj_visibility_set(EINA_TRUE));
              break;
           }
      case ITEM_TYPE:
           {
              eo_do(g->main_win->contentview_box, evas_obj_visibility_set(EINA_FALSE));
              eo_do(g->main_win->itemview_box, evas_obj_visibility_set(EINA_TRUE));

              if (wdg_is_container(wdg, DB_DEF_MENU_CLASS))
                {
                   eo_do(g->main_win->itemview_add_item_nested_but, elm_obj_widget_disabled_set(EINA_FALSE));
                   eo_do(g->main_win->itemview_add_separator_but, elm_obj_widget_disabled_set(EINA_FALSE));
                }
              else if (wdg_is_container(wdg, DB_DEF_DISKSELECTOR_CLASS) ||
                       wdg_is_container(wdg, DB_DEF_CTXPOPUP_CLASS) ||
                       wdg_is_container(wdg, DB_DEF_TOOLBAR_CLASS))
                {
                   eo_do(g->main_win->itemview_add_item_nested_but, elm_obj_widget_disabled_set(EINA_TRUE));
                   eo_do(g->main_win->itemview_add_separator_but, elm_obj_widget_disabled_set(EINA_TRUE));
                }
              break;
           }
     }
}

/* Build property view for current widget.
 * Show propeties, which defined in class hyerarchy
 * for current widget's class. And fill fields, if property
 * is defined for current widget.(or put default values into fields.)
 * Called, when item in objtree is selected. */
void
propview_build(const Gui_Widget *wdg)
{
   It_Data_Type type = _new_type;

   eo_do(cb_list, elm_obj_genlist_clear());
   eo_do(desc_list, elm_obj_genlist_clear());
   eo_do(prop_list, elm_obj_genlist_clear());
   eo_do(ctn_list, elm_obj_genlist_clear());

   if (op_item_table)
     {
        eina_hash_free(op_item_table);
        op_item_table = NULL;
     }

   if (!wdg) return;

   /* type ITEM_TYPE not assigned to any toolbar's item.
    * It's assigned when toolbar's item is CONTENT and widget is menu.
    * So if current type is ITEM_TYPEm we need to assign it to CONTENT_TYPE,
    * and it will be resolved according to widget's type. */
   if (type == ITEM_TYPE) type = CONTENT_TYPE;

   if ((type == CONTENT_TYPE) &&
      (wdg_is_container(wdg, DB_DEF_MENU_CLASS) ||
       wdg_is_container(wdg, DB_DEF_DISKSELECTOR_CLASS) ||
       wdg_is_container(wdg, DB_DEF_CTXPOPUP_CLASS) ||
       wdg_is_container(wdg, DB_DEF_TOOLBAR_CLASS)))
     {
        type = ITEM_TYPE;
     }

   switch(type)
     {
      case DESCRIPTION_TYPE:
           {
              _description_build(wdg);
              break;
           }
      case PROPERTY_TYPE:
           {
              _properties_build(wdg);
              break;
           }
      case CALLBACK_TYPE:
           {
              _callbacks_build(wdg);
              break;
           }
      case CONTENT_TYPE:
           {
              _content_build(wdg);
              break;
           }
      case ITEM_TYPE:
           {
              itemview_clear();
              _item_build(wdg);
              break;
           }
      default:
         ERR("switch default");
     }
   _propview_build_post_cb(wdg, type);
}

/* API to select property in genlist.
 * Op_Desc is used to be able to select empty property. */
void
propview_item_selected_set(const Op_Desc *op_desc)
{
   if (!op_desc) return;
   Elm_Object_Item *it = elm_genlist_first_item_get(prop_list);
   for (; it; it = elm_genlist_item_next_get(it))
     {
        if (elm_genlist_item_item_class_get(it) != _itc_prop)
          continue;

        It_Data *it_data = elm_object_item_data_get(it);
        if (prop_op_desc_get(it_data->prop) == op_desc)
          {
             elm_genlist_item_selected_set(it, EINA_TRUE);
             elm_genlist_item_bring_in(it, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
             break;
          }
     }
}

void
propview_item_update(const Gui_Widget_Property *prop)
{
   const char *prop_name;
   Eo *item_box;
   It_Data *it_data = NULL;

   if (!prop) return;
   prop_name = prop_full_name_get(prop);
   /* get item_data from hash. */
   it_data = eina_hash_find(op_item_table, prop_name);
   /* if item of genlist is not visible, box will be NULL, so don't need to update prop.*/
   if (!it_data) return;
   /* Get the item box from item data */
   item_box = it_data->box;
   /* if item box is not realized or any other reason please return.*/
   if (!item_box) return;
   /* If property assigned to widget, make this box white. */
   if (prop_wdg_get(prop))
     eo_do(item_box, evas_obj_color_set(255, 255, 255, 255));

   /* When Undo/Redo only one item is updated.
    * So if this item is doing to be changed from default, this prop must be deleted*/
   if ((it_data->prop) && (!prop_wdg_get(it_data->prop)))
     {
        prop_ref((Gui_Widget_Property *) it_data->prop);
        prop_unref((Gui_Widget_Property *) it_data->prop);
     }

   it_data->prop = prop;

   // Update the fields of the box with properties
   _prop_field_update(prop, item_box, it_data);
}

/* FIXME: need to change signature to Eo_Callback, when it will be supported.
 * This callback is used in Egui Layout JSON. */
void
_propsview_toolbar_clicked(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
//(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
{
   Elm_Object_Item *it = event_info;
   elm_toolbar_item_selected_set(it, EINA_TRUE);
   const Gui_Context *ctx = _active_context_get();
   if (!ctx) return;
   const Gui_Widget *wdg  = gui_context_data_get(ctx, SELECTED_WDG);
   _new_type = (int) (intptr_t) elm_object_item_data_get(it);
   propview_build(wdg);
}

/* API to switch propsview Description->Properties->Callbacks->Contents */
void
propsview_view_switch(It_Data_Type type)
{
   Elm_Object_Item *it;
   Egui_Layout_Widgets *g = egui_layout_gui_get();
   switch (type)
     {
      case PROPERTY_TYPE:
           {
              it = g->main_win->propsview_toolbar_prop_it;
              break;
           }
      case CALLBACK_TYPE:
           {
              it = g->main_win->propsview_toolbar_cb_it;
              break;
           }
      case DESCRIPTION_TYPE:
           {
              it = g->main_win->propsview_toolbar_desc_it;
              break;
           }
         /* Currently ITEM_TYPE cannot appear here.
          * This case is only to shut compiler up. */
      case ITEM_TYPE:
      case CONTENT_TYPE:
           {
              it = g->main_win->propsview_toolbar_cont_it;
              break;
           }
     }
   _propsview_toolbar_clicked(NULL, NULL, it);
}

static Eina_Bool
_propview_filter_entry_changed_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                                  const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   const Gui_Context *ctx = _active_context_get();
   if (!ctx) return EO_CALLBACK_CONTINUE;
   const Gui_Widget *wdg  = gui_context_data_get(ctx, SELECTED_WDG);
   propview_build(wdg);

   return EO_CALLBACK_CONTINUE;
}

static void
_selected_callback_move(int dir)
{
   Elm_Object_Item *sel = elm_genlist_selected_item_get(cb_list);
   if ((sel) && (elm_genlist_item_item_class_get(sel) == _itc_cb))
     {
        It_Data *it_data = elm_object_item_data_get(sel);
        if (cb_sequence_id_get(it_data->cb))
          {
             Callback_Container *cc_new = NULL, *cc_old = NULL;
             Gui_Widget_Callback *cb = it_data->cb;
             const Gui_Widget *wdg = it_data->wdg;
             cc_old = (Callback_Container *) wdg_cb_container_get(wdg);
             cc_new = cb_container_copy(cc_old);
             if (cb_container_cb_move(cc_new, cb, dir))
               {
                  Gui_Memento *memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_CALLBACK_ADD_DEL, cc_old, cc_new);
                  gui_context_memento_add((Gui_Context *) wdg_context_get(wdg), memento);

                  wdg_cb_container_unset((Gui_Widget *) wdg);
                  wdg_cb_container_set((Gui_Widget *) wdg, cc_new);

                  Egui_Layout_Widgets *g = egui_layout_gui_get();
                  elm_object_item_disabled_set(g->main_win->toolbar_redo_it, EINA_TRUE);
                  elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE);

                  propview_build(wdg);
                  _select_callback_item(cb_dep_id_get(cb));
               }
             /* If nothing wasn't move, delete Callback_Container */
             else
               {
                  cb_container_ref(cc_new);
                  cb_container_unref(cc_new);
               }
          }
     }
}

Eina_Bool
_callbacksview_up_btn_clicked(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
  _selected_callback_move(-1);
  return EO_CALLBACK_CONTINUE;
}

Eina_Bool
_callbacksview_down_btn_clicked(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   _selected_callback_move(1);
   return EO_CALLBACK_CONTINUE;
}

Eina_Bool
_callbacksview_del_btn_clicked(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Elm_Object_Item *sel = elm_genlist_selected_item_get(cb_list);
   if ((sel) && (elm_genlist_item_item_class_get(sel) == _itc_cb))
     {
        It_Data *it_data = elm_object_item_data_get(sel);
        if (cb_sequence_id_get(it_data->cb))
          {
             const Gui_Widget *wdg = it_data->wdg;
             Callback_Container *cc_new = NULL, *cc_old = NULL;
             cc_old = (Callback_Container *) wdg_cb_container_get(wdg);
             cc_new = cb_container_copy(cc_old);

             cb_container_cb_remove(cc_new, it_data->cb);
             elm_object_item_del(sel);

             Gui_Memento *memento = gui_memento_new(wdg_dep_id_get(wdg), MEMENTO_CALLBACK_ADD_DEL, cc_old, cc_new);
             gui_context_memento_add((Gui_Context *) wdg_context_get(wdg), memento);

             wdg_cb_container_unset((Gui_Widget *) wdg);
             wdg_cb_container_set((Gui_Widget *) wdg, cc_new);

             Egui_Layout_Widgets *g = egui_layout_gui_get();
             elm_object_item_disabled_set(g->main_win->toolbar_redo_it, EINA_TRUE);
             elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE);
          }
     }
   return EO_CALLBACK_CONTINUE;
}

void
propview_init()
{
   if (!_itc_class)
     {
        _itc_class = elm_genlist_item_class_new();
        _itc_class->item_style = "default";
        _itc_class->func.text_get = _class_item_label_get;
        _itc_class->func.del = _class_item_del;
     }

   if (!_itc_prop)
     {
        _itc_prop = elm_genlist_item_class_new();
        _itc_prop->item_style = "full";
        _itc_prop->func.content_get = _prop_item_content_get;
        _itc_prop->func.del = _prop_item_del;
     }

   if (!_itc_notfound)
     {
        _itc_notfound = elm_genlist_item_class_new();
        _itc_notfound->item_style = "default";
        _itc_notfound->func.text_get = _notfound_item_text_get;
     }

   if (!_itc_cb)
     {
        _itc_cb = elm_genlist_item_class_new();
        _itc_cb->item_style = "full";
        _itc_cb->func.content_get = _callbacks_item_content_get;
        _itc_cb->func.del = _callbacks_item_del;
     }

   if (!_itc_desc)
     {
        _itc_desc = elm_genlist_item_class_new();
        _itc_desc->item_style = "full";
        _itc_desc->func.content_get = _desc_item_content_get;
        _itc_desc->func.del = _desc_item_del;
     }

   if (!_itc_ctn)
     {
        _itc_ctn = elm_genlist_item_class_new();
        _itc_ctn->item_style = "full";
        _itc_ctn->func.content_get = _contents_item_content_get;
        _itc_ctn->func.del = _contents_item_del;
     }

   Egui_Layout_Widgets *g = egui_layout_gui_get();

   propview_table = g->main_win->propsview_table;

   prop_list = g->main_win->properties_list;

   /* Put it here, because it Enums defined in propsview.h */
   elm_object_item_data_set(g->main_win->propsview_toolbar_desc_it, (void *) (intptr_t) DESCRIPTION_TYPE);
   elm_object_item_data_set(g->main_win->propsview_toolbar_prop_it, (void *) (intptr_t) PROPERTY_TYPE);
   elm_object_item_data_set(g->main_win->propsview_toolbar_cb_it, (void *) (intptr_t) CALLBACK_TYPE);
   elm_object_item_data_set(g->main_win->propsview_toolbar_cont_it, (void *) (intptr_t) CONTENT_TYPE);

   evas_object_smart_callback_add(prop_list, "expand,request", _expand_request_cb, NULL);
   evas_object_smart_callback_add(prop_list, "contract,request", _contract_request_cb, NULL);
   evas_object_smart_callback_add(prop_list, "expanded", _props_expanded_cb, NULL);
   evas_object_smart_callback_add(prop_list, "contracted", _props_contracted_cb, NULL);

   eo_do(g->main_win->propsview_filter_entry,
         eo_event_callback_add(ELM_ENTRY_EVENT_CHANGED_USER,
                               _propview_filter_entry_changed_cb,
                               NULL));

   cb_list = g->main_win->callbacksview_list;

   evas_object_smart_callback_add(cb_list, "expand,request", _expand_request_cb, NULL);
   evas_object_smart_callback_add(cb_list, "contract,request", _contract_request_cb, NULL);
   evas_object_smart_callback_add(cb_list, "expanded", _callbacks_expanded_cb, NULL);
   evas_object_smart_callback_add(cb_list, "contracted", _callbacks_contracted_cb, NULL);

   desc_list = g->main_win->description_list;

   ctn_list = g->main_win->contentview_list;

   _mempool_cache_init();
   expanded_classes = eina_hash_string_superfast_new(NULL);
}

void
propview_shutdown()
{
   elm_genlist_item_class_free(_itc_class);
   _itc_class = NULL;
   elm_genlist_item_class_free(_itc_prop);
   _itc_prop = NULL;
   elm_genlist_item_class_free(_itc_notfound);
   _itc_notfound = NULL;
   elm_genlist_item_class_free(_itc_cb);
   _itc_cb = NULL;
   elm_genlist_item_class_free(_itc_desc);
   _itc_desc = NULL;
   elm_genlist_item_class_free(_itc_ctn);
   _itc_ctn = NULL;

   eo_do(prop_list, elm_obj_genlist_clear());
   eo_do(cb_list, elm_obj_genlist_clear());
   eo_do(desc_list, elm_obj_genlist_clear());
   eo_do(ctn_list, elm_obj_genlist_clear());

   prop_list = cb_list = desc_list = ctn_list = NULL;

   _mempool_cache_free();

   if (op_item_table) eina_hash_free(op_item_table);
   eina_hash_free(expanded_classes);
}