ui/common/context.c

changeset 906
edfdf9776da9
parent 905
41614c767451
child 916
6fdcf1cbbec9
equal deleted inserted replaced
905:41614c767451 906:edfdf9776da9
122 var_ctx = var_ctx->parent; 122 var_ctx = var_ctx->parent;
123 } 123 }
124 } 124 }
125 125
126 static void uic_context_unbind_vars(UiContext *ctx) { 126 static void uic_context_unbind_vars(UiContext *ctx) {
127 ui_onchange_events_enable(FALSE);
127 CxMapIterator mi = cxMapIterator(ctx->vars); 128 CxMapIterator mi = cxMapIterator(ctx->vars);
128 cx_foreach(CxMapEntry*, entry, mi) { 129 cx_foreach(CxMapEntry*, entry, mi) {
130 printf("detach %.*s\n", (int)entry->key->len, (char*)entry->key->data);
129 UiVar *var = entry->value; 131 UiVar *var = entry->value;
130 // var->from && var->from_ctx && var->from_ctx != ctx 132 // var->from && var->from_ctx && var->from_ctx != ctx
131 uic_save_var(var); 133 uic_save_var(var);
132 if(var->from) { 134 if(var->from) {
133 uic_copy_var_binding(var, var->from, FALSE); 135 uic_copy_var_binding(var, var->from, FALSE);
134 cxMapPut(var->from->from_ctx->vars, *entry->key, var->from); 136 cxMapPut(var->from->from_ctx->vars, *entry->key, var->from);
135 var->from = NULL; 137 var->from = NULL;
136 } 138 }
139 uic_unbind_var(var);
137 } 140 }
138 141
139 if(ctx->documents) { 142 if(ctx->documents) {
140 CxIterator i = cxListIterator(ctx->documents); 143 CxIterator i = cxListIterator(ctx->documents);
141 cx_foreach(void *, doc, i) { 144 cx_foreach(void *, doc, i) {
142 UiContext *subctx = ui_document_context(doc); 145 UiContext *subctx = ui_document_context(doc);
143 uic_context_unbind_vars(subctx); 146 uic_context_unbind_vars(subctx);
144 } 147 }
145 } 148 }
149
150 ui_onchange_events_enable(TRUE);
146 } 151 }
147 152
148 void uic_context_detach_document(UiContext *ctx, void *document) { 153 void uic_context_detach_document(UiContext *ctx, void *document) {
149 // find the document in the documents list 154 // find the document in the documents list
150 size_t docIndex = cxListFind(ctx->documents, document); 155 size_t docIndex = cxListFind(ctx->documents, document);
213 var->original_value = NULL; 218 var->original_value = NULL;
214 var->from = NULL; 219 var->from = NULL;
215 var->from_ctx = ctx; 220 var->from_ctx = ctx;
216 var->bound = FALSE; 221 var->bound = FALSE;
217 222
218 cxMempoolSetDestructor(var, (cx_destructor_func)uic_unbind_var); 223 cxMempoolSetDestructor(var, (cx_destructor_func)uic_unbind_var); // TODO: use another destructor that cleans the value (UiString free, UiText destroy, ...)
219 224
220 cxMapPut(ctx->vars, name, var); 225 cxMapPut(ctx->vars, name, var);
221 226
222 return var; 227 return var;
223 } 228 }
334 to->value = to->original_value; 339 to->value = to->original_value;
335 tovalue = to->value; 340 tovalue = to->value;
336 } 341 }
337 } 342 }
338 343
339 uic_copy_value_binding(from->type, from->value, to->value); 344 uic_copy_value_binding(from->type, fromvalue, tovalue);
340 } 345 }
341 346
342 void uic_copy_value_binding(UiVarType type, void *from, void *to) { 347 void uic_copy_value_binding(UiVarType type, void *from, void *to) {
343 ui_setop_enable(TRUE); 348 ui_setop_enable(TRUE);
344 349

mercurial