]> uap-core.de Git - note.git/commitdiff
simplify note renaming
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 5 Aug 2026 19:27:24 +0000 (21:27 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 5 Aug 2026 19:27:24 +0000 (21:27 +0200)
application/backend/src/backend.rs
application/note/src/file.rs
application/note/src/note.rs

index 33d98a758b002fe3d0d610eefde506511bd674f2..efda52b2a2cbe7974468230131a97c09789c1c4a 100644 (file)
@@ -732,7 +732,8 @@ impl BackendHandle {
                     update = update.col_expr(Column::Title, Expr::value(title)).col_expr(Column::FixedTitle, Expr::value(true));
                 }
 
-                let tx = bhandle.backend.db.begin().await?;
+                // for some reason using the transaction doesn't work and this function hangs
+                //let tx = bhandle.backend.db.begin().await?;
 
                 let result = update
                     .filter(Column::NoteId.eq(note_id))
@@ -752,8 +753,8 @@ impl BackendHandle {
                         }
                     } // else: should not happen
                 }
-                
-                tx.commit().await?;
+
+                //tx.commit().await?;
                 Ok(RenameNoteRet::Ok)
             }.await;
 
index 5dbcd4de25e1ca41b793b337aa9910dc65ecd9cd..c6c19ca3faabde5711bdec8dd8f48527c6fd56e2 100644 (file)
@@ -30,7 +30,7 @@ use std::mem;
 use std::path::{Path, PathBuf};
 use std::rc::Rc;
 use url::Url;
-use backend::backend::{BackendHandle, BroadcastMessage, NoteId, NoteTitleUpdate, OpenExternResult};
+use backend::backend::{BackendHandle, BroadcastMessage, NoteId, NoteTitleUpdate, OpenExternResult, RenameNoteRet};
 use ui_rs::{action, doc_cast, ui_actions, UiModel};
 use ui_rs::ui::*;
 use crate::AppStates;
@@ -243,17 +243,25 @@ impl NoteViewModel for FileNote {
         let proxy = doc.doc_proxy();
         self.backend.rename_note(note_id, Some(self.nodename.clone()), Some(new_title), |result|{
             proxy.call_mainthread(move |_doc, note|{
+                let mut restore_nodename = true;
                 match result {
-                    Ok(updated) => {
-                        if updated.rows_affected != 1 {
-                            println!("rename_note: unexpected number of rows affected");
-                        }
+                    RenameNoteRet::Ok => {
+                       restore_nodename = false;
+                    },
+                    RenameNoteRet::NameAlreadyExists => {
+                        // TODO
+                    },
+                    RenameNoteRet::Error(e) => {
+                        eprintln!("note update failed: {:?}", e);
                     },
-                    Err(e) => {
-                        println!("note update failed: {:?}", e);
-                        note.nodename = nodename; // restore previous nodename
+                    RenameNoteRet::FileError(e) => {
+                        eprintln!("cannot rename file: {:?}", e);
                     }
                 }
+
+                if restore_nodename {
+                    note.nodename = nodename;
+                }
             });
         });
 
index 2ba7f84d66d184171213ad60b8e1aa3dba88a342..9c755ee27cf982d46e3f39db977de2dc1f95c719 100644 (file)
@@ -489,37 +489,20 @@ impl Note {
                     // Rename OK
                     // check if the new nodename is available
                     let new_nodename = new_name.clone();
-                    backend.check_nodename(note_id, new_name.as_str(), move|result|{
-                        proxy.call_mainthread(move|doc, note| {
+                    backend.rename_note(note_id, Some(new_nodename.clone()), None, |result|{
+                        proxy.call_mainthread(|_doc, note|{
                             match result {
-                                Ok(available) => {
-                                    if available {
-                                        let proxy = doc.doc_proxy();
-                                        note.backend.rename_note(note_id, Some(new_nodename.clone()), None, |result|{
-                                            proxy.call_mainthread(|_doc, note|{
-                                                match result {
-                                                    RenameNoteRet::Ok => {
-                                                        note.nodename = Some(new_nodename);
-                                                    },
-                                                    RenameNoteRet::NameAlreadyExists => {
-                                                        // TODO
-                                                    },
-                                                    RenameNoteRet::Error(e) => {
-                                                        eprintln!("note update failed: {:?}", e);
-                                                    },
-                                                    RenameNoteRet::FileError(e) => {
-                                                        eprintln!("cannot rename file: {:?}", e);
-                                                    }
-                                                }
-                                            });
-                                        });
-                                    } else {
-                                        let msg = format!("File {} already exists", new_nodename);
-                                        dialog!(title = "Rename Note", content = msg.as_str(), button1_label = "OK");
-                                    }
-                                }
-                                Err(e) => {
-                                    eprintln!("check_nodename failed: {:?}", e);
+                                RenameNoteRet::Ok => {
+                                    note.nodename = Some(new_nodename);
+                                },
+                                RenameNoteRet::NameAlreadyExists => {
+                                    // TODO
+                                },
+                                RenameNoteRet::Error(e) => {
+                                    eprintln!("note update failed: {:?}", e);
+                                },
+                                RenameNoteRet::FileError(e) => {
+                                    eprintln!("cannot rename file: {:?}", e);
                                 }
                             }
                         });