diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2018-09-04 02:10:37 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-10 19:40:32 +0300 |
commit | 8d3a2d82366cc86a405ed194eba02e0d47cac70e (patch) | |
tree | 0f2aed412dc2c40dba7ba3fcdd3de5fb55ea7b72 /ui/src/components | |
parent | b94687cdb0ddda05bbf983042f4218dea35b80b1 (diff) |
ui: refactor compose actions
Diffstat (limited to 'ui/src/components')
-rw-r--r-- | ui/src/components/mail/compose.rs | 11 | ||||
-rw-r--r-- | ui/src/components/mail/listing/compact.rs | 7 | ||||
-rw-r--r-- | ui/src/components/mail/listing/mod.rs | 41 | ||||
-rw-r--r-- | ui/src/components/mail/view/thread.rs | 4 | ||||
-rw-r--r-- | ui/src/components/mod.rs | 10 | ||||
-rw-r--r-- | ui/src/components/utilities.rs | 8 |
6 files changed, 17 insertions, 64 deletions
diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs index 5f339f93..22f5f565 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 fad02727..026fc6f3 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 a96ff7bf..5fa12240 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 f28cbd87..e434cd08 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 b91f33da..4eba1579 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<u8> { - // 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 2eb3ceea..620d3028 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(); |