diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index a8cc3d804..43bcbf703 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -37,7 +37,7 @@ pub use self::envelope::*; use mime_apps::query_default_app; -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Debug, Clone)] enum ViewMode { Normal, Url, @@ -77,6 +77,18 @@ pub struct MailView { id: ComponentId, } +impl Clone for MailView { + fn clone(&self) -> Self { + MailView { + subview: None, + cmd_buf: String::with_capacity(4), + pager: self.pager.clone(), + mode: self.mode.clone(), + ..*self + } + } +} + impl fmt::Display for MailView { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // TODO display subject/info @@ -974,6 +986,12 @@ impl Component for MailView { } } } + UIEvent::Action(Listing(OpenInNewTab)) => { + context + .replies + .push_back(UIEvent::Action(Tab(New(Some(Box::new(self.clone())))))); + return true; + } _ => {} } false @@ -1035,7 +1053,15 @@ impl Component for MailView { fn id(&self) -> ComponentId { self.id } + fn set_id(&mut self, id: ComponentId) { self.id = 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)))); + } } diff --git a/ui/src/components/mail/view/thread.rs b/ui/src/components/mail/view/thread.rs index 7c74c0a02..a329788ad 100644 --- a/ui/src/components/mail/view/thread.rs +++ b/ui/src/components/mail/view/thread.rs @@ -44,7 +44,7 @@ struct ThreadEntry { heading: String, } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct ThreadView { new_cursor_pos: usize, cursor_pos: usize, @@ -896,9 +896,24 @@ impl Component for ThreadView { } } fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { + match event { + UIEvent::Action(Listing(OpenInNewTab)) => { + /* Handle this before self.mailview does */ + context + .replies + .push_back(UIEvent::Action(Tab(New(Some(Box::new(Self { + initiated: false, + ..self.clone() + })))))); + return true; + } + _ => {} + } + if self.show_mailview && self.mailview.process_event(event, context) { return true; } + let shortcuts = &self.get_shortcuts(context)[ThreadView::DESCRIPTION]; match *event { UIEvent::Input(Key::Char('R')) => { @@ -1102,7 +1117,15 @@ impl Component for ThreadView { fn id(&self) -> ComponentId { self.id } + fn set_id(&mut self, id: ComponentId) { self.id = 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)))); + } } diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index 4b6763858..c73d2344e 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -263,7 +263,7 @@ impl Component for VSplit { } } -#[derive(Debug)] +#[derive(Debug, Clone, Copy)] pub enum PageMovement { Home, PageUp, @@ -274,7 +274,7 @@ pub enum PageMovement { /// A pager for text. /// `Pager` holds its own content in its own `CellBuffer` and when `draw` is called, it draws the /// current view of the text. It is responsible for scrolling etc. -#[derive(Default, Debug)] +#[derive(Default, Debug, Clone)] pub struct Pager { text: String, cursor_pos: usize, @@ -1393,7 +1393,7 @@ impl Component for Tabbed { type EntryIdentifier = Vec; /// Shows selection to user -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub struct Selector { single_only: bool, /// allow only one selection diff --git a/ui/src/execute.rs b/ui/src/execute.rs index a65881a48..18e3a47e5 100644 --- a/ui/src/execute.rs +++ b/ui/src/execute.rs @@ -285,6 +285,17 @@ define_commands!([ ) ); ) + }, + { tags: ["open-in-tab"], + desc: "opens envelope view in new tab", + parser:( + named!( open_in_new_tab, + do_parse!( + ws!(tag!("open-in-tab")) + >> (Listing(OpenInNewTab)) + ) + ); + ) } ]); @@ -334,7 +345,7 @@ named!( named!( listing_action, - alt_complete!(toggle | envelope_action | filter | toggle_thread_snooze) + alt_complete!(toggle | envelope_action | filter | toggle_thread_snooze | open_in_new_tab) ); named!( diff --git a/ui/src/execute/actions.rs b/ui/src/execute/actions.rs index 135b66df3..23605402c 100644 --- a/ui/src/execute/actions.rs +++ b/ui/src/execute/actions.rs @@ -42,6 +42,7 @@ pub enum ListingAction { SetSeen, SetUnseen, Delete, + OpenInNewTab, } #[derive(Debug)]