# HG changeset patch
# User Olaf Wintermann <olaf.wintermann@gmail.com>
# Date 1706438562 -3600
# Node ID e2b33055113f41156d7f8feb7f005dc25dc8ca39
# Parent  e160bb392148462ece5e5ab8e54efd92a59d1c93
fix list binding not copied correctly when attaching a document

diff -r e160bb392148 -r e2b33055113f ui/common/context.c
--- a/ui/common/context.c	Sun Jan 28 10:06:54 2024 +0100
+++ b/ui/common/context.c	Sun Jan 28 11:42:42 2024 +0100
@@ -314,11 +314,15 @@
             break;
         }
         case UI_VAR_LIST: {
-            UiList *f = fromvalue;
-            UiList *t = to->value;
-            if(!f->obj) break;
-            uic_list_copy(f, t);
-            t->update(t, -1);
+            // TODO: not sure how correct this is
+
+            UiVar tmp = *from;
+            *from = *to;
+            *to = tmp;
+
+            UiList* t = to->value;
+            ui_notify(t->observers, NULL);
+            
             break;
         }
         case UI_VAR_RANGE: {
diff -r e160bb392148 -r e2b33055113f ui/common/document.c
--- a/ui/common/document.c	Sun Jan 28 10:06:54 2024 +0100
+++ b/ui/common/document.c	Sun Jan 28 11:42:42 2024 +0100
@@ -38,7 +38,9 @@
 static CxMap *documents;
 
 void uic_docmgr_init() {
-    documents = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32);
+    if (!documents) {
+        documents = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32);
+    }
 }
 
 void ui_set_document(UiObject *obj, void *document) {
@@ -80,7 +82,7 @@
 }
 
 void* ui_document_new(size_t size) {
-    CxMempool *mp = cxBasicMempoolCreate(256);
+    CxMempool *mp = cxMempoolCreate(256, NULL);
     const CxAllocator *a = mp->allocator;
     UiContext *ctx = cxCalloc(a, 1, sizeof(UiContext));
     ctx->attach_document = uic_context_attach_document;
diff -r e160bb392148 -r e2b33055113f ui/common/menu.c
--- a/ui/common/menu.c	Sun Jan 28 10:06:54 2024 +0100
+++ b/ui/common/menu.c	Sun Jan 28 11:42:42 2024 +0100
@@ -237,6 +237,10 @@
 
 
 void uic_add_menu_to_stack(UiMenu* menu) {
+    if (!current) {
+        current = cxLinkedListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS);
+    }
+
     cxListInsert(current, 0, menu);
 }
 
diff -r e160bb392148 -r e2b33055113f ui/winui/toolkit.cpp
--- a/ui/winui/toolkit.cpp	Sun Jan 28 10:06:54 2024 +0100
+++ b/ui/winui/toolkit.cpp	Sun Jan 28 11:42:42 2024 +0100
@@ -34,6 +34,7 @@
 #include <cx/mempool.h>
 
 #include "../common/context.h"
+#include "../common/document.h"
 #include "../common/toolbar.h"
 
 #include "icons.h"
@@ -158,6 +159,7 @@
 	//ui_appsdk_bootstrap();
 
 	uic_init_global_context();
+	uic_docmgr_init();
 	uic_toolbar_init();
 }