Tue, 18 Nov 2025 12:55:28 +0100
disable onchange events when detaching a document
| ui/common/context.c | file | annotate | diff | comparison | revisions | |
| ui/common/types.c | file | annotate | diff | comparison | revisions | |
| ui/gtk/text.c | file | annotate | diff | comparison | revisions | |
| ui/ui/toolkit.h | file | annotate | diff | comparison | revisions |
--- a/ui/common/context.c Tue Nov 18 10:23:42 2025 +0100 +++ b/ui/common/context.c Tue Nov 18 12:55:28 2025 +0100 @@ -124,8 +124,10 @@ } static void uic_context_unbind_vars(UiContext *ctx) { + ui_onchange_events_enable(FALSE); CxMapIterator mi = cxMapIterator(ctx->vars); cx_foreach(CxMapEntry*, entry, mi) { + printf("detach %.*s\n", (int)entry->key->len, (char*)entry->key->data); UiVar *var = entry->value; // var->from && var->from_ctx && var->from_ctx != ctx uic_save_var(var); @@ -134,6 +136,7 @@ cxMapPut(var->from->from_ctx->vars, *entry->key, var->from); var->from = NULL; } + uic_unbind_var(var); } if(ctx->documents) { @@ -143,6 +146,8 @@ uic_context_unbind_vars(subctx); } } + + ui_onchange_events_enable(TRUE); } void uic_context_detach_document(UiContext *ctx, void *document) { @@ -215,7 +220,7 @@ var->from_ctx = ctx; var->bound = FALSE; - cxMempoolSetDestructor(var, (cx_destructor_func)uic_unbind_var); + cxMempoolSetDestructor(var, (cx_destructor_func)uic_unbind_var); // TODO: use another destructor that cleans the value (UiString free, UiText destroy, ...) cxMapPut(ctx->vars, name, var); @@ -336,7 +341,7 @@ } } - uic_copy_value_binding(from->type, from->value, to->value); + uic_copy_value_binding(from->type, fromvalue, tovalue); } void uic_copy_value_binding(UiVarType type, void *from, void *to) {
--- a/ui/common/types.c Tue Nov 18 10:23:42 2025 +0100 +++ b/ui/common/types.c Tue Nov 18 12:55:28 2025 +0100 @@ -798,6 +798,7 @@ } static int ui_set_op = 0; +static int ui_onchange_events_enabled = TRUE; void ui_setop_enable(int set) { ui_set_op = set; @@ -807,6 +808,14 @@ return ui_set_op; } +void ui_onchange_events_enable(UiBool enable) { + ui_onchange_events_enabled = enable; +} + +UiBool ui_onchange_events_is_enabled(void) { + return ui_onchange_events_enabled; +} + /* ---------------- List initializers and wrapper functions ---------------- */ void ui_global_list_initializer(ui_list_init_func func, void *userdata) {
--- a/ui/gtk/text.c Tue Nov 18 10:23:42 2025 +0100 +++ b/ui/gtk/text.c Tue Nov 18 12:55:28 2025 +0100 @@ -335,6 +335,10 @@ void ui_textbuf_changed(GtkTextBuffer *textbuffer, UiTextArea *textarea) { + if(!ui_onchange_events_is_enabled()) { + return; + } + UiText *value = textarea->var->value; UiEvent e; @@ -698,6 +702,10 @@ } void ui_textfield_changed(GtkEditable *editable, UiTextField *textfield) { + if(!ui_onchange_events_is_enabled()) { + return; + } + UiString *value = textfield->var->value; UiEvent e;
--- a/ui/ui/toolkit.h Tue Nov 18 10:23:42 2025 +0100 +++ b/ui/ui/toolkit.h Tue Nov 18 12:55:28 2025 +0100 @@ -681,6 +681,8 @@ UIEXPORT void ui_setop_enable(int set); UIEXPORT int ui_get_setop(void); +UIEXPORT void ui_onchange_events_enable(UiBool enable); +UIEXPORT UiBool ui_onchange_events_is_enabled(void); UIEXPORT void ui_global_list_initializer(ui_list_init_func func, void *userdata);