]> uap-core.de Git - note.git/commitdiff
selecting notebooks attaches a Notebook model to the window
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 21 May 2026 19:15:17 +0000 (21:15 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 21 May 2026 19:15:17 +0000 (21:15 +0200)
application/src/newnotebook.rs
application/src/window.rs
ui-rs/src/ui/event.rs
ui-rs/src/ui/list.rs
ui-rs/src/ui/toolkit.rs

index 297d93631c8e7762e26ef9098742e3bbaec215d9..f22cbc706a22ebbf46b3da6629f96508de5a7556 100644 (file)
@@ -107,7 +107,7 @@ pub fn new_notebook_dialog<T>(parent: &UiObject<T>, groups: &Vec<Collection>, ba
         .create(data, |obj, data|
     {
         // init data
-        data.groups.data().extend(groups.clone());
+        data.groups.data_mut().extend(groups.clone());
 
         // create dialog UI
         obj.grid(|a| {
index 9f4810e2da138617c24fe2b470eb4eeeb2768498..84d07ef38d4bcef5b3e2b5bc1dabc2deef8c5eb5 100644 (file)
@@ -99,7 +99,7 @@ impl MainWindow {
             let mut notebook = SubList::new();
             notebook.set_header(elm.collection.name.as_str());
 
-            let sublist_data = notebook.list().data();
+            let sublist_data = notebook.list().data_mut();
             for child in elm.children.iter() {
                 sublist_data.push(child.collection.clone());
             }
@@ -126,7 +126,19 @@ pub fn create_window(app: &App, ctx: &AppContext<MainWindow>) -> UiObject<MainWi
                 });
                 b.onactivate(|e|{
                     if let EventType::SubList(sl) = &e.event_type {
-                        
+                        if let Some(nb) = sl.get_from(&e.data.notebooks) {
+                            if let Some(current) = &e.data.selected_notebook {
+                                e.obj.ctx.detach(current);
+                            }
+
+                            let notebook = Notebook::new();
+                            let doc = UiDoc::new(notebook);
+
+                            // TODO: load notes
+
+                            e.obj.ctx.attach(&doc);
+                            e.data.selected_notebook = Some(doc);
+                        }
                     }
                 });
             });
index 378737446bde172d4fc883c55a5f8783d0e950ac..1ba0850b1d266ffea474e6dedeb2fb70a5ceab7c 100644 (file)
@@ -29,7 +29,7 @@
 #![allow(dead_code)]
 
 use std::ffi::{c_char, c_void, CStr, CString};
-use crate::ui::{event, ffi, UiDouble, UiInteger, UiString, UiText, UiRange, ListSelection, UiObject, NoAppData};
+use crate::ui::{event, ffi, UiDouble, UiInteger, UiString, UiText, UiRange, ListSelection, UiObject, NoAppData, UiSourceList};
 use crate::ui::ffi::{UiEvent, UiSubListEventData};
 
 pub struct Event<'a, T> {
@@ -237,6 +237,17 @@ impl SubListEvent {
             }
         }
     }
+
+    pub fn get_from<'a, T>(&self, sourcelist: &'a UiSourceList<T>) -> Option<&'a T> {
+        if self.row_index < 0 {
+            return None;
+        }
+
+        sourcelist
+            .get(self.sublist_index)?
+            .data()
+            .get(self.row_index as usize)
+    }
 }
 
 
index 437d60e309bc0a89584ac69e4c32577721a37fa8..c9e7e102de74e4a52138c945f6f74d58e28e0448 100644 (file)
@@ -777,7 +777,11 @@ impl<E> SubList<E> {
         &mut self.list
     }
 
-    pub fn data(&mut self) -> &mut Vec<E> {
+    pub fn data_mut(&mut self) -> &mut Vec<E> {
+        self.list.data_mut()
+    }
+
+    pub fn data(&self) -> &Vec<E> {
         self.list.data()
     }
 }
index 917f948afb3b8735f3abcdfde3a00ea0fd8a979c..162bdb845ad9e57bfd203e795e5882f13fac4c85 100644 (file)
@@ -596,9 +596,13 @@ impl<T> UiList<T> {
         list
     }
 
-    pub fn data(&mut self) -> &mut Vec<T> {
+    pub fn data_mut(&mut self) -> &mut Vec<T> {
         self.data.as_mut()
     }
+    
+    pub fn data(&self) -> &Vec<T> {
+        self.data.as_ref()
+    }
 
     pub fn init(&mut self, ctx: &UiContext, name: Option<&str>) {
         let c_string = name.map(|n| CString::new(n).unwrap());