summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Alzyod <ali198724@gmail.com>2020-01-23 08:54:11 +0000
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2020-01-23 10:04:08 +0100
commit279f2eca06f79b3e752bbd2c82687873ea7151b5 (patch)
treeefe18d7d0c7008ddc2c9be7dbcca71bf31a95979
parent6c6ac71f5689e74403e0fcb6ed404957b2e82dd7 (diff)
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
-rw-r--r--src/lib/elementary/efl_ui_internal_text_interactive.c160
-rw-r--r--src/lib/elementary/efl_ui_internal_text_interactive.eo7
-rw-r--r--src/lib/elementary/efl_ui_textbox.c152
-rw-r--r--src/lib/elementary/efl_ui_textbox.eo8
4 files changed, 167 insertions, 160 deletions
diff --git a/src/lib/elementary/efl_ui_internal_text_interactive.c b/src/lib/elementary/efl_ui_internal_text_interactive.c
index 63b722cfea..146deb7de5 100644
--- a/src/lib/elementary/efl_ui_internal_text_interactive.c
+++ b/src/lib/elementary/efl_ui_internal_text_interactive.c
@@ -20,12 +20,15 @@ typedef struct _Efl_Ui_Internal_Text_Interactive_Data
20 Ecore_Timer *pw_timer; 20 Ecore_Timer *pw_timer;
21 Eina_List *seq; 21 Eina_List *seq;
22 char *selection; 22 char *selection;
23 const char *file;
24 Elm_Text_Format format;
23 Eina_Bool composing : 1; 25 Eina_Bool composing : 1;
24 Eina_Bool selecting : 1; 26 Eina_Bool selecting : 1;
25 Eina_Bool have_selection : 1; 27 Eina_Bool have_selection : 1;
26 Eina_Bool select_allow : 1; 28 Eina_Bool select_allow : 1;
27 Eina_Bool editable : 1; 29 Eina_Bool editable : 1;
28 Eina_Bool had_sel : 1; 30 Eina_Bool had_sel : 1;
31 Eina_Bool auto_save : 1;
29 Eina_Bool prediction_allow : 1; 32 Eina_Bool prediction_allow : 1;
30 Eina_Bool anchors_updated : 1; 33 Eina_Bool anchors_updated : 1;
31 Eina_Bool auto_return_key : 1; 34 Eina_Bool auto_return_key : 1;
@@ -1812,6 +1815,14 @@ _efl_ui_internal_text_interactive_efl_object_constructor(Eo *obj, Efl_Ui_Interna
1812 return obj; 1815 return obj;
1813} 1816}
1814 1817
1818EOLIAN static void
1819_efl_ui_internal_text_interactive_efl_object_destructor(Eo *obj, Efl_Ui_Internal_Text_Interactive_Data *sd)
1820{
1821 eina_stringshare_del(sd->file);
1822 sd->file = NULL;
1823 efl_destructor(efl_super(obj, MY_CLASS));
1824}
1825
1815EOLIAN static Efl_Object * 1826EOLIAN static Efl_Object *
1816_efl_ui_internal_text_interactive_efl_object_finalize(Eo *obj, Efl_Ui_Internal_Text_Interactive_Data *en) 1827_efl_ui_internal_text_interactive_efl_object_finalize(Eo *obj, Efl_Ui_Internal_Text_Interactive_Data *en)
1817{ 1828{
@@ -2315,5 +2326,154 @@ _efl_ui_internal_text_interactive_efl_input_text_autocapitalization_get(const Eo
2315#endif 2326#endif
2316} 2327}
2317 2328
2329
2330static char *
2331_file_load(Eo *obj)
2332{
2333 Eina_File *f;
2334 char *text = NULL;
2335 void *tmp = NULL;
2336
2337 f = eina_file_dup(efl_file_mmap_get(obj));
2338
2339 tmp = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
2340 if (!tmp) goto on_error;
2341
2342 text = malloc(eina_file_size_get(f) + 1);
2343 if (!text) goto on_error;
2344
2345 memcpy(text, tmp, eina_file_size_get(f));
2346 text[eina_file_size_get(f)] = 0;
2347
2348 if (eina_file_map_faulted(f, tmp))
2349 {
2350 ELM_SAFE_FREE(text, free);
2351 }
2352
2353 on_error:
2354 if (tmp) eina_file_map_free(f, tmp);
2355 eina_file_close(f);
2356
2357 return text;
2358}
2359
2360static char *
2361_plain_load(Eo *obj)
2362{
2363 return _file_load(obj);
2364}
2365
2366static Eina_Error
2367_load_do(Evas_Object *obj)
2368{
2369 char *text;
2370 Eina_Error err = 0;
2371
2372 Efl_Ui_Internal_Text_Interactive_Data * sd = efl_data_scope_get(obj, MY_CLASS);
2373
2374 if (!sd->file)
2375 {
2376 efl_text_set(obj, "");
2377 return 0;
2378 }
2379
2380 switch (sd->format)
2381 {
2382 /* Only available format */
2383 case ELM_TEXT_FORMAT_PLAIN_UTF8:
2384 text = _plain_load(obj);
2385 if (!text)
2386 {
2387 err = errno;
2388 if (!err) err = ENOENT;
2389 }
2390 break;
2391
2392 default:
2393 text = NULL;
2394 break;
2395 }
2396
2397 if (text)
2398 {
2399 efl_text_set(obj, text);
2400 free(text);
2401 return 0;
2402 }
2403 efl_text_set(obj, "");
2404 return err;
2405}
2406
2407static void
2408_text_save(const char *file,
2409 const char *text)
2410{
2411 FILE *f;
2412
2413 if (!text)
2414 {
2415 ecore_file_unlink(file);
2416 return;
2417 }
2418
2419 f = fopen(file, "wb");
2420 if (!f)
2421 {
2422 ERR("Failed to open %s for writing", file);
2423 return;
2424 }
2425
2426 if (fputs(text, f) == EOF)
2427 ERR("Failed to write text to file %s", file);
2428 fclose(f);
2429}
2430
2431static void
2432_save_do(Evas_Object *obj)
2433{
2434 Efl_Ui_Internal_Text_Interactive_Data * sd = efl_data_scope_get(obj, MY_CLASS);
2435
2436 if (!sd->file) return;
2437 switch (sd->format)
2438 {
2439 /* Only supported format */
2440 case ELM_TEXT_FORMAT_PLAIN_UTF8:
2441 _text_save(sd->file, efl_text_get(obj));
2442 break;
2443
2444 case ELM_TEXT_FORMAT_MARKUP_UTF8:
2445 default:
2446 break;
2447 }
2448}
2449
2450
2451EOLIAN static Eina_Error
2452_efl_ui_internal_text_interactive_efl_file_file_set(Eo *obj, Efl_Ui_Internal_Text_Interactive_Data *sd, const char *file)
2453{
2454 eina_stringshare_replace(&sd->file, file);
2455 return efl_file_set(efl_super(obj, MY_CLASS), file);
2456}
2457
2458EOLIAN static void
2459_efl_ui_internal_text_interactive_efl_file_unload(Eo *obj, Efl_Ui_Internal_Text_Interactive_Data *sd EINA_UNUSED)
2460{
2461 efl_file_unload(efl_super(obj, MY_CLASS));
2462 efl_text_set(obj, "");
2463}
2464
2465EOLIAN static Eina_Error
2466_efl_ui_internal_text_interactive_efl_file_load(Eo *obj, Efl_Ui_Internal_Text_Interactive_Data *sd)
2467{
2468 Eina_Error err;
2469
2470 if (efl_file_loaded_get(obj)) return 0;
2471 err = efl_file_load(efl_super(obj, MY_CLASS));
2472 if (err) return err;
2473 if (sd->auto_save) _save_do(obj);
2474 return _load_do(obj);
2475}
2476
2477
2318#include "efl_ui_internal_text_interactive.eo.c" 2478#include "efl_ui_internal_text_interactive.eo.c"
2319#include "efl_text_interactive.eo.c" 2479#include "efl_text_interactive.eo.c"
diff --git a/src/lib/elementary/efl_ui_internal_text_interactive.eo b/src/lib/elementary/efl_ui_internal_text_interactive.eo
index 0688334500..ebe694b006 100644
--- a/src/lib/elementary/efl_ui_internal_text_interactive.eo
+++ b/src/lib/elementary/efl_ui_internal_text_interactive.eo
@@ -1,4 +1,4 @@
1class @beta Efl.Ui.Internal.Text.Interactive extends Efl.Canvas.Textblock implements Efl.Text_Interactive, Efl.Input_Text 1class @beta Efl.Ui.Internal.Text.Interactive extends Efl.Canvas.Textblock implements Efl.Text_Interactive, Efl.Input_Text, Efl.File
2{ 2{
3 [[An internal object in charge of the interactive aspect of the text widget. 3 [[An internal object in charge of the interactive aspect of the text widget.
4 4
@@ -6,6 +6,7 @@ class @beta Efl.Ui.Internal.Text.Interactive extends Efl.Canvas.Textblock implem
6 ]] 6 ]]
7 implements { 7 implements {
8 Efl.Object.constructor; 8 Efl.Object.constructor;
9 Efl.Object.destructor;
9 Efl.Object.finalize; 10 Efl.Object.finalize;
10 Efl.Text_Interactive.main_cursor { get; } 11 Efl.Text_Interactive.main_cursor { get; }
11 Efl.Text_Interactive.selection_allowed { get; set; } 12 Efl.Text_Interactive.selection_allowed { get; set; }
@@ -29,5 +30,9 @@ class @beta Efl.Ui.Internal.Text.Interactive extends Efl.Canvas.Textblock implem
29 Efl.Input_Text.input_panel_show; 30 Efl.Input_Text.input_panel_show;
30 Efl.Input_Text.input_panel_hide; 31 Efl.Input_Text.input_panel_hide;
31 Efl.Input_Text.input_panel_imdata { get; set; } 32 Efl.Input_Text.input_panel_imdata { get; set; }
33 //FIXME Efl.File should be implemented later at Efl.Ui.TextBox level
34 Efl.File.file { set; }
35 Efl.File.load;
36 Efl.File.unload;
32 } 37 }
33} 38}
diff --git a/src/lib/elementary/efl_ui_textbox.c b/src/lib/elementary/efl_ui_textbox.c
index 83ecb12c41..72e692c3e8 100644
--- a/src/lib/elementary/efl_ui_textbox.c
+++ b/src/lib/elementary/efl_ui_textbox.c
@@ -49,8 +49,6 @@ struct _Efl_Ui_Textbox_Data
49 int append_text_len; 49 int append_text_len;
50 /* Only for clipboard */ 50 /* Only for clipboard */
51 const char *text; 51 const char *text;
52 const char *file;
53 Elm_Text_Format format;
54 Evas_Coord ent_w, ent_h; 52 Evas_Coord ent_w, ent_h;
55 Evas_Coord downx, downy; 53 Evas_Coord downx, downy;
56 Evas_Coord ox, oy; 54 Evas_Coord ox, oy;
@@ -98,7 +96,6 @@ struct _Efl_Ui_Textbox_Data
98 Eina_Bool deferred_decoration_anchor : 1; 96 Eina_Bool deferred_decoration_anchor : 1;
99 Eina_Bool context_menu_enabled : 1; 97 Eina_Bool context_menu_enabled : 1;
100 Eina_Bool long_pressed : 1; 98 Eina_Bool long_pressed : 1;
101 Eina_Bool auto_save : 1;
102 Eina_Bool has_text : 1; 99 Eina_Bool has_text : 1;
103 Eina_Bool use_down : 1; 100 Eina_Bool use_down : 1;
104 Eina_Bool sel_mode : 1; 101 Eina_Bool sel_mode : 1;
@@ -213,126 +210,6 @@ static Eina_Position2D _decoration_calc_offset(Efl_Ui_Textbox_Data *sd);
213static void _update_text_theme(Eo *obj, Efl_Ui_Textbox_Data *sd); 210static void _update_text_theme(Eo *obj, Efl_Ui_Textbox_Data *sd);
214static void _efl_ui_textbox_selection_paste_type(Eo *obj, Efl_Ui_Selection_Type type); 211static void _efl_ui_textbox_selection_paste_type(Eo *obj, Efl_Ui_Selection_Type type);
215 212
216static char *
217_file_load(Eo *obj)
218{
219 Eina_File *f;
220 char *text = NULL;
221 void *tmp = NULL;
222
223 f = eina_file_dup(efl_file_mmap_get(obj));
224
225 tmp = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
226 if (!tmp) goto on_error;
227
228 text = malloc(eina_file_size_get(f) + 1);
229 if (!text) goto on_error;
230
231 memcpy(text, tmp, eina_file_size_get(f));
232 text[eina_file_size_get(f)] = 0;
233
234 if (eina_file_map_faulted(f, tmp))
235 {
236 ELM_SAFE_FREE(text, free);
237 }
238
239 on_error:
240 if (tmp) eina_file_map_free(f, tmp);
241 eina_file_close(f);
242
243 return text;
244}
245
246static char *
247_plain_load(Eo *obj)
248{
249 return _file_load(obj);
250}
251
252static Eina_Error
253_load_do(Evas_Object *obj)
254{
255 char *text;
256 Eina_Error err = 0;
257
258 EFL_UI_TEXT_DATA_GET(obj, sd);
259
260 if (!sd->file)
261 {
262 efl_text_set(obj, "");
263 return 0;
264 }
265
266 switch (sd->format)
267 {
268 /* Only available format */
269 case ELM_TEXT_FORMAT_PLAIN_UTF8:
270 text = _plain_load(obj);
271 if (!text)
272 {
273 err = errno;
274 if (!err) err = ENOENT;
275 }
276 break;
277
278 default:
279 text = NULL;
280 break;
281 }
282
283 if (text)
284 {
285 efl_text_set(obj, text);
286 free(text);
287 return 0;
288 }
289 efl_text_set(obj, "");
290 return err;
291}
292
293static void
294_text_save(const char *file,
295 const char *text)
296{
297 FILE *f;
298
299 if (!text)
300 {
301 ecore_file_unlink(file);
302 return;
303 }
304
305 f = fopen(file, "wb");
306 if (!f)
307 {
308 ERR("Failed to open %s for writing", file);
309 return;
310 }
311
312 if (fputs(text, f) == EOF)
313 ERR("Failed to write text to file %s", file);
314 fclose(f);
315}
316
317static void
318_save_do(Evas_Object *obj)
319{
320 EFL_UI_TEXT_DATA_GET(obj, sd);
321
322 if (!sd->file) return;
323 switch (sd->format)
324 {
325 /* Only supported format */
326 case ELM_TEXT_FORMAT_PLAIN_UTF8:
327 _text_save(sd->file, efl_text_get(obj));
328 break;
329
330 case ELM_TEXT_FORMAT_MARKUP_UTF8:
331 default:
332 break;
333 }
334}
335
336static void 213static void
337_efl_ui_textbox_guide_update(Evas_Object *obj, 214_efl_ui_textbox_guide_update(Evas_Object *obj,
338 Eina_Bool has_text) 215 Eina_Bool has_text)
@@ -1838,7 +1715,6 @@ _efl_ui_textbox_efl_object_constructor(Eo *obj, Efl_Ui_Textbox_Data *sd)
1838 sd->entry_edje = wd->resize_obj; 1715 sd->entry_edje = wd->resize_obj;
1839 sd->cnp_mode = EFL_UI_SELECTION_FORMAT_TEXT; 1716 sd->cnp_mode = EFL_UI_SELECTION_FORMAT_TEXT;
1840 sd->context_menu_enabled = EINA_TRUE; 1717 sd->context_menu_enabled = EINA_TRUE;
1841 sd->auto_save = EINA_TRUE;
1842 efl_text_interactive_editable_set(obj, EINA_TRUE); 1718 efl_text_interactive_editable_set(obj, EINA_TRUE);
1843 efl_text_interactive_selection_allowed_set(obj, EINA_TRUE); 1719 efl_text_interactive_selection_allowed_set(obj, EINA_TRUE);
1844 sd->drop_format = EFL_UI_SELECTION_FORMAT_MARKUP | EFL_UI_SELECTION_FORMAT_IMAGE; 1720 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)
1916{ 1792{
1917 efl_event_freeze(obj); 1793 efl_event_freeze(obj);
1918 1794
1919 eina_stringshare_del(sd->file);
1920
1921 _popup_dismiss(sd); 1795 _popup_dismiss(sd);
1922 if ((sd->api) && (sd->api->obj_unhook)) 1796 if ((sd->api) && (sd->api->obj_unhook))
1923 sd->api->obj_unhook(obj); // module - unhook 1797 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
2198 return sd->context_menu_enabled; 2072 return sd->context_menu_enabled;
2199} 2073}
2200 2074
2201EOLIAN static Eina_Error
2202_efl_ui_textbox_efl_file_file_set(Eo *obj, Efl_Ui_Textbox_Data *sd, const char *file)
2203{
2204 eina_stringshare_replace(&sd->file, file);
2205 return efl_file_set(efl_super(obj, MY_CLASS), file);
2206}
2207
2208EOLIAN static void
2209_efl_ui_textbox_efl_file_unload(Eo *obj, Efl_Ui_Textbox_Data *sd EINA_UNUSED)
2210{
2211 efl_file_unload(efl_super(obj, MY_CLASS));
2212 efl_text_set(obj, "");
2213}
2214
2215EOLIAN static Eina_Error
2216_efl_ui_textbox_efl_file_load(Eo *obj, Efl_Ui_Textbox_Data *sd)
2217{
2218 Eina_Error err;
2219
2220 if (efl_file_loaded_get(obj)) return 0;
2221 err = efl_file_load(efl_super(obj, MY_CLASS));
2222 if (err) return err;
2223 if (sd->auto_save) _save_do(obj);
2224 return _load_do(obj);
2225}
2226
2227EOLIAN static void 2075EOLIAN static void
2228_efl_ui_textbox_cnp_mode_set(Eo *obj, Efl_Ui_Textbox_Data *sd, Efl_Ui_Selection_Format cnp_mode) 2076_efl_ui_textbox_cnp_mode_set(Eo *obj, Efl_Ui_Textbox_Data *sd, Efl_Ui_Selection_Format cnp_mode)
2229{ 2077{
diff --git a/src/lib/elementary/efl_ui_textbox.eo b/src/lib/elementary/efl_ui_textbox.eo
index e3c86e18ad..67ed430848 100644
--- a/src/lib/elementary/efl_ui_textbox.eo
+++ b/src/lib/elementary/efl_ui_textbox.eo
@@ -1,5 +1,5 @@
1class @beta Efl.Ui.Textbox extends Efl.Ui.Layout_Base implements Efl.Input.Clickable, 1class @beta Efl.Ui.Textbox extends Efl.Ui.Layout_Base implements Efl.Input.Clickable,
2 Efl.Access.Text, Efl.Access.Editable.Text, Efl.File 2 Efl.Access.Text, Efl.Access.Editable.Text
3 composites 3 composites
4 Efl.Text_Interactive, Efl.Text_Markup, Efl.Input_Text 4 Efl.Text_Interactive, Efl.Text_Markup, Efl.Input_Text
5{ 5{
@@ -100,9 +100,6 @@ class @beta Efl.Ui.Textbox extends Efl.Ui.Layout_Base implements Efl.Input.Click
100 Efl.Ui.Widget.disabled {set;} 100 Efl.Ui.Widget.disabled {set;}
101 Efl.Text_Format.password {set;} 101 Efl.Text_Format.password {set;}
102 Efl.Text_Format.multiline {set;} 102 Efl.Text_Format.multiline {set;}
103 //Efl.Ui.Widget.widget_sub_object_del;
104 //Elm.Interface_Scrollable.policy { set; }
105 //Elm.Interface_Scrollable.bounce_allow { set; }
106 Efl.Access.Object.state_set { get; } 103 Efl.Access.Object.state_set { get; }
107 Efl.Access.Object.i18n_name { get; } 104 Efl.Access.Object.i18n_name { get; }
108 Efl.Access.Text.access_text { get; } 105 Efl.Access.Text.access_text { get; }
@@ -127,9 +124,6 @@ class @beta Efl.Ui.Textbox extends Efl.Ui.Layout_Base implements Efl.Input.Click
127 Efl.Access.Editable.Text.cut; 124 Efl.Access.Editable.Text.cut;
128 Efl.Access.Editable.Text.delete; 125 Efl.Access.Editable.Text.delete;
129 Efl.Access.Editable.Text.paste; 126 Efl.Access.Editable.Text.paste;
130 Efl.File.file { set; }
131 Efl.File.load;
132 Efl.File.unload;
133 Efl.Text_Interactive.editable { set; } 127 Efl.Text_Interactive.editable { set; }
134 Efl.Part.part_get; 128 Efl.Part.part_get;
135 } 129 }