90 void uic_context_attach_document(UiContext *ctx, void *document) { |
90 void uic_context_attach_document(UiContext *ctx, void *document) { |
91 cxListAdd(ctx->documents, document); |
91 cxListAdd(ctx->documents, document); |
92 ctx->document = document; |
92 ctx->document = document; |
93 |
93 |
94 UiContext *doc_ctx = ui_document_context(document); |
94 UiContext *doc_ctx = ui_document_context(document); |
|
95 doc_ctx->parent = ctx; |
95 |
96 |
96 // check if any parent context has an unbound variable with the same name |
97 // check if any parent context has an unbound variable with the same name |
97 // as any document variable |
98 // as any document variable |
98 UiContext *var_ctx = ctx; |
99 UiContext *var_ctx = ctx; |
99 while(var_ctx) { |
100 while(var_ctx) { |
109 cxIteratorFlagRemoval(i); |
110 cxIteratorFlagRemoval(i); |
110 } |
111 } |
111 } |
112 } |
112 } |
113 } |
113 |
114 |
114 var_ctx = ctx->parent; |
115 var_ctx = var_ctx->parent; |
115 } |
116 } |
116 } |
117 } |
117 |
118 |
118 static void uic_context_unbind_vars(UiContext *ctx) { |
119 static void uic_context_unbind_vars(UiContext *ctx) { |
119 CxMapIterator mi = cxMapIterator(ctx->vars); |
120 CxMapIterator mi = cxMapIterator(ctx->vars); |
120 cx_foreach(CxMapEntry*, entry, mi) { |
121 cx_foreach(CxMapEntry*, entry, mi) { |
121 UiVar *var = entry->value; |
122 UiVar *var = entry->value; |
122 if(var->from && var->from_ctx) { |
123 if(var->from && var->from_ctx && var->from_ctx != ctx) { |
123 uic_save_var2(var); |
124 uic_save_var2(var); |
124 uic_copy_binding(var, var->from, FALSE); |
125 uic_copy_binding(var, var->from, FALSE); |
125 cxMapPut(var->from_ctx->vars_unbound, *entry->key, var->from); |
126 cxMapPut(var->from_ctx->vars_unbound, *entry->key, var->from); |
126 var->from_ctx = ctx; |
127 var->from_ctx = ctx; |
127 } |
128 } |
146 cxListRemove(ctx->documents, docIndex); |
147 cxListRemove(ctx->documents, docIndex); |
147 ctx->document = cxListAt(ctx->documents, 0); |
148 ctx->document = cxListAt(ctx->documents, 0); |
148 |
149 |
149 UiContext *docctx = ui_document_context(document); |
150 UiContext *docctx = ui_document_context(document); |
150 uic_context_unbind_vars(docctx); // unbind all doc/subdoc vars from the parent |
151 uic_context_unbind_vars(docctx); // unbind all doc/subdoc vars from the parent |
|
152 docctx->parent = NULL; |
151 } |
153 } |
152 |
154 |
153 void uic_context_detach_all(UiContext *ctx) { |
155 void uic_context_detach_all(UiContext *ctx) { |
154 // copy list |
156 // copy list |
155 CxList *ls = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS); |
157 CxList *ls = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS); |