e_entry: Rework e_entry dialog to be more sane

This commit fixes an issue where e_entry_dialog would have a giant
entry widget and looked incredibly stupid.

This commit also fixes another issue where it was possible to close the
dialog behind the entry (ie: parent dialog) and the entry dialog would remain
open (eg: Add a shelf, the Shelf Name dialog shows up, and it was possible to
close the Shelf Settings dialog behind it)
devs/bu5hm4n/swipe_real
Christopher Michael 2 years ago
parent f4e0d7612e
commit efb062efe2
  1. 180
      src/bin/e_entry_dialog.c
  2. 45
      src/bin/e_entry_dialog.h

@ -1,96 +1,29 @@
#include "e.h"
/* Private function definitions */
static void _e_entry_dia_del(void *data);
static void _e_entry_dialog_free(E_Entry_Dialog *dia);
static void _e_entry_dialog_ok(void *data, E_Dialog *dia);
static void _e_entry_dialog_cancel(void *data, E_Dialog *dia);
static void _e_entry_dialog_delete(E_Dialog *dia, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED);
static void _e_entry_cb_key_down(void *data, Evas_Object *obj, void *event_info);
/* Externally accessible functions */
E_API E_Entry_Dialog *
e_entry_dialog_show(const char *title, const char *icon, const char *text,
const char *initial_text,
const char *button_text, const char *button2_text,
void (*ok_func)(void *data, char *text),
void (*cancel_func)(void *data), void *data)
static void
_e_entry_dialog_free(E_Entry_Dialog *ed)
{
E_Entry_Dialog *ed;
E_Dialog *dia;
Evas_Object *o, *ob;
Evas_Modifier_Mask mask;
int w, h;
Evas *e;
ed = E_OBJECT_ALLOC(E_Entry_Dialog, E_ENTRY_DIALOG_TYPE, _e_entry_dialog_free);
ed->ok.func = ok_func;
ed->ok.data = data;
ed->cancel.func = cancel_func;
ed->cancel.data = data;
if (initial_text)
ed->text = strdup(initial_text);
dia = e_dialog_new(NULL, "E", "_entry_dialog");
if (!dia)
{
e_object_del(E_OBJECT(ed));
return NULL;
}
dia->data = ed;
ed->dia = dia;
mask = 0;
evas_object_key_ungrab(dia->event_object, "space", mask, ~mask);
e_object_del_attach_func_set(E_OBJECT(dia), _e_entry_dia_del);
evas_object_event_callback_add(dia->win, EVAS_CALLBACK_DEL, (Evas_Object_Event_Cb)_e_entry_dialog_delete, dia);
if (title) e_dialog_title_set(dia, title);
if (icon) e_dialog_icon_set(dia, icon, 64);
e = evas_object_evas_get(dia->win);
o = e_widget_list_add(e, 0, 0);
if (text)
{
ob = e_widget_label_add(e, text);
e_widget_list_object_append(o, ob, 1, 0, 0.5);
}
ed->entry = e_widget_entry_add(dia->win, &(ed->text), NULL, NULL, NULL);
evas_object_smart_callback_add(ed->entry, "key_down", _e_entry_cb_key_down, ed);
evas_object_size_hint_weight_set(ed->entry, EVAS_HINT_EXPAND, 0.5);
e_widget_list_object_append(o, ed->entry, 1, 1, 0.5);
e_widget_size_min_get(o, &w, &h);
e_dialog_content_set(dia, o, 2 * w, h);
e_dialog_button_add(dia, !button_text ? _("OK") : button_text, NULL, _e_entry_dialog_ok, ed);
e_dialog_button_add(dia, !button2_text ? _("Cancel") : button2_text, NULL, _e_entry_dialog_cancel, ed);
elm_win_center(dia->win, 1, 1);
e_dialog_resizable_set(dia, 1);
e_dialog_show(dia);
e_widget_focus_set(ed->entry, 1);
e_widget_entry_select_all(ed->entry);
return ed;
e_object_del(E_OBJECT(ed->dia));
E_FREE(ed->text);
free(ed);
}
/* Private Function Bodies */
static void
_e_entry_dia_del(void *data)
_e_entry_dialog_delete(E_Dialog *dia, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
E_Dialog *dia = data;
evas_object_event_callback_add(dia->win, EVAS_CALLBACK_DEL, (Evas_Object_Event_Cb)_e_entry_dialog_delete, dia);
e_object_del(dia->data);
e_object_del(E_OBJECT(dia->data));
}
static void
_e_entry_dialog_free(E_Entry_Dialog *ed)
_e_entry_dialog_del(void *data)
{
e_object_del(E_OBJECT(ed->dia));
E_FREE(ed->text);
free(ed);
E_Dialog *dia;
dia = data;
evas_object_event_callback_add(dia->win, EVAS_CALLBACK_DEL,
(Evas_Object_Event_Cb)_e_entry_dialog_delete,
dia);
e_object_del(dia->data);
}
static void
@ -104,7 +37,6 @@ _e_entry_dialog_ok(void *data, E_Dialog *dia EINA_UNUSED)
e_object_del(E_OBJECT(ed));
e_object_unref(E_OBJECT(ed));
}
static void
_e_entry_dialog_cancel(void *data, E_Dialog *dia EINA_UNUSED)
{
@ -117,12 +49,6 @@ _e_entry_dialog_cancel(void *data, E_Dialog *dia EINA_UNUSED)
e_object_unref(E_OBJECT(ed));
}
static void
_e_entry_dialog_delete(E_Dialog *dia, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
e_object_del(E_OBJECT(dia->data));
}
static void
_e_entry_cb_key_down(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{
@ -133,8 +59,80 @@ _e_entry_cb_key_down(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
if (!(ed = data)) return;
if (!strcmp(ev->key, "Return"))
_e_entry_dialog_ok(data, ed->dia);
else
if (!strcmp(ev->key, "Escape"))
else if (!strcmp(ev->key, "Escape"))
_e_entry_dialog_cancel(data, ed->dia);
}
E_API E_Entry_Dialog *
e_entry_dialog_show(Evas_Object *parent, const char *title, const char *icon, const char *text, const char *initial_text, const char *button_text, const char *button2_text, void (*ok_func) (void *data, char *text), void (*cancel_func) (void *data), void *data)
{
E_Entry_Dialog *ed;
E_Dialog *dia;
Evas_Object *o, *obj;
Evas_Modifier_Mask mask;
Evas *e;
int w, h;
ed = E_OBJECT_ALLOC(E_Entry_Dialog, E_ENTRY_DIALOG_TYPE,
_e_entry_dialog_free);
ed->ok.func = ok_func;
ed->ok.data = data;
ed->cancel.func = cancel_func;
ed->cancel.data = data;
if (initial_text) ed->text = strdup(initial_text);
dia = e_dialog_new(parent, "E", "_entry_dialog");
if (!dia)
{
e_object_del(E_OBJECT(ed));
return NULL;
}
dia->data = ed;
ed->dia = dia;
mask = 0;
evas_object_key_ungrab(dia->event_object, "space", mask, ~mask);
e_object_del_attach_func_set(E_OBJECT(dia), _e_entry_dialog_del);
evas_object_event_callback_add(dia->win, EVAS_CALLBACK_DEL,
(Evas_Object_Event_Cb)_e_entry_dialog_delete,
dia);
if (title) e_dialog_title_set(dia, title);
if (icon) e_dialog_icon_set(dia, icon, 64);
e = evas_object_evas_get(dia->win);
/* create main packing table */
o = e_widget_table_add(e, 0);
if (text)
{
obj = e_widget_label_add(e, text);
e_widget_table_object_append(o, obj, 0, 0, 1, 1, 1, 1, 0, 0);
}
ed->entry = e_widget_entry_add(dia->win, &(ed->text), NULL, NULL, NULL);
evas_object_smart_callback_add(ed->entry, "key_down",
_e_entry_cb_key_down, ed);
evas_object_size_hint_weight_set(ed->entry, EVAS_HINT_EXPAND, 0.5);
e_widget_table_object_append(o, ed->entry, 1, 0, 1, 1, 1, 1, 1, 0);
e_widget_size_min_get(o, &w, &h);
e_dialog_content_set(dia, o, w, h);
e_dialog_button_add(dia, !button_text ? _("OK") : button_text, NULL,
_e_entry_dialog_ok, ed);
e_dialog_button_add(dia, !button2_text ? _("Cancel") : button2_text, NULL,
_e_entry_dialog_cancel, ed);
elm_win_center(dia->win, 1, 1);
e_dialog_resizable_set(dia, 1);
e_dialog_show(dia);
e_widget_focus_set(ed->entry, 1);
e_widget_entry_select_all(ed->entry);
return ed;
}

@ -3,10 +3,10 @@
typedef struct _E_Entry_Dialog E_Entry_Dialog;
#else
#ifndef E_ENTRY_DIALOG_H
#define E_ENTRY_DIALOG_H
# ifndef E_ENTRY_DIALOG_H
# define E_ENTRY_DIALOG_H
#define E_ENTRY_DIALOG_TYPE 0xE0b0101d
# define E_ENTRY_DIALOG_TYPE 0xE0b0101d
struct _E_Entry_Dialog
{
@ -15,25 +15,28 @@ struct _E_Entry_Dialog
E_Dialog *dia;
Evas_Object *entry;
char *text;
struct {
void (*func) (void *data, char *text);
void *data;
} ok;
struct {
void (*func) (void *data);
void *data;
} cancel;
struct
{
void (*func) (void *data, char *text);
void *data;
} ok;
struct
{
void (*func) (void *data);
void *data;
} cancel;
};
E_API E_Entry_Dialog *e_entry_dialog_show(const char *title,
const char *icon,
const char *text,
const char *initial_text,
const char *button_text,
const char *button2_text,
void (*ok_func) (void *data, char *text),
void (*cancel_func) (void *data),
void *data);
E_API E_Entry_Dialog *e_entry_dialog_show(Evas_Object *parent,
const char *title,
const char *icon,
const char *text,
const char *initial_text,
const char *button_text,
const char *button2_text,
void (*ok_func) (void *data, char *text),
void (*cancel_func) (void *data),
void *data);
#endif
# endif
#endif

Loading…
Cancel
Save