summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2015-10-23 17:25:42 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-10-23 17:25:42 +0900
commita94ebf9451bc37fadeb6b1f56fd57f62f7384e53 (patch)
treefc1df17e9da1b272760b68aa1f6992ae7b402712
parent7caf4f701cce0d29cd5b96760cb3ee7af5f068ea (diff)
save on exit with popupHEADmaster
-rw-r--r--lib/eynote.c16
-rw-r--r--lib/eynote.eo5
-rw-r--r--lib/eynote_widget.c16
-rw-r--r--lib/utils.h1
-rw-r--r--main.c161
5 files changed, 157 insertions, 42 deletions
diff --git a/lib/eynote.c b/lib/eynote.c
index 0778209..2f986c3 100644
--- a/lib/eynote.c
+++ b/lib/eynote.c
@@ -453,9 +453,7 @@ _key_up(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *eve
453 return; 453 return;
454 } 454 }
455 } 455 }
456 // FIXME: Save on exit? 456 eo_do(pd->self, eo_event_callback_call(EYNOTE_EVENT_REQUEST_CLOSE, NULL));
457 //eo_del(pd->self); // BROKEN
458 elm_exit();
459 } 457 }
460 else if (!strcmp(ev->key, KEY_PAGE_UP) || !strcmp(ev->key, KEY_KP_PAGE_UP) || 458 else if (!strcmp(ev->key, KEY_PAGE_UP) || !strcmp(ev->key, KEY_KP_PAGE_UP) ||
461 !strcmp(ev->key, KEY_UP) || !strcmp(ev->key, KEY_KP_UP)) 459 !strcmp(ev->key, KEY_UP) || !strcmp(ev->key, KEY_KP_UP))
@@ -610,7 +608,11 @@ _eynote_efl_file_save(const Eo *obj, Eynote_Data *pd EINA_UNUSED, const char *fi
610 err = eet_close(ef); 608 err = eet_close(ef);
611 609
612 if (err == EET_ERROR_NONE) 610 if (err == EET_ERROR_NONE)
613 eo_do(pd->self, eynote_notify(_("Saved successfully"), false)); 611 {
612 eo_do(pd->self,
613 eynote_notify(_("Saved successfully"), false);
614 eo_event_callback_call(EYNOTE_EVENT_SAVED, (void *) pd->file));
615 }
614 else 616 else
615 eo_do(pd->self, eynote_notify(_("Error while saving!"), true)); 617 eo_do(pd->self, eynote_notify(_("Error while saving!"), true));
616 618
@@ -756,4 +758,10 @@ _eynote_config_get(Eo *obj EINA_UNUSED, Eynote_Data *pd)
756 return pd->cfg; 758 return pd->cfg;
757} 759}
758 760
761EOLIAN static void
762_eynote_save_request(Eo *obj EINA_UNUSED, Eynote_Data *pd)
763{
764 _eynote_save(pd, true);
765}
766
759#include "eynote.eo.c" 767#include "eynote.eo.c"
diff --git a/lib/eynote.eo b/lib/eynote.eo
index 35138b6..a7e3a0f 100644
--- a/lib/eynote.eo
+++ b/lib/eynote.eo
@@ -48,6 +48,7 @@ class Eynote(Elm.Layout, Efl.File, Serializable)
48 get {} 48 get {}
49 values { cfg: Config *; } 49 values { cfg: Config *; }
50 } 50 }
51 save_request {}
51 } 52 }
52 implements { 53 implements {
53 Eo.Base.constructor; 54 Eo.Base.constructor;
@@ -58,4 +59,8 @@ class Eynote(Elm.Layout, Efl.File, Serializable)
58 Serializable.serialize; 59 Serializable.serialize;
59 Serializable.deserialize; 60 Serializable.deserialize;
60 } 61 }
62 events {
63 request,close;
64 saved;
65 }
61} 66}
diff --git a/lib/eynote_widget.c b/lib/eynote_widget.c
index c52d7c6..fd610c3 100644
--- a/lib/eynote_widget.c
+++ b/lib/eynote_widget.c
@@ -328,15 +328,15 @@ _eynote_widget_snap(Eo *obj, Eynote_Widget_Data *pd, Eina_Bool real_geom)
328 if (pd->move.resizing_left) 328 if (pd->move.resizing_left)
329 { 329 {
330 if (x <= pd->move.geom_orig_x) 330 if (x <= pd->move.geom_orig_x)
331 col = x * gw / sw; 331 col = (x - sx) * gw / sw;
332 else 332 else
333 col = (x + snapx / 2) * gw / sw; 333 col = (x - sx + snapx / 2) * gw / sw;
334 nx = col * sw / gw; 334 nx = col * sw / gw;
335 colspan = (w + x - nx + snapx / 2) * gw / sw; 335 colspan = (w + x - sx - nx + snapx / 2) * gw / sw;
336 } 336 }
337 else 337 else
338 { 338 {
339 col = (x + snapx / 2) * gw / sw; 339 col = (x - sx + snapx / 2) * gw / sw;
340 if (w < pd->move.geom_orig_w) 340 if (w < pd->move.geom_orig_w)
341 colspan = w * gw / sw; 341 colspan = w * gw / sw;
342 else 342 else
@@ -345,15 +345,15 @@ _eynote_widget_snap(Eo *obj, Eynote_Widget_Data *pd, Eina_Bool real_geom)
345 if (pd->move.resizing_top) 345 if (pd->move.resizing_top)
346 { 346 {
347 if (y <= pd->move.geom_orig_y) 347 if (y <= pd->move.geom_orig_y)
348 row = y * gh / sh; 348 row = (y - sy) * gh / sh;
349 else 349 else
350 row = (y + snapy / 2) * gh / sh; 350 row = (y - sy + snapy / 2) * gh / sh;
351 ny = row * sh / gh; 351 ny = row * sh / gh;
352 rowspan = (h + y - ny + snapy / 2) * gh / sh; 352 rowspan = (h + y - sy - ny + snapy / 2) * gh / sh;
353 } 353 }
354 else 354 else
355 { 355 {
356 row = (y + snapy / 2) * gh / sh; 356 row = (y - sy + snapy / 2) * gh / sh;
357 if (h < pd->move.geom_orig_h) 357 if (h < pd->move.geom_orig_h)
358 rowspan = h * gh / sh; 358 rowspan = h * gh / sh;
359 else 359 else
diff --git a/lib/utils.h b/lib/utils.h
index 32076f4..a865361 100644
--- a/lib/utils.h
+++ b/lib/utils.h
@@ -92,6 +92,7 @@ __sprintfx(char *a, size_t sz, const char *fmt, ...)
92#define KEY_S "s" 92#define KEY_S "s"
93#define KEY_T "t" 93#define KEY_T "t"
94#define KEY_W "w" 94#define KEY_W "w"
95#define KEY_F11 "F11"
95#define KEY_CTRL "Control" 96#define KEY_CTRL "Control"
96#define KEY_SHIFT "Shift" 97#define KEY_SHIFT "Shift"
97 98
diff --git a/main.c b/main.c
index 523f237..c2fb744 100644
--- a/main.c
+++ b/main.c
@@ -1,49 +1,150 @@
1#include <eynote.h> 1#include <eynote.h>
2 2
3/* 3typedef struct {
4 Elm_Win *win;
5 Elm_Bg *bg;
6 Eynote *note;
7 Elm_Popup *popup;
8} App_Private_Data;
9
4static Eina_Bool 10static Eina_Bool
5_note_del_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) 11_saved_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
12{
13 App_Private_Data *pd = data;
14
15 eo_del(pd->win);
16 return true;
17}
18
19static void
20_popup_save_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
21{
22 App_Private_Data *pd = data;
23 const char *file = NULL, *key;
24
25 eo_del(pd->popup);
26 if (!pd->note)
27 eo_del(pd->win);
28
29 eo_do(pd->note, efl_file_get(&file, &key));
30
31 eo_do(pd->note, eo_event_callback_add(EYNOTE_EVENT_SAVED, _saved_cb, pd));
32 if (file)
33 eo_do(pd->note, efl_file_save(file, key, NULL));
34 else
35 eo_do(pd->note, eynote_save_request());
36}
37
38static void
39_popup_discard_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
6{ 40{
7 INF("Good bye"); 41 App_Private_Data *pd = data;
8 eo_do(obj, eo_parent_set(NULL)); 42
9 evas_damage_rectangle_add(E(obj), 0, 0, 2000, 2000); 43 eo_del(pd->popup);
10 //eo_del(data); 44 eo_del(pd->win);
11 return EO_CALLBACK_STOP; 45}
46
47static void
48_popup_cancel_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
49{
50 App_Private_Data *pd = data;
51
52 eo_del(pd->popup);
53}
54
55static void
56_ask_save_popup(App_Private_Data *pd)
57{
58 Elm_Popup *popup;
59 Evas_Object *btn;
60
61 popup = elm_popup_add(pd->win);
62 pd->popup = popup;
63
64 elm_object_part_text_set(popup, "title,text", _("Au revoir!"));
65 elm_object_text_set(popup, _("Do you want to save before leaving?"));
66
67 btn = elm_button_add(popup);
68 elm_object_text_set(btn, _("Save & Exit"));
69 elm_object_part_content_set(popup, "button1", btn);
70 evas_object_smart_callback_add(btn, "clicked", _popup_save_cb, pd);
71
72 btn = elm_button_add(popup);
73 elm_object_text_set(btn, _("Discard & Exit"));
74 elm_object_part_content_set(popup, "button2", btn);
75 evas_object_smart_callback_add(btn, "clicked", _popup_discard_cb, pd);
76
77 btn = elm_button_add(popup);
78 elm_object_text_set(btn, _("Cancel"));
79 elm_object_part_content_set(popup, "button3", btn);
80 evas_object_smart_callback_add(btn, "clicked", _popup_cancel_cb, pd);
81
82 SX(btn);
83 SX(popup);
84}
85
86static void
87_key_up(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
88{
89 Evas_Event_Key_Up *ev = event_info;
90 App_Private_Data *pd = data;
91
92 if (!strcmp(ev->keyname, KEY_F11))
93 {
94 elm_win_fullscreen_set(pd->win, !elm_win_fullscreen_get(pd->win));
95 return;
96 }
97 else if (!strcmp(ev->key, KEY_ESC))
98 {
99 _ask_save_popup(pd);
100 }
101}
102
103static Eina_Bool
104_request_close(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
105{
106 App_Private_Data *pd = data;
107
108 _ask_save_popup(pd);
109
110 return true;
12} 111}
13*/
14 112
15int 113int
16elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) 114elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
17{ 115{
18 Elm_Win *win; 116 App_Private_Data pd;
19 Eynote *note; 117 bool ok;
20 Elm_Bg *bg;
21 118
22 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); 119 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
23 120
24 win = elm_win_add(NULL, "eynote", ELM_WIN_BASIC); 121 pd.win = elm_win_add(NULL, "eynote", ELM_WIN_BASIC);
25 elm_win_title_set(win, _("Eynote writer")); 122 elm_win_title_set(pd.win, _("Eynote writer"));
26 elm_win_autodel_set(win, true);
27 123
28 bg = elm_bg_add(win); 124 pd.bg = elm_bg_add(pd.win);
29 elm_win_resize_object_add(win, bg); 125 elm_win_resize_object_add(pd.win, pd.bg);
30 126
31 note = eo_add(eynote_class_get(), win); 127 pd.note = eo_add(eynote_class_get(), pd.win);
32 if (argc > 1) 128 if (argc > 1)
33 eo_do(note, efl_file_set(argv[1], NULL)); 129 eo_do(pd.note, efl_file_set(argv[1], NULL));
34 130
35 evas_object_resize(win, 800, 600); 131 evas_object_resize(pd.win, 800, 600);
36 elm_win_resize_object_add(win, note); 132 elm_win_resize_object_add(pd.win, pd.note);
37 SX(note); 133 elm_bg_file_set(pd.bg, eynote_theme(pd.note), EYNOTE_BG_LAYOUT);
38 134
39 elm_bg_file_set(bg, eynote_theme(note), EYNOTE_BG_LAYOUT); 135 ok = true;
40 SX(bg); 136 ok &= evas_object_key_grab(pd.bg, KEY_F11, 0, ~0, true);
137 //ok &= evas_object_key_grab(pd.bg, KEY_ESC, 0, ~0, false);
138 if (!ok) ERR("Failed to grab some keys. No big deal.");
139 evas_object_event_callback_add(pd.bg, EVAS_CALLBACK_KEY_UP, _key_up, &pd);
41 140
42 // FIXME: Eo doesn't give a callback after delete? Fuck me. 141 eo_do(pd.win, eo_event_callback_add(ELM_WIN_EVENT_DELETE_REQUEST, _request_close, &pd));
43 //eo_do(note, eo_event_callback_add(EO_BASE_EVENT_DEL, _note_del_cb, win)); 142 eo_do(pd.note, eo_event_callback_add(EYNOTE_EVENT_REQUEST_CLOSE, _request_close, &pd));
44 143
45 S(win); 144 SX(pd.note);
46 elm_run(); 145 SX(pd.bg);
47 return 0; 146 S(pd.win);
147 elm_run();
148 return 0;
48} 149}
49ELM_MAIN() 150ELM_MAIN()