diff --git a/melib/src/mailbox/email/mod.rs b/melib/src/mailbox/email/mod.rs index 7f282521e..3d93e6ff5 100644 --- a/melib/src/mailbox/email/mod.rs +++ b/melib/src/mailbox/email/mod.rs @@ -636,7 +636,6 @@ impl Envelope { } } } - // TODO: Check what references should be like again. fn set_references(&mut self, new_val: &[u8]) -> () { match self.references { Some(ref mut s) => { diff --git a/src/bin.rs b/src/bin.rs index 1a3eee563..9fdd10af0 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -64,8 +64,7 @@ fn main() { let menu = Entity::from(Box::new(AccountMenu::new(&state.context.accounts))); let listing = CompactListing::new(); let b = Entity::from(Box::new(listing)); - let mut tabs = Box::new(Tabbed::new(vec![Box::new(VSplit::new(menu, b, 90, true))])); - tabs.add_component(Box::new(Composer::default())); + let tabs = Box::new(Tabbed::new(vec![Box::new(VSplit::new(menu, b, 90, true))])); let window = Entity::from(tabs); let status_bar = Entity::from(Box::new(StatusBar::new(window))); diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs index 5f339f93c..22f5f565b 100644 --- a/ui/src/components/mail/compose.rs +++ b/ui/src/components/mail/compose.rs @@ -431,17 +431,6 @@ impl Component for Composer { self.dirty = true; return true; } - // TODO: Replace EditDraft with compose tabs - UIEventType::Input(Key::Char('m')) => { - let mut f = - create_temp_file(self.draft.to_string().unwrap().as_str().as_bytes(), None); - context.replies.push_back(UIEvent { - id: 0, - event_type: UIEventType::EditDraft(f), - }); - self.draft = Draft::default(); - return true; - } _ => {} } false diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index fad027272..026fc6f34 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -441,6 +441,13 @@ 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)), + }); + return true; + } _ => {} } false diff --git a/ui/src/components/mail/listing/mod.rs b/ui/src/components/mail/listing/mod.rs index a96ff7bff..5fa122403 100644 --- a/ui/src/components/mail/listing/mod.rs +++ b/ui/src/components/mail/listing/mod.rs @@ -640,48 +640,9 @@ impl Component for PlainListing { return true; } UIEventType::Input(Key::Char('m')) if !self.unfocused => { - use std::process::{Command, Stdio}; - /* Kill input thread so that spawned command can be sole receiver of stdin */ - { - /* I tried thread::park() here but for some reason it never blocked and always - * returned. Spinlocks are also useless because you have to keep the mutex - * guard alive til the child process exits, which requires some effort. - * - * The only problem with this approach is tht the user has to send some input - * in order for the input-thread to wake up and realise it should kill itself. - * - * I tried writing to stdin/tty manually but for some reason rustty didn't - * acknowledge it. - */ - - /* - * tx sends to input-thread and it kills itself. - */ - context.input_kill(); - } - let mut f = create_temp_file(&new_draft(context), None); - //let mut f = Box::new(std::fs::File::create(&dir).unwrap()); - - // TODO: check exit status - let mut output = Command::new("vim") - .arg("+/^$") - .arg(&f.path()) - .stdin(Stdio::inherit()) - .stdout(Stdio::inherit()) - .spawn() - .expect("failed to execute process"); - - /* - * Main loop will wait on children and when they reap them the loop spawns a new - * input-thread - */ context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::Fork(ForkType::NewDraft(f, output)), - }); - context.replies.push_back(UIEvent { - id: 0, - event_type: UIEventType::ChangeMode(UIMode::Fork), + event_type: UIEventType::Action(Tab(NewDraft)), }); return true; } diff --git a/ui/src/components/mail/view/thread.rs b/ui/src/components/mail/view/thread.rs index f28cbd873..e434cd08f 100644 --- a/ui/src/components/mail/view/thread.rs +++ b/ui/src/components/mail/view/thread.rs @@ -567,10 +567,10 @@ impl Component for ThreadView { UIEventType::Input(Key::Char('R')) => { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::Reply( + event_type: UIEventType::Action(Tab(Reply( self.coordinates, self.entries[self.expanded_pos].index.1, - ), + ))), }); return true; } diff --git a/ui/src/components/mod.rs b/ui/src/components/mod.rs index b91f33da3..4eba15791 100644 --- a/ui/src/components/mod.rs +++ b/ui/src/components/mod.rs @@ -135,16 +135,6 @@ pub trait Component: Display + Debug { fn kill(&mut self, _uuid: Uuid) {} } -fn new_draft(_context: &mut Context) -> Vec { - // TODO: Generate proper message-id https://www.jwz.org/doc/mid.html - let mut v = String::with_capacity(500); - v.push_str("From: \n"); - v.push_str("To: \n"); - v.push_str("Subject: \n"); - v.push_str("Message-Id: \n\n"); - v.into_bytes() -} - /* pub(crate) fn is_box_char(ch: char) -> bool { match ch { diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index 2eb3ceea2..620d3028a 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -798,7 +798,13 @@ impl Component for Tabbed { self.set_dirty(); return true; } - UIEventType::Reply(coordinates, msg) => { + UIEventType::Action(Tab(NewDraft)) => { + self.add_component(Box::new(Composer::default())); + self.cursor_pos = self.children.len() - 1; + self.children[self.cursor_pos].set_dirty(); + return true; + } + UIEventType::Action(Tab(Reply(coordinates, msg))) => { self.add_component(Box::new(Composer::with_context(coordinates, msg, context))); self.cursor_pos = self.children.len() - 1; self.children[self.cursor_pos].set_dirty(); diff --git a/ui/src/conf/pager.rs b/ui/src/conf/pager.rs index 54d3a5529..0575d98fb 100644 --- a/ui/src/conf/pager.rs +++ b/ui/src/conf/pager.rs @@ -19,8 +19,6 @@ * along with meli. If not, see . */ -// TODO: Move this to `ui` crate. - fn false_val() -> bool { true } diff --git a/ui/src/execute/actions.rs b/ui/src/execute/actions.rs index e2e587e43..e76b00f7c 100644 --- a/ui/src/execute/actions.rs +++ b/ui/src/execute/actions.rs @@ -35,6 +35,8 @@ pub enum ListingAction { #[derive(Debug, Clone)] pub enum TabAction { + NewDraft, + Reply((usize, usize, usize), usize), // thread coordinates (account, mailbox, root_set idx) and message idx Close, Kill(Uuid), } diff --git a/ui/src/state.rs b/ui/src/state.rs index d7afbab70..8312e53fc 100644 --- a/ui/src/state.rs +++ b/ui/src/state.rs @@ -521,28 +521,6 @@ impl State { } return; } - UIEventType::EditDraft(mut file) => { - eprintln!("edit draft event"); - use std::io::Read; - use std::process::{Command, Stdio}; - let mut output = Command::new("msmtp") - .arg("-t") - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn() - .expect("failed to execute process"); - { - let mut in_pipe = output.stdin.as_mut().unwrap(); - let mut buf = Vec::new(); - let mut f = file.file(); - - f.read_to_end(&mut buf).unwrap(); - in_pipe.write_all(&buf).unwrap(); - } - output.wait_with_output().expect("Failed to read stdout"); - - return; - } UIEventType::Input(Key::Char('t')) => for i in 0..self.entities.len() { self.entities[i].rcv_event( &UIEvent { @@ -618,12 +596,6 @@ impl State { } }; if should_return_flag { - if let Some(ForkType::NewDraft(f, _)) = std::mem::replace(&mut self.child, None) { - self.rcv_event(UIEvent { - id: 0, - event_type: UIEventType::EditDraft(f), - }); - } return Some(true); } Some(false) diff --git a/ui/src/types/mod.rs b/ui/src/types/mod.rs index 3fd70b65e..0978f51a1 100644 --- a/ui/src/types/mod.rs +++ b/ui/src/types/mod.rs @@ -90,14 +90,10 @@ pub enum UIEventType { ChangeMode(UIMode), Command(String), Notification(String), - EditDraft(File), Action(Action), StatusEvent(StatusEvent), MailboxUpdate((usize, usize)), // (account_idx, mailbox_idx) - - Reply((usize, usize, usize), usize), // thread coordinates (account, mailbox, root_set idx) and message idx EntityKill(Uuid), - StartupCheck, }