From a866e060a1d837d59a87a519e3df17bfbfa7a951 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 7 Sep 2019 22:07:13 +0300 Subject: [PATCH] ui: open MessageRfc822 attachments in new tab --- ui/src/components.rs | 2 +- ui/src/components/contacts/contact_list.rs | 11 +++-------- ui/src/components/mail/accounts.rs | 2 +- ui/src/components/mail/compose.rs | 2 +- ui/src/components/mail/view.rs | 15 ++++++++------- ui/src/components/mail/view/envelope.rs | 8 ++++++++ ui/src/components/utilities.rs | 4 ++-- ui/src/execute/actions.rs | 2 +- 8 files changed, 25 insertions(+), 21 deletions(-) diff --git a/ui/src/components.rs b/ui/src/components.rs index 6e753ed60..fd8faaf80 100644 --- a/ui/src/components.rs +++ b/ui/src/components.rs @@ -93,7 +93,7 @@ pub trait Component: Display + Debug + Send { true } fn set_dirty(&mut self); - fn kill(&mut self, _id: ComponentId) {} + fn kill(&mut self, _id: ComponentId, _context: &mut Context) {} fn set_id(&mut self, _id: ComponentId) {} fn id(&self) -> ComponentId; diff --git a/ui/src/components/contacts/contact_list.rs b/ui/src/components/contacts/contact_list.rs index 632bdefac..3807bc12a 100644 --- a/ui/src/components/contacts/contact_list.rs +++ b/ui/src/components/contacts/contact_list.rs @@ -8,7 +8,6 @@ const MAX_COLS: usize = 500; enum ViewMode { List, View(CardId), - Close(Uuid), } #[derive(Debug)] @@ -158,11 +157,6 @@ impl ContactList { impl Component for ContactList { fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { - if let ViewMode::Close(u) = self.mode { - context.replies.push_back(UIEvent::Action(Tab(Kill(u)))); - return; - } - if let Some(mgr) = self.view.as_mut() { mgr.draw(grid, area, context); return; @@ -289,8 +283,9 @@ impl Component for ContactList { self.dirty = true; } - fn kill(&mut self, uuid: Uuid) { - self.mode = ViewMode::Close(uuid); + fn kill(&mut self, uuid: Uuid, context: &mut Context) { + debug_assert!(uuid == self.id); + context.replies.push_back(UIEvent::Action(Tab(Kill(uuid)))); } fn get_shortcuts(&self, context: &Context) -> ShortcutMaps { let mut map = self diff --git a/ui/src/components/mail/accounts.rs b/ui/src/components/mail/accounts.rs index ded7b002b..cde1b3753 100644 --- a/ui/src/components/mail/accounts.rs +++ b/ui/src/components/mail/accounts.rs @@ -65,7 +65,7 @@ impl Component for AccountsPanel { UIEvent::Input(Key::Char('\n')) => { context .replies - .push_back(UIEvent::Action(Tab(TabOpen(Some(Box::new( + .push_back(UIEvent::Action(Tab(New(Some(Box::new( ContactList::for_account(self.cursor), )))))); return true; diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs index 4e76b61e7..006c6dcfc 100644 --- a/ui/src/components/mail/compose.rs +++ b/ui/src/components/mail/compose.rs @@ -713,7 +713,7 @@ impl Component for Composer { } } - fn kill(&mut self, uuid: Uuid) { + fn kill(&mut self, uuid: Uuid, _context: &mut Context) { self.mode = ViewMode::Discard(uuid); } diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index aa3f04ccf..0e7a24beb 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -731,15 +731,16 @@ impl Component for MailView { if let Some(u) = envelope.body(op).attachments().get(lidx) { match u.content_type() { ContentType::MessageRfc822 => { - self.mode = ViewMode::Subview; match EnvelopeWrapper::new(u.raw().to_vec()) { Ok(wrapper) => { - self.subview = Some(Box::new(EnvelopeView::new( - wrapper, - None, - None, - self.coordinates.0, - ))); + context.replies.push_back(UIEvent::Action(Tab(New(Some( + Box::new(EnvelopeView::new( + wrapper, + None, + None, + self.coordinates.0, + )), + ))))); } Err(e) => { context.replies.push_back(UIEvent::StatusEvent( diff --git a/ui/src/components/mail/view/envelope.rs b/ui/src/components/mail/view/envelope.rs index cc708868d..3cb4a5162 100644 --- a/ui/src/components/mail/view/envelope.rs +++ b/ui/src/components/mail/view/envelope.rs @@ -555,6 +555,14 @@ impl Component for EnvelopeView { fn id(&self) -> ComponentId { self.id } + + fn kill(&mut self, id: ComponentId, context: &mut Context) { + debug_assert!(self.id == id); + context + .replies + .push_back(UIEvent::Action(Tab(Kill(self.id)))); + } + fn set_id(&mut self, id: ComponentId) { self.id = id; } diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index dfde2a02b..b150627af 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -1345,7 +1345,7 @@ impl Component for Tabbed { self.children[self.cursor_pos].set_dirty(); return true; } - UIEvent::Action(Tab(TabOpen(ref mut e))) if e.is_some() => { + UIEvent::Action(Tab(New(ref mut e))) if e.is_some() => { self.add_component(e.take().unwrap()); self.cursor_pos = self.children.len() - 1; self.children[self.cursor_pos].set_dirty(); @@ -1356,7 +1356,7 @@ impl Component for Tabbed { return true; } let id = self.children[self.cursor_pos].id(); - self.children[self.cursor_pos].kill(id); + self.children[self.cursor_pos].kill(id, context); self.set_dirty(); return true; } diff --git a/ui/src/execute/actions.rs b/ui/src/execute/actions.rs index 06aaceb06..6010afa01 100644 --- a/ui/src/execute/actions.rs +++ b/ui/src/execute/actions.rs @@ -44,7 +44,7 @@ pub enum ListingAction { #[derive(Debug)] pub enum TabAction { - TabOpen(Option>), + New(Option>), NewDraft(usize, Option), Reply((usize, usize, usize), ThreadHash), // thread coordinates (account, mailbox, root_set idx) and thread hash Close,