]> uap-core.de Git - note.git/commitdiff
implement notes loading in the notebook ui model
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 22 May 2026 16:41:39 +0000 (18:41 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 22 May 2026 16:41:39 +0000 (18:41 +0200)
application/src/notebook.rs
application/src/window.rs
ui/common/wrapper.c

index 7386fe9e067931eb9d82c8edcef2131fa76b6342..86dd00649fe8c8f9715b4c2b17c9c9819b40d13e 100644 (file)
@@ -7,7 +7,7 @@ use entity::note::Model as Note;
 pub struct Notebook {
     pub collection_id: i32,
 
-    #[bind]
+    #[bind("notes")]
     pub notes: UiList<Note>
 }
 
@@ -18,6 +18,15 @@ impl Notebook {
             collection_id: id, ..Default::default()
         }
     }
+
+    pub fn set_notes(&mut self, notes: Vec<Note>) {
+        let notes_list = self.notes.data_mut();
+        notes_list.clear();
+        for note in notes {
+            notes_list.push(note);
+        }
+        self.notes.update();
+    }
 }
 
 pub fn note_getvalue<'a>(elm: &Note, col: i32, _row: i32) -> ListValue<'a> {
index b7a2cbf733f9b268a18613e3ee7003dcb0e4ecca..9d399329c525dc80435888d4ab514c45a0c05d10 100644 (file)
@@ -134,8 +134,19 @@ pub fn create_window(app: &App, ctx: &AppContext<MainWindow>) -> UiObject<MainWi
 
                             let notebook = Notebook::new(nb.collection_id);
                             let doc = UiDoc::new(notebook);
-
-                            // TODO: load notes
+                            let proxy = doc.doc_proxy();
+                            e.data.backend.get_notes(nb.collection_id, |result|{
+                                proxy.call_mainthread(|nb| {
+                                    match result {
+                                        Ok(notes) => {
+                                            nb.set_notes(notes);
+                                        },
+                                        Err(err) => {
+                                            eprintln!("get_notes failed: {}", err);
+                                        }
+                                    }
+                                });
+                            });
 
                             e.obj.ctx.attach(&doc);
                             e.data.selected_notebook = Some(doc);
@@ -152,6 +163,7 @@ pub fn create_window(app: &App, ctx: &AppContext<MainWindow>) -> UiObject<MainWi
 
             obj.tableview_builder::<Note>()
                 .varname("notes")
+                .model(&model)
                 .fill(true)
                 .getvalue(note_getvalue)
                 .create();
index b457e201a98c586c5398d2cb2132e8cd492e72ee..a6ef56a089634f00eea7bb96d309af9cff79766f 100644 (file)
@@ -55,6 +55,8 @@ static int obj_unref(void *ptr) {
 }
 
 void ui_mainthread_object_unref(UiObject *obj) {
+    // TODO: detect if this is already the main thread and call
+    //       ui_object_unref directly in that case
     ui_call_mainthread(obj_unref, obj);
 }
 
@@ -63,6 +65,7 @@ static int doc_unref(void *ptr) {
 }
 
 void ui_mainthread_document_unref(void *doc) {
+    // TODO: see ui_mainthread_object_unref
     ui_call_mainthread(doc_unref, doc);
 }