1use crate::app::App; 2use crate::app::tabs::Tab; 3use rune::{Key, KeyEvent, Tx}; 4 5pub fn on_key(s: &mut App, ev: &KeyEvent, tx: &mut Tx) -> bool { 6 match ev.key { 7 Key::Command('o') => s.pick_dir(tx), 8 Key::Command('s') => { 9 if let Tab::Prompt(stem) = s.tab().clone() { 10 s.save_prompt(&stem); 11 } 12 } 13 Key::Command('w') => s.close(s.active), 14 Key::Command('n') if s.ws.is_some() => { 15 let stem = s.ws.as_mut().map(|w| w.new_prompt()).unwrap_or_default(); 16 s.open_prompt(&stem); 17 } 18 Key::Command(',') => s.open(Tab::Settings), 19 _ => return false, 20 } 21 true 22} 23 24impl App { 25 pub fn pick_dir(&mut self, tx: &mut Tx) { 26 let opts = rune::FileDialogOptions { 27 title: "Open directory".into(), 28 ..Default::default() 29 }; 30 tx.open_folder(opts, |s: &mut App, result, _| match result { 31 Ok(Some(dir)) => s.open_dir(&dir), 32 Ok(None) => {} 33 Err(e) => s.fail(e.to_string()), 34 }); 35 } 36}