remy_widgets/widgets/explorer/
input.rs1use crate::events::{Event, Key};
2use crate::widgets::core::RemyWidgetCommandConverter;
3use crate::widgets::explorer::FileExplorerState;
4use crate::widgets::text_input::{DefaultTextInputInputConverter, TextInputAction, TextInputState};
5use crate::widgets::util::cursor::TypingBehaviour;
6
7#[derive(Debug, Copy, Clone, PartialEq, Eq)]
8pub enum FileExplorerCommand {
9 ArrowUp,
10 ArrowDown,
11 DirectoryUp,
12 DirectoryDown,
13 Exit,
14 Confirm,
15 EnterFileName,
16 FileNameDialogInput(TextInputAction)
17}
18
19pub struct DefaultFileExplorerInputConverter;
20
21impl<T> RemyWidgetCommandConverter<FileExplorerState<T>> for DefaultFileExplorerInputConverter
22where
23 T: TypingBehaviour
24{
25 type Event = FileExplorerCommand;
26
27 fn convert(event: Event, state: &FileExplorerState<T>) -> Option<Self::Event> {
28 if let Some(s) = state.filename_input_state.as_ref() {
29 let inner = <DefaultTextInputInputConverter as RemyWidgetCommandConverter<TextInputState<T>>>::convert(event, s);
30 inner.map(FileExplorerCommand::FileNameDialogInput)
31 } else {
32 match event {
33 Event::KeyPress { key, .. } => {
34 match key {
35 Key::ArrowUp => Some(FileExplorerCommand::ArrowUp),
36 Key::ArrowDown => Some(FileExplorerCommand::ArrowDown),
37 Key::ArrowLeft => Some(FileExplorerCommand::DirectoryUp),
38 Key::ArrowRight => Some(FileExplorerCommand::DirectoryDown),
39 Key::Enter => Some(FileExplorerCommand::Confirm),
40 Key::Esc => Some(FileExplorerCommand::Exit),
41 Key::Character('n') => Some(FileExplorerCommand::EnterFileName),
42 _ => None
43 }
44 }
45 Event::Null => None
46 }
47 }
48 }
49}