| 137 |
137 |
| 138 cxMempoolFree(ctx->mp); |
138 cxMempoolFree(ctx->mp); |
| 139 } |
139 } |
| 140 |
140 |
| 141 void uic_context_update_bindings(UiContext *ctx) { |
141 void uic_context_update_bindings(UiContext *ctx) { |
| |
142 int onchange_enabled = ui_onchange_events_is_enabled(); |
| |
143 int onselection_enabled = ui_selection_events_is_enabled(); |
| |
144 ui_onchange_events_enable(FALSE); |
| |
145 ui_selection_events_enable(FALSE); |
| 142 // if a document variable has the same name as a parent variable, |
146 // if a document variable has the same name as a parent variable, |
| 143 // move the bindings to the document |
147 // move the bindings to the document |
| 144 UiContext *var_ctx = ctx->parent; |
148 UiContext *var_ctx = ctx->parent; |
| 145 while(var_ctx) { |
149 while(var_ctx) { |
| 146 CxMapIterator i = cxMapIterator(var_ctx->vars); |
150 CxMapIterator i = cxMapIterator(var_ctx->vars); |
| 165 cx_foreach(void *, doc, i) { |
169 cx_foreach(void *, doc, i) { |
| 166 UiContext *subctx = ui_document_context(doc); |
170 UiContext *subctx = ui_document_context(doc); |
| 167 uic_context_update_bindings(subctx); |
171 uic_context_update_bindings(subctx); |
| 168 } |
172 } |
| 169 } |
173 } |
| |
174 ui_onchange_events_enable(onchange_enabled); |
| |
175 ui_selection_events_enable(onselection_enabled); |
| 170 } |
176 } |
| 171 |
177 |
| 172 void uic_context_attach_document(UiContext *ctx, void *document) { |
178 void uic_context_attach_document(UiContext *ctx, void *document) { |
| 173 if(ctx->single_document_mode) { |
179 if(ctx->single_document_mode) { |
| 174 if(ctx->document) { |
180 if(ctx->document) { |
| 185 |
191 |
| 186 uic_context_update_bindings(doc_ctx); |
192 uic_context_update_bindings(doc_ctx); |
| 187 } |
193 } |
| 188 |
194 |
| 189 static void uic_context_unbind_vars(UiContext *ctx) { |
195 static void uic_context_unbind_vars(UiContext *ctx) { |
| |
196 int onchange_enabled = ui_onchange_events_is_enabled(); |
| |
197 int onselection_enabled = ui_selection_events_is_enabled(); |
| 190 ui_onchange_events_enable(FALSE); |
198 ui_onchange_events_enable(FALSE); |
| |
199 ui_selection_events_enable(FALSE); |
| 191 CxMapIterator mi = cxMapIterator(ctx->vars); |
200 CxMapIterator mi = cxMapIterator(ctx->vars); |
| 192 cx_foreach(CxMapEntry*, entry, mi) { |
201 cx_foreach(CxMapEntry*, entry, mi) { |
| 193 //printf("detach %.*s\n", (int)entry->key->len, (char*)entry->key->data); |
202 //printf("detach %.*s\n", (int)entry->key->len, (char*)entry->key->data); |
| 194 UiVar *var = entry->value; |
203 UiVar *var = entry->value; |
| 195 // var->from && var->from_ctx && var->from_ctx != ctx |
204 // var->from && var->from_ctx && var->from_ctx != ctx |
| 208 UiContext *subctx = ui_document_context(doc); |
217 UiContext *subctx = ui_document_context(doc); |
| 209 uic_context_unbind_vars(subctx); |
218 uic_context_unbind_vars(subctx); |
| 210 } |
219 } |
| 211 } |
220 } |
| 212 |
221 |
| 213 ui_onchange_events_enable(TRUE); |
222 ui_onchange_events_enable(onchange_enabled); |
| |
223 ui_selection_events_enable(onselection_enabled); |
| 214 } |
224 } |
| 215 |
225 |
| 216 void uic_context_detach_document(UiContext *ctx, void *document) { |
226 void uic_context_detach_document(UiContext *ctx, void *document) { |
| 217 // find the document in the documents list |
227 // find the document in the documents list |
| 218 size_t docIndex = cxListFind(ctx->documents, document); |
228 size_t docIndex = cxListFind(ctx->documents, document); |