From 2bc63b6615d6836fae01258a34e6561d1d091606 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sat, 15 Aug 2026 09:41:24 +0200 Subject: [PATCH] open trash collection in read-only mode --- application/note/src/file.rs | 5 ++++- application/note/src/main.rs | 1 + application/note/src/note.rs | 10 +++++++++- application/note/src/notebook.rs | 6 ++++-- application/note/src/window.rs | 9 ++++++--- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/application/note/src/file.rs b/application/note/src/file.rs index f933fd0..9773a85 100644 --- a/application/note/src/file.rs +++ b/application/note/src/file.rs @@ -52,6 +52,7 @@ pub struct FileNote { pub local_path: Option, pub is_tmp_file: bool, pub is_opening: bool, + pub read_only: bool, #[bind("note_type")] pub note_type: UiInteger, @@ -84,6 +85,7 @@ impl FileNote { local_path: None, is_tmp_file: false, is_opening: false, + read_only: false, note_type: Default::default(), preview_tab: Default::default(), @@ -93,11 +95,12 @@ impl FileNote { } } - pub fn into_doc(self, model: &entity::note::Model) -> UiDoc { + pub fn into_doc(self, model: &entity::note::Model, readonly: bool) -> UiDoc { let doc: UiDoc = UiDoc::new_from_box2(Box::new(self), |n,d| { n.doc = d.doc_ref(); n.nodename = model.nodename.clone(); n.content_type = model.content_type.clone(); + n.read_only = readonly; n.note_type.set(NoteTypeTabView::File as i64); n.note_nodename.set(model.nodename.as_str()); diff --git a/application/note/src/main.rs b/application/note/src/main.rs index 0ed0902..af0652e 100644 --- a/application/note/src/main.rs +++ b/application/note/src/main.rs @@ -195,6 +195,7 @@ pub enum AppStates { NoteShowExtModInfo, NoteMaximized, NoteTitleInput, + NoteEditable, } impl From for i32 { diff --git a/application/note/src/note.rs b/application/note/src/note.rs index 3f09c8e..1695c23 100644 --- a/application/note/src/note.rs +++ b/application/note/src/note.rs @@ -70,6 +70,7 @@ pub struct Note { modified: bool, is_saving: bool, fixed_title: bool, + read_only: bool, pub local_path: Option, pub local_lastmodified: Option, @@ -108,6 +109,7 @@ impl Note { modified: false, is_saving: false, fixed_title: false, + read_only: false, local_path: None, local_lastmodified: None, @@ -118,9 +120,10 @@ impl Note { } } - pub fn into_doc(self, model: &entity::note::Model) -> UiDoc { + pub fn into_doc(self, model: &entity::note::Model, readonly: bool) -> UiDoc { let doc: UiDoc = UiDoc::new_from_box2(Box::new(self), |n,d| { n.doc = d.doc_ref(); + n.read_only = readonly; if n.id.is_new() { n.init_new(); d.ctx.suppress_state(AppStates::NoteEnableNew); @@ -130,6 +133,11 @@ impl Note { } // make sure we receive an event, when this note is attached or detached d.ctx.on_attachment_status_change_action("attachment_status_changed"); + + if readonly { + n.text.set_readonly(true); + d.ctx.suppress_state(AppStates::NoteEditable); + } }); doc_cast!(doc, dyn NoteViewModel) } diff --git a/application/note/src/notebook.rs b/application/note/src/notebook.rs index 5c84162..a091dfa 100644 --- a/application/note/src/notebook.rs +++ b/application/note/src/notebook.rs @@ -52,6 +52,7 @@ pub struct Notebook { pub instance_id: u64, pub broadcast_rx: tokio::sync::broadcast::Receiver, pub collection_id: i32, + pub read_only: bool, pub selected_note: Option, @@ -72,6 +73,7 @@ impl Notebook { instance_id: INSTANCE_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed), broadcast_rx: backend.btx.subscribe(), collection_id: id, + read_only: false, selected_note: None, note_maximized: Default::default(), notes: Default::default() @@ -227,12 +229,12 @@ impl Notebook { match note.data.kind { NoteType::File => { let note_data = crate::file::FileNote::new(self.instance_id, note.id.clone(), self.collection_id, self.backend.clone()); - note_data.into_doc(¬e.data) + note_data.into_doc(¬e.data, self.read_only) }, _ => { // default: text note (plain text or md) let note_data = crate::note::Note::new(self.instance_id, note.id.clone(), self.collection_id, self.backend.clone()); - note_data.into_doc(¬e.data) + note_data.into_doc(¬e.data, self.read_only) } } }; diff --git a/application/note/src/window.rs b/application/note/src/window.rs index 7538daf..5642e06 100644 --- a/application/note/src/window.rs +++ b/application/note/src/window.rs @@ -133,7 +133,9 @@ impl MainWindow { 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); + let mut notebook = Notebook::new(trash.data.collection_id, &self.backend); + notebook.read_only = true; + let notebook_doc = notebook.into_doc(); (notebook_doc, nav) } else { return; @@ -229,9 +231,10 @@ pub fn create_window(app: &App, ctx: &AppContext) -> UiObject