add function for disabling selection events

Sun, 25 Jan 2026 11:44:49 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 25 Jan 2026 11:44:49 +0100
changeset 1057
b0bc313dea43
parent 1056
541cec5e913c
child 1058
92592a640fe3

add function for disabling selection events

ui/cocoa/ListDelegate.m file | annotate | diff | comparison | revisions
ui/cocoa/list.m file | annotate | diff | comparison | revisions
ui/common/types.c file | annotate | diff | comparison | revisions
ui/gtk/list.c file | annotate | diff | comparison | revisions
ui/qt/model.cpp file | annotate | diff | comparison | revisions
ui/ui/toolkit.h file | annotate | diff | comparison | revisions
--- a/ui/cocoa/ListDelegate.m	Sun Jan 25 11:24:02 2026 +0100
+++ b/ui/cocoa/ListDelegate.m	Sun Jan 25 11:44:49 2026 +0100
@@ -59,7 +59,7 @@
 }
 
 - (void) tableViewSelectionDidChange:(NSNotification *) notification {
-    if(_onselection) {
+    if(_onselection && ui_selection_events_is_enabled()) {
         UiListSelection sel = ui_tableview_selection(_tableview);
         
         UiEvent  event;
--- a/ui/cocoa/list.m	Sun Jan 25 11:24:02 2026 +0100
+++ b/ui/cocoa/list.m	Sun Jan 25 11:44:49 2026 +0100
@@ -263,7 +263,7 @@
     event.eventdatatype = UI_EVENT_DATA_LIST_ELM;
     event.intval = index;
     
-    if(_onselection) {
+    if(_onselection && ui_selection_events_is_enabled()) {
         _onselection(&event, _onselectiondata);
     }
     
--- a/ui/common/types.c	Sun Jan 25 11:24:02 2026 +0100
+++ b/ui/common/types.c	Sun Jan 25 11:44:49 2026 +0100
@@ -810,13 +810,22 @@
 }
 
 UIEXPORT void ui_list_setselection(UiList *list, int index) {
+    ui_list_setselection2(list, index, TRUE);
+}
+
+UIEXPORT void ui_list_setselection2(UiList *list, int index, UiBool selection_event) {
     if (list->setselection) {
         UiListSelection sel = { 0, NULL };
         if(index >= 0) {
             sel.count = 1;
             sel.rows = &index;
         }
+        UiBool events = ui_selection_events_is_enabled();
+        if(!selection_event) {
+            ui_selection_events_enable(FALSE);
+        }
         list->setselection(list, sel);
+        ui_selection_events_enable(events);
     }
 }
 
@@ -883,6 +892,7 @@
 
 static int ui_set_op = 0;
 static int ui_onchange_events_enabled = TRUE;
+static int ui_selection_events_enabled = TRUE;
 
 void ui_setop_enable(int set) {
     ui_set_op = set;
@@ -900,6 +910,14 @@
     return ui_onchange_events_enabled;
 }
 
+void ui_selection_events_enable(UiBool enable) {
+    ui_selection_events_enabled = enable;
+}
+
+UiBool ui_selection_events_is_enabled(void) {
+    return ui_selection_events_enabled;
+}
+
 /* ---------------- List initializers and wrapper functions ---------------- */
 
 void ui_global_list_initializer(ui_list_init_func func, void *userdata) {
--- a/ui/gtk/list.c	Sun Jan 25 11:24:02 2026 +0100
+++ b/ui/gtk/list.c	Sun Jan 25 11:44:49 2026 +0100
@@ -874,7 +874,9 @@
 void ui_listview_selection_changed(GtkSelectionModel* self, guint position, guint n_items, gpointer userdata) {
     UiListView *view = userdata;
     listview_update_selection(view);
-    listview_event(view->onselection, view->onselectiondata, view);
+    if(ui_selection_events_is_enabled()) {
+        listview_event(view->onselection, view->onselectiondata, view);
+    }
 }
 
 void ui_dropdown_activate(GtkDropDown* self, gpointer userdata) {
@@ -1795,6 +1797,10 @@
         GtkTreeSelection *treeselection,
         UiTreeEventData *event)
 {
+    if(!ui_selection_events_is_enabled()) {
+        return;
+    }
+    
     UiListSelection selection = ui_listview_get_selection(treeselection, event);
     
     UiEvent e;
--- a/ui/qt/model.cpp	Sun Jan 25 11:24:02 2026 +0100
+++ b/ui/qt/model.cpp	Sun Jan 25 11:44:49 2026 +0100
@@ -99,6 +99,10 @@
 }
 
 void ListModel::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) {
+    if(!ui_selection_events_is_enabled()) {
+        return;
+    }
+    
     UiListSelection sel;
     if(listview) {
         sel = ui_selection_model_to_selection(listview->selectionModel());
--- a/ui/ui/toolkit.h	Sun Jan 25 11:24:02 2026 +0100
+++ b/ui/ui/toolkit.h	Sun Jan 25 11:44:49 2026 +0100
@@ -689,6 +689,7 @@
 
 UIEXPORT int ui_list_getselection(UiList *list);
 UIEXPORT void ui_list_setselection(UiList *list, int index);
+UIEXPORT void ui_list_setselection2(UiList *list, int index, UiBool selection_event);
 
 UIEXPORT void ui_listselection_free(UiListSelection selection);
 
@@ -719,6 +720,8 @@
 UIEXPORT int ui_get_setop(void);
 UIEXPORT void ui_onchange_events_enable(UiBool enable);
 UIEXPORT UiBool ui_onchange_events_is_enabled(void);
+UIEXPORT void ui_selection_events_enable(UiBool enable);
+UIEXPORT UiBool ui_selection_events_is_enabled(void);
 
     
 UIEXPORT void ui_global_list_initializer(ui_list_init_func func, void *userdata);

mercurial