From: Olaf Wintermann Date: Fri, 29 May 2026 10:18:23 +0000 (+0200) Subject: save notes when exiting the application X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=b43432af670d1fad09c7e673f2e17cb7bbd30991;p=note.git save notes when exiting the application --- diff --git a/application/src/notebook.rs b/application/src/notebook.rs index 366590b..cfafe64 100644 --- a/application/src/notebook.rs +++ b/application/src/notebook.rs @@ -37,33 +37,35 @@ impl Notebook { self.notes.update(); } + /// Saves and detaches the current note. This does NOT change self.selected_note + pub fn detach_current_note(&self) { + // detach the current note + if let Some(current) = &self.selected_note { + // doc_ref.get_doc() should never fail here + if let Some(mut doc) = self.doc_ref.get_doc() { + // save the note + let note_proxy = current.doc_proxy(); + let backend = self.backend.clone(); + let collection_id = self.collection_id; + note_proxy.call_mainthread(move |_doc, note|{ + note.save(collection_id, &backend); + }); + + // detach the note + doc.ctx.detach(current); + } + } + } + #[action] pub fn note_selected(&mut self, event: &ActionEvent) { if let EventType::ListSelection(s) = event.event_type { if let Some(note) = s.selected_element(self.notes.data()) { - // detach the current note - if let Some(current) = &self.selected_note { - // doc_ref.get_doc() should never fail here - if let Some(mut doc) = self.doc_ref.get_doc() { - // save the note - let note_proxy = current.doc_proxy(); - let backend = self.backend.clone(); - let collection_id = self.collection_id; - note_proxy.call_mainthread(move |_doc, note|{ - note.save(collection_id, &backend); - }); - - // detach the note - doc.ctx.detach(current); - self.selected_note = None; - } - } + self.detach_current_note(); + self.selected_note = None; // Create the new note let note_data: crate::note::Note = Default::default(); - // TODO: setting the text here is the right thing to do, but for some - // reasons it doesn't work yet. Fix this shit. - //note_data.text.set(note.content.as_str()); // Create the note document object let note_doc = UiDoc::new2(note_data, |n,d| { @@ -115,6 +117,6 @@ pub fn notelist_getvalue<'a>(elm: &Note, col: i32, _row: i32) -> ListValue<'a> { impl Drop for Notebook { fn drop(&mut self) { - println!("Notebook dropped"); + } } \ No newline at end of file diff --git a/application/src/window.rs b/application/src/window.rs index 2a7436f..dab067f 100644 --- a/application/src/window.rs +++ b/application/src/window.rs @@ -194,8 +194,13 @@ pub fn create_window(app: &App, ctx: &AppContext) -> UiObject