dialogs: a hook runs around the native dialog's blocking show

This commit is contained in:
bflatastic
2026-11-21 22:13:27 +07:00
parent 4cac56f5a5
commit 6766559d37
2 changed files with 23 additions and 5 deletions
+20 -2
View File
@@ -289,12 +289,18 @@ pub struct Dialogs<T> {
open: Option<Open<T>>,
answers: Vec<(T, Answer)>,
show: Show,
hook: Option<ShowHook>,
}
impl<T> Dialogs<T> {
/// A dialog queue that calls `wake` when an answer arrives.
pub fn new(wake: Wake) -> Self {
Self { wake, queue: VecDeque::new(), open: None, answers: Vec::new(), show: Show::Native }
Self { wake, queue: VecDeque::new(), open: None, answers: Vec::new(), show: Show::Native, hook: None }
}
/// Runs `hook` around every native dialog's blocking show.
pub fn set_show_hook(&mut self, hook: ShowHook) {
self.hook = Some(hook);
}
/// Queues a file dialog. It shows at the next [`Self::show_pending`] once the dialogs asked
@@ -328,7 +334,19 @@ impl<T> Dialogs<T> {
// A panic while showing (rfd's own checks) must not unwind into winit's handler.
let shown = match &mut self.show {
Show::Override(answer_with) => catch_unwind(AssertUnwindSafe(|| reply.send(answer_with(&request)))).map(|()| None),
Show::Native => catch_unwind(AssertUnwindSafe(|| native::show(request, parent, reply))),
Show::Native => catch_unwind(AssertUnwindSafe(|| {
let (mut asked, mut shown) = (Some((request, reply)), None);
let mut run = || {
if let Some((request, reply)) = asked.take() {
shown = Some(native::show(request, parent, reply));
}
};
match &mut self.hook {
Some(hook) => hook(&mut run),
None => run(),
}
shown.flatten()
})),
#[cfg(test)]
Show::Custom(show) => catch_unwind(AssertUnwindSafe(|| show(request, reply))).map(|()| None),
};
+3 -3
View File
@@ -319,9 +319,9 @@ impl FilePanels {
}
/// Runs `hook` around every native dialog's blocking show, so the app can mark the wait as waiting for the user.
pub fn show_hook(self, hook: crate::ShowHook) -> Self {
let _ = hook;
todo!("q348")
pub fn show_hook(mut self, hook: crate::ShowHook) -> Self {
self.dialogs.set_show_hook(hook);
self
}
/// Sets whether the panels ask the Replace question when the native panel did not.