From: Olaf Wintermann Date: Fri, 31 Jul 2026 19:31:27 +0000 (+0200) Subject: add textfield for custom note titles X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=c1eba51b86be3281be7c4b419d58ca464c30619e;p=note.git add textfield for custom note titles --- diff --git a/application/note/src/main.rs b/application/note/src/main.rs index 7d695b4..dfe9151 100644 --- a/application/note/src/main.rs +++ b/application/note/src/main.rs @@ -145,6 +145,7 @@ fn create_menubar(app: &AppContext) { menu.item("New Window").onclick(|_| new_app_window() ).create(); menu.separator(); menu.item("Delete").action("note_delete").create(); + menu.item("Edit Title").action("note_edit_title").create(); }); } @@ -171,6 +172,7 @@ fn create_toolbar(app: &AppContext) { menu.item("New Window").onclick(|_| new_app_window() ).create(); menu.separator(); menu.item("Delete").action("delete_note").create(); + menu.item("Edit Title").action("note_edit_title").create(); }); } @@ -181,7 +183,8 @@ pub enum AppStates { NoteEnableNew, NoteShowInfo, NoteShowExtModInfo, - NoteMaximized + NoteMaximized, + NoteTitleInput, } fn username() -> String { diff --git a/application/note/src/note.rs b/application/note/src/note.rs index dee8194..175d965 100644 --- a/application/note/src/note.rs +++ b/application/note/src/note.rs @@ -69,6 +69,7 @@ pub struct Note { modified: bool, is_saving: bool, + fixed_title: bool, pub local_path: Option, pub local_lastmodified: Option, @@ -76,6 +77,9 @@ pub struct Note { #[bind("note_type")] pub note_type: UiInteger, + #[bind("note_title")] + pub title: UiString, + #[bind("note_text")] pub text: UiText, @@ -103,10 +107,12 @@ impl Note { title_end: -1, modified: false, is_saving: false, + fixed_title: false, local_path: None, local_lastmodified: None, note_type: Default::default(), + title: Default::default(), text: Default::default(), info: Default::default(), } @@ -201,6 +207,8 @@ impl Note { _ => NoteTypeTabView::Empty }; self.note_type.set(tab as i64); + self.title.set(model.title.as_str()); + self.fixed_title = model.fixed_title; } pub fn init_new(&mut self) { @@ -258,16 +266,22 @@ impl Note { } }; + self.title.set(title); + if notify { - let update = NoteTitleUpdate { - collection_id: self.collection_id, - note_id: self.id.clone(), - title: title.to_string(), - }; - _ = self.backend.as_ref().send_broadcast(BroadcastMessage::NoteTitleUpdate(update)); + self.notify_title_change(title); } } + pub fn notify_title_change(&mut self, title: &str) { + let update = NoteTitleUpdate { + collection_id: self.collection_id, + note_id: self.id.clone(), + title: title.to_string(), + }; + _ = self.backend.as_ref().send_broadcast(BroadcastMessage::NoteTitleUpdate(update)); + } + #[action(Event)] pub fn filesystem_notify(&mut self, _event: &ActionEvent, event: &Event) { // for now we only care about modify events @@ -361,12 +375,32 @@ impl Note { } } - if !event.set && self.extract_title { + if !event.set && self.extract_title && !self.fixed_title { self.update_title(self.text.get().as_str(), true); } self.extract_title = false; } + #[action] + pub fn note_edit_title(&mut self, _event: &ActionEvent) { + let Some(doc) = self.doc.get_doc() else { + return; + }; + doc.ctx.set_state(AppStates::NoteTitleInput as i32); + self.fixed_title = true; + } + + #[action] + pub fn note_title_changed(&mut self, event: &ActionEvent) { + if event.set { + return; + } + + let title = self.title.get(); + self.notify_title_change(title.as_str()); + self.modified = true; + } + #[action] pub fn notebook_view_changed(&mut self, event: &mut ActionEvent) { // This action is for the toolbar button, to change the notebook view @@ -409,9 +443,18 @@ impl NoteViewModel for Note { }; let content = self.text.get(); - let title = match generate_title(content.as_str()) { - Some(title) => title.0.to_string(), - None => "New Note".to_string() // TODO: see NoteItem::new() + let title = if self.fixed_title { + let title = self.title.get(); + if title.is_empty() { + "New Note".to_string() + } else { + title + } + } else { + match generate_title(content.as_str()) { + Some(title) => title.0.to_string(), + None => "New Note".to_string() // TODO: see NoteItem::new() + } }; let (note_id, created) = match &self.id { @@ -427,6 +470,7 @@ impl NoteViewModel for Note { title: Set(title), lastmodified: Set(Utc::now().into()), created: created, + fixed_title: Set(self.fixed_title), version: Set(self.version) }; diff --git a/application/note/src/window.rs b/application/note/src/window.rs index 9607ebf..4d4ec77 100644 --- a/application/note/src/window.rs +++ b/application/note/src/window.rs @@ -254,6 +254,10 @@ pub fn create_window(app: &App, ctx: &AppContext) -> UiObject