From fea0159a8e1949b10077e962090c2747bddd3cbe Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sun, 31 May 2026 09:42:52 +0200 Subject: [PATCH] move content loading to the note module --- application/src/note.rs | 20 ++++++++++++++++++++ application/src/notebook.rs | 28 ++-------------------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/application/src/note.rs b/application/src/note.rs index 1c75503..dd84d89 100644 --- a/application/src/note.rs +++ b/application/src/note.rs @@ -66,6 +66,26 @@ impl Note { self.update_title(content.content.as_str(), false); } + pub fn load_content(&mut self, doc: &UiDoc) { + 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) => { diff --git a/application/src/notebook.rs b/application/src/notebook.rs index 9693319..a96138d 100644 --- a/application/src/notebook.rs +++ b/application/src/notebook.rs @@ -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(¬e.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); -- 2.47.3