]> uap-core.de Git - note.git/commitdiff
save notes when another notebook is selected
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 8 Jun 2026 18:53:05 +0000 (20:53 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 8 Jun 2026 18:53:05 +0000 (20:53 +0200)
application/src/note.rs
application/src/notebook.rs
application/src/window.rs

index 118820faf0dd4ada0be8c452a88668b3e54c714a..6f6e59817fa2407551462ff34cdba371ddf6dec6 100644 (file)
@@ -121,7 +121,12 @@ impl Note {
         }
     }
 
-    pub fn save(&self, collection_id: i32, backend: &BackendHandle) {
+    #[action]
+    pub fn save(&mut self, _event: &ActionEvent) {
+        self.save_note();
+    }
+
+    pub fn save_note(&self) {
         let Some(doc) = self.doc.get_doc() else {
             return;
         };
@@ -139,7 +144,7 @@ impl Note {
 
         let note = entity::note::ActiveModel {
             note_id: note_id.clone(),
-            collection_id: Set(collection_id),
+            collection_id: Set(self.collection_id),
             kind: Set(self.kind.clone()),
             title: Set(title),
             lastmodified: Set(Utc::now().into()),
@@ -153,7 +158,7 @@ impl Note {
         };
 
         let proxy = doc.doc_proxy();
-        backend.save_note(note, Some(notecontent), |result|{
+        self.backend.save_note(note, Some(notecontent), |result|{
             proxy.call_mainthread(move |_doc, note|{
                 match result {
                     Ok((note_id, content_id)) => {
index 66f43471c89c3d2752071f85c035c16e6736dd18..b198fd29716f0e714a3e45c0439cd334851d5e31 100644 (file)
@@ -56,10 +56,8 @@ impl Notebook {
             if let Some(mut doc) = self.doc_ref.get_doc() {
                 // save the note
                 let note_proxy = current.doc_proxy();
-                let backend = self.backend.as_ref().clone();
-                let collection_id = self.collection_id;
                 note_proxy.call_mainthread(move |_doc, note|{
-                    note.save(collection_id, &backend);
+                    note.save_note();
                 });
 
                 // detach the note
index c3b968dc7c3ace6fd320fa899d0600f6c1d9fe13..0d2aa50f743f8e1c0081010da4f13c6425e89ebd 100644 (file)
@@ -202,6 +202,7 @@ pub fn create_window(app: &App, ctx: &AppContext<MainWindow>) -> UiObject<MainWi
                             let nav = NavigationItem { collection_id: nb.data.collection_id, note_id: None };
                             // detach current notebook
                             if let Some(current) = &e.data.selected_notebook {
+                                current.ctx.call_action("save");
                                 e.obj.ctx.detach(current);
                             }