From: Olaf Wintermann Date: Thu, 21 May 2026 19:15:17 +0000 (+0200) Subject: selecting notebooks attaches a Notebook model to the window X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=7a905c657d6115a9c7372338a7800783a8f71e5e;p=note.git selecting notebooks attaches a Notebook model to the window --- diff --git a/application/src/newnotebook.rs b/application/src/newnotebook.rs index 297d936..f22cbc7 100644 --- a/application/src/newnotebook.rs +++ b/application/src/newnotebook.rs @@ -107,7 +107,7 @@ pub fn new_notebook_dialog(parent: &UiObject, groups: &Vec, 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| { diff --git a/application/src/window.rs b/application/src/window.rs index 9f4810e..84d07ef 100644 --- a/application/src/window.rs +++ b/application/src/window.rs @@ -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) -> UiObject { @@ -237,6 +237,17 @@ impl SubListEvent { } } } + + pub fn get_from<'a, T>(&self, sourcelist: &'a UiSourceList) -> Option<&'a T> { + if self.row_index < 0 { + return None; + } + + sourcelist + .get(self.sublist_index)? + .data() + .get(self.row_index as usize) + } } diff --git a/ui-rs/src/ui/list.rs b/ui-rs/src/ui/list.rs index 437d60e..c9e7e10 100644 --- a/ui-rs/src/ui/list.rs +++ b/ui-rs/src/ui/list.rs @@ -777,7 +777,11 @@ impl SubList { &mut self.list } - pub fn data(&mut self) -> &mut Vec { + pub fn data_mut(&mut self) -> &mut Vec { + self.list.data_mut() + } + + pub fn data(&self) -> &Vec { self.list.data() } } diff --git a/ui-rs/src/ui/toolkit.rs b/ui-rs/src/ui/toolkit.rs index 917f948..162bdb8 100644 --- a/ui-rs/src/ui/toolkit.rs +++ b/ui-rs/src/ui/toolkit.rs @@ -596,9 +596,13 @@ impl UiList { list } - pub fn data(&mut self) -> &mut Vec { + pub fn data_mut(&mut self) -> &mut Vec { self.data.as_mut() } + + pub fn data(&self) -> &Vec { + self.data.as_ref() + } pub fn init(&mut self, ctx: &UiContext, name: Option<&str>) { let c_string = name.map(|n| CString::new(n).unwrap());