Ecrire: Added support to save unsaved changes before closing.
Summary: While closing the editor if there are any unsaved changes, then ask if the changes should be saved. If yes, then save the changes. Signed-off-by: Srivardhan Hebbar <sri.hebbar@samsung.com> Reviewers: tasn Differential Revision: https://phab.enlightenment.org/D1436
This commit is contained in:
parent
8bda72dad7
commit
725127adbc
1
TODO
1
TODO
|
@ -1,4 +1,3 @@
|
|||
* Have "you have unsaved changes, do you want to close this without saving?" dialog.
|
||||
* Undo/redo
|
||||
* Also add a stack limit? Replace should also affect undo/redo.
|
||||
* This is just an example policy, should possibly be implemented differently.
|
||||
|
|
|
@ -374,8 +374,8 @@ _fs_open_done(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
|
|||
_load_to_entry(main_ec_ent, selected);
|
||||
}
|
||||
|
||||
static void
|
||||
_save_do(const char *file, Ecrire_Entry *ent)
|
||||
void
|
||||
save_do(const char *file, Ecrire_Entry *ent)
|
||||
{
|
||||
if (plain_utf8)
|
||||
_save_plain_utf8(file, elm_object_text_get(ent->entry));
|
||||
|
@ -395,7 +395,7 @@ _fs_save_done(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
|
|||
|
||||
if (selected)
|
||||
{
|
||||
_save_do(selected, main_ec_ent);
|
||||
save_do(selected, main_ec_ent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -421,15 +421,15 @@ _open(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
|||
}
|
||||
|
||||
void
|
||||
editor_save(Ecrire_Entry *ent)
|
||||
editor_save(Ecrire_Entry *ent, void *callback_func)
|
||||
{
|
||||
if (ent->filename)
|
||||
{
|
||||
_save_do(ent->filename, ent);
|
||||
save_do(ent->filename, ent);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui_file_open_save_dialog_open(ent->win, _fs_save_done, EINA_TRUE);
|
||||
ui_file_open_save_dialog_open(ent->win, callback_func, EINA_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -437,7 +437,7 @@ static void
|
|||
_save(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||
{
|
||||
Ecrire_Entry *ent = data;
|
||||
editor_save(ent);
|
||||
editor_save(ent, _fs_save_done);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -34,7 +34,8 @@ Eina_Bool _save_markup_utf8(const char *file, const char *text);
|
|||
Eina_Bool _save_plain_utf8(const char *file, const char *text);
|
||||
|
||||
void editor_font_choose(Ecrire_Entry *ent, const char *font, int size);
|
||||
void editor_save(Ecrire_Entry *ent);
|
||||
void editor_save(Ecrire_Entry *ent, void *callback_func);
|
||||
void save_do(const char *file, Ecrire_Entry *ent);
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
|
|
|
@ -18,14 +18,26 @@ _discard(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
|||
done_cb(ent);
|
||||
}
|
||||
|
||||
static void
|
||||
_fs_save_done(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
|
||||
void *event_info)
|
||||
{
|
||||
const char *selected = event_info;
|
||||
|
||||
if (selected)
|
||||
{
|
||||
save_do(selected, done_data);
|
||||
done_cb(data);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_save(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||
{
|
||||
Ecrire_Entry *ent = done_data;
|
||||
|
||||
evas_object_del(data);
|
||||
editor_save(ent);
|
||||
done_cb(done_data);
|
||||
editor_save(ent, _fs_save_done);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -37,7 +49,6 @@ _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
|||
void
|
||||
ui_alert_need_saving(Evas_Object *entry, void (*done)(void *data), void *data)
|
||||
{
|
||||
Ecrire_Entry *ent = data;
|
||||
Evas_Object *popup, *bx, *hbx, *btn, *lbl;
|
||||
popup = elm_popup_add(elm_object_top_widget_get(entry));
|
||||
evas_object_show(popup);
|
||||
|
@ -73,11 +84,6 @@ ui_alert_need_saving(Evas_Object *entry, void (*done)(void *data), void *data)
|
|||
evas_object_show(btn);
|
||||
evas_object_smart_callback_add(btn, "clicked", _save, popup);
|
||||
|
||||
if (elm_object_item_disabled_get(ent->save_item) || !ent->filename)
|
||||
{
|
||||
elm_object_disabled_set(btn, EINA_TRUE);
|
||||
}
|
||||
|
||||
btn = elm_button_add(popup);
|
||||
elm_object_text_set(btn, _("Discard"));
|
||||
elm_box_pack_end(hbx, btn);
|
||||
|
|
Loading…
Reference in New Issue