netstar pushed a commit to branch master. http://git.enlightenment.org/apps/ecrire.git/commit/?id=a3f3db066b09f711d9365afe3e82ad63937d5896
commit a3f3db066b09f711d9365afe3e82ad63937d5896 Author: Alastair Poole <nets...@gmail.com> Date: Thu Apr 8 07:48:34 2021 +0100 instances: keep track. --- src/bin/main.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/bin/main.c b/src/bin/main.c index 95fcb63..10726a6 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -7,6 +7,8 @@ #include "cfg.h" #include "ui/ui.h" +static Eina_List *instances = NULL; + static Eina_Unicode plain_utf8 = EINA_TRUE; /* specific log domain to help debug only ecrire */ @@ -15,16 +17,28 @@ int _ecrire_log_dom = -1; static void _editor_del(void *data) { - Ecrire_Editor *inst = data; + Eina_List *l, *l_next; + Ecrire_Editor *editor, *inst = data; + + EINA_LIST_FOREACH_SAFE(instances, l, l_next, editor) + { + if (editor == inst) + { + instances = eina_list_remove_list(instances, l); + break; + } + } evas_object_del(inst->win); eina_stringshare_del(inst->filename); free(inst); } static void -_init_entry(Ecrire_Editor *inst) +_editor_reset(Ecrire_Editor *inst) { Elm_Entry_Change_Info *inf; + + elm_object_text_set(inst->entry, ""); ecrire_editor_font_set(inst, inst->font.name, inst->font.size); /* Init the undo stack */ @@ -354,7 +368,7 @@ _load_to_entry(Ecrire_Editor *inst, const char *file) Eina_Bool ok = 1; if (!file) - _init_entry(inst); + _editor_reset(inst); else { char *buf; @@ -368,8 +382,7 @@ _load_to_entry(Ecrire_Editor *inst, const char *file) ok = 0; else { - elm_object_text_set(inst->entry, ""); - _init_entry(inst); + _editor_reset(inst); elm_entry_entry_append(inst->entry, buf); elm_object_item_disabled_set(inst->menu.save, EINA_TRUE); elm_object_item_disabled_set(inst->toolbar.save, EINA_TRUE); @@ -582,6 +595,8 @@ ecrire_editor_font_set(Ecrire_Editor *inst, const char *font, int font_size) evas_textblock_style_set(ts, eina_strbuf_string_get(sbuf)); evas_object_textblock_style_user_push((Evas_Object *) tb, ts); + + evas_textblock_style_free(ts); } elm_entry_calc_force(inst->entry); @@ -692,6 +707,10 @@ ecrire_editor_add(const char *filename, const char *font_name, int font_size) Evas_Coord w = 600, h = 600; Ecrire_Editor *inst = calloc(1, sizeof(Ecrire_Editor)); + EINA_SAFETY_ON_NULL_RETURN(inst); + + instances = eina_list_append(instances, inst); + inst->unsaved = 1; inst->filename = NULL; inst->last_saved_stack_ptr = NULL; --