From 170519c302591bdeb0d68349c199a62684bf3d81 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Fri, 19 Jun 2026 22:42:17 +0200 Subject: [PATCH] move note_maximized var to the notebook --- application/src/note.rs | 13 ++++--------- application/src/notebook.rs | 28 +++++++++++++++++++++------- ui-rs/src/ui/toolkit.rs | 8 +------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/application/src/note.rs b/application/src/note.rs index 705228c..225011d 100644 --- a/application/src/note.rs +++ b/application/src/note.rs @@ -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; }; diff --git a/application/src/notebook.rs b/application/src/notebook.rs index 4f8d352..2a0b51c 100644 --- a/application/src/notebook.rs +++ b/application/src/notebook.rs @@ -52,8 +52,8 @@ pub struct Notebook { pub selected_note: Option, - #[bind("notebook_dual_view")] - pub view: UiInteger, + #[bind("note_maximized")] + pub note_maximized: UiInteger, #[bind("notes")] pub notes: UiList @@ -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 { + 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) { 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 { // 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(); diff --git a/ui-rs/src/ui/toolkit.rs b/ui-rs/src/ui/toolkit.rs index 473396e..d40d07b 100644 --- a/ui-rs/src/ui/toolkit.rs +++ b/ui-rs/src/ui/toolkit.rs @@ -157,12 +157,6 @@ impl UiContext { None } - pub fn list(&self) -> UiList { - let mut ls = UiList::::default(); - ls.init(self, None); - ls - } - pub unsafe fn add_action(&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(&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 }); -- 2.52.0