From: Olaf Wintermann Date: Fri, 12 Jun 2026 15:01:46 +0000 (+0200) Subject: make obj in ActionEvents mutable X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=HEAD;p=note.git make obj in ActionEvents mutable --- diff --git a/application/src/notebook.rs b/application/src/notebook.rs index 43a0370..884e350 100644 --- a/application/src/notebook.rs +++ b/application/src/notebook.rs @@ -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); + } } } diff --git a/application/src/window.rs b/application/src/window.rs index 8fc9aee..25512fb 100644 --- a/application/src/window.rs +++ b/application/src/window.rs @@ -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()); } } diff --git a/ui-rs/src/ui/event.rs b/ui-rs/src/ui/event.rs index 2e7e2aa..a691e9a 100644 --- a/ui-rs/src/ui/event.rs +++ b/ui-rs/src/ui/event.rs @@ -46,7 +46,7 @@ pub struct Event<'a, T> { } pub struct ActionEvent<'a> { - pub obj: Option<&'a UiObject>, + pub obj: Option<&'a mut UiObject>, pub event_type: EventType<'a>, pub intval: i32, pub set: bool @@ -274,7 +274,7 @@ pub extern "C" fn event_wrapper_oneshot(e: *const ffi::UiEvent, data: *mut c_ } pub struct ActionEventWrapper { - pub callback: Box, + pub callback: Box, pub target: *mut T } @@ -290,7 +290,7 @@ pub extern "C" fn action_event_wrapper(e: *const ffi::UiEvent, data: *mut c_v } fn action_callback(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 + pub callback: Box } pub extern "C" fn untyped_event_wrapper(e: *const ffi::UiEvent, data: *mut c_void) { diff --git a/ui-rs/src/ui/toolkit.rs b/ui-rs/src/ui/toolkit.rs index 35cbfef..5fc3452 100644 --- a/ui-rs/src/ui/toolkit.rs +++ b/ui-rs/src/ui/toolkit.rs @@ -93,7 +93,7 @@ impl UiContext { } pub unsafe fn add_action(&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(&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(&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 UiDoc { } pub fn add_action(&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);