From: Olaf Wintermann Date: Wed, 5 Aug 2026 19:27:24 +0000 (+0200) Subject: simplify note renaming X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=HEAD;p=note.git simplify note renaming --- diff --git a/application/backend/src/backend.rs b/application/backend/src/backend.rs index 33d98a7..efda52b 100644 --- a/application/backend/src/backend.rs +++ b/application/backend/src/backend.rs @@ -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; diff --git a/application/note/src/file.rs b/application/note/src/file.rs index 5dbcd4d..c6c19ca 100644 --- a/application/note/src/file.rs +++ b/application/note/src/file.rs @@ -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; + } }); }); diff --git a/application/note/src/note.rs b/application/note/src/note.rs index 2ba7f84..9c755ee 100644 --- a/application/note/src/note.rs +++ b/application/note/src/note.rs @@ -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); } } });