diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index fe88f422b..d6bb66610 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -37,6 +37,8 @@ use std::collections::HashMap; use std::path::Path; use std::{error::Error, path::PathBuf}; +use self::picker::PickerKeyHandler; + struct Utf8PathBuf { path: String, is_dir: bool, @@ -299,18 +301,16 @@ pub fn file_explorer(root: PathBuf, editor: &Editor) -> Result = Box::new(|cx: &mut Context| { - log::error!("delete file"); - }); - let create: Box = Box::new(|cx: &mut Context| { - log::error!("create file"); - }); - let rename: Box = Box::new(|cx: &mut Context| { - log::error!("rename file"); - }); - let copy: Box = Box::new(|cx: &mut Context| { - log::error!("copy file"); - }); + macro_rules! declare_key_handlers { + ($($op:literal $key:expr => $handler:expr),*) => { + hashmap!( + $( + $key => Box::new($handler) + as Box + ),* + ) + }; + } let picker = Picker::new( columns, @@ -341,12 +341,20 @@ pub fn file_explorer(root: PathBuf, editor: &Editor) -> Result |cx: &mut Context| { + log::error!("create file"); + }, + "Delete" alt!('d') => |cx: &mut Context| { + log::error!("delete file"); + }, + "Copy" alt!('y') => |cx: &mut Context| { + log::error!("copy file"); + }, + "Rename" alt!('r') => |cx: &mut Context| { + log::error!("rename file"); + } + }); Ok(picker) } diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 81ced9a8e..3513717b6 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -395,7 +395,7 @@ impl Picker { } } - pub fn with_key_handler(mut self, handlers: PickerKeyHandler) -> Self { + pub fn with_key_handlers(mut self, handlers: PickerKeyHandler) -> Self { self.custom_key_handlers = handlers; self } @@ -1179,4 +1179,4 @@ impl Drop for Picker { } type PickerCallback = Box; -type PickerKeyHandler = HashMap>; +pub type PickerKeyHandler = HashMap>;