]> uap-core.de Git - note.git/commitdiff
add MainWindow.show_collection method to simplify/remove duplicated code main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 9 Aug 2026 20:17:35 +0000 (22:17 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 9 Aug 2026 20:17:35 +0000 (22:17 +0200)
application/backend/src/backend.rs
application/backend/src/storage.rs
application/note/src/window.rs

index 39fd72d4e7cea465b3c1e501939158bae4cd98ab..d198a73d68cd325077c07c818ae53ead8bb44e83 100644 (file)
@@ -785,7 +785,6 @@ impl BackendHandle {
         let bhandle = self.clone();
         let pathbuf = path.to_path_buf();
         let cmd = Box::pin(async move {
-            let name = pathbuf.as_path().file_name();
             // check file and get the file name
             let result: Result<&OsStr, Error> = async {
                 let metadata = fs::metadata(pathbuf.as_path()).await?;
index 7ab717874741a9ce0fb31a75a6f72e57cf501638..a90687476b747f8d2343c8933deb5244ff9e0d74 100644 (file)
@@ -189,7 +189,7 @@ pub async fn generate_nodename_in_collection(db: &DatabaseConnection, collection
         let node_path = path.join(nodename);
         let metadata = fs::metadata(node_path).await;
         match metadata {
-            Ok(metadata) => {
+            Ok(_metadata) => {
                 local_exists = true;
             },
             Err(err) if err.kind() == ErrorKind::NotFound => {
index 7e4d4d63cedab5f368a73bca4e813b8c8c5504a4..7e330254624c501005db50373b90f61097de57b5 100644 (file)
@@ -110,28 +110,35 @@ impl MainWindow {
         }
     }
 
-    #[action]
-    pub fn show_trash(&mut self, _event: &ActionEvent) {
+    pub fn show_collection(&mut self, doc: UiDoc<Notebook>, nav: NavigationItem) {
         let Some(mut obj) = self.obj.get_object() else {
             return;
         };
 
-        if let Some(trash) = &mut self.trash {
-            let nav = NavigationItem { collection_id: trash.data.collection_id, ..Default::default() };
-            // detach current notebook
-            if let Some(current) = &self.selected_notebook {
-                current.ctx.call_action("save");
-                obj.ctx.detach(current);
-            }
+        // detach current notebook
+        if let Some(current) = &self.selected_notebook {
+            current.ctx.call_action("save");
+            obj.ctx.detach(current);
+        }
 
-            let notebook_doc = trash.get_doc(&self.backend);
-            obj.splitview_set_visible(0, true);
-            obj.ctx.attach(&notebook_doc);
-            self.selected_notebook = Some(notebook_doc);
-            //e.obj.splitview_set_visible(0, !nav.note_maximized);
+        obj.splitview_set_visible(0, true);
+        obj.ctx.attach(&doc);
+        self.selected_notebook = Some(doc);
+        //e.obj.splitview_set_visible(0, !nav.note_maximized);
 
-            self.navigation.push(nav);
-        }
+        self.navigation.push(nav);
+    }
+
+    #[action]
+    pub fn show_trash(&mut self, _event: &ActionEvent) {
+        let (doc, nav) = if let Some(trash) = &mut self.trash {
+            let nav = NavigationItem { collection_id: trash.data.collection_id, ..Default::default() };
+            let notebook_doc = trash.get_doc(&self.backend);
+            (notebook_doc, nav)
+        } else {
+            return;
+        };
+        self.show_collection(doc, nav);
     }
 
     pub fn do_nav(&mut self, direction: NavDirection) -> Option<()> {
@@ -236,19 +243,8 @@ pub fn create_window(app: &App, ctx: &AppContext<MainWindow>) -> UiObject<MainWi
                     if let EventType::SubList(sl) = &e.event_type {
                         if let Some(nb) = sl.get_mut_from(&mut e.data.notebooks) {
                             let nav = NavigationItem { collection_id: nb.data.collection_id, ..Default::default() };
-                            // detach current notebook
-                            if let Some(current) = &e.data.selected_notebook {
-                                current.ctx.call_action("save");
-                                e.obj.ctx.detach(current);
-                            }
-
                             let notebook_doc = nb.get_doc(&e.data.backend);
-                            e.obj.splitview_set_visible(0, true);
-                            e.obj.ctx.attach(&notebook_doc);
-                            e.data.selected_notebook = Some(notebook_doc);
-                            //e.obj.splitview_set_visible(0, !nav.note_maximized);
-
-                            e.data.navigation.push(nav);
+                            e.data.show_collection(notebook_doc, nav);
                         }
                     }
                 }