ui/common/context.c

changeset 1169
c69f2941d536
parent 1168
2f9d8af6a499
equal deleted inserted replaced
1168:2f9d8af6a499 1169:c69f2941d536
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);
462 break; 472 break;
463 } 473 }
464 case UI_VAR_LIST: { 474 case UI_VAR_LIST: {
465 UiList *f = from; 475 UiList *f = from;
466 UiList *t = to; 476 UiList *t = to;
477 // save selection
478 ui_list_selection_free(f->saved_selection);
479 if(f->getselection && f->save_selection) {
480 f->saved_selection = ui_list_get_selection_allocated(f);
481 } else {
482 f->saved_selection = NULL;
483 }
484
467 uic_list_copy(f, t); 485 uic_list_copy(f, t);
468 ui_list_update(t); 486 ui_list_update(t);
469 if(t->setselection && t->saved_selection) { 487 if(t->setselection && t->saved_selection) {
470 t->setselection(t, *t->saved_selection); 488 t->setselection(t, *t->saved_selection);
471 } 489 }

mercurial