opensave: save/open directories.

Guards against one action (selecting a directory).

Show a little popup.
This commit is contained in:
Alastair Poole 2021-04-06 13:08:31 +01:00
parent b2a6f80ed7
commit 6d63c0cb09
1 changed files with 59 additions and 6 deletions

View File

@ -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);
}