summaryrefslogtreecommitdiff
path: root/src/bin/egui_gui/egui_logic.c
blob: 77a3b656ec3c42a91bd12646b73181ef1268712e (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
#include <Elementary.h>
#include <Ecore.h>

#include "elm_widget_container.h"
#include "elm_interface_scrollable.h"
#include "elm_interface_fileselector.h"
#ifdef HAVE_GRAPHVIZ
#include <graphviz/cgraph.h>
#include <graphviz/gvc.h>
#endif

#include "egui_log.h"
#include "gui_widget.h"
#include "gui_parser.h"
#include "generator.h"
#include "simulator.h"
#include "ffi_glue.h"
#include "target.h"

/*FIXME: remove this include */
#include "objtree.h"

#include "egui_logic_private.h"
#include "egui_logic.h"
#include "settings_view.h"
#include "rmview.h"

#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"

static const Egui_Layout_Widgets *g_main_wdgs = NULL;
static Egui_Layout_Fs_Win_Widgets *fs_win = NULL;

static GuiLogicCbs *_guilogic_cbs = NULL;

static Ecore_Idle_Enterer *_idle_enterer = NULL;

GuiLogicCbs *guilogic_cbs_get()
{
   if (!_guilogic_cbs) _guilogic_cbs = calloc(1, sizeof(*_guilogic_cbs));
   return _guilogic_cbs;
}

static Eo *project_menu;
enum
{
   ITEM_OPEN = 1,
   ITEM_CLOSE,
   ITEM_SAVE,
   ITEM_SAVEAS,
   ITEM_EXPORT,
   ITEM_NEW,
   CTX_REFRESH,
   CTX_UNDO,
   CTX_REDO,
   RSRC_MNGR,
   SETTINGS_WIN,
   WDG_DELETE,
   OBJTREE_VIEW,
   PROPERTIES_VIEW,
   FACTORY_VIEW,
   FACTORY_VIEW_SWITCH
};

Eo *
canvas_get()
{
   return g_main_wdgs->main_win->main_win;
}

static void
_main_win_del_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
{
   printf("win del\n");
   elm_exit();
}

static Elm_Object_Item*
_menu_item_find(Eo *menu, int _item_type)
{
   Elm_Object_Item *it;
   Eina_List *items;
   Eina_List *itr;
   if (!menu) return NULL;
   items = (Eina_List *) elm_menu_items_get(menu);
   EINA_LIST_FOREACH(items, itr, it)
     {
        intptr_t item_type = 0;
        item_type = (intptr_t) elm_object_item_data_get(it);
        if ((item_type) && (item_type == _item_type))
          return it;
     }
   return NULL;
}

static void
_menu_item_disabled_set(Eo *menu, intptr_t _item_type, Eina_Bool disabled)
{
   if (!menu) return;
   Elm_Object_Item *it;
   it = _menu_item_find(menu, _item_type);
   if (it)
     elm_object_item_disabled_set(it, disabled);
}

static void
_canvas_name_update(const Gui_Context *ctx)
{
   const char* project_name;
   char name[100];
   if (!ctx)
     {
        sprintf(name, "Erigo - EFL GUI Builder");
     }
   else
     {
        project_name = gui_context_project_name_get(ctx);
        if (!project_name) project_name = "untitled";
        sprintf(name, "Erigo - %s", project_name);
     }
   eo_do(g_main_wdgs->main_win->main_win, elm_obj_win_title_set(name));
}

static void
_on_fs_done(void *data, Evas_Object *obj EINA_UNUSED, void *event)
{
   const Gui_Context *ctx = _active_context_get();
   const char *path = event;
   Eina_Bool path_exists;
   Eina_Bool is_dir;

   if (!path)
     {
        goto end;
     }
   path_exists = ecore_file_exists(path);
   is_dir = ecore_file_is_dir(path);

   char *parent_dir = ecore_file_dir_get(path);
   const char *filename = ecore_file_file_get(path);
   int fs_mode = (int)(intptr_t) data;

   /* fs_mode is ITEM_SAVEAS or ITEM_EXPORT or ITEM_NEW or ITEM_OPEN */

   switch (fs_mode)
     {
      case ITEM_OPEN:
           {
              if ((!path_exists) || (path_exists && is_dir)) goto end;
              if (_guilogic_cbs->_project_new(path))
                {
                   ctx = _active_context_get();
                   _canvas_name_update(ctx);
                   _menu_item_disabled_set(project_menu, ITEM_OPEN, EINA_TRUE);
                   _menu_item_disabled_set(project_menu, ITEM_NEW, EINA_TRUE);
                   _menu_item_disabled_set(project_menu, ITEM_CLOSE, EINA_FALSE);
                   _menu_item_disabled_set(project_menu, ITEM_SAVE, EINA_FALSE);
                   _menu_item_disabled_set(project_menu, ITEM_SAVEAS, EINA_FALSE);
                   _menu_item_disabled_set(project_menu, ITEM_EXPORT, EINA_FALSE);
                }
              break;
           }
      case ITEM_NEW:
           {
              /* User can choose existing directory or create new one.*/
              if (!path_exists && ecore_file_exists(parent_dir))
                {
                   ecore_file_mkdir(path);
                }
              else if (!path_exists && !ecore_file_exists(parent_dir))
                {
                   ERR("Can not create: \"%s\", because \"%s\" doesn't exist.", path, parent_dir);
                   break;
                }

              if (_guilogic_cbs->_project_new(NULL))
                {
                   ctx = _active_context_get();
                   _canvas_name_update(ctx);
                   _menu_item_disabled_set(project_menu, ITEM_OPEN, EINA_TRUE);
                   _menu_item_disabled_set(project_menu, ITEM_NEW, EINA_TRUE);
                   _menu_item_disabled_set(project_menu, ITEM_CLOSE, EINA_FALSE);
                   _menu_item_disabled_set(project_menu, ITEM_SAVE, EINA_FALSE);
                   _menu_item_disabled_set(project_menu, ITEM_SAVEAS, EINA_FALSE);
                   _menu_item_disabled_set(project_menu, ITEM_EXPORT, EINA_FALSE);
                   const char *project_name = eo_do(fs_win->fs_project_name_entry, elm_obj_widget_part_text_get(NULL));
                   if (!strlen(project_name)) project_name = "New Project";

                   char *default_filename = strdup(project_name), *p;
                   eina_str_tolower(&default_filename);
                   p = default_filename;
                   while (*p)
                     {
                        if ((*p) == ' ') (*p) = '_';
                        p++;
                     }

                   char full_path[PATH_MAX] = {'\0'};
                   char full_filename[PATH_MAX] = {'\0'};
                   int i = 1;
                   sprintf(full_filename, "%s", default_filename);
                   sprintf(full_path, "%s/%s", path, full_filename);
                   /* If file exists, add number in the end of file. */
                   while (ecore_file_exists(full_path))
                     {
                        sprintf(full_filename, "%s%d", default_filename, i++);
                        sprintf(full_path, "%s/%s", path, full_filename);
                     }

                   gui_context_project_name_set((Gui_Context *) ctx, project_name);
                   gui_context_project_path_set((Gui_Context *) ctx, path);
                   gui_context_project_filename_set((Gui_Context *) ctx, full_filename);
                   generator_ctx_source_generate(ctx, GENERATE_JSON);
                   _canvas_name_update(ctx);
                   free(default_filename);
                }
              break;
           }
      case ITEM_EXPORT:
           {
              if (!ecore_file_exists(parent_dir)) goto end;
              if (path_exists)
                {
                   /* FIXME: File exists, check if want to save*/
                   ERR("can save, but file exists, show confirmation window");
                }
              gui_context_export_filename_set((Gui_Context *) ctx, filename);
              gui_context_export_path_set((Gui_Context *) ctx, (const char *) parent_dir);
              int state = -1;
              eo_do(fs_win->fs_radio_c, state = elm_obj_radio_value_get());
              switch (state)
                {
                 case 0:
                      {
                         generator_ctx_source_generate(ctx, GENERATE_C);
                         break;
                      }
                 case 1:
                      {
                         generator_ctx_source_generate(ctx, GENERATE_CPP);
                         break;
                      }
                }
              break;
           }
      case ITEM_SAVEAS:
           {
              if (!ecore_file_exists(parent_dir)) goto end;
              if (path_exists)
                {
                   /* FIXME: File exists, check if want to save*/
                   ERR("can save, but file exists, show confirmation window");
                }
              gui_context_project_filename_set((Gui_Context *) ctx, filename);
              gui_context_project_path_set((Gui_Context *) ctx, (const char *) parent_dir);
              generator_ctx_source_generate(ctx, GENERATE_JSON);
              _canvas_name_update(ctx);
              break;
           }
     }
   free(parent_dir);

end:
   eo_del(fs_win->fs_win);
}

static void
_fs_mode_open(int fs_mode)
{
   const char *fs_path = NULL, *fs_file = NULL;
   const Gui_Context *ctx = _active_context_get();

   fs_win = egui_layout_fs_win_create(g_main_wdgs->main_win->main_win);

   eo_do(fs_win->fileselector, elm_interface_fileselector_folder_only_set(EINA_FALSE));
   eo_do(fs_win->fileselector, elm_interface_fileselector_is_save_set(EINA_FALSE));
   switch (fs_mode)
     {
      case ITEM_EXPORT:
           {
              eo_do(fs_win->fs_radio_box, evas_obj_visibility_set(EINA_TRUE));
              eo_do(fs_win->fileselector, elm_interface_fileselector_is_save_set(EINA_TRUE));
              fs_path = gui_context_export_path_get(ctx);
              fs_file = gui_context_export_filename_get(ctx);
              break;
           }
      case ITEM_NEW:
           {
              eo_do(fs_win->fs_project_name_box, evas_obj_visibility_set(EINA_TRUE));
              eo_do(fs_win->fileselector, elm_interface_fileselector_is_save_set(EINA_TRUE));
              eo_do(fs_win->fileselector, elm_interface_fileselector_folder_only_set(EINA_TRUE));
              break;
           }
      case ITEM_SAVEAS:
           {
              eo_do(fs_win->fileselector, elm_interface_fileselector_is_save_set(EINA_TRUE));
              fs_file = gui_context_project_filename_get(ctx);
              fs_path = gui_context_project_path_get(ctx);
              break;
           }
      case ITEM_OPEN:
           {
              break;
           }
      default:
           {
              ERR("switch default for fs_mode: %d", fs_mode);
              break;
           }
     }

   if (!fs_path) fs_path = getenv("HOME");
   eo_do(fs_win->fileselector, elm_interface_fileselector_path_set(fs_path));

   /* filename (for save or export mode) are exist, show it as default in fileselector*/
   if (fs_file)
     {
        eo_do(fs_win->fileselector, elm_interface_fileselector_current_name_set(fs_file));
     }
   evas_object_smart_callback_add(fs_win->fileselector, "done", _on_fs_done, (void *)(intptr_t) fs_mode);
}

#if 0
static void
_toggle_menu(Eo *menu)
{
   Elm_Transit *trans;
   int x, y, w, h;

   eo_do(menu, evas_obj_position_get(&x, &y));
   eo_do(menu, evas_obj_size_get(&w, &h));
   if (y == 0)
     {
        x = -w;
        y = -h;
     }
   else if (y == -h)
     {
        x = w;
        y = h;
     }
   else
     return;

   trans = elm_transit_add();
   elm_transit_tween_mode_set(trans, ELM_TRANSIT_TWEEN_MODE_ACCELERATE);
   elm_transit_effect_translation_add(trans, 0, 0, 0, y);
   elm_transit_object_add(trans, menu);
   elm_transit_duration_set(trans, 0.5);
   elm_transit_objects_final_state_keep_set(trans, EINA_TRUE);
   elm_transit_go(trans);
}

static void
_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   _toggle_menu(g_main_wdgs->menu_box);
}
#endif

#if 0
static Eina_Bool
_event(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, Evas_Object *src EINA_UNUSED, Evas_Callback_Type type, void *event_info)
{
   /*FIXME: when I change focus, sometimes this event is sent twice. */
   if (type == EVAS_CALLBACK_KEY_DOWN)
     {
        ERR("asdf");
        Evas_Event_Key_Down *ev = event_info;
        if (!strcmp(ev->key, "Delete"))
          {
             _editor_selected_wdg_del_cb();
          }
        return EINA_TRUE;
     }
   else if (type == EVAS_CALLBACK_MOUSE_DOWN)
     {
        ERR("win event");
        return EINA_TRUE;
     }
   else
     return EINA_FALSE;
}
#endif

Eina_Bool
_on_factory_item_down(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   const char *class_name = data;
   _guilogic_cbs->_editor_factory_wdg_create(class_name,
         _guilogic_cbs->_editor_selected_wdg_get());
   return EO_CALLBACK_CONTINUE;
}

#define FACTORY_CB_ADD(obj1, obj2) eo_do((obj1), eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_DOWN, _on_factory_item_down, eo_class_name_get(eo_class_get((obj2)))));

#define FACTORY_CB_ADD_NAME(obj1, name) eo_do((obj1), eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_DOWN, _on_factory_item_down, (name)));

static void
_factory_vertical_pack(Eina_Bool vertical_pack);

/* FIXME: need to change signature to Eo_Callback, when it will be supported.
 * This callback is used in Egui Layout JSON. */
void
_toolbar_item_sel_cb
(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)
{
   const Gui_Context *ctx = _active_context_get();
   Elm_Object_Item *item = event_info;
   intptr_t action = (intptr_t) elm_object_item_data_get(item);

   /* Unselect clicked toolbar item. */
   eo_do(obj, elm_toolbar_item_selected_set(item, EINA_FALSE));
   if (!ctx)
     {
        printf("project is not open\n");
        return;
     }
   switch (action)
     {
      case WDG_DELETE:
           {
              _guilogic_cbs->_editor_selected_wdg_del_cb();
              break;
           }
      case RSRC_MNGR:
           {
              rm_win_set(egui_layout_rm_win_create(g_main_wdgs->main_win->main_win));
              rm_win_post_configure();
              break;
           }
      case SETTINGS_WIN:
           {
              settings_win_set(egui_layout_settings_win_create(g_main_wdgs->main_win->main_win));
              settings_win_post_configure();
              break;
           }
      case CTX_REFRESH:
           {
              _guilogic_cbs->_layout_clear(_active_context_get());
              _guilogic_cbs->_editor_ctx_call(_active_context_get());
              break;
           }
      case CTX_UNDO:
           {
              _guilogic_cbs->_editor_undo(_active_context_get());
              break;
           }
      case CTX_REDO:
           {
              _guilogic_cbs->_editor_redo(_active_context_get());
              break;
           }
      default:
           {
              ERR("switch default");
           }
     }
}

static void
_project_menu_item_sel_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   intptr_t action = (intptr_t) data;
   switch (action)
     {
      case ITEM_OPEN:
           {
              _fs_mode_open(action);
              break;
           }
      case ITEM_CLOSE:
           {
              _guilogic_cbs->_project_close(_active_context_get());
             _canvas_name_update(_active_context_get());
             _menu_item_disabled_set(project_menu, ITEM_OPEN, EINA_FALSE);
             _menu_item_disabled_set(project_menu, ITEM_NEW, EINA_FALSE);
             _menu_item_disabled_set(project_menu, ITEM_CLOSE, EINA_TRUE);
             _menu_item_disabled_set(project_menu, ITEM_SAVE, EINA_TRUE);
             _menu_item_disabled_set(project_menu, ITEM_SAVEAS, EINA_TRUE);
             _menu_item_disabled_set(project_menu, ITEM_EXPORT, EINA_TRUE);
              break;
           }
      case ITEM_SAVE:
           {
              const Gui_Context * ctx = _active_context_get();
              const char *dir = gui_context_project_path_get(ctx);
              const char *filename = gui_context_project_filename_get(ctx);
              if (!dir || !filename)
                {
                   _fs_mode_open(ITEM_SAVEAS);
                   return;
                }
              generator_ctx_source_generate(ctx, GENERATE_JSON);
              break;
           }
      case ITEM_SAVEAS:
      case ITEM_EXPORT:
           {
              _fs_mode_open(action);
              break;
           }
      case ITEM_NEW:
           {

              _fs_mode_open(action);
              break;
           }
      default:
           {
              ERR("switch default");
           }
     }
}

static void
_sub_wins_hide_show_cb(void *data, Evas_Object *_obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Eo *obj = NULL;
   intptr_t action = (intptr_t) data;
   static Eina_Bool fctr_table_vertical = EINA_FALSE;
   switch (action)
     {
      case FACTORY_VIEW:
         obj = g_main_wdgs->main_win->fctr_table;
         break;
      case FACTORY_VIEW_SWITCH:
           {
              _factory_vertical_pack(fctr_table_vertical);
              fctr_table_vertical = !fctr_table_vertical;
              break;
           }
      case OBJTREE_VIEW:
         obj = g_main_wdgs->main_win->objtree_table;
         break;
      case PROPERTIES_VIEW:
         obj = g_main_wdgs->main_win->propsview_table;
         break;
      default:
         return;
     }
   Eina_Bool state = EINA_TRUE;
   eo_do(obj, state = evas_obj_visibility_get());
   state = !state;
   eo_do(obj, evas_obj_visibility_set(state));
   if (state)
     {
        switch(action)
          {
           case FACTORY_VIEW:
              //eo_do(g_main_wdgs->left_panel_box, elm_obj_box_pack_start(obj));
              break;
           case OBJTREE_VIEW:
              eo_do(g_main_wdgs->main_win->right_panel_box, elm_obj_box_pack_start(obj));
              break;
           case PROPERTIES_VIEW:
              eo_do(g_main_wdgs->main_win->right_panel_box, elm_obj_box_pack_end(obj));
              break;
           default:
              break;
          }
     }
   else
     {
        switch(action)
          {
           case FACTORY_VIEW:
              //eo_do(g_main_wdgs->left_panel_box, elm_obj_box_unpack(obj));
              break;
           case OBJTREE_VIEW:
           case PROPERTIES_VIEW:
              eo_do(g_main_wdgs->main_win->right_panel_box, elm_obj_box_unpack(obj));
              break;
           default:
              break;
          }
     }
}

#ifdef HAVE_GRAPHVIZ
static Agnode_t *
_graphviz_widget_build(Agraph_t *ag, const Gui_Widget *wdg)
{
   Agnode_t *wdg_node = agnode(ag, (char *)wdg_name_get(wdg), 1);
   if (wdg_children_list_get(wdg))
     {
        agsafeset(wdg_node, "shape", "box", "");
        agsafeset(wdg_node, "fillcolor", "orangered:white", "");
     }
   else
     {
        agsafeset(wdg_node, "shape", "ellipse", "");
        agsafeset(wdg_node, "fillcolor", "orange:white", "");
     }

   agsafeset(wdg_node, "style", "filled", "");
   agsafeset(wdg_node, "gradientangle", "270", "");
   const Eina_List *children = NULL, *itr;
   Dep_Id *w_id;

   children = wdg_children_list_get(wdg);
   EINA_LIST_FOREACH(children, itr, w_id)
     {
        const Gui_Widget *w = wdg_get(w_id);
        Agnode_t *w_node = _graphviz_widget_build(ag, w);
        agedge(ag, wdg_node, w_node, 0, 1);
     }

   Dep_Id *cb_dep_id;
   EINA_LIST_FOREACH(wdg_cb_list_get(wdg), itr, cb_dep_id)
     {
        Gui_Widget_Callback *cb = cb_get(cb_dep_id);
        Dep_Id *action_id = cb_action_id_get(cb);
        const Gui_Action *action = action_get(action_id);
        switch (action_type_get(action))
          {
           case CREATION_ACTION:
                {
                   w_id = action_widget_id_get(action);
                   const Gui_Widget *w = wdg_get(w_id);
                   if (w)
                     {
                        Agnode_t *w_node = agnode(ag, (char *)wdg_name_get(w), 1);
                        agedge(ag, wdg_node, w_node, 0, 1);
                     }
                   break;
                }
           case MODIF_ACTION:
                {
                   w_id = action_widget_id_get(action);
                   const Gui_Widget *w = wdg_get(w_id);
                   if (w)
                     {
                        Agnode_t *w_node = agnode(ag, (char *)wdg_name_get(w), 1);
                        Agedge_t *e = agedge(ag, wdg_node, w_node, 0, 1);
                        agsafeset(e, "style", "dashed", "");
                     }
                   break;
                }
           default:
                {
                }
          }
     }
   return wdg_node;
}
#endif

/* Callback can not be static, because used in egui_layout. */
Eina_Bool
_graphviz_button_clicked_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
#ifdef HAVE_GRAPHVIZ
   Agraph_t *ag;
   GVC_t *gvc = gvContext();
   /* gvParseArgs(gvc, argc, argv); */

   ag = agopen("ag", Agdirected, NULL);

   const Gui_Context *ctx = _active_context_get();
   const Eina_List* start_pts = gui_context_start_points_get(ctx), *itr;
   const char *start_pt;
   Agnode_t *start_node = NULL;
   Dep_Id *wdg_id;
   if (start_pts)
     {
        start_node = agnode(ag, "Start", 1);
        agsafeset(start_node, "shape", "diamond", "");
        agsafeset(start_node, "style", "radial", "");
        agsafeset(start_node, "fillcolor", "white:blue", "");
     }
   EINA_LIST_FOREACH(start_pts, itr, start_pt)
     {
        wdg_id = gui_context_dep_id_by_name_get(ctx, start_pt);
        const Gui_Widget *wdg = wdg_get(wdg_id);
        if (wdg)
          {
             Agnode_t *wdg_node = agnode(ag, (char *)dep_name_get(wdg_id), 1);
             agedge(ag, start_node, wdg_node, 0, 1);
          }
     }
   EINA_LIST_FOREACH(gui_context_main_widgets_get(ctx), itr, wdg_id)
     {
        const Gui_Widget *wdg = wdg_get(wdg_id);
        if (wdg) _graphviz_widget_build(ag, wdg);
     }
   gvLayout(gvc, ag, "dot");
   gvRenderFilename(gvc, ag, "png", "/tmp/truc.png");
   gvFreeLayout(gvc, ag);
   agclose(ag);
   gvFreeContext(gvc);

   Egui_Layout_Gvc_Win_Widgets *wdgs = egui_layout_gvc_win_create(NULL);
   eo_do(wdgs->gvc_img, efl_file_set("/tmp/truc.png", NULL));
   return EO_CALLBACK_CONTINUE;
#else
   return EO_CALLBACK_STOP;
#endif
}

static void
_toolbar_session_kill_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Gui_Session *session = data;
   Eina_List *wins = session_wins_get(session);
   Eina_List *itr, *itr2;
   Gui_Widget *wdg;
   /* Kill session by removing its Eo objects. */
   EINA_LIST_FOREACH_SAFE(wins, itr, itr2, wdg)
     {
        manager_widget_delete(session, wdg, MODE_SIMULATOR, NULL);
     }
}

/* Callback is called, when all session's Eo objects are deleted*/
static void
_population_zero_cb(Gui_Session *session, void *data)
{
   /* When all Eo objects are deleted, we can delete target window.
    * Mainly this can happen, when we Kill session from menu.
    * T.e. all session's Eo objects will be deleted, which will cause deletion of the window. */
   session_target_win_unset(session);
   /* Remove session from list of sessions in progress. */
   gui_context_simulate_session_remove(_active_context_get(), session);
   session_del(session);
   Elm_Object_Item *it = data;
   elm_object_item_del(it);
}

/* Func adds session's info into 'Sessions' menu */
static void
_toolbar_simulate_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Target_Desc *td = data;
   Gui_Session *session = NULL;
   session = simulator_ctx_call(_active_context_get(), target_name_get(td));
   if (session)
     {
        Eo *menu = elm_toolbar_item_menu_get(g_main_wdgs->main_win->toolbar_simulate_it);
        Elm_Object_Item *it = elm_menu_item_add(menu, NULL, NULL, target_name_get(td), NULL, NULL);
        elm_menu_item_add(menu, it, NULL, "Kill", _toolbar_session_kill_cb, session);
        session_population_zero_cb_set(session, _population_zero_cb, it);
     }
}

static void
_factory_item_finalize(Eo *item_box, char *image_name, char *egui_class_name)
{
   if (!item_box) return;
   /* Add MOUSE_DOWN callback to factory widget. */
   FACTORY_CB_ADD_NAME(item_box, egui_class_name);
   evas_object_size_hint_align_set(item_box, 0, EVAS_HINT_FILL);

   Eina_List *lst = elm_box_children_get(item_box);

   // update of the image icon
   Eo *o = eina_list_data_get(lst);
   char path[100] = {'\0'};
   sprintf(path, "%s/images/%s", PACKAGE_DATA_DIR, image_name);
   eo_do(o, efl_file_set(path, NULL));

   eina_list_free(lst);
}

static void
_factory_vertical_pack(Eina_Bool vertical_pack)
{
   elm_table_clear(g_main_wdgs->main_win->fctr_table, EINA_FALSE);
   if (vertical_pack)
     {
        //elm_table_homogeneous_set(g_main_wdgs->main_win->fctr_table, EINA_TRUE);
        evas_object_size_hint_align_set(g_main_wdgs->main_win->fctr_table, 0.1, -1);
        elm_table_padding_set(g_main_wdgs->main_win->fctr_table, 6, 7);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_win_it, 0, 0, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_bg_it, 0, 1, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_box_it, 0, 2, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_button_it, 0, 3, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_label_it, 0, 4, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_check_it, 0, 5, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_radio_it, 0, 6, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_icon_it, 0, 7, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_image_it, 0, 8, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_actionslider_it, 0, 9, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_clock_it, 0, 10, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_dayselector_it, 0, 11, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_calendar_it, 0, 12, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_bubble_it, 0, 13, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_colorselector_it, 0, 14, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_entry_it, 0, 15, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_flip_it, 0, 16, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_genlist_it, 0, 17, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_gengrid_it, 0, 18, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_table_it, 0, 19, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_menu_it, 0, 20, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_diskselector_it, 0, 21, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_ctxpopup_it, 0, 22, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_toolbar_it, 0, 23, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_layout_it, 0, 24, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_naviframe_it, 0, 25, 1, 1);
     }
   else
     {
        elm_table_padding_set(g_main_wdgs->main_win->fctr_table, 2, 2);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_win_it, 0, 0, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_bg_it, 1, 0, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_box_it, 2, 0, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_button_it, 0, 1, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_label_it, 1, 1, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_check_it, 2, 1, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_radio_it, 0, 2, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_icon_it, 1, 2, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_image_it, 2, 2, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_actionslider_it, 0, 3, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_clock_it, 1, 3, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_dayselector_it, 2, 3, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_calendar_it, 0, 4, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_bubble_it, 1, 4, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_colorselector_it, 2, 4, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_entry_it, 0, 5, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_flip_it, 1, 5, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_genlist_it, 2, 5, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_gengrid_it, 0, 6, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_table_it, 1, 6, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_menu_it, 2, 6, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_diskselector_it, 0, 7, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_ctxpopup_it, 1, 7, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_toolbar_it, 2, 7, 1, 1);

        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_layout_it, 0, 8, 1, 1);
        elm_table_pack(g_main_wdgs->main_win->fctr_table, g_main_wdgs->main_win->fctr_naviframe_it, 1, 8, 1, 1);
     }
}

/* Filter function to be called, when Filter entry is changed. */
static void
_entry_changed_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   const char *str = elm_entry_entry_get(obj);
   if (!str)
     {
        objtree_item_selected_set(NULL);
        return;
     }
   Gui_Widget *wdg = wdg_first_find(_active_context_get(), str);
   objtree_item_selected_set(wdg);
}

Eina_Bool
_canvas_bg_show_on_idle(void *data EINA_UNUSED)
{
   Evas_Coord cv_x, cv_y, cv_w, cv_h, tmp;

   eo_do(g_main_wdgs->main_win->left_panes, evas_obj_size_get(&cv_x, NULL));
   cv_x = (double)cv_x * elm_panes_content_left_size_get(g_main_wdgs->main_win->left_panes);
   cv_x += 7;

   eo_do(g_main_wdgs->main_win->right_panes, evas_obj_position_get(&cv_w, NULL));
   eo_do(g_main_wdgs->main_win->right_panes, evas_obj_size_get(&tmp, NULL));
   tmp = (double)tmp * elm_panes_content_left_size_get(g_main_wdgs->main_win->right_panes);
   cv_w += tmp;
   cv_w -= (cv_x + 7);
   eo_do(g_main_wdgs->main_win->toolbar, evas_obj_size_get(NULL, &cv_y));
   eo_do(g_main_wdgs->main_win->main_win, evas_obj_size_get(NULL, &cv_h));
   cv_h -= cv_y;

   eo_do(g_main_wdgs->main_win->canvas_bg,
         evas_obj_position_set(cv_x, cv_y),
         evas_obj_size_set(cv_w, cv_h));
   return ECORE_CALLBACK_RENEW;
}

static void
_assign_image_to_button(Eo *btn, const char* path)
{
  Eo *ic = eo_add(ELM_ICON_CLASS, btn);
  eo_do(ic, efl_file_set(path, NULL));
  eo_do(btn, elm_obj_container_content_set("icon", ic));
}

void
egui_start()
{
   g_main_wdgs = egui_layout_gui_get();

   // Post-configuration
   eo_do(g_main_wdgs->main_win->main_win, elm_obj_win_maximized_set(EINA_TRUE));
   eo_do(evas_object_smart_parent_get(g_main_wdgs->main_win->main_box), evas_obj_smart_member_add(g_main_wdgs->main_win->canvas_bg));
   eo_do(g_main_wdgs->main_win->canvas_bg, evas_obj_stack_below(g_main_wdgs->main_win->main_box));

   //Eo *mmenu;
   //eo_do(g_main_wdgs->main_win->main_win, elm_obj_win_main_menu_get(&mmenu));
   //eo_do(mmenu, elm_obj_menu_item_add(NULL, NULL, "OPEN", NULL, NULL, NULL));

   Evas_Object *objtree_rect = evas_object_rectangle_add(evas_object_evas_get(g_main_wdgs->main_win->objtree_table));
   evas_object_size_hint_min_set(objtree_rect, 300, 100);
   evas_object_size_hint_weight_set(objtree_rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(objtree_rect, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_table_pack(g_main_wdgs->main_win->objtree_table, objtree_rect, 0, 1, 1, 1);

   Evas_Object *propsview_rect = evas_object_rectangle_add(evas_object_evas_get(g_main_wdgs->main_win->propsview_table));
   evas_object_size_hint_min_set(propsview_rect, 300, 100);
   evas_object_size_hint_weight_set(propsview_rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(propsview_rect, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_table_pack(g_main_wdgs->main_win->propsview_table, propsview_rect, 0, 2, 1, 1);

   editor_init(guilogic_cbs_get());

   evas_object_smart_callback_add(g_main_wdgs->main_win->objtree_filter_entry, "changed,user", _entry_changed_cb, NULL);
   //elm_object_event_callback_add(g_main_wdgs->main_win->main_win, _event, NULL);

   /*Adding resizing to canvas frame*/
   /*
   evas_object_event_callback_add(g_main_wdgs->canvas_fr, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down_ui, NULL);
   eo_do(g_main_wdgs->canvas_fr, eo_event_callback_add(EVAS_OBJECT_EVENT_MOUSE_UP, _mouse_up_ui, NULL));
   */

   _idle_enterer = ecore_idle_enterer_add(_canvas_bg_show_on_idle, NULL);
   /* Toolbar */
   Eo *menu;
   elm_toolbar_item_selected_set(g_main_wdgs->main_win->toolbar_project_it, EINA_FALSE);
   elm_toolbar_item_menu_set(g_main_wdgs->main_win->toolbar_project_it, EINA_TRUE);
   elm_toolbar_item_priority_set(g_main_wdgs->main_win->toolbar_project_it, -9999);
   elm_toolbar_menu_parent_set(g_main_wdgs->main_win->toolbar, g_main_wdgs->main_win->main_win);
   menu = elm_toolbar_item_menu_get(g_main_wdgs->main_win->toolbar_project_it);
   project_menu = menu;

   Elm_Object_Item *it;
   it = elm_menu_item_add(menu, NULL, "window-new", "New Project", _project_menu_item_sel_cb, (void *) (intptr_t) ITEM_NEW);
   elm_object_item_data_set(it, (void *) ITEM_NEW);
   it = elm_menu_item_add(menu, NULL, "fileopen", "Open", _project_menu_item_sel_cb,(void *) (intptr_t) ITEM_OPEN);
   elm_object_item_data_set(it, (void *) ITEM_OPEN);
   it = elm_menu_item_add(menu, NULL, "document-save", "Save", _project_menu_item_sel_cb, (void *) (intptr_t) ITEM_SAVE);
   elm_object_item_data_set(it, (void *) ITEM_SAVE);
   elm_object_item_disabled_set(it, EINA_TRUE);
   it = elm_menu_item_add(menu, NULL, "document-save-as", "Save As", _project_menu_item_sel_cb, (void *) (intptr_t) ITEM_SAVEAS);
   elm_object_item_data_set(it, (void *) ITEM_SAVEAS);
   elm_object_item_disabled_set(it, EINA_TRUE);
   it = elm_menu_item_add(menu, NULL, "go-next", "Export", _project_menu_item_sel_cb, (void *) (intptr_t) ITEM_EXPORT);
   elm_object_item_data_set(it, (void *) ITEM_EXPORT);
   elm_object_item_disabled_set(it, EINA_TRUE);
   it = elm_menu_item_add(menu, NULL, "window-close", "Close Project", _project_menu_item_sel_cb, (void *) (intptr_t) ITEM_CLOSE);
   elm_object_item_data_set(it, (void *) ITEM_CLOSE);
   elm_object_item_disabled_set(it, EINA_TRUE);

   elm_toolbar_item_separator_set(g_main_wdgs->main_win->toolbar_separator1_it, EINA_TRUE);

   elm_object_item_data_set(g_main_wdgs->main_win->toolbar_rm_it, (void *) (intptr_t) RSRC_MNGR);
   elm_object_item_data_set(g_main_wdgs->main_win->toolbar_settings_it, (void *) (intptr_t) SETTINGS_WIN);

   elm_toolbar_item_separator_set(g_main_wdgs->main_win->toolbar_separator2_it, EINA_TRUE);

   elm_object_item_data_set(g_main_wdgs->main_win->toolbar_undo_it, (void *) (intptr_t) CTX_UNDO);
   elm_object_item_disabled_set(g_main_wdgs->main_win->toolbar_undo_it, EINA_TRUE);
   elm_object_item_data_set(g_main_wdgs->main_win->toolbar_redo_it, (void *) (intptr_t) CTX_REDO);
   elm_object_item_disabled_set(g_main_wdgs->main_win->toolbar_redo_it, EINA_TRUE);
   elm_object_item_data_set(g_main_wdgs->main_win->toolbar_reload_it, (void *) (intptr_t) CTX_REFRESH);
   elm_object_item_data_set(g_main_wdgs->main_win->toolbar_delete_it, (void *) (intptr_t) WDG_DELETE);

   elm_toolbar_item_menu_set(g_main_wdgs->main_win->toolbar_view_it, EINA_TRUE);
   elm_toolbar_item_priority_set(g_main_wdgs->main_win->toolbar_view_it, -9999);

   menu = elm_toolbar_item_menu_get(g_main_wdgs->main_win->toolbar_view_it);
   it = elm_menu_item_add(menu, NULL, "window-new", "Factory show/hide", _sub_wins_hide_show_cb,(void *) (intptr_t) FACTORY_VIEW);
   elm_object_item_disabled_set(it, EINA_TRUE);
   it = elm_menu_item_add(menu, NULL, "window-new", "Factory vert/hor", _sub_wins_hide_show_cb,(void *) (intptr_t) FACTORY_VIEW_SWITCH);
   it = elm_menu_item_add(menu, NULL, "window-new", "Objects Tree", _sub_wins_hide_show_cb,(void *) (intptr_t) OBJTREE_VIEW);
   elm_object_item_disabled_set(it, EINA_TRUE);
   it = elm_menu_item_add(menu, NULL, "window-new", "Properties", _sub_wins_hide_show_cb,(void *) (intptr_t) PROPERTIES_VIEW);
   elm_object_item_disabled_set(it, EINA_TRUE);

   elm_toolbar_item_selected_set(g_main_wdgs->main_win->toolbar_simulate_it, EINA_FALSE);
   elm_toolbar_item_priority_set(g_main_wdgs->main_win->toolbar_simulate_it, -9999);
   elm_toolbar_item_menu_set(g_main_wdgs->main_win->toolbar_simulate_it, EINA_TRUE);
   menu = elm_toolbar_item_menu_get(g_main_wdgs->main_win->toolbar_simulate_it);
   it = elm_menu_item_add(menu, NULL, NULL, "Create a new session...", NULL, NULL);
     {
        Eina_List *itr;
        Target_Desc *td;
        EINA_LIST_FOREACH((Eina_List *) targets_list_get(), itr, td)
          {
             elm_menu_item_add(menu, it, NULL, target_name_get(td), _toolbar_simulate_cb, td);
          }
     }

   /* Disable GraphViz item if library not installed. */
#ifndef HAVE_GRAPHVIZ
   elm_object_item_disabled_set(g_main_wdgs->main_win->toolbar_graph_it, EINA_TRUE);
#endif

    // Put signs on up down buttons
    _assign_image_to_button(g_main_wdgs->main_win->contentview_down_btn, _PATH_ICON_DOWN_ARROW);
    _assign_image_to_button(g_main_wdgs->main_win->contentview_up_btn, _PATH_ICON_UP_ARROW);
    _assign_image_to_button(g_main_wdgs->main_win->callbacksview_down_btn, _PATH_ICON_DOWN_ARROW);
    _assign_image_to_button(g_main_wdgs->main_win->callbacksview_up_btn, _PATH_ICON_UP_ARROW);

   _factory_item_finalize(g_main_wdgs->main_win->fctr_actionslider_it, "factory_actionslider.png", DB_DEF_ACTIONSLIDER_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_bg_it, "factory_bg.png", DB_DEF_BG_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_box_it, "factory_box.png", DB_DEF_BOX_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_bubble_it, "factory_bubble.png", DB_DEF_BUBBLE_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_button_it, "factory_button.png", DB_DEF_BUTTON_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_calendar_it, "factory_calendar.png", DB_DEF_CALENDAR_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_check_it, "factory_check.png", DB_DEF_CHECK_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_radio_it, "factory_radio.png", DB_DEF_RADIO_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_clock_it, "factory_clock.png", DB_DEF_CLOCK_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_colorselector_it, "factory_colorselector.png", DB_DEF_COLORSELECTOR_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_dayselector_it, "factory_dayselector.png", DB_DEF_DAYSELECTOR_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_image_it, "factory_image.png", DB_DEF_IMAGE_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_icon_it, "factory_icon.png", DB_DEF_ICON_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_label_it, "factory_label.png", DB_DEF_LABEL_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_win_it, "factory_win.png", DB_DEF_WIN_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_entry_it, "factory_entry.png", DB_DEF_ENTRY_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_flip_it, "factory_flip.png", DB_DEF_FLIP_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_genlist_it, "factory_genlist.png", DB_DEF_GENLIST_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_gengrid_it, "factory_gengrid.png", DB_DEF_GENGRID_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_table_it, "factory_table.png", DB_DEF_TABLE_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_menu_it, "factory_menu.png", DB_DEF_MENU_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_diskselector_it, "factory_diskselector.png", DB_DEF_DISKSELECTOR_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_ctxpopup_it, "factory_ctxpopup.png", DB_DEF_CTXPOPUP_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_toolbar_it, "factory_toolbar.png", DB_DEF_TOOLBAR_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_layout_it, "factory_layout.png", DB_DEF_LAYOUT_CLASS);
   _factory_item_finalize(g_main_wdgs->main_win->fctr_naviframe_it, "factory_naviframe.png", DB_DEF_NAVIFRAME_CLASS);

   /*FIXME: Need to unpack inline image, so pass it into delete callback*/
   evas_object_smart_callback_add(g_main_wdgs->main_win->main_win, "delete,request", _main_win_del_cb, NULL);
}

void
egui_stop()
{
   editor_shutdown();
   ecore_idle_enterer_del(_idle_enterer);
   _idle_enterer = NULL;
}

void
egui_project_open(char *filename)
{
   if (filename)
     {
        if (_guilogic_cbs->_project_new(filename))
          {
             _canvas_name_update(_active_context_get());
             _menu_item_disabled_set(project_menu, ITEM_OPEN, EINA_TRUE);
             _menu_item_disabled_set(project_menu, ITEM_NEW, EINA_TRUE);
             _menu_item_disabled_set(project_menu, ITEM_CLOSE, EINA_FALSE);
             _menu_item_disabled_set(project_menu, ITEM_SAVE, EINA_FALSE);
             _menu_item_disabled_set(project_menu, ITEM_SAVEAS, EINA_FALSE);
             _menu_item_disabled_set(project_menu, ITEM_EXPORT, EINA_FALSE);
          }
     }
}

void
egui_project_close()
{
   const Gui_Context *ctx = _active_context_get();
   if (ctx)
     {
        _guilogic_cbs->_project_close(ctx);
     }
}