ui: refactor compose actions
parent
b94687cdb0
commit
8d3a2d8236
|
@ -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) => {
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// TODO: Move this to `ui` crate.
|
||||
|
||||
fn false_val() -> bool {
|
||||
true
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue