save selections when copying bindings, fix invalid selections in gtk4 column view

Thu, 04 Jun 2026 20:35:31 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 04 Jun 2026 20:35:31 +0200
changeset 1169
c69f2941d536
parent 1168
2f9d8af6a499
child 1170
b79469a55540

save selections when copying bindings, fix invalid selections in gtk4 column view

ui/common/context.c file | annotate | diff | comparison | revisions
ui/gtk/list.c file | annotate | diff | comparison | revisions
--- a/ui/common/context.c	Thu Jun 04 19:59:58 2026 +0200
+++ b/ui/common/context.c	Thu Jun 04 20:35:31 2026 +0200
@@ -139,6 +139,10 @@
 }
 
 void uic_context_update_bindings(UiContext *ctx) {
+    int onchange_enabled = ui_onchange_events_is_enabled();
+    int onselection_enabled = ui_selection_events_is_enabled();
+    ui_onchange_events_enable(FALSE);
+    ui_selection_events_enable(FALSE);
     // if a document variable has the same name as a parent variable,
     // move the bindings to the document
     UiContext *var_ctx = ctx->parent;
@@ -167,6 +171,8 @@
             uic_context_update_bindings(subctx);
         }
     }
+    ui_onchange_events_enable(onchange_enabled);
+    ui_selection_events_enable(onselection_enabled);
 }
 
 void uic_context_attach_document(UiContext *ctx, void *document) {
@@ -187,7 +193,10 @@
 }
 
 static void uic_context_unbind_vars(UiContext *ctx) {
+    int onchange_enabled = ui_onchange_events_is_enabled();
+    int onselection_enabled = ui_selection_events_is_enabled();
     ui_onchange_events_enable(FALSE);
+    ui_selection_events_enable(FALSE);
     CxMapIterator mi = cxMapIterator(ctx->vars);
     cx_foreach(CxMapEntry*, entry, mi) {
         //printf("detach %.*s\n", (int)entry->key->len, (char*)entry->key->data);
@@ -210,7 +219,8 @@
         }
     }
     
-    ui_onchange_events_enable(TRUE);
+    ui_onchange_events_enable(onchange_enabled);
+    ui_selection_events_enable(onselection_enabled);
 }
 
 void uic_context_detach_document(UiContext *ctx, void *document) {
@@ -464,6 +474,14 @@
         case UI_VAR_LIST: {         
             UiList *f = from;
             UiList *t = to;
+            // save selection
+            ui_list_selection_free(f->saved_selection);
+            if(f->getselection && f->save_selection) {
+                f->saved_selection = ui_list_get_selection_allocated(f);
+            } else {
+                f->saved_selection = NULL;
+            }
+    
             uic_list_copy(f, t);
             ui_list_update(t);
             if(t->setselection && t->saved_selection) {
--- a/ui/gtk/list.c	Thu Jun 04 19:59:58 2026 +0200
+++ b/ui/gtk/list.c	Thu Jun 04 20:35:31 2026 +0200
@@ -938,6 +938,9 @@
     if(i < 0) {
         cxMapClear(view->bound_rows);
         ui_update_liststore(view->liststore, list);
+        free(view->selection.rows);
+        view->selection.rows = NULL;
+        view->selection.count = 0;
     } else {
         void *value = list->get(list, i);
         if(value) {

mercurial