summaryrefslogtreecommitdiff
path: root/src/bin/egui_gui/settings_view.c
blob: 01b44bf5980546ac401796d6dbd5dac1e41c3956 (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

#include <Elementary.h>
#include "egui_log.h"
#include "settings_view.h"
#include "gui_widget.h"
#include "egui_logic_private.h"

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

static SettingsView_Type _toolbar_selected_type = SETTINGSVIEW_NOT_SELECTED;

static Egui_Layout_Settings_Win_Widgets *g_settings_win = NULL;

void settings_win_set(Egui_Layout_Settings_Win_Widgets *settings_win)
{
   if (g_settings_win) free(g_settings_win);
   g_settings_win = settings_win;
}

/* Enable "Apply" button." */
Eina_Bool
_settings_apply_button_enable(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   eo_do(g_settings_win->settings_button_apply, elm_obj_widget_disabled_set(EINA_FALSE));
   return EO_CALLBACK_CONTINUE;
}

/* Toolbar item clicked callback. */
static void
_settingsview_toolbar_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   SettingsView_Type type = (int) (intptr_t) data;
   if (_toolbar_selected_type == type)
     return;
   _toolbar_selected_type = type;

   const Gui_Context *ctx = _active_context_get();
   eo_do(g_settings_win->project_name_entry, elm_obj_widget_part_text_set(NULL, gui_context_project_name_get(ctx)));
   eo_do(g_settings_win->images_prefix_entry, elm_obj_widget_part_text_set(NULL, gui_context_images_prefix_get(ctx)));
}

/* "Apply" button "clicked" callback." */
Eina_Bool
_settings_apply_button_clicked(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   const Gui_Context *ctx = _active_context_get();
   const char *new_val = NULL, *old_val;
   eo_do(g_settings_win->project_name_entry, new_val = elm_obj_widget_part_text_get(NULL));
   old_val = gui_context_project_name_get(ctx);
   if (!old_val) old_val = "";

   if (strlen(new_val) && (strcmp(new_val, old_val)))
     {
        gui_context_project_name_set((Gui_Context *) ctx, new_val);
     }
   else if (!strlen(new_val))
     {
        eo_do(g_settings_win->project_name_entry, elm_obj_widget_part_text_set(NULL, old_val));
     }

   eo_do(g_settings_win->images_prefix_entry, new_val = elm_obj_widget_part_text_get(NULL));
   old_val = gui_context_images_prefix_get(ctx);

   //if (new_val && old_val && strlen(new_val) && (strcmp(new_val, old_val)))
   /* FIXME add checks */
   if (new_val)
     {
        gui_context_images_prefix_set((Gui_Context *) ctx, new_val);
     }
   else if (!new_val || !strlen(new_val))
     {
        eo_do(g_settings_win->images_prefix_entry, elm_obj_widget_part_text_set(NULL, old_val));
     }

   eo_do(g_settings_win->settings_button_apply, elm_obj_widget_disabled_set(EINA_TRUE));
   return EO_CALLBACK_CONTINUE;
}

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

/* This callback is called in the end of creation of settings view window. */
void
settings_win_post_configure()
{
   eo_do(g_settings_win->settings_toolbar, elm_obj_toolbar_item_append("preferences-system", "Project",
                                                    _settingsview_toolbar_clicked, (void *) (intptr_t) SETTINGSVIEW_MAIN));
}