modal: Respond confirm events only when on_ok or footer present (#786)
This commit is contained in:
parent
d0a73011de
commit
8ef4e2eb17
1 changed files with 15 additions and 8 deletions
|
|
@ -83,7 +83,7 @@ pub struct Modal {
|
|||
margin_top: Option<Pixels>,
|
||||
|
||||
on_close: Rc<dyn Fn(&ClickEvent, &mut Window, &mut App) + 'static>,
|
||||
on_ok: Rc<dyn Fn(&ClickEvent, &mut Window, &mut App) -> bool + 'static>,
|
||||
on_ok: Option<Rc<dyn Fn(&ClickEvent, &mut Window, &mut App) -> bool + 'static>>,
|
||||
on_cancel: Rc<dyn Fn(&ClickEvent, &mut Window, &mut App) -> bool + 'static>,
|
||||
button_props: ModalButtonProps,
|
||||
show_close: bool,
|
||||
|
|
@ -137,7 +137,7 @@ impl Modal {
|
|||
layer_ix: 0,
|
||||
overlay_visible: true,
|
||||
on_close: Rc::new(|_, _, _| {}),
|
||||
on_ok: Rc::new(|_, _, _| true),
|
||||
on_ok: None,
|
||||
on_cancel: Rc::new(|_, _, _| true),
|
||||
button_props: ModalButtonProps::default(),
|
||||
show_close: true,
|
||||
|
|
@ -202,7 +202,7 @@ impl Modal {
|
|||
mut self,
|
||||
on_ok: impl Fn(&ClickEvent, &mut Window, &mut App) -> bool + 'static,
|
||||
) -> Self {
|
||||
self.on_ok = Rc::new(on_ok);
|
||||
self.on_ok = Some(Rc::new(on_ok));
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -302,9 +302,11 @@ impl RenderOnce for Modal {
|
|||
let on_close = on_close.clone();
|
||||
|
||||
move |_, window, cx| {
|
||||
if on_ok(&ClickEvent::default(), window, cx) {
|
||||
on_close(&ClickEvent::default(), window, cx);
|
||||
window.close_modal(cx);
|
||||
if let Some(on_ok) = &on_ok {
|
||||
if on_ok(&ClickEvent::default(), window, cx) {
|
||||
on_close(&ClickEvent::default(), window, cx);
|
||||
window.close_modal(cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -399,9 +401,14 @@ impl RenderOnce for Modal {
|
|||
.on_action({
|
||||
let on_ok = on_ok.clone();
|
||||
let on_close = on_close.clone();
|
||||
let has_footer = self.footer.is_some();
|
||||
move |_: &Confirm, window, cx| {
|
||||
if on_ok(&ClickEvent::default(), window, cx) {
|
||||
on_close(&ClickEvent::default(), window, cx);
|
||||
if let Some(on_ok) = &on_ok {
|
||||
if on_ok(&ClickEvent::default(), window, cx) {
|
||||
on_close(&ClickEvent::default(), window, cx);
|
||||
window.close_modal(cx);
|
||||
}
|
||||
} else if has_footer {
|
||||
window.close_modal(cx);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue