]> uap-core.de Git - note.git/commitdiff
fix ListSelection.selection method main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 20 May 2026 18:59:01 +0000 (20:59 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 20 May 2026 18:59:01 +0000 (20:59 +0200)
application/src/newnotebook.rs
ui-rs/src/ui/toolkit.rs

index 1bb1aeb75da003544af108cbca56e203e4d47d78..297d93631c8e7762e26ef9098742e3bbaec215d9 100644 (file)
@@ -53,10 +53,8 @@ impl NewNotebookDialog {
             self.message.set("Name required");
             return;
         }
-
-        let i = self.groups.selected_index();
-        let collections = self.groups.data();
-        let parent = usize::try_from(i).ok().and_then(|idx| collections.get(idx));
+        
+        let parent = self.groups.selected_element();
         if let Some(parent) = parent {
             let proxy = obj.obj_proxy();
 
index 5ee295f98556a922fdda202f39a0b72ea0d50567..f63a89c605b59d7bb7178886fff80ddb485ecd0f 100644 (file)
@@ -622,7 +622,7 @@ impl<T> UiList<T> {
         }
     }
 
-    pub fn selection(&mut self) -> Vec<i32> {
+    pub fn selection(&self) -> Vec<i32> {
         unsafe {
             let selection = ListSelection {
                 ptr: ui_list_get_selection_allocated(self.ptr),
@@ -638,6 +638,15 @@ impl<T> UiList<T> {
         }
     }
 
+    pub fn selected_element(&self) -> Option<&T> {
+        let sel = self.selection();
+        if sel.len() == 1 {
+            let index = sel[0];
+            return self.data.get(index as usize);
+        }
+        None
+    }
+
     pub fn set_selection(&mut self, sel: &Vec<i32>) {
         unsafe {
             ui_list_set_selected_indices(self.ptr, sel.as_ptr(), sel.len() as c_int);
@@ -687,7 +696,6 @@ impl ListSelection {
             let count = ui_list_selection_get_count(self.ptr) as usize;
             if count > 0 {
                 let indices = ui_list_selection_get_rows(self.ptr);
-                sel.set_len(count as usize);
                 for i in 0..count {
                     sel.push(*indices.add(i) as i32);
                 }