ui/common/context.c

changeset 103
6606616eca9f
parent 102
64ded9f6a6c6
child 108
77254bd6dccb
equal deleted inserted replaced
102:64ded9f6a6c6 103:6606616eca9f
137 } 137 }
138 } 138 }
139 139
140 void uic_context_detach_document2(UiContext *ctx, void *document) { 140 void uic_context_detach_document2(UiContext *ctx, void *document) {
141 // find the document in the documents list 141 // find the document in the documents list
142 ssize_t docIndex = cxListFind(ctx->documents, document); 142 size_t docIndex = cxListFind(ctx->documents, document);
143 if(docIndex < 0) { 143 if(!cxListIndexValid(ctx->documents, docIndex)) {
144 return; 144 return;
145 } 145 }
146 146
147 cxListRemove(ctx->documents, docIndex); 147 cxListRemove(ctx->documents, docIndex);
148 ctx->document = cxListAt(ctx->documents, 0); 148 ctx->document = cxListAt(ctx->documents, 0);
289 // update var 289 // update var
290 if(copytodoc) { 290 if(copytodoc) {
291 to->from = from; 291 to->from = from;
292 to->from_ctx = from->from_ctx; 292 to->from_ctx = from->from_ctx;
293 } 293 }
294
295 ui_setop_enable(TRUE);
294 296
295 // copy binding 297 // copy binding
296 // we don't copy the observer, because the from var has never one 298 // we don't copy the observer, because the from var has never one
297 switch(from->type) { 299 switch(from->type) {
298 default: fprintf(stderr, "uic_copy_binding: wtf!\n"); break; 300 default: fprintf(stderr, "uic_copy_binding: wtf!\n"); break;
325 case UI_VAR_TEXT: { 327 case UI_VAR_TEXT: {
326 UiText *f = fromvalue; 328 UiText *f = fromvalue;
327 UiText *t = to->value; 329 UiText *t = to->value;
328 if(!f->obj) break; 330 if(!f->obj) break;
329 uic_text_copy(f, t); 331 uic_text_copy(f, t);
330 char *tvalue = t->value.ptr ? t->value.ptr : ""; 332 t->restore(t);
331 t->set(t, tvalue);
332 t->setposition(t, t->pos);
333 break; 333 break;
334 } 334 }
335 case UI_VAR_LIST: { 335 case UI_VAR_LIST: {
336 // TODO: not sure how correct this is 336 // TODO: not sure how correct this is
337 337
347 UiVar tmp = *from; 347 UiVar tmp = *from;
348 *from = *to; 348 *from = *to;
349 *to = tmp; 349 *to = tmp;
350 350
351 UiList* t2 = to->value; 351 UiList* t2 = to->value;
352 ui_notify(t2->observers, NULL); 352 if(t->update) {
353 t->update(t, -1);
354 }
355 ui_notify(t2->observers, NULL); // TODO: why not t?
353 356
354 break; 357 break;
355 } 358 }
356 case UI_VAR_RANGE: { 359 case UI_VAR_RANGE: {
357 UiRange *f = fromvalue; 360 UiRange *f = fromvalue;
370 uic_generic_copy(f, t); 373 uic_generic_copy(f, t);
371 t->set(t, t->value, t->type); 374 t->set(t, t->value, t->type);
372 break; 375 break;
373 } 376 }
374 } 377 }
378
379 ui_setop_enable(FALSE);
375 } 380 }
376 381
377 void uic_save_var2(UiVar *var) { 382 void uic_save_var2(UiVar *var) {
378 switch(var->type) { 383 switch(var->type) {
379 case UI_VAR_SPECIAL: break; 384 case UI_VAR_SPECIAL: break;

mercurial