# HG changeset patch # User Olaf Wintermann # Date 1474180777 -7200 # Node ID 774b741984a28a31d7d535ad4ad3d5ddf458f8ce # Parent 212b63dd61be47a8936fdf9f70c487f6beb278e8 detaching variables correctly diff -r 212b63dd61be -r 774b741984a2 ui/common/context.c --- a/ui/common/context.c Sun Sep 18 07:45:42 2016 +0200 +++ b/ui/common/context.c Sun Sep 18 08:39:37 2016 +0200 @@ -61,6 +61,10 @@ } void uic_context_set_document(UiContext *ctx, void *document) { + if(ctx->document == document) { + return; + } + UiContext *docctx = ui_document_context(document); if(!docctx) { return; @@ -228,6 +232,10 @@ } else { f->value = f->get(f); f->pos = f->position(f); + f->set = NULL; + f->get = NULL; + f->setposition = NULL; + f->position = NULL; } break; } diff -r 212b63dd61be -r 774b741984a2 ui/gtk/text.c --- a/ui/gtk/text.c Sun Sep 18 07:45:42 2016 +0200 +++ b/ui/gtk/text.c Sun Sep 18 08:39:37 2016 +0200 @@ -242,6 +242,25 @@ gtk_widget_grab_focus(widget); } +void ui_text_set(UiText *text, char *str) { + if(text->set) { + text->set(text, str); + } else { + if(text->value) { + g_free(text->value); + } + text->value = g_strdup(str); + } +} + +char* ui_text_get(UiText *text) { + if(text->get) { + return text->get(text); + } else { + return text->value; + } +} + // undo manager functions diff -r 212b63dd61be -r 774b741984a2 ui/motif/text.c --- a/ui/motif/text.c Sun Sep 18 07:45:42 2016 +0200 +++ b/ui/motif/text.c Sun Sep 18 08:39:37 2016 +0200 @@ -157,6 +157,27 @@ return (int)XmTextGetLastPosition(text->obj); } + +void ui_text_set(UiText *text, char *str) { + if(text->set) { + text->set(text, str); + } else { + if(text->value) { + XtFree(text->value); + } + text->value = XtNewString(str); + } +} + +char* ui_text_get(UiText *text) { + if(text->get) { + return text->get(text); + } else { + return text->value; + } +} + + UiUndoMgr* ui_create_undomgr() { UiUndoMgr *mgr = malloc(sizeof(UiUndoMgr)); mgr->begin = NULL;