]> uap-core.de Git - note.git/commitdiff
make obj in ActionEvents mutable main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 12 Jun 2026 15:01:46 +0000 (17:01 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 12 Jun 2026 15:01:46 +0000 (17:01 +0200)
application/src/notebook.rs
application/src/window.rs
ui-rs/src/ui/event.rs
ui-rs/src/ui/toolkit.rs

index 43a03709bad099680b29a278dd1429afd7d2a1de..884e350e72a3b9aebeb224e00eb7b33ac7bf099a 100644 (file)
@@ -144,9 +144,12 @@ impl Notebook {
     }
 
     #[action]
-    pub fn note_activated(&mut self, event: &ActionEvent) {
+    pub fn note_activated(&mut self, event: &mut ActionEvent) {
         if let EventType::ListSelection(s) = event.event_type {
             self.select_note_from(NoteSelectFrom::ListSelection(s));
+            if let Some(obj) = &mut event.obj {
+                obj.splitview_set_visible(0, false);
+            }
         }
     }
 
index 8fc9aeeab81c2b3f5591ca0cf0681967e35f2109..25512fb52c5a314705a656d1179ed5fef87ba417 100644 (file)
@@ -69,7 +69,7 @@ impl MainWindow {
 
     #[action]
     pub fn new_notebook(&mut self, event: &ActionEvent) {
-        if let Some(obj) = event.obj {
+        if let Some(obj) = &event.obj {
             new_notebook_dialog(obj, &self.groups, self.backend.clone());
         }
     }
index 2e7e2aabde026ea554ec3ec11c05438ff57bd1be..a691e9ac5698713a958332901deff8736a1fc540 100644 (file)
@@ -46,7 +46,7 @@ pub struct Event<'a, T> {
 }
 
 pub struct ActionEvent<'a> {
-    pub obj: Option<&'a UiObject<NoAppData>>,
+    pub obj: Option<&'a mut UiObject<NoAppData>>,
     pub event_type: EventType<'a>,
     pub intval: i32,
     pub set: bool
@@ -274,7 +274,7 @@ pub extern "C" fn event_wrapper_oneshot<T>(e: *const ffi::UiEvent, data: *mut c_
 }
 
 pub struct ActionEventWrapper<T> {
-    pub callback: Box<dyn FnMut(&mut T, &ActionEvent)>,
+    pub callback: Box<dyn FnMut(&mut T, &mut ActionEvent)>,
     pub target: *mut T
 }
 
@@ -290,7 +290,7 @@ pub extern "C" fn action_event_wrapper<T>(e: *const ffi::UiEvent, data: *mut c_v
 }
 
 fn action_callback<F>(e: *const ffi::UiEvent, f: F)
-where F: FnOnce(&ActionEvent) {
+where F: FnOnce(&mut ActionEvent) {
     unsafe {
         let ev_int = ui_event_get_int(e);
         let ev_set = ui_event_get_set(e) != 0;
@@ -302,22 +302,22 @@ where F: FnOnce(&ActionEvent) {
         let obj = if obj_ptr.is_null() {
             None
         } else {
-            Some(&UiObject::from_ptr(obj_ptr))
+            Some(&mut UiObject::from_ptr(obj_ptr))
         };
 
-        let event = ActionEvent {
+        let mut event = ActionEvent {
             obj: obj,
             event_type: event_type,
             intval: ev_int,
             set: ev_set
         };
         
-        f(&event);
+        f(&mut event);
     }
 }
 
 pub struct UntypedEventWrapper {
-    pub callback: Box<dyn FnMut(&ActionEvent)>
+    pub callback: Box<dyn FnMut(&mut ActionEvent)>
 }
 
 pub extern "C" fn untyped_event_wrapper(e: *const ffi::UiEvent, data: *mut c_void) {
index 35cbfefe9dfad37ae413f203fc547e52cbf431d5..5fc3452a5f70546c43eeaedfdc9de20a2ff39db1 100644 (file)
@@ -93,7 +93,7 @@ impl UiContext {
     }
 
     pub unsafe fn add_action<T, F>(&self, name: &str, f: F)
-    where F: FnMut(&mut T, &event::ActionEvent) + 'static {
+    where F: FnMut(&mut T, &mut event::ActionEvent) + 'static {
         // if this is a document context, use the document pointer as target
         // otherwise it is a UiObject context, in that case we use the window_data as target
         let doc_ptr = ui_context_document(self.ptr) as *mut T;
@@ -111,7 +111,7 @@ impl UiContext {
     }
     
     pub unsafe fn add_action_for_target<T, F>(&self, target_ptr: *mut T, name: &str, f: F)
-    where F: FnMut(&mut T, &event::ActionEvent) + 'static {
+    where F: FnMut(&mut T, &mut event::ActionEvent) + 'static {
         let wrapper = Box::new(ActionEventWrapper { callback: Box::new(f), target: target_ptr });
         let ptr = self.reg_box(wrapper);
         let cstr = CString::new(name).unwrap();
@@ -119,7 +119,7 @@ impl UiContext {
     }
 
     pub fn add_action_untyped<F>(&self, name: &str, f: F)
-    where F: FnMut(&event::ActionEvent) + 'static {
+    where F: FnMut(&mut event::ActionEvent) + 'static {
         unsafe {
             let wrapper = Box::new(UntypedEventWrapper { callback: Box::new(f) });
             let ptr = self.reg_box(wrapper);
@@ -240,7 +240,7 @@ impl<T: UiModel + UiActions> UiDoc<T> {
     }
 
     pub fn add_action<F>(&mut self, name: &str, f: F)
-    where F: FnMut(&mut T, &event::ActionEvent) + 'static {
+    where F: FnMut(&mut T, &mut event::ActionEvent) + 'static {
         unsafe {
             let wrapper = Box::new(ActionEventWrapper { callback: Box::new(f), target: self.get_data_ptr() });
             let ptr = self.ctx.reg_box(wrapper);