Thu, 04 Jun 2026 19:20:04 +0200
fix that attaching a document does not update bindings of subdocuments
| ui/common/context.c | file | annotate | diff | comparison | revisions | |
| ui/common/context.h | file | annotate | diff | comparison | revisions |
--- a/ui/common/context.c Wed Jun 03 20:19:27 2026 +0200 +++ b/ui/common/context.c Thu Jun 04 19:20:04 2026 +0200 @@ -141,6 +141,37 @@ cxMempoolFree(ctx->mp); } +void uic_context_update_bindings(UiContext *ctx) { + // if a document variable has the same name as a parent variable, + // move the bindings to the document + UiContext *var_ctx = ctx->parent; + while(var_ctx) { + CxMapIterator i = cxMapIterator(var_ctx->vars); + cx_foreach(CxMapEntry*, entry, i) { + printf("attach %.*s\n", (int)entry->key->len, (char*)entry->key->data); + UiVar *var = entry->value; + UiVar *docvar = cxMapGet(ctx->vars, *entry->key); + if(docvar) { + // bind var to document var + uic_copy_var_binding(var, docvar, TRUE); + cxIteratorFlagRemoval(i); + } + } + + var_ctx = var_ctx->parent; + } + + ui_update_action_bindings(ctx); + + if(ctx->documents) { + CxIterator i = cxListIterator(ctx->documents); + cx_foreach(void *, doc, i) { + UiContext *subctx = ui_document_context(doc); + uic_context_update_bindings(subctx); + } + } +} + void uic_context_attach_document(UiContext *ctx, void *document) { if(ctx->single_document_mode) { if(ctx->document) { @@ -155,26 +186,7 @@ doc_ctx->parent = ctx; doc_ctx->ref++; - // if a document variable has the same name as a parent variable, - // move the bindings to the document - UiContext *var_ctx = ctx; - while(var_ctx) { - CxMapIterator i = cxMapIterator(var_ctx->vars); - cx_foreach(CxMapEntry*, entry, i) { - printf("attach %.*s\n", (int)entry->key->len, (char*)entry->key->data); - UiVar *var = entry->value; - UiVar *docvar = cxMapGet(doc_ctx->vars, *entry->key); - if(docvar) { - // bind var to document var - uic_copy_var_binding(var, docvar, TRUE); - cxIteratorFlagRemoval(i); - } - } - - var_ctx = var_ctx->parent; - } - - ui_update_action_bindings(ctx); + uic_context_update_bindings(doc_ctx); } static void uic_context_unbind_vars(UiContext *ctx) {
--- a/ui/common/context.h Wed Jun 03 20:19:27 2026 +0200 +++ b/ui/common/context.h Thu Jun 04 19:20:04 2026 +0200 @@ -139,6 +139,7 @@ void uic_context_prepare_close(UiContext *ctx); void uic_context_destroy(UiContext *ctx, void *document); +void uic_context_update_bindings(UiContext *ctx); void uic_context_attach_document(UiContext *ctx, void *document); void uic_context_detach_document(UiContext *ctx, void *document); void uic_context_attach_context(UiContext *ctx, UiContext *doc_ctx); // TODO