summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <netstar@gmail.com>2021-04-08 07:48:34 +0100
committerAlastair Poole <netstar@gmail.com>2021-04-08 07:48:34 +0100
commita3f3db066b09f711d9365afe3e82ad63937d5896 (patch)
tree65ddf70547f538aac86f427d1e037c28f2f1c1b7
parentd5848bfda6e726f08ea33145280845ace26535ab (diff)
instances: keep track.
-rw-r--r--src/bin/main.c29
1 files 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 @@
7#include "cfg.h" 7#include "cfg.h"
8#include "ui/ui.h" 8#include "ui/ui.h"
9 9
10static Eina_List *instances = NULL;
11
10static Eina_Unicode plain_utf8 = EINA_TRUE; 12static Eina_Unicode plain_utf8 = EINA_TRUE;
11 13
12/* specific log domain to help debug only ecrire */ 14/* specific log domain to help debug only ecrire */
@@ -15,16 +17,28 @@ int _ecrire_log_dom = -1;
15static void 17static void
16_editor_del(void *data) 18_editor_del(void *data)
17{ 19{
18 Ecrire_Editor *inst = data; 20 Eina_List *l, *l_next;
21 Ecrire_Editor *editor, *inst = data;
22
23 EINA_LIST_FOREACH_SAFE(instances, l, l_next, editor)
24 {
25 if (editor == inst)
26 {
27 instances = eina_list_remove_list(instances, l);
28 break;
29 }
30 }
19 evas_object_del(inst->win); 31 evas_object_del(inst->win);
20 eina_stringshare_del(inst->filename); 32 eina_stringshare_del(inst->filename);
21 free(inst); 33 free(inst);
22} 34}
23 35
24static void 36static void
25_init_entry(Ecrire_Editor *inst) 37_editor_reset(Ecrire_Editor *inst)
26{ 38{
27 Elm_Entry_Change_Info *inf; 39 Elm_Entry_Change_Info *inf;
40
41 elm_object_text_set(inst->entry, "");
28 ecrire_editor_font_set(inst, inst->font.name, inst->font.size); 42 ecrire_editor_font_set(inst, inst->font.name, inst->font.size);
29 43
30 /* Init the undo stack */ 44 /* Init the undo stack */
@@ -354,7 +368,7 @@ _load_to_entry(Ecrire_Editor *inst, const char *file)
354 Eina_Bool ok = 1; 368 Eina_Bool ok = 1;
355 369
356 if (!file) 370 if (!file)
357 _init_entry(inst); 371 _editor_reset(inst);
358 else 372 else
359 { 373 {
360 char *buf; 374 char *buf;
@@ -368,8 +382,7 @@ _load_to_entry(Ecrire_Editor *inst, const char *file)
368 ok = 0; 382 ok = 0;
369 else 383 else
370 { 384 {
371 elm_object_text_set(inst->entry, ""); 385 _editor_reset(inst);
372 _init_entry(inst);
373 elm_entry_entry_append(inst->entry, buf); 386 elm_entry_entry_append(inst->entry, buf);
374 elm_object_item_disabled_set(inst->menu.save, EINA_TRUE); 387 elm_object_item_disabled_set(inst->menu.save, EINA_TRUE);
375 elm_object_item_disabled_set(inst->toolbar.save, EINA_TRUE); 388 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)
582 evas_textblock_style_set(ts, eina_strbuf_string_get(sbuf)); 595 evas_textblock_style_set(ts, eina_strbuf_string_get(sbuf));
583 596
584 evas_object_textblock_style_user_push((Evas_Object *) tb, ts); 597 evas_object_textblock_style_user_push((Evas_Object *) tb, ts);
598
599 evas_textblock_style_free(ts);
585 } 600 }
586 601
587 elm_entry_calc_force(inst->entry); 602 elm_entry_calc_force(inst->entry);
@@ -692,6 +707,10 @@ ecrire_editor_add(const char *filename, const char *font_name, int font_size)
692 Evas_Coord w = 600, h = 600; 707 Evas_Coord w = 600, h = 600;
693 708
694 Ecrire_Editor *inst = calloc(1, sizeof(Ecrire_Editor)); 709 Ecrire_Editor *inst = calloc(1, sizeof(Ecrire_Editor));
710 EINA_SAFETY_ON_NULL_RETURN(inst);
711
712 instances = eina_list_append(instances, inst);
713
695 inst->unsaved = 1; 714 inst->unsaved = 1;
696 inst->filename = NULL; 715 inst->filename = NULL;
697 inst->last_saved_stack_ptr = NULL; 716 inst->last_saved_stack_ptr = NULL;