]> uap-core.de Git - note.git/commitdiff
move note_maximized var to the notebook main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 19 Jun 2026 20:42:17 +0000 (22:42 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 19 Jun 2026 20:42:17 +0000 (22:42 +0200)
application/src/note.rs
application/src/notebook.rs
ui-rs/src/ui/toolkit.rs

index 705228cfb5cb0220be0b64a5b09964b997ac322a..225011daae79609e68891a2df19bf9acb4d45927 100644 (file)
@@ -61,9 +61,6 @@ pub struct Note {
 
     modified: bool,
 
-    #[bind("note_maximized")]
-    pub note_maximized: UiInteger,
-
     #[bind("note_type")]
     pub note_type: UiInteger,
 
@@ -93,7 +90,6 @@ impl Note {
             title_end: -1,
             modified: false,
 
-            note_maximized: Default::default(),
             note_type: Default::default(),
             text: Default::default(),
             info: Default::default(),
@@ -121,7 +117,7 @@ impl Note {
     pub fn attachment_status_changed(&mut self, _event: &mut ActionEvent) -> Option<()>{
         let doc = self.doc.get_doc()?;
 
-        if let Some(mut obj) = doc.ctx.get_parent_object() {
+        if doc.ctx.is_attached_to_obj() {
             // attached to an obj also means, this note is visible and the editor should
             // require the lock for this note
             // self.lock should always be none here
@@ -138,11 +134,7 @@ impl Note {
                     doc.ctx.unset_state(AppStates::NoteShowInfo as i32);
                 }
             }
-
-            let val = self.note_maximized.get();
-            obj.splitview_set_visible(0, val == 0);
         } else {
-            // clean self.lock, however don't clean self.vhandle
             self.lock = None;
             self.text.set_readonly(false);
         }
@@ -357,6 +349,9 @@ impl Note {
 
     #[action]
     pub fn notebook_view_changed(&mut self, event: &mut ActionEvent) {
+        // This action is for the toolbar button, to change the notebook view
+        // (dual view or maximized note), however, the view status variable is stored
+        // in the notebook.
         let Some(obj) = &mut event.obj else {
             return;
         };
index 4f8d3528912edad47876cced4ca9bc7536864911..2a0b51c2d273c47a53b9335ca2df908d4debb4b2 100644 (file)
@@ -52,8 +52,8 @@ pub struct Notebook {
 
     pub selected_note: Option<NoteSelection>,
 
-    #[bind("notebook_dual_view")]
-    pub view: UiInteger,
+    #[bind("note_maximized")]
+    pub note_maximized: UiInteger,
 
     #[bind("notes")]
     pub notes: UiList<NoteItem>
@@ -69,11 +69,28 @@ impl Notebook {
             broadcast_rx: backend.btx.subscribe(),
             collection_id: id,
             selected_note: None,
-            view: Default::default(),
+            note_maximized: Default::default(),
             notes: Default::default()
         }
     }
 
+    pub fn into_doc(self) -> UiDoc<Notebook> {
+        UiDoc::new2(self, |notebook, doc| {
+            notebook.doc_ref = doc.doc_ref();
+            doc.ctx.on_attach_action("notebook_on_attach")
+        })
+    }
+
+    #[action]
+    pub fn notebook_on_attach(&mut self, event: &mut ActionEvent) {
+        let Some(obj) = &mut event.obj else {
+            return;
+        };
+
+        let val = self.note_maximized.get();
+        obj.splitview_set_visible(0, val == 0);
+    }
+
     pub fn set_notes(&mut self, notes: Vec<Note>) {
         let notes_list = self.notes.data_mut();
         notes_list.clear();
@@ -197,7 +214,6 @@ impl Notebook {
         if let EventType::ListSelection(s) = event.event_type {
             let result = self.select_note_from(NoteSelectFrom::ListSelection(s));
             //obj.splitview_set_visible(0, false);
-            self.view.set(1);
             // in case select_note_from didn't return a result, the note was already selected
             // and no new navigation item was added
             if result.is_none() {
@@ -360,9 +376,7 @@ impl NotebookItem {
     pub fn load_notebook(&mut self, backend: &BackendHandle) -> UiDoc<Notebook> {
         // Create Notebook UI model
         let notebook = Notebook::new(self.data.collection_id, backend);
-        let doc = UiDoc::new2(notebook, |notebook, doc| {
-            notebook.doc_ref = doc.doc_ref();
-        });
+        let doc = notebook.into_doc();
 
         // Load notes
         let proxy = doc.doc_proxy();
index 473396eded137898c795edecef0ee4ed1d0dd8dd..d40d07b0b9fb2021fde724a6b1b028a45a0117f5 100644 (file)
@@ -157,12 +157,6 @@ impl UiContext {
         None
     }
 
-    pub fn list<T>(&self) -> UiList<T> {
-        let mut ls = UiList::<T>::default();
-        ls.init(self, None);
-        ls
-    }
-
     pub unsafe fn add_action<T, F>(&self, name: &str, f: F)
     where F: FnMut(&mut T, &mut event::ActionEvent) + 'static {
         // if this is a document context, use the document pointer as target
@@ -182,7 +176,7 @@ impl UiContext {
             self.add_action_for_target(target_ptr, name, f);
         }
     }
-    
+
     pub unsafe fn add_action_for_target<T, F>(&self, target_ptr: *mut T, name: &str, f: F)
     where F: FnMut(&mut T, &mut event::ActionEvent) + 'static {
         let wrapper = Box::new(ActionEventWrapper { callback: Box::new(f), target: target_ptr });