]> uap-core.de Git - note.git/commitdiff
generate a note title in add_file_note (backend) main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 14 Aug 2026 20:08:46 +0000 (22:08 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 14 Aug 2026 20:08:46 +0000 (22:08 +0200)
application/backend/src/backend.rs
application/backend/src/note.rs
application/note/src/file.rs

index 4ccf080ea96abaf8756ee0ee842483aefd504f9e..87feda5288b1f78c97f840dbbeae010291d6056e 100644 (file)
@@ -49,7 +49,7 @@ use entity::note::{Column, Entity as Note, NoteType};
 use entity::notecontent::{Entity as NoteContent};
 use migration::prelude::Utc;
 use crate::lockmanager::LockManager;
-use crate::note::{create_nodename, nodename_to_contenttype, randomize_nodename};
+use crate::note::{create_nodename, nodename_to_contenttype, nodename_to_title, randomize_nodename};
 use crate::notify::{fs_notify, FSWatch};
 use crate::storage::{*};
 
@@ -820,7 +820,7 @@ impl BackendHandle {
             let result: Result<note::Model, DbErr> = async {
                 // prepare db insert
                 let nodename = generate_nodename_in_collection(&bhandle.backend.db, collection_id, name.as_str()).await?;
-                let title = nodename.clone(); // TODO
+                let title = nodename_to_title(&nodename).to_string();
                 let contenttype = nodename_to_contenttype(nodename.as_str()).to_string();
                 let insert = note::ActiveModel {
                     collection_id: Set(collection_id),
@@ -971,7 +971,8 @@ impl BackendHandle {
                     if let Some(old_path) = old_path && let Some(new_path) = new_path {
                         let result = tokio::fs::rename(new_path, old_path).await;
                         if let Err(e) = result {
-                            msg.push_str("; moving file back from trash failed");
+                            msg.push_str("; moving file back from trash failed: ");
+                            msg.push_str(e.to_string().as_str());
                         }
                     }
                     Err(DbErr::Custom(msg))
index f1db72bf3267ca22551149a7559ab6f9a172022b..c2e2b5671519e85f2608cd553e2ea8b1f49eaa91 100644 (file)
@@ -61,6 +61,19 @@ pub fn randomize_nodename(nodename: &str) -> String {
     }
 }
 
+pub fn nodename_to_title(s: &str) -> &str {
+    if !s.trim().is_empty() {
+        let name = Path::new(s)
+            .file_stem()
+            .and_then(|s| s.to_str())
+            .unwrap_or(s);
+        return name;
+    }
+    // TODO: the default file name needs to be configured somewhere
+    "file"
+}
+
+
 pub fn nodename_to_contenttype(name: &str) -> &'static str {
     let ext = Path::new(name)
         .extension()
index f7b3ddb3f7faa9afb4ff1ddfac8a3d59b36b273b..f933fd0b2807ca5158985b0a35ebb45b46321476 100644 (file)
@@ -31,6 +31,7 @@ use std::path::{Path, PathBuf};
 use std::rc::Rc;
 use url::Url;
 use backend::backend::{BackendHandle, BroadcastMessage, NoteId, NoteTitleUpdate, OpenExternResult, RenameNoteRet};
+use backend::note::nodename_to_title;
 use ui_rs::{action, doc_cast, ui_actions, UiModel};
 use ui_rs::ui::*;
 use crate::AppStates;
@@ -188,7 +189,7 @@ impl FileNote {
     }
 
     pub fn update_title(&mut self, s: &str, notify: bool) {
-        let title = generate_title(s).unwrap_or("file");
+        let title = nodename_to_title(s);
 
         if notify {
             let update = NoteTitleUpdate {
@@ -234,9 +235,8 @@ impl NoteViewModel for FileNote {
             // nothing has changed
             return;
         }
-
-        // TODO: "file" is also used in update_title() and needs to be configured somewhere
-        let new_title = generate_title(&nodename).unwrap_or("file").to_string();
+        
+        let new_title = nodename_to_title(&nodename).to_string();
 
         mem::swap(&mut self.nodename, &mut nodename);
 
@@ -268,14 +268,3 @@ impl NoteViewModel for FileNote {
     }
 }
 
-fn generate_title(s: &str) -> Option<&str> {
-    if !s.trim().is_empty() {
-        let name = Path::new(s)
-            .file_stem()
-            .and_then(|s| s.to_str())
-            .unwrap_or(s);
-        return Some(name);
-    }
-
-    None
-}