summaryrefslogtreecommitdiff
path: root/src/bin/egui_gui/rmview.c
blob: ffca6c2fe248e4da4e7c8789f13f7368ee190d51 (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
#include <Elementary.h>
#include "egui_log.h"
#include "egui_layout.h"
#include "gui_widget.h"
#include "egui_logic_private.h"
#include "rmview.h"
#include "prop_layout.h"

#include "elm_widget.h"
#include "elm_widget_container.h"
#include "elm_interface_scrollable.h"
#include "elm_interface_fileselector.h"

#define _STR_RMVIEW "rmview"

#define EO_CALLBACK_STR "EO_CALLBACK"
#define EVAS_CALLBACK_STR "EVAS_CALLBACK"
#define EVAS_SMART_CALLBACK_STR "EVAS_SMART_CALLBACK"

/* currently selected toolbar item */
static Rmview_Resource_Type _rmview_toolbar_selected_type = RMVIEW_NOT_SELECTED;

static Egui_Layout_Rm_Win_Widgets *g_rm_win = NULL;

void rm_win_set(Egui_Layout_Rm_Win_Widgets *rm_win)
{
   if (g_rm_win) free(g_rm_win);
   g_rm_win = rm_win;
}

static void
_rmview_build(Rmview_Resource_Type type);

/* Struct holds data about objects, which are in one line of table
 * and resource. */
typedef struct
{
   Gui_Resource *res;
   Eo *en1;
   Eo *en2;
   Eo *en3;
   Eo *bt_save;
   int ref_count;
   unsigned int changed;
} Rmview_Item_Data;

/* Struct to hold idx of element in line. */
typedef struct
{
   Rmview_Item_Data *it_data;
   int idx;
} Rmview_Field_Data;

#define RMVIEW_FIELD_DATA_BUILD(_idx, _it_data) \
   ({ \
    Rmview_Field_Data *_data = calloc(1, sizeof(Rmview_Field_Data )); \
    _data->idx = _idx; \
    _data->it_data = _it_data; \
    _it_data->ref_count++; \
    _data; \
    })

static void
_field_data_free(void *_data)
{
   Rmview_Field_Data *data = _data;
   if (--data->it_data->ref_count == 0)
     {
        free(data->it_data);
     }
   free(data);
}

/* Helper func to create label */
static Eo*
_rmview_label_add(Eo *parent, const char* str)
{
   Eo *label;
   char buf[NAME_MAX] = {0};
   sprintf(buf, "<font_size=12>%s</font_size>", str);
   label = eo_add(ELM_LABEL_CLASS, parent);
   eo_do(label, elm_obj_widget_part_text_set(NULL, buf));
   eo_do(label, evas_obj_visibility_set(EINA_TRUE),
         evas_obj_size_hint_weight_set(1, 0.0),
         evas_obj_size_hint_align_set(EVAS_HINT_FILL, 0));
   return label;
}

/* Helper func to create entry */
static Eo*
_rmview_entry_add(Eo *parent, const char* str)
{
   Eo *en;
   en = eo_add(ELM_ENTRY_CLASS, parent);
   eo_do(en,
         elm_obj_entry_scrollable_set(EINA_TRUE),
         evas_obj_size_hint_weight_set(1, 0.0),
         evas_obj_size_hint_align_set(EVAS_HINT_FILL, 0),
         elm_obj_widget_part_text_set(NULL, str),
         elm_interface_scrollable_policy_set(ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF),
         elm_obj_entry_single_line_set(EINA_TRUE),
         elm_obj_entry_text_style_user_push("DEFAULT='color=#FFFFFF'"),
         evas_obj_visibility_set(EINA_TRUE));
   return en;
}

/* Helper func to create fileselector entry */
static Eo*
_rmview_fs_entry_add(Eo *parent, const char* str)
{
   Eo *en;
   en = eo_add(ELM_FILESELECTOR_ENTRY_CLASS, parent);
   eo_do(en,
         evas_obj_size_hint_weight_set(1, 0.0),
         evas_obj_size_hint_align_set(EVAS_HINT_FILL, 0),
         elm_obj_widget_part_text_set(NULL, str),
         evas_obj_visibility_set(EINA_TRUE));
   return en;
}

/* Helper func to create button */
static Eo*
_rmview_button_add(Eo *parent, const char* str)
{
   Eo *bt;
   bt = eo_add(ELM_BUTTON_CLASS, parent);
   eo_do(bt, evas_obj_visibility_set(EINA_TRUE));
   if (str)
     eo_do(bt, elm_obj_widget_part_text_set(NULL, str));
   return bt;
}

/* Helper func to create box */
static Eo *
_rmview_box_add(Eo *parent, Eina_Bool horiz)
{
   Eo *box = eo_add(ELM_BOX_CLASS, parent);
   eo_do(box,
            evas_obj_visibility_set(EINA_TRUE),
            evas_obj_size_hint_weight_set(1, 0.0),
            evas_obj_size_hint_align_set(EVAS_HINT_FILL, 0),
            elm_obj_box_horizontal_set(horiz));
   return box;
}

/* Callback on entry change.
 * Used to enable/disable SAVE button. */
static Eina_Bool
_res_changed(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Rmview_Field_Data *f_data;
   eo_do(obj, f_data = eo_key_data_get(_STR_RMVIEW));
   Eo *entry_field = NULL;
   const char *res_str = NULL, *str;
   switch (f_data->idx)
     {
      case 0:
           {
              entry_field = f_data->it_data->en1;
              eo_do(entry_field, str = elm_obj_widget_part_text_get(NULL));
              res_str = resource_name_get(f_data->it_data->res);
              /* Set bit, in order to know if change needed */
              if (strcmp(str, res_str))
                {
                   f_data->it_data->changed |= (1 << 0);
                }
              else
                {
                   f_data->it_data->changed &= ~(1 << 0);
                }

              break;
           }
      case 1:
           {
              Gui_Resource_Type res_type = resource_type_get(f_data->it_data->res);
              if (res_type == RESOURCE_IMAGE || res_type == RESOURCE_EDJE)
                {
                   entry_field = f_data->it_data->en2;
                   eo_do(entry_field, str = elm_interface_fileselector_path_get());
                   res_str = resource_value_get(f_data->it_data->res);
                   /* Set bit, in order to know if change needed */
                   if (strcmp(str, res_str))
                     {
                        f_data->it_data->changed |= (1 << 1);
                     }
                   else
                     {
                        f_data->it_data->changed &= ~(1 << 1);
                     }
                }
              else
                {
                   entry_field = f_data->it_data->en2;
                   eo_do(entry_field, str = elm_obj_widget_part_text_get(NULL));
                   res_str = resource_value_get(f_data->it_data->res);
                   /* Set bit, in order to know if change needed */
                   if (strcmp(str, res_str))
                     {
                        f_data->it_data->changed |= (1 << 1);
                     }
                   else
                     {
                        f_data->it_data->changed &= ~(1 << 1);
                     }
                }
              break;
           }
      case 2:
           {
              Gui_Resource_Type res_type = resource_type_get(f_data->it_data->res);
              if (res_type == RESOURCE_EDJE)
                {
                   entry_field = f_data->it_data->en3;
                   eo_do(entry_field, str = elm_interface_fileselector_path_get());
                   res_str = resource_edc_path_get(f_data->it_data->res);
                   /* Set bit, in order to know if change needed */
                   if (strcmp(str, res_str))
                     {
                        f_data->it_data->changed |= (1 << 2);
                     }
                   else
                     {
                        f_data->it_data->changed &= ~(1 << 2);
                     }
                }
              break;
           }
      default:
           {
              ERR("switch - default: %d", f_data->idx);
           }
     }

   eo_do(f_data->it_data->bt_save, elm_obj_widget_disabled_set(!f_data->it_data->changed));
   return EO_CALLBACK_CONTINUE;
}

#ifdef HAVE_ENVENTOR
static Eina_Bool
_enventor_clicked(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Rmview_Field_Data *f_data = eo_do(obj, eo_key_data_get(_STR_RMVIEW));
   const char *edc_file = eo_do(f_data->it_data->en3, elm_interface_fileselector_path_get());
   if (strlen(edc_file))
     {
        Eina_Stringshare *path = gui_context_project_path_get(resource_context_get(f_data->it_data->res));
        Eina_Strbuf *strbuf = eina_strbuf_new();
        Ecore_Exe_Flags flags =
           (ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_PIPE_READ |
            ECORE_EXE_PIPE_ERROR_LINE_BUFFERED | ECORE_EXE_PIPE_ERROR);

        eina_strbuf_append_printf(strbuf, "enventor %s", edc_file);
        eina_strbuf_append_printf(strbuf, " -id %s/images", path);
        eina_strbuf_append_printf(strbuf, " -sd %s/sounds", path);
        eina_strbuf_append_printf(strbuf, " -fd %s/fonts", path);
        eina_strbuf_append_printf(strbuf, " -dd %s/data", path);

        ecore_exe_pipe_run(eina_strbuf_string_get(strbuf), flags, NULL);

        //printf("%s\n", eina_strbuf_string_get(strbuf));
        eina_strbuf_free(strbuf);
     }
   return EO_CALLBACK_CONTINUE;
}
#endif

/* callback on sve_button 'clicked' event */
static Eina_Bool
_bt_save_clicked(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Rmview_Field_Data *f_data;
   const char *str = NULL, *res_name;
   Eina_Bool status = EINA_TRUE;
   eo_do(obj, f_data = eo_key_data_get(_STR_RMVIEW));
   Gui_Resource *res = f_data->it_data->res;
   Gui_Resource_Type res_type = resource_type_get(res);
   const Gui_Context *ctx = resource_context_get(res);

   eo_do(f_data->it_data->en1, str = elm_obj_widget_part_text_get(NULL));
   res_name = resource_name_get(res);
   if (strcmp(str, res_name))
     {
        Eid *eid = resource_eid_get(res);

        if (!eid_rename(eid, str))
          {
             ERR("Resource \"%s\" already exists!", str);
             status = EINA_FALSE;
          }
     }

   /* For IMAGE take data from fileselector. */
   if (res_type == RESOURCE_IMAGE)
     {
        eo_do(f_data->it_data->en2, str = elm_interface_fileselector_path_get());
        if (strlen(str))
          {
             resource_value_set(res, str);
          }
        else
          {
             eo_do(f_data->it_data->en2, elm_interface_fileselector_path_set(resource_value_get(res)));
          }
        const Gui_Widget *wdg  = gui_context_data_get(ctx, SELECTED_WDG);
        proplayout_build(wdg);
     }
   /* For EDJE take data from fileselector. */
   else if (res_type == RESOURCE_EDJE)
     {
        eo_do(f_data->it_data->en2, str = elm_interface_fileselector_path_get());
        if (strlen(str))
          {
             resource_edj_path_set(res, str);
          }
        else
          {
             eo_do(f_data->it_data->en2, elm_interface_fileselector_path_set(resource_edj_path_get(res)));
          }
        eo_do(f_data->it_data->en3, str = elm_interface_fileselector_path_get());
        resource_edc_path_set(res, str);
        const Gui_Widget *wdg  = gui_context_data_get(ctx, SELECTED_WDG);
        proplayout_build(wdg);
        observers_invoke(resource_eid_get(res));
     }
   /* For CALLBACKS and STRINGS. */
   else
     {
        eo_do(f_data->it_data->en2, str = elm_obj_widget_part_text_get(NULL));
        if (strlen(str))
          {
             resource_value_set(res, str);
          }
     }

   if (status)
     eo_do(obj, elm_obj_widget_disabled_set(EINA_TRUE));

   return EO_CALLBACK_CONTINUE;
}

/* callback on del_button 'clicked' event */
static Eina_Bool
_bt_del_clicked(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Rmview_Field_Data *f_data;

   eo_do(obj, f_data = eo_key_data_get(_STR_RMVIEW));

   Gui_Resource *res = f_data->it_data->res;
   Eid *eid = resource_eid_get(res);

   eid_del(eid);
   resource_del(res);
   _rmview_build(_rmview_toolbar_selected_type);

   return EO_CALLBACK_CONTINUE;
}

static void
_rmview_build(Rmview_Resource_Type type)
{
   Gui_Context *ctx = _active_context_get();
   Eo *label, *en, *bt;
   const char *header1 = NULL, *header2 = NULL;
   Gui_Resource_Type type_start, type_end, type_itr;
   eo_do(g_rm_win->rm_table, elm_obj_table_clear(EINA_TRUE));

   switch (type)
     {
      case RMVIEW_IMAGE:
           {
              header1 = "Alias";
              header2 = "Image path";
              type_start = RESOURCE_IMAGE;
              type_end = RESOURCE_IMAGE + 1;
              break;
           }
      case RMVIEW_EDJE:
           {
              header1 = "Alias";
              header2 = "Paths";
              type_start = RESOURCE_EDJE;
              type_end = RESOURCE_EDJE + 1;
              break;
           }
      case RMVIEW_CALLBACK:
           {
              header1 = "Alias";
              header2 = "Callback name";
              type_start = RESOURCE_EO_CALLBACK;
              type_end = RESOURCE_EO_CALLBACK + 1;
              break;
           }
      case RMVIEW_STRING:
           {
              header1 = "Alias";
              header2 = "String";
              type_start = RESOURCE_STRING;
              type_end = RESOURCE_STRING + 1;
              break;
           }
      default:
           {
              ERR("switch default");
              break;
           }
     }
   label = _rmview_label_add(g_rm_win->rm_table, header1);
   eo_do(g_rm_win->rm_table, elm_obj_table_pack(label, 0, 0, 1, 1));

   label = _rmview_label_add(g_rm_win->rm_table, header2);
   eo_do(g_rm_win->rm_table, elm_obj_table_pack(label, 1, 0, 1, 1));

   Eina_List *itr;
   Eid *res_id;

   int table_line = 1;
   int table_col = 0;
   for (type_itr = type_start; type_itr < type_end; type_itr++)
     {
        Eina_List *lst = (Eina_List *) gui_context_resource_list_get(ctx, type_itr);
        if (!lst) continue;
        EINA_LIST_FOREACH(lst, itr, res_id)
          {
             const Gui_Resource *res = resource_get_from_id(res_id);
             table_col = 0;
             const char *res_name, *value;
             Rmview_Field_Data *data;
             Gui_Resource_Type res_type;
             res_name = resource_name_get(res);
             value = resource_value_get(res);
             res_type = resource_type_get(res);

             Rmview_Item_Data *it_data = calloc(1, sizeof(Rmview_Item_Data));
             it_data->res = (Gui_Resource *)res;

             en = _rmview_entry_add(g_rm_win->rm_table,res_name);
             elm_object_tooltip_text_set(en, "Alias name");
             it_data->en1 = en;
             eo_do(g_rm_win->rm_table, elm_obj_table_pack(en, table_col++, table_line, 1, 1));
             data = RMVIEW_FIELD_DATA_BUILD(0, it_data);

             eo_do(en, eo_key_data_set(_STR_RMVIEW, data, _field_data_free));
             eo_do(en, eo_event_callback_add(ELM_ENTRY_EVENT_CHANGED_USER, _res_changed, NULL));

             switch (res_type)
               {
                  /* Add fields specific to CALLBACKs */
                case RESOURCE_EO_CALLBACK:
                     {
                        en = _rmview_entry_add(g_rm_win->rm_table, value);
                        elm_object_tooltip_text_set(en, "Callback name");
                        it_data->en2 = en;
                        eo_do(g_rm_win->rm_table, elm_obj_table_pack(en, table_col++, table_line, 1, 1));
                        data = RMVIEW_FIELD_DATA_BUILD(1, it_data);
                        eo_do(en, eo_key_data_set(_STR_RMVIEW, data, _field_data_free));
                        eo_do(en, eo_event_callback_add(ELM_ENTRY_EVENT_CHANGED_USER, _res_changed, NULL));
                        break;
                     }
                  /* Add field (fileselector entry) specific to IMAGE */
                case RESOURCE_IMAGE:
                     {
                        en = _rmview_fs_entry_add(g_rm_win->rm_table, "...");
                        elm_object_tooltip_text_set(en, "Image path");
                        eo_do(en, elm_interface_fileselector_path_set(value));

                        it_data->en2 = en;
                        eo_do(g_rm_win->rm_table, elm_obj_table_pack(en, table_col++, table_line, 1, 1));
                        data = RMVIEW_FIELD_DATA_BUILD(1, it_data);
                        eo_do(en, eo_key_data_set(_STR_RMVIEW, data, _field_data_free));
                        eo_do(en, eo_event_callback_add(ELM_FILESELECTOR_ENTRY_EVENT_CHANGED, _res_changed, NULL));
                        break;
                     }
                  /* Add field (double entry) specific to EDJE */
                case RESOURCE_EDJE:
                     {
                        Eo *box = _rmview_box_add(g_rm_win->rm_table, EINA_FALSE);

                        en = _rmview_fs_entry_add(box, "...");
                        elm_object_tooltip_text_set(en, "Edj file path");
                        value = resource_edj_path_get(res);
                        eo_do(en, elm_interface_fileselector_path_set(value));
                        eo_do(en, eo_event_callback_add(ELM_FILESELECTOR_ENTRY_EVENT_CHANGED, _res_changed, NULL));
                        data = RMVIEW_FIELD_DATA_BUILD(1, it_data);
                        eo_do(en, eo_key_data_set(_STR_RMVIEW, data, _field_data_free));
                        eo_do(box, elm_obj_box_pack_end(en));
                        it_data->en2 = en;

                        en = _rmview_fs_entry_add(box, "...");
                        elm_object_tooltip_text_set(en, "Edc file path");
                        value = resource_edc_path_get(res);
                        eo_do(en, elm_interface_fileselector_path_set(value));
                        eo_do(en, eo_event_callback_add(ELM_FILESELECTOR_ENTRY_EVENT_CHANGED, _res_changed, NULL));
                        data = RMVIEW_FIELD_DATA_BUILD(2, it_data);
                        eo_do(en, eo_key_data_set(_STR_RMVIEW, data, _field_data_free));
                        eo_do(box, elm_obj_box_pack_end(en));
                        it_data->en3 = en;

                        eo_do(g_rm_win->rm_table, elm_obj_table_pack(box, table_col++, table_line, 1, 1));
                        break;
                     }
                  /* Add field (entry) specific to STRING */
                case RESOURCE_STRING:
                     {
                        en = _rmview_entry_add(g_rm_win->rm_table, value);
                        elm_object_tooltip_text_set(en, "Value");
                        it_data->en2 = en;
                        eo_do(g_rm_win->rm_table, elm_obj_table_pack(en, table_col++, table_line, 1, 1));
                        data = RMVIEW_FIELD_DATA_BUILD(1, it_data);
                        eo_do(en, eo_key_data_set(_STR_RMVIEW, data, _field_data_free));
                        eo_do(en, eo_event_callback_add(ELM_ENTRY_EVENT_CHANGED_USER, _res_changed, NULL));
                        break;
                     }
                case RESOURCE_SENTINEL:
                     {
                        break;
                     }
               }

#ifdef HAVE_ENVENTOR
             if (res_type == RESOURCE_EDJE)
               {
                  Eo *icon = elm_image_add(g_rm_win->rm_table);
                  eo_do(icon,
                        efl_file_set(PACKAGE_DATA_DIR"/images/enventor_icon.png", NULL),
                        evas_obj_size_hint_min_set(25, 25),
                        elm_obj_image_resizable_set(EINA_TRUE, EINA_TRUE),
                        evas_obj_visibility_set(EINA_TRUE)
                       );
                  bt = _rmview_button_add(g_rm_win->rm_table, "");
                  eo_do(bt,
                        elm_obj_container_content_set("icon", icon),
                        elm_obj_widget_disabled_set(EINA_FALSE)
                       );
                  eo_do(g_rm_win->rm_table, elm_obj_table_pack(bt, table_col++, table_line, 1, 1));

                  data = RMVIEW_FIELD_DATA_BUILD(2, it_data);
                  eo_do(bt, eo_key_data_set(_STR_RMVIEW, data, _field_data_free));
                  eo_do(bt, eo_event_callback_add(EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _enventor_clicked, NULL));
               }
#endif

             bt = _rmview_button_add(g_rm_win->rm_table, "save");
             it_data->bt_save = bt;
             eo_do(bt, elm_obj_widget_disabled_set(EINA_TRUE));
             eo_do(bt, eo_event_callback_add(EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _bt_save_clicked, NULL));

             eo_do(g_rm_win->rm_table, elm_obj_table_pack(bt, table_col++, table_line, 1, 1));
             data = RMVIEW_FIELD_DATA_BUILD(2, it_data);
             eo_do(bt, eo_key_data_set(_STR_RMVIEW, data, _field_data_free));

             bt = _rmview_button_add(g_rm_win->rm_table, "del");
             eo_do(bt, eo_event_callback_add(EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _bt_del_clicked, NULL));

             eo_do(g_rm_win->rm_table, elm_obj_table_pack(bt, table_col++, table_line, 1, 1));
             data = RMVIEW_FIELD_DATA_BUILD(3, it_data);
             eo_do(bt, eo_key_data_set(_STR_RMVIEW, data, _field_data_free));

             table_line++;
          }
     }
   /* Adding last line of buttons to add new resources. */
     {
        eo_do(g_rm_win->rm_buttons_box, elm_obj_box_unpack_all());
        eo_do(g_rm_win->rm_buttons_box, elm_obj_box_pack_end(g_rm_win->rm_alias_entry));

        eo_do(g_rm_win->rm_value_entry, evas_obj_visibility_set(EINA_FALSE));
        eo_do(g_rm_win->rm_image_fileselector, evas_obj_visibility_set(EINA_FALSE));
        eo_do(g_rm_win->rm_edje_box, evas_obj_visibility_set(EINA_FALSE));
        eo_do(g_rm_win->rm_edje_fs_edj, evas_obj_visibility_set(EINA_FALSE));
        eo_do(g_rm_win->rm_edje_fs_edc, evas_obj_visibility_set(EINA_FALSE));

        switch (_rmview_toolbar_selected_type )
          {
           case RMVIEW_IMAGE:
                {
                   eo_do(g_rm_win->rm_image_fileselector, evas_obj_visibility_set(EINA_TRUE));
                   eo_do(g_rm_win->rm_buttons_box, elm_obj_box_pack_end(g_rm_win->rm_image_fileselector));
                   break;
                }
           case RMVIEW_CALLBACK:
                {
                   eo_do(g_rm_win->rm_value_entry, evas_obj_visibility_set(EINA_TRUE));
                   eo_do(g_rm_win->rm_buttons_box, elm_obj_box_pack_end(g_rm_win->rm_value_entry));
                   break;
                }
           case RMVIEW_EDJE:
                {
                   eo_do(g_rm_win->rm_edje_box, evas_obj_visibility_set(EINA_TRUE));
                   eo_do(g_rm_win->rm_edje_fs_edj, evas_obj_visibility_set(EINA_TRUE));
                   eo_do(g_rm_win->rm_edje_fs_edc, evas_obj_visibility_set(EINA_TRUE));
                   eo_do(g_rm_win->rm_buttons_box, elm_obj_box_pack_end(g_rm_win->rm_edje_box));
                   break;
                }
           case RMVIEW_STRING:
                {
                   eo_do(g_rm_win->rm_value_entry, evas_obj_visibility_set(EINA_TRUE));
                   eo_do(g_rm_win->rm_buttons_box, elm_obj_box_pack_end(g_rm_win->rm_value_entry));
                   break;
                }
           default:
                {
                   ERR("switch - default: %d", _rmview_toolbar_selected_type);
                }
          }

        eo_do(g_rm_win->rm_buttons_box, elm_obj_box_pack_end(g_rm_win->rm_button_add));
     }
}

/* Delete window callback. */
Eina_Bool
_rm_win_request_delete(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   _rmview_toolbar_selected_type = RMVIEW_NOT_SELECTED;
   return EO_CALLBACK_CONTINUE;
}

/* Callback called, when toolbar item is clicked */
static void
_rmview_toolbar_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Rmview_Resource_Type type = (int) (intptr_t) data;

   if (_rmview_toolbar_selected_type == type)
     return;
   _rmview_toolbar_selected_type = type;

   _rmview_build(type);
}

/* "Add Resource" button's "clicked" callback." */
Eina_Bool
_rm_add_button_clicked(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Gui_Resource_Type res_type;
   const char *alias_str = NULL, *value_str = NULL;
   const Gui_Context *ctx = _active_context_get();
   eo_do(g_rm_win->rm_alias_entry, alias_str = elm_obj_widget_part_text_get(NULL));

   if (!strlen(alias_str))
     return EO_CALLBACK_CONTINUE;

   if (gui_context_eid_get_by_name(ctx, alias_str))
     {
        ERR("Resource \"%s\" already exists", alias_str);
        return EO_CALLBACK_CONTINUE;
     }

   Gui_Resource *gui_res;

   switch (_rmview_toolbar_selected_type)
     {
      case RMVIEW_IMAGE:
           {
              res_type = RESOURCE_IMAGE;
              break;
           }
      case RMVIEW_STRING:
           {
              res_type = RESOURCE_STRING;
              break;
           }
      case RMVIEW_EDJE:
           {
              res_type = RESOURCE_EDJE;
              break;
           }
      case RMVIEW_CALLBACK:
           {
              res_type = RESOURCE_EO_CALLBACK;
              break;
           }
      default:
           {
              ERR("switch - default: %d", _rmview_toolbar_selected_type);
           }
     }

   /* For CALLBACKS and STRINGS: check that value str is not empty. */
   if ((res_type != RESOURCE_IMAGE) && (res_type != RESOURCE_EDJE))
     {
        eo_do(g_rm_win->rm_value_entry, value_str = elm_obj_widget_part_text_get(NULL));
        if (!strlen(value_str))
          return EO_CALLBACK_CONTINUE;
     }
   /* For IMAGES: check that path is not empty. */
   else if (res_type == RESOURCE_IMAGE)
     {
        eo_do(g_rm_win->rm_image_fileselector, value_str = elm_interface_fileselector_path_get());
        if (!strlen(value_str))
          return EO_CALLBACK_CONTINUE;
     }
   /* For EDJES: check that edj path is not empty. */
   else if (res_type == RESOURCE_EDJE)
     {
        eo_do(g_rm_win->rm_edje_fs_edj, value_str = elm_interface_fileselector_path_get());
        if (!strlen(value_str))
          return EO_CALLBACK_CONTINUE;
     }

   gui_res = gui_context_resource_new((Gui_Context *) ctx, res_type, alias_str);
   if (!gui_res)
     {
        ERR("Cannot create resource of type: %d for alias %s", res_type, alias_str);
        return EO_CALLBACK_CONTINUE;
     }

   if (res_type == RESOURCE_IMAGE || res_type == RESOURCE_EDJE)
     {
        resource_value_set(gui_res, value_str);
        if (res_type == RESOURCE_EDJE)
          {
             resource_edc_path_set(gui_res, eo_do(g_rm_win->rm_edje_fs_edc, elm_interface_fileselector_path_get()));
             resource_edj_path_set(gui_res, value_str);
             eo_do(g_rm_win->rm_edje_fs_edc, elm_obj_widget_part_text_set(NULL, NULL));
             eo_do(g_rm_win->rm_edje_fs_edj, elm_obj_widget_part_text_set(NULL, NULL));
          }
        const Gui_Widget *wdg  = gui_context_data_get(ctx, SELECTED_WDG);
        proplayout_build(wdg);
     }
   else
     {
        resource_value_set(gui_res, value_str);
     }

   _rmview_build(_rmview_toolbar_selected_type);
   eo_do(g_rm_win->rm_image_fileselector, elm_interface_fileselector_path_set(getenv("HOME")));
   eo_do(g_rm_win->rm_alias_entry, elm_obj_widget_part_text_set(NULL, NULL));
   eo_do(g_rm_win->rm_value_entry, elm_obj_widget_part_text_set(NULL, NULL));
   return EO_CALLBACK_CONTINUE;
}

/* This callback is called in the end of creation of RM view window. */
void
rm_win_post_configure()
{
   eo_do(g_rm_win->rm_toolbar, elm_obj_toolbar_item_append("emblem-photos", "Images",
                                                    _rmview_toolbar_clicked, (void *) (intptr_t) RMVIEW_IMAGE));
   eo_do(g_rm_win->rm_toolbar, elm_obj_toolbar_item_append("emblem-photos", "Edjes",
                                                    _rmview_toolbar_clicked, (void *) (intptr_t) RMVIEW_EDJE));
   eo_do(g_rm_win->rm_toolbar, elm_obj_toolbar_item_append("call-start", "Callbacks",
                                                    _rmview_toolbar_clicked, (void *) (intptr_t) RMVIEW_CALLBACK));
   eo_do(g_rm_win->rm_toolbar, elm_obj_toolbar_item_append("format-text-bold", "Strings",
                                                    _rmview_toolbar_clicked, (void *) (intptr_t) RMVIEW_STRING));
   elm_object_tooltip_text_set(g_rm_win->rm_alias_entry, "Alias name");
   elm_object_tooltip_text_set(g_rm_win->rm_value_entry, "Value");
   elm_object_tooltip_text_set(g_rm_win->rm_edje_fs_edj, "Edj file name");
   elm_object_tooltip_text_set(g_rm_win->rm_edje_fs_edc, "Edc file name");
   elm_object_tooltip_text_set(g_rm_win->rm_image_fileselector, "Image path");
}