netstar pushed a commit to branch master. http://git.enlightenment.org/apps/ecrire.git/commit/?id=6d63c0cb0953c35618b234b37509e6f2f2899923
commit 6d63c0cb0953c35618b234b37509e6f2f2899923 Author: Alastair Poole <nets...@gmail.com> Date: Tue Apr 6 13:08:31 2021 +0100 opensave: save/open directories. Guards against one action (selecting a directory). Show a little popup. --- src/bin/ui/file_related.c | 65 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/src/bin/ui/file_related.c b/src/bin/ui/file_related.c index 6c33a4d..8374d61 100644 --- a/src/bin/ui/file_related.c +++ b/src/bin/ui/file_related.c @@ -1,20 +1,71 @@ #include "config.h" #include <Elementary.h> +#include "../mess_header.h" + typedef struct _File_Selector_Data { + Evas_Object *parent; Evas_Object *inwin; + Eina_Bool save; void (*func)(void *, Evas_Object *, void *); void *data; } File_Selector_Data; +static void +_warning_popup_close_cb(void *data, Evas_Object *obj, void *event_info) +{ + evas_object_del((Evas_Object *) data); +} + +static void +_warning_popup(Evas_Object *parent, const char *msg) +{ + Evas_Object *popup, *btn; + + popup = elm_popup_add(parent); + elm_object_part_text_set(popup, "title,text", _("Warning")); + elm_object_text_set(popup, eina_slstr_printf("<align=center>%s.</>", msg)); + + btn = elm_button_add(popup); + elm_object_text_set(btn, _("Close")); + evas_object_show(btn); + evas_object_smart_callback_add(btn, "clicked", _warning_popup_close_cb, popup); + elm_object_part_content_set(popup, "button1", btn); + + elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER); + evas_object_show(popup); +} + static void _cleaning_cb(void *data, Evas_Object *obj, void *event_info) { + char *path; + const char *error = NULL; File_Selector_Data *fsdata = data; - fsdata->func(fsdata->data, obj, event_info); - evas_object_del(fsdata->inwin); - free(fsdata); + path = event_info; + + if (fsdata->save) + { + if (ecore_file_is_dir(path)) + error = eina_slstr_printf(_("Unable to save to directory '%s'"), path); + } + else + { + if (ecore_file_is_dir(path)) + error = eina_slstr_printf(_("Unable to open directory '%s'"), path); + } + + if (error) + _warning_popup(fsdata->parent, error); + else + { + if (path) + fsdata->func(fsdata->data, obj, path); + + evas_object_del(fsdata->inwin); + free(fsdata); + } } void @@ -36,9 +87,11 @@ ui_file_open_save_dialog_open(Evas_Object *parent, Eina_Bool save, evas_object_show(fs); fsdata = malloc(sizeof(File_Selector_Data)); - fsdata->inwin = inwin; - fsdata->func = func; - fsdata->data = data; + fsdata->parent = parent; + fsdata->inwin = inwin; + fsdata->save = save; + fsdata->func = func; + fsdata->data = data; evas_object_smart_callback_add(fs, "done", _cleaning_cb, fsdata); } --