From c7825c76c3ac6be89f64f1f04afd9c0ca08bdf76 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 2 Sep 2023 19:38:27 +0300 Subject: [PATCH] mail/view: handle dialog Esc in the parent component Dialogues handled Esc themselves, which meant the event didn't bubble up to their parent to let them know they should remove the dialogue. This commit fixes that. Signed-off-by: Manos Pitsidianakis --- meli/src/mail/view.rs | 25 +++++++++++++++---------- meli/src/mail/view/thread.rs | 3 ++- meli/src/types.rs | 1 + meli/src/utilities/dialogs.rs | 30 ++++++++++++++++++++++-------- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/meli/src/mail/view.rs b/meli/src/mail/view.rs index 313c72c2..eea75aeb 100644 --- a/meli/src/mail/view.rs +++ b/meli/src/mail/view.rs @@ -356,13 +356,6 @@ impl Component for MailView { } fn process_event(&mut self, mut event: &mut UIEvent, context: &mut Context) -> bool { - let Some(coordinates) = self.coordinates else { - return false; - }; - if coordinates.0.is_null() || coordinates.1.is_null() { - return false; - } - if let Some(ref mut s) = self.contact_selector { if s.process_event(event, context) { return true; @@ -375,6 +368,13 @@ impl Component for MailView { } } + let Some(coordinates) = self.coordinates else { + return false; + }; + if coordinates.0.is_null() || coordinates.1.is_null() { + return false; + } + /* If envelope data is loaded, pass it to envelope views */ if self.state.process_event(event, context) { return true; @@ -612,8 +612,12 @@ impl Component for MailView { UIEvent::Input(Key::Esc) | UIEvent::Input(Key::Alt('')) if self.contact_selector.is_some() || self.forward_dialog.is_some() => { - self.contact_selector = None; - self.forward_dialog = None; + if let Some(s) = self.contact_selector.take() { + s.unrealize(context); + } + if let Some(s) = self.forward_dialog.take() { + s.unrealize(context); + } self.set_dirty(true); return true; } @@ -778,7 +782,8 @@ impl Component for MailView { }; } UIEvent::Action(Listing(OpenInNewTab)) => { - let new_tab = Self::new(self.coordinates, context); + let mut new_tab = Self::new(self.coordinates, context); + new_tab.set_dirty(true); context .replies .push_back(UIEvent::Action(Tab(New(Some(Box::new(new_tab)))))); diff --git a/meli/src/mail/view/thread.rs b/meli/src/mail/view/thread.rs index 35b424ef..2ae2d492 100644 --- a/meli/src/mail/view/thread.rs +++ b/meli/src/mail/view/thread.rs @@ -1024,7 +1024,7 @@ impl Component for ThreadView { fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { if let UIEvent::Action(Listing(OpenInNewTab)) = event { /* Handle this before self.mailview does */ - let new_tab = Self::new( + let mut new_tab = Self::new( self.coordinates, self.thread_group, Some(self.entries[self.expanded_pos].msg_hash), @@ -1032,6 +1032,7 @@ impl Component for ThreadView { Some(self.focus), context, ); + new_tab.set_dirty(true); context .replies .push_back(UIEvent::Action(Tab(New(Some(Box::new(new_tab)))))); diff --git a/meli/src/types.rs b/meli/src/types.rs index 7aca12d8..7d1aba26 100644 --- a/meli/src/types.rs +++ b/meli/src/types.rs @@ -154,6 +154,7 @@ pub enum UIEvent { Contacts(ContactEvent), Compose(ComposeEvent), FinishedUIDialog(ComponentId, UIMessage), + CanceledUIDialog(ComponentId), IntraComm { from: ComponentId, to: ComponentId, diff --git a/meli/src/utilities/dialogs.rs b/meli/src/utilities/dialogs.rs index 50391142..0958d6cb 100644 --- a/meli/src/utilities/dialogs.rs +++ b/meli/src/utilities/dialogs.rs @@ -170,12 +170,14 @@ impl Component f for e in self.entries.iter_mut() { e.1 = false; } - self.done = true; - if let Some(event) = self.done() { - context.replies.push_back(event); + if !self.done { self.unrealize(context); } - return true; + self.done = true; + _ = self.done(); + context.replies.push_back(self.cancel()); + + return false; } (UIEvent::Input(Key::Char('\n')), SelectorCursor::Cancel) if !self.single_only => { for e in self.entries.iter_mut() { @@ -495,12 +497,14 @@ impl Component for UIConfirmationDialog { for e in self.entries.iter_mut() { e.1 = false; } - self.done = true; - if let Some(event) = self.done() { - context.replies.push_back(event); + if !self.done { self.unrealize(context); } - return true; + self.done = true; + _ = self.done(); + context.replies.push_back(self.cancel()); + + return false; } (UIEvent::Input(Key::Char('\n')), SelectorCursor::Cancel) if !self.single_only => { for e in self.entries.iter_mut() { @@ -950,6 +954,11 @@ impl UIDialog ) }) } + + fn cancel(&mut self) -> UIEvent { + let Self { ref id, .. } = self; + UIEvent::CanceledUIDialog(*id) + } } impl UIConfirmationDialog { @@ -972,4 +981,9 @@ impl UIConfirmationDialog { ) }) } + + fn cancel(&mut self) -> UIEvent { + let Self { ref id, .. } = self; + UIEvent::CanceledUIDialog(*id) + } }