From: Olaf Wintermann Date: Tue, 12 May 2026 19:44:32 +0000 (+0200) Subject: add file dialog functions X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=650ae037370de78f693cb6fa7c390d4e7f87ce21;p=note.git add file dialog functions --- diff --git a/ui-rs/src/ui/window.rs b/ui-rs/src/ui/window.rs index 408e9c1..8b71fd4 100644 --- a/ui-rs/src/ui/window.rs +++ b/ui-rs/src/ui/window.rs @@ -30,9 +30,9 @@ #[allow(unused_imports)] use std::ffi::{c_char, c_int, c_void}; -use std::ffi::CString; +use std::ffi::{c_uint, CString}; use std::marker::PhantomData; -use crate::ui::{event, ffi, toolkit, ui_object_ref, AppContext, EventWrapper, NoAppData, UiActions, UiModel}; +use crate::ui::{event, event_wrapper_oneshot, ffi, toolkit, ui_object_ref, AppContext, EventWrapper, NoAppData, UiActions, UiModel}; use crate::ui::ffi::{UiButtonArgs, UiCallback, UiContext, UiDestructor, UiDialogArgs, UiObject}; use crate::ui::widget::widget_fn; @@ -241,6 +241,21 @@ impl toolkit::UiObject { build(&mut builder); builder.create(); } + + pub fn openfile_dialog(&mut self, multiselect: bool, callback: F) + where F: FnMut(&mut event::Event) + 'static { + openfile_dialog(self, multiselect as c_uint, callback); + } + + pub fn selectdirectory_dialog(&mut self, callback: F) + where F: FnMut(&mut event::Event) + 'static { + openfile_dialog(self, 2, callback); + } + + pub fn savefile_dialog(&mut self, name: &str, callback: F) + where F: FnMut(&mut event::Event) + 'static { + savefile_dialog(self, name, callback); + } } pub fn dialog_builder() -> DialogBuilder { @@ -260,6 +275,25 @@ where builder.create(); } +fn openfile_dialog(obj: &toolkit::UiObject, mode: c_uint, f: F) +where F: FnMut(&mut event::Event) + 'static { + let b: Box> = Box::new(EventWrapper { callback: Box::new(f) }); + let ptr = Box::into_raw(b); + unsafe { + ui_openfiledialog(obj.ptr, mode, Some(event_wrapper_oneshot::), ptr as *mut c_void); + } +} + +fn savefile_dialog(obj: &toolkit::UiObject, name: &str, f: F) +where F: FnMut(&mut event::Event) + 'static { + let cstr = CString::new(name).unwrap(); + let b: Box> = Box::new(EventWrapper { callback: Box::new(f) }); + let ptr = Box::into_raw(b); + unsafe { + ui_savefiledialog(obj.ptr, cstr.as_ptr(), Some(event_wrapper_oneshot::), ptr as *mut c_void); + } +} + /* ---------------------------------- C functions ---------------------------------- */ @@ -293,4 +327,7 @@ extern "C" { fn ui_dialog_args_set_result(args: *mut UiDialogArgs, callback: UiCallback); fn ui_dialog_args_set_resultdata(args: *mut UiDialogArgs, data: *mut c_void); fn ui_dialog_args_free(args: *mut UiDialogArgs); + + fn ui_openfiledialog(obj: *mut ffi::UiObject, mode: c_uint, callback: UiCallback, data: *mut c_void); + fn ui_savefiledialog(obj: *mut ffi::UiObject, name: *const c_char, callback: UiCallback, data: *mut c_void); }