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 <manos@pitsidianak.is>
pull/295/head
Manos Pitsidianakis 2023-09-02 19:38:27 +03:00
parent 3344a8dbf6
commit c7825c76c3
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
4 changed files with 40 additions and 19 deletions

View File

@ -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))))));

View File

@ -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))))));

View File

@ -154,6 +154,7 @@ pub enum UIEvent {
Contacts(ContactEvent),
Compose(ComposeEvent),
FinishedUIDialog(ComponentId, UIMessage),
CanceledUIDialog(ComponentId),
IntraComm {
from: ComponentId,
to: ComponentId,

View File

@ -170,12 +170,14 @@ impl<T: 'static + PartialEq + std::fmt::Debug + Clone + Sync + Send> 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<T: 'static + PartialEq + std::fmt::Debug + Clone + Sync + Send> UIDialog<T>
)
})
}
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)
}
}