From 4bf1f6b9c920182c5ba0bae85a5192be14a7a9dc Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 6 Apr 2019 00:43:50 +0300 Subject: [PATCH] ui: make Composer account specific --- melib/src/mailbox/email/compose.rs | 2 +- ui/src/components/mail/compose.rs | 6 ++++++ ui/src/components/mail/listing/compact.rs | 2 +- ui/src/components/mail/listing/plain.rs | 2 +- ui/src/components/mail/listing/thread.rs | 2 +- ui/src/components/utilities.rs | 4 ++-- ui/src/execute/actions.rs | 2 +- 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/melib/src/mailbox/email/compose.rs b/melib/src/mailbox/email/compose.rs index 2c6916473..f24f27d35 100644 --- a/melib/src/mailbox/email/compose.rs +++ b/melib/src/mailbox/email/compose.rs @@ -12,7 +12,7 @@ mod random; use super::parser; use fnv::FnvHashMap; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub struct Draft { // FIXME: Preserve header order // FIXME: Validate headers, allow custom ones diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs index 268bd4449..50bb2ed37 100644 --- a/ui/src/components/mail/compose.rs +++ b/ui/src/components/mail/compose.rs @@ -112,6 +112,12 @@ impl fmt::Display for Composer { } impl Composer { + pub fn new(account_cursor: usize) -> Self { + Composer { + account_cursor, + ..Default::default() + } + } /* * coordinates: (account index, mailbox index, root set thread_node index) * msg: index of message we reply to in thread_nodes diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index a748c372d..deaf70bbc 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -530,7 +530,7 @@ impl Component for CompactListing { UIEventType::Input(Key::Char('m')) if !self.unfocused => { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::Action(Tab(NewDraft)), + event_type: UIEventType::Action(Tab(NewDraft(self.cursor_pos.0))), }); return true; } diff --git a/ui/src/components/mail/listing/plain.rs b/ui/src/components/mail/listing/plain.rs index 278018870..01e1f6209 100644 --- a/ui/src/components/mail/listing/plain.rs +++ b/ui/src/components/mail/listing/plain.rs @@ -437,7 +437,7 @@ impl Component for PlainListing { UIEventType::Input(Key::Char('m')) if !self.unfocused => { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::Action(Tab(NewDraft)), + event_type: UIEventType::Action(Tab(NewDraft(self.cursor_pos.0))), }); return true; } diff --git a/ui/src/components/mail/listing/thread.rs b/ui/src/components/mail/listing/thread.rs index d1f55abab..a6ccfccc4 100644 --- a/ui/src/components/mail/listing/thread.rs +++ b/ui/src/components/mail/listing/thread.rs @@ -599,7 +599,7 @@ impl Component for ThreadListing { UIEventType::Input(Key::Char('m')) if !self.unfocused => { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::Action(Tab(NewDraft)), + event_type: UIEventType::Action(Tab(NewDraft(self.cursor_pos.0))), }); return true; } diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index 53e6679cc..8f713396a 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -999,8 +999,8 @@ impl Component for Tabbed { self.set_dirty(); return true; } - UIEventType::Action(Tab(NewDraft)) => { - self.add_component(Box::new(Composer::default())); + UIEventType::Action(Tab(NewDraft(account_idx))) => { + self.add_component(Box::new(Composer::new(account_idx))); self.cursor_pos = self.children.len() - 1; self.children[self.cursor_pos].set_dirty(); return true; diff --git a/ui/src/execute/actions.rs b/ui/src/execute/actions.rs index a0113c62c..a84232b84 100644 --- a/ui/src/execute/actions.rs +++ b/ui/src/execute/actions.rs @@ -39,7 +39,7 @@ pub enum ListingAction { #[derive(Debug)] pub enum TabAction { TabOpen(Option>), - NewDraft, + NewDraft(usize), Reply((usize, usize, usize), usize), // thread coordinates (account, mailbox, root_set idx) and message idx Close, Edit((usize, usize, usize), usize), // thread coordinates (account, mailbox, root_set idx) and message idx