]> uap-core.de Git - note.git/commitdiff
open trash collection in read-only mode
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 15 Aug 2026 07:41:24 +0000 (09:41 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 15 Aug 2026 07:41:24 +0000 (09:41 +0200)
application/note/src/file.rs
application/note/src/main.rs
application/note/src/note.rs
application/note/src/notebook.rs
application/note/src/window.rs

index f933fd0b2807ca5158985b0a35ebb45b46321476..9773a85d6c1cc7b4eec4701be744d1f900c535fe 100644 (file)
@@ -52,6 +52,7 @@ pub struct FileNote {
     pub local_path: Option<PathBuf>,
     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<dyn NoteViewModel> {
+    pub fn into_doc(self, model: &entity::note::Model, readonly: bool) -> UiDoc<dyn NoteViewModel> {
         let doc: UiDoc<FileNote> = 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());
index 0ed09021658a47446192262d794da316e8557877..af0652eefb8c44b4f34d43158e80ff69056891b0 100644 (file)
@@ -195,6 +195,7 @@ pub enum AppStates {
     NoteShowExtModInfo,
     NoteMaximized,
     NoteTitleInput,
+    NoteEditable,
 }
 
 impl From<AppStates> for i32 {
index 3f09c8e9e82fe46128399ac3afec88a78d559827..1695c234d3d92c4d05f675c9f9499beec1df0de1 100644 (file)
@@ -70,6 +70,7 @@ pub struct Note {
     modified: bool,
     is_saving: bool,
     fixed_title: bool,
+    read_only: bool,
 
     pub local_path: Option<PathBuf>,
     pub local_lastmodified: Option<SystemTime>,
@@ -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<dyn NoteViewModel> {
+    pub fn into_doc(self, model: &entity::note::Model, readonly: bool) -> UiDoc<dyn NoteViewModel> {
         let doc: UiDoc<Note> = 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)
     }
index 5c84162013e10a661cf45bccb05a433e0d525198..a091dfa12eefe056951ff80316b10885c718fbab 100644 (file)
@@ -52,6 +52,7 @@ pub struct Notebook {
     pub instance_id: u64,
     pub broadcast_rx: tokio::sync::broadcast::Receiver<BroadcastMessage>,
     pub collection_id: i32,
+    pub read_only: bool,
 
     pub selected_note: Option<NoteSelection>,
 
@@ -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(&note.data)
+                    note_data.into_doc(&note.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(&note.data)
+                    note_data.into_doc(&note.data, self.read_only)
                 }
             }
         };
index 7538daf88335cdbdab614dca9d7f34db440deca6..5642e06e5a63991e6cc348c323abd3674a5e5055 100644 (file)
@@ -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<MainWindow>) -> UiObject<MainWi
         init_window_data(data, app);
         data.obj = obj.obj_ref();
         
-        // this state is basically always set, however there are some situations, where
-        // it is suppressed
+        // These states are basically always set, however there are some situations, where
+        // they are suppressed (for example by a note)
         obj.ctx.set_state(AppStates::NoteEnableNew);
+        obj.ctx.set_state(AppStates::NoteEditable);
 
         obj.sidebar().create(|obj|{
             sourcelist!(obj,