summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <netstar@gmail.com>2021-04-07 12:45:20 +0100
committerAlastair Poole <netstar@gmail.com>2021-04-07 12:45:20 +0100
commit221fc9dd50fa0f62993f46036946a98fba051abe (patch)
treec3f7f84974307a1acd2f76e263cbf4dba9f1e61e
parente0139c5da992731b4ed00b749879adcd510039af (diff)
alert: move the warning to alerts.
File selector has issues...
-rw-r--r--src/bin/main.c34
-rw-r--r--src/bin/ui/alerts.c26
-rw-r--r--src/bin/ui/file_related.c27
-rw-r--r--src/bin/ui/ui.h20
4 files changed, 61 insertions, 46 deletions
diff --git a/src/bin/main.c b/src/bin/main.c
index c39b69e..199518a 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -394,35 +394,39 @@ _cb_fs_open_done(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
394 ecrire_editor_open(selected, _ent_cfg->font.name, _ent_cfg->font.size); 394 ecrire_editor_open(selected, _ent_cfg->font.name, _ent_cfg->font.size);
395} 395}
396 396
397static void
398_cb_fs_ecrire_editor_save(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
399 void *event_info)
400{
401 Ecrire_Editor *inst = data;
402 const char *filename = event_info;
403
404 if (filename)
405 ecrire_editor_save(inst, filename);
406}
407
397void 408void
398ecrire_editor_save(Ecrire_Editor *inst, const char *file) 409ecrire_editor_save(Ecrire_Editor *inst, const char *file)
399{ 410{
400 Eina_Bool ok; 411 Eina_Bool ok;
401 412
402 if (plain_utf8) 413 if (plain_utf8)
403 ok = file_plain_save(file, elm_object_text_get(inst->entry)); 414 ok = file_plain_save(file, elm_object_text_get(inst->entry));
404 else 415 else
405 ok = file_save(file, elm_object_text_get(inst->entry)); 416 ok = file_save(file, elm_object_text_get(inst->entry));
406 417
407 if (ok) 418 if (!ok)
419 {
420 ui_alert_warning_popup(inst->win, eina_slstr_printf("Unable to save to %s <br>(%s)", file, strerror(errno)));
421 ui_file_open_save_dialog_open(inst->win, EINA_TRUE, _cb_fs_ecrire_editor_save, inst);
422 }
423 else
408 { 424 {
409 elm_object_item_disabled_set(inst->menu.save, EINA_TRUE); 425 elm_object_item_disabled_set(inst->menu.save, EINA_TRUE);
410 elm_object_item_disabled_set(inst->toolbar.save, EINA_TRUE); 426 elm_object_item_disabled_set(inst->toolbar.save, EINA_TRUE);
411 inst->last_saved_stack_ptr = inst->undo_stack_ptr; 427 inst->last_saved_stack_ptr = inst->undo_stack_ptr;
412 _update_cur_file(file, inst); 428 _update_cur_file(file, inst);
413 } 429 }
414 else ERR("couldn't save %s", file);
415}
416
417static void
418_cb_fs_ecrire_editor_save(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
419 void *event_info)
420{
421 Ecrire_Editor *inst = data;
422 const char *filename = event_info;
423
424 if (filename)
425 ecrire_editor_save(inst, filename);
426} 430}
427 431
428static void 432static void
diff --git a/src/bin/ui/alerts.c b/src/bin/ui/alerts.c
index c9b6a6a..a68a352 100644
--- a/src/bin/ui/alerts.c
+++ b/src/bin/ui/alerts.c
@@ -79,3 +79,29 @@ ui_alert_need_saving(Evas_Object *entry, void (*done)(void *data), void *data)
79 elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER); 79 elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
80 evas_object_show(popup); 80 evas_object_show(popup);
81} 81}
82
83static void
84_warning_popup_close_cb(void *data, Evas_Object *obj, void *event_info)
85{
86 evas_object_del((Evas_Object *) data);
87}
88
89void
90ui_alert_warning_popup(Evas_Object *parent, const char *msg)
91{
92 Evas_Object *popup, *btn;
93
94 popup = elm_popup_add(parent);
95 elm_object_part_text_set(popup, "title,text", _("Warning"));
96 elm_object_text_set(popup, eina_slstr_printf("<align=center>%s.</>", msg));
97
98 btn = elm_button_add(popup);
99 elm_object_text_set(btn, _("Close"));
100 evas_object_show(btn);
101 evas_object_smart_callback_add(btn, "clicked", _warning_popup_close_cb, popup);
102 elm_object_part_content_set(popup, "button1", btn);
103
104 elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
105 evas_object_show(popup);
106}
107
diff --git a/src/bin/ui/file_related.c b/src/bin/ui/file_related.c
index ebd868b..ed1b790 100644
--- a/src/bin/ui/file_related.c
+++ b/src/bin/ui/file_related.c
@@ -13,31 +13,6 @@ typedef struct _File_Selector_Data
13} File_Selector_Data; 13} File_Selector_Data;
14 14
15static void 15static void
16_warning_popup_close_cb(void *data, Evas_Object *obj, void *event_info)
17{
18 evas_object_del((Evas_Object *) data);
19}
20
21static void
22_warning_popup(Evas_Object *parent, const char *msg)
23{
24 Evas_Object *popup, *btn;
25
26 popup = elm_popup_add(parent);
27 elm_object_part_text_set(popup, "title,text", _("Warning"));
28 elm_object_text_set(popup, eina_slstr_printf("<align=center>%s.</>", msg));
29
30 btn = elm_button_add(popup);
31 elm_object_text_set(btn, _("Close"));
32 evas_object_show(btn);
33 evas_object_smart_callback_add(btn, "clicked", _warning_popup_close_cb, popup);
34 elm_object_part_content_set(popup, "button1", btn);
35
36 elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
37 evas_object_show(popup);
38}
39
40static void
41_cleaning_cb(void *data, Evas_Object *obj, void *event_info) 16_cleaning_cb(void *data, Evas_Object *obj, void *event_info)
42{ 17{
43 char *path; 18 char *path;
@@ -57,7 +32,7 @@ _cleaning_cb(void *data, Evas_Object *obj, void *event_info)
57 } 32 }
58 33
59 if (error) 34 if (error)
60 _warning_popup(fsdata->parent, error); 35 ui_alert_warning_popup(fsdata->parent, error);
61 else 36 else
62 { 37 {
63 if (path) 38 if (path)
diff --git a/src/bin/ui/ui.h b/src/bin/ui/ui.h
index 65fef8e..3231dbd 100644
--- a/src/bin/ui/ui.h
+++ b/src/bin/ui/ui.h
@@ -3,12 +3,22 @@
3 3
4#include "../Ecrire.h" 4#include "../Ecrire.h"
5 5
6void ui_file_open_save_dialog_open(Evas_Object *parent, Eina_Bool save, Evas_Smart_Cb func, void *data); 6void
7ui_file_open_save_dialog_open(Evas_Object *parent, Eina_Bool save, Evas_Smart_Cb func, void *data);
7 8
8Evas_Object *ui_find_dialog_open(Evas_Object *parent, Ecrire_Editor *inst); 9Evas_Object *
9Evas_Object *ui_goto_dialog_open(Evas_Object *parent, Ecrire_Editor *inst); 10ui_find_dialog_open(Evas_Object *parent, Ecrire_Editor *inst);
10Evas_Object *ui_settings_open(Evas_Object *parent, Ecrire_Editor *inst);
11 11
12void ui_alert_need_saving(Evas_Object *entry, void (*done)(void *data), void *data); 12Evas_Object *
13ui_goto_dialog_open(Evas_Object *parent, Ecrire_Editor *inst);
14
15Evas_Object *
16ui_settings_open(Evas_Object *parent, Ecrire_Editor *inst);
17
18void
19ui_alert_need_saving(Evas_Object *entry, void (*done)(void *data), void *data);
20
21void
22ui_alert_warning_popup(Evas_Object *parent, const char *msg);
13 23
14#endif 24#endif