]> uap-core.de Git - note.git/commitdiff
move content loading to the note module main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 31 May 2026 07:42:52 +0000 (09:42 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 31 May 2026 07:42:52 +0000 (09:42 +0200)
application/src/note.rs
application/src/notebook.rs

index 1c7550324cf4df3bc7cf655e0c79337c081244eb..dd84d8984b78f8ef9b60c89714d6ba07a99ae06b 100644 (file)
@@ -66,6 +66,26 @@ impl Note {
         self.update_title(content.content.as_str(), false);
     }
 
+    pub fn load_content(&mut self, doc: &UiDoc<Note>) {
+        let proxy = doc.doc_proxy();
+        self.backend.get_note_content(self.note_id, move|result|{
+            proxy.call_mainthread(|doc, note|{
+                match result {
+                    Ok(content) => {
+                        if let Some(content) = content {
+                            note.init_content(&content);
+                        } else {
+                            println!("note {}: no content", note.note_id);
+                        }
+                    },
+                    Err(e) => {
+                        println!("Cannot get note content: {}", e);
+                    }
+                }
+            });
+        });
+    }
+
     pub fn update_title(&mut self, s: &str, notify: bool) {
         match generate_title(s) {
             Some(result) => {
index 96933193fa11082ed0ee3578ea71b2c3de76be9c..a96138ddbe18862410a1d30b437a76aaa661f5d9 100644 (file)
@@ -74,37 +74,13 @@ impl Notebook {
                 } else {
                     // Create the new note
                     let note_data = crate::note::Note::new(self.collection_id, self.backend.clone());
-
                     // Create the note document object
                     UiDoc::new2(note_data, |n,d| {
-                        // TODO: remove this when toolkit is not that buggy
-                        //       for some reason we have to attach the doc first, before we can
-                        //       set the text
-                        if let Some(mut nb) = self.doc_ref.get_doc() {
-                            nb.ctx.attach(&d);
-                        }
-
                         n.init_from_model(&note.data);
-
-                        let proxy = d.doc_proxy();
-                        self.backend.get_note_content(note.data.note_id, move|result|{
-                            proxy.call_mainthread(|doc, note|{
-                                match result {
-                                    Ok(content) => {
-                                        if let Some(content) = content {
-                                            note.init_content(&content);
-                                        } else {
-                                            println!("note {}: no content", note.note_id);
-                                        }
-                                    },
-                                    Err(e) => {
-                                        println!("Cannot get note content: {}", e);
-                                    }
-                                }
-                            });
-                        });
+                        n.load_content(d);
                     })
                 };
+                note.model = Some(doc.clone());
 
                 if let Some(mut nb) = self.doc_ref.get_doc() {
                     nb.ctx.attach(&doc);