efl.ui.textbox: move file implementation in to internal class
We want to keep implementation for file interface in a safe place and remove it from our side world (eo). This is a simple copy-paste, from efl.ui.textbox into efl_ui_internal_text_interactive Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D11153
This commit is contained in:
parent
6c6ac71f56
commit
279f2eca06
|
@ -20,12 +20,15 @@ typedef struct _Efl_Ui_Internal_Text_Interactive_Data
|
|||
Ecore_Timer *pw_timer;
|
||||
Eina_List *seq;
|
||||
char *selection;
|
||||
const char *file;
|
||||
Elm_Text_Format format;
|
||||
Eina_Bool composing : 1;
|
||||
Eina_Bool selecting : 1;
|
||||
Eina_Bool have_selection : 1;
|
||||
Eina_Bool select_allow : 1;
|
||||
Eina_Bool editable : 1;
|
||||
Eina_Bool had_sel : 1;
|
||||
Eina_Bool auto_save : 1;
|
||||
Eina_Bool prediction_allow : 1;
|
||||
Eina_Bool anchors_updated : 1;
|
||||
Eina_Bool auto_return_key : 1;
|
||||
|
@ -1812,6 +1815,14 @@ _efl_ui_internal_text_interactive_efl_object_constructor(Eo *obj, Efl_Ui_Interna
|
|||
return obj;
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_efl_ui_internal_text_interactive_efl_object_destructor(Eo *obj, Efl_Ui_Internal_Text_Interactive_Data *sd)
|
||||
{
|
||||
eina_stringshare_del(sd->file);
|
||||
sd->file = NULL;
|
||||
efl_destructor(efl_super(obj, MY_CLASS));
|
||||
}
|
||||
|
||||
EOLIAN static Efl_Object *
|
||||
_efl_ui_internal_text_interactive_efl_object_finalize(Eo *obj, Efl_Ui_Internal_Text_Interactive_Data *en)
|
||||
{
|
||||
|
@ -2315,5 +2326,154 @@ _efl_ui_internal_text_interactive_efl_input_text_autocapitalization_get(const Eo
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
_file_load(Eo *obj)
|
||||
{
|
||||
Eina_File *f;
|
||||
char *text = NULL;
|
||||
void *tmp = NULL;
|
||||
|
||||
f = eina_file_dup(efl_file_mmap_get(obj));
|
||||
|
||||
tmp = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
||||
if (!tmp) goto on_error;
|
||||
|
||||
text = malloc(eina_file_size_get(f) + 1);
|
||||
if (!text) goto on_error;
|
||||
|
||||
memcpy(text, tmp, eina_file_size_get(f));
|
||||
text[eina_file_size_get(f)] = 0;
|
||||
|
||||
if (eina_file_map_faulted(f, tmp))
|
||||
{
|
||||
ELM_SAFE_FREE(text, free);
|
||||
}
|
||||
|
||||
on_error:
|
||||
if (tmp) eina_file_map_free(f, tmp);
|
||||
eina_file_close(f);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
static char *
|
||||
_plain_load(Eo *obj)
|
||||
{
|
||||
return _file_load(obj);
|
||||
}
|
||||
|
||||
static Eina_Error
|
||||
_load_do(Evas_Object *obj)
|
||||
{
|
||||
char *text;
|
||||
Eina_Error err = 0;
|
||||
|
||||
Efl_Ui_Internal_Text_Interactive_Data * sd = efl_data_scope_get(obj, MY_CLASS);
|
||||
|
||||
if (!sd->file)
|
||||
{
|
||||
efl_text_set(obj, "");
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (sd->format)
|
||||
{
|
||||
/* Only available format */
|
||||
case ELM_TEXT_FORMAT_PLAIN_UTF8:
|
||||
text = _plain_load(obj);
|
||||
if (!text)
|
||||
{
|
||||
err = errno;
|
||||
if (!err) err = ENOENT;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
text = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (text)
|
||||
{
|
||||
efl_text_set(obj, text);
|
||||
free(text);
|
||||
return 0;
|
||||
}
|
||||
efl_text_set(obj, "");
|
||||
return err;
|
||||
}
|
||||
|
||||
static void
|
||||
_text_save(const char *file,
|
||||
const char *text)
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
if (!text)
|
||||
{
|
||||
ecore_file_unlink(file);
|
||||
return;
|
||||
}
|
||||
|
||||
f = fopen(file, "wb");
|
||||
if (!f)
|
||||
{
|
||||
ERR("Failed to open %s for writing", file);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fputs(text, f) == EOF)
|
||||
ERR("Failed to write text to file %s", file);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void
|
||||
_save_do(Evas_Object *obj)
|
||||
{
|
||||
Efl_Ui_Internal_Text_Interactive_Data * sd = efl_data_scope_get(obj, MY_CLASS);
|
||||
|
||||
if (!sd->file) return;
|
||||
switch (sd->format)
|
||||
{
|
||||
/* Only supported format */
|
||||
case ELM_TEXT_FORMAT_PLAIN_UTF8:
|
||||
_text_save(sd->file, efl_text_get(obj));
|
||||
break;
|
||||
|
||||
case ELM_TEXT_FORMAT_MARKUP_UTF8:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EOLIAN static Eina_Error
|
||||
_efl_ui_internal_text_interactive_efl_file_file_set(Eo *obj, Efl_Ui_Internal_Text_Interactive_Data *sd, const char *file)
|
||||
{
|
||||
eina_stringshare_replace(&sd->file, file);
|
||||
return efl_file_set(efl_super(obj, MY_CLASS), file);
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_efl_ui_internal_text_interactive_efl_file_unload(Eo *obj, Efl_Ui_Internal_Text_Interactive_Data *sd EINA_UNUSED)
|
||||
{
|
||||
efl_file_unload(efl_super(obj, MY_CLASS));
|
||||
efl_text_set(obj, "");
|
||||
}
|
||||
|
||||
EOLIAN static Eina_Error
|
||||
_efl_ui_internal_text_interactive_efl_file_load(Eo *obj, Efl_Ui_Internal_Text_Interactive_Data *sd)
|
||||
{
|
||||
Eina_Error err;
|
||||
|
||||
if (efl_file_loaded_get(obj)) return 0;
|
||||
err = efl_file_load(efl_super(obj, MY_CLASS));
|
||||
if (err) return err;
|
||||
if (sd->auto_save) _save_do(obj);
|
||||
return _load_do(obj);
|
||||
}
|
||||
|
||||
|
||||
#include "efl_ui_internal_text_interactive.eo.c"
|
||||
#include "efl_text_interactive.eo.c"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class @beta Efl.Ui.Internal.Text.Interactive extends Efl.Canvas.Textblock implements Efl.Text_Interactive, Efl.Input_Text
|
||||
class @beta Efl.Ui.Internal.Text.Interactive extends Efl.Canvas.Textblock implements Efl.Text_Interactive, Efl.Input_Text, Efl.File
|
||||
{
|
||||
[[An internal object in charge of the interactive aspect of the text widget.
|
||||
|
||||
|
@ -6,6 +6,7 @@ class @beta Efl.Ui.Internal.Text.Interactive extends Efl.Canvas.Textblock implem
|
|||
]]
|
||||
implements {
|
||||
Efl.Object.constructor;
|
||||
Efl.Object.destructor;
|
||||
Efl.Object.finalize;
|
||||
Efl.Text_Interactive.main_cursor { get; }
|
||||
Efl.Text_Interactive.selection_allowed { get; set; }
|
||||
|
@ -29,5 +30,9 @@ class @beta Efl.Ui.Internal.Text.Interactive extends Efl.Canvas.Textblock implem
|
|||
Efl.Input_Text.input_panel_show;
|
||||
Efl.Input_Text.input_panel_hide;
|
||||
Efl.Input_Text.input_panel_imdata { get; set; }
|
||||
//FIXME Efl.File should be implemented later at Efl.Ui.TextBox level
|
||||
Efl.File.file { set; }
|
||||
Efl.File.load;
|
||||
Efl.File.unload;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,6 @@ struct _Efl_Ui_Textbox_Data
|
|||
int append_text_len;
|
||||
/* Only for clipboard */
|
||||
const char *text;
|
||||
const char *file;
|
||||
Elm_Text_Format format;
|
||||
Evas_Coord ent_w, ent_h;
|
||||
Evas_Coord downx, downy;
|
||||
Evas_Coord ox, oy;
|
||||
|
@ -98,7 +96,6 @@ struct _Efl_Ui_Textbox_Data
|
|||
Eina_Bool deferred_decoration_anchor : 1;
|
||||
Eina_Bool context_menu_enabled : 1;
|
||||
Eina_Bool long_pressed : 1;
|
||||
Eina_Bool auto_save : 1;
|
||||
Eina_Bool has_text : 1;
|
||||
Eina_Bool use_down : 1;
|
||||
Eina_Bool sel_mode : 1;
|
||||
|
@ -213,126 +210,6 @@ static Eina_Position2D _decoration_calc_offset(Efl_Ui_Textbox_Data *sd);
|
|||
static void _update_text_theme(Eo *obj, Efl_Ui_Textbox_Data *sd);
|
||||
static void _efl_ui_textbox_selection_paste_type(Eo *obj, Efl_Ui_Selection_Type type);
|
||||
|
||||
static char *
|
||||
_file_load(Eo *obj)
|
||||
{
|
||||
Eina_File *f;
|
||||
char *text = NULL;
|
||||
void *tmp = NULL;
|
||||
|
||||
f = eina_file_dup(efl_file_mmap_get(obj));
|
||||
|
||||
tmp = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
|
||||
if (!tmp) goto on_error;
|
||||
|
||||
text = malloc(eina_file_size_get(f) + 1);
|
||||
if (!text) goto on_error;
|
||||
|
||||
memcpy(text, tmp, eina_file_size_get(f));
|
||||
text[eina_file_size_get(f)] = 0;
|
||||
|
||||
if (eina_file_map_faulted(f, tmp))
|
||||
{
|
||||
ELM_SAFE_FREE(text, free);
|
||||
}
|
||||
|
||||
on_error:
|
||||
if (tmp) eina_file_map_free(f, tmp);
|
||||
eina_file_close(f);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
static char *
|
||||
_plain_load(Eo *obj)
|
||||
{
|
||||
return _file_load(obj);
|
||||
}
|
||||
|
||||
static Eina_Error
|
||||
_load_do(Evas_Object *obj)
|
||||
{
|
||||
char *text;
|
||||
Eina_Error err = 0;
|
||||
|
||||
EFL_UI_TEXT_DATA_GET(obj, sd);
|
||||
|
||||
if (!sd->file)
|
||||
{
|
||||
efl_text_set(obj, "");
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (sd->format)
|
||||
{
|
||||
/* Only available format */
|
||||
case ELM_TEXT_FORMAT_PLAIN_UTF8:
|
||||
text = _plain_load(obj);
|
||||
if (!text)
|
||||
{
|
||||
err = errno;
|
||||
if (!err) err = ENOENT;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
text = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (text)
|
||||
{
|
||||
efl_text_set(obj, text);
|
||||
free(text);
|
||||
return 0;
|
||||
}
|
||||
efl_text_set(obj, "");
|
||||
return err;
|
||||
}
|
||||
|
||||
static void
|
||||
_text_save(const char *file,
|
||||
const char *text)
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
if (!text)
|
||||
{
|
||||
ecore_file_unlink(file);
|
||||
return;
|
||||
}
|
||||
|
||||
f = fopen(file, "wb");
|
||||
if (!f)
|
||||
{
|
||||
ERR("Failed to open %s for writing", file);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fputs(text, f) == EOF)
|
||||
ERR("Failed to write text to file %s", file);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void
|
||||
_save_do(Evas_Object *obj)
|
||||
{
|
||||
EFL_UI_TEXT_DATA_GET(obj, sd);
|
||||
|
||||
if (!sd->file) return;
|
||||
switch (sd->format)
|
||||
{
|
||||
/* Only supported format */
|
||||
case ELM_TEXT_FORMAT_PLAIN_UTF8:
|
||||
_text_save(sd->file, efl_text_get(obj));
|
||||
break;
|
||||
|
||||
case ELM_TEXT_FORMAT_MARKUP_UTF8:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_efl_ui_textbox_guide_update(Evas_Object *obj,
|
||||
Eina_Bool has_text)
|
||||
|
@ -1838,7 +1715,6 @@ _efl_ui_textbox_efl_object_constructor(Eo *obj, Efl_Ui_Textbox_Data *sd)
|
|||
sd->entry_edje = wd->resize_obj;
|
||||
sd->cnp_mode = EFL_UI_SELECTION_FORMAT_TEXT;
|
||||
sd->context_menu_enabled = EINA_TRUE;
|
||||
sd->auto_save = EINA_TRUE;
|
||||
efl_text_interactive_editable_set(obj, EINA_TRUE);
|
||||
efl_text_interactive_selection_allowed_set(obj, EINA_TRUE);
|
||||
sd->drop_format = EFL_UI_SELECTION_FORMAT_MARKUP | EFL_UI_SELECTION_FORMAT_IMAGE;
|
||||
|
@ -1916,8 +1792,6 @@ _efl_ui_textbox_efl_object_destructor(Eo *obj, Efl_Ui_Textbox_Data *sd)
|
|||
{
|
||||
efl_event_freeze(obj);
|
||||
|
||||
eina_stringshare_del(sd->file);
|
||||
|
||||
_popup_dismiss(sd);
|
||||
if ((sd->api) && (sd->api->obj_unhook))
|
||||
sd->api->obj_unhook(obj); // module - unhook
|
||||
|
@ -2198,32 +2072,6 @@ _efl_ui_textbox_context_menu_enabled_get(const Eo *obj EINA_UNUSED, Efl_Ui_Textb
|
|||
return sd->context_menu_enabled;
|
||||
}
|
||||
|
||||
EOLIAN static Eina_Error
|
||||
_efl_ui_textbox_efl_file_file_set(Eo *obj, Efl_Ui_Textbox_Data *sd, const char *file)
|
||||
{
|
||||
eina_stringshare_replace(&sd->file, file);
|
||||
return efl_file_set(efl_super(obj, MY_CLASS), file);
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_efl_ui_textbox_efl_file_unload(Eo *obj, Efl_Ui_Textbox_Data *sd EINA_UNUSED)
|
||||
{
|
||||
efl_file_unload(efl_super(obj, MY_CLASS));
|
||||
efl_text_set(obj, "");
|
||||
}
|
||||
|
||||
EOLIAN static Eina_Error
|
||||
_efl_ui_textbox_efl_file_load(Eo *obj, Efl_Ui_Textbox_Data *sd)
|
||||
{
|
||||
Eina_Error err;
|
||||
|
||||
if (efl_file_loaded_get(obj)) return 0;
|
||||
err = efl_file_load(efl_super(obj, MY_CLASS));
|
||||
if (err) return err;
|
||||
if (sd->auto_save) _save_do(obj);
|
||||
return _load_do(obj);
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_efl_ui_textbox_cnp_mode_set(Eo *obj, Efl_Ui_Textbox_Data *sd, Efl_Ui_Selection_Format cnp_mode)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class @beta Efl.Ui.Textbox extends Efl.Ui.Layout_Base implements Efl.Input.Clickable,
|
||||
Efl.Access.Text, Efl.Access.Editable.Text, Efl.File
|
||||
Efl.Access.Text, Efl.Access.Editable.Text
|
||||
composites
|
||||
Efl.Text_Interactive, Efl.Text_Markup, Efl.Input_Text
|
||||
{
|
||||
|
@ -100,9 +100,6 @@ class @beta Efl.Ui.Textbox extends Efl.Ui.Layout_Base implements Efl.Input.Click
|
|||
Efl.Ui.Widget.disabled {set;}
|
||||
Efl.Text_Format.password {set;}
|
||||
Efl.Text_Format.multiline {set;}
|
||||
//Efl.Ui.Widget.widget_sub_object_del;
|
||||
//Elm.Interface_Scrollable.policy { set; }
|
||||
//Elm.Interface_Scrollable.bounce_allow { set; }
|
||||
Efl.Access.Object.state_set { get; }
|
||||
Efl.Access.Object.i18n_name { get; }
|
||||
Efl.Access.Text.access_text { get; }
|
||||
|
@ -127,9 +124,6 @@ class @beta Efl.Ui.Textbox extends Efl.Ui.Layout_Base implements Efl.Input.Click
|
|||
Efl.Access.Editable.Text.cut;
|
||||
Efl.Access.Editable.Text.delete;
|
||||
Efl.Access.Editable.Text.paste;
|
||||
Efl.File.file { set; }
|
||||
Efl.File.load;
|
||||
Efl.File.unload;
|
||||
Efl.Text_Interactive.editable { set; }
|
||||
Efl.Part.part_get;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue