wip: midi import/export browser, pt.2

This commit is contained in:
🪞👃🪞 2024-11-24 19:09:31 +01:00
parent 6d8dbc6780
commit fab6113478
3 changed files with 42 additions and 5 deletions

View file

@ -149,7 +149,7 @@ impl<T: PhrasesControl> Command<T> for PhrasesCommand {
Import(command) => match command {
FileBrowserCommand::Begin => {
*state.phrases_mode_mut() = Some(
PhrasesMode::Import(state.phrase_index(), FileBrowser::new())
PhrasesMode::Import(state.phrase_index(), FileBrowser::new(None)?)
);
None
},
@ -158,7 +158,7 @@ impl<T: PhrasesControl> Command<T> for PhrasesCommand {
Export(command) => match command {
FileBrowserCommand::Begin => {
*state.phrases_mode_mut() = Some(
PhrasesMode::Export(state.phrase_index(), FileBrowser::new())
PhrasesMode::Export(state.phrase_index(), FileBrowser::new(None)?)
);
None
},

View file

@ -316,7 +316,34 @@ fn to_phrases_command <T: PhrasesControl> (state: &T, input: &TuiInput) -> Optio
impl<T: PhrasesControl> InputToCommand<Tui, T> for FileBrowserCommand {
fn input_to_command (state: &T, from: &TuiInput) -> Option<Self> {
todo!()
use KeyCode::{Up, Down, Right, Left, Enter, Esc, Char, Backspace};
if let Some(PhrasesMode::Import(index, browser)) = state.phrases_mode() {
Some(match from.event() {
key!(Up) => Self::Select(0),
key!(Down) => Self::Select(0),
key!(Right) => Self::Chdir(browser.cwd.clone()),
key!(Left) => Self::Chdir(browser.cwd.clone()),
key!(Enter) => { todo!() },
key!(Char(c)) => { todo!() },
key!(Backspace) => { todo!() },
key!(Esc) => Self::Cancel,
_ => return None
})
} else if let Some(PhrasesMode::Export(index, browser)) = state.phrases_mode() {
Some(match from.event() {
key!(Up) => Self::Select(0),
key!(Down) => Self::Select(0),
key!(Right) => Self::Chdir(browser.cwd.clone()),
key!(Left) => Self::Chdir(browser.cwd.clone()),
key!(Enter) => { todo!() },
key!(Char(c)) => { todo!() },
key!(Backspace) => { todo!() },
key!(Esc) => Self::Cancel,
_ => return None
})
} else {
unreachable!()
}
}
}

View file

@ -174,14 +174,24 @@ pub struct FileBrowser {
pub cwd: PathBuf,
pub dirs: Vec<PathBuf>,
pub files: Vec<PathBuf>,
pub filter: String,
pub index: usize,
pub scroll: usize,
pub size: Measure<Tui>
}
impl FileBrowser {
pub fn new () -> Self {
todo!()
pub fn new (cwd: Option<PathBuf>) -> Usually<Self> {
let cwd = if let Some(cwd) = cwd { cwd } else { std::env::current_dir()? };
Ok(Self {
cwd,
dirs: vec![/*todo*/],
files: vec![/*todo*/],
filter: "".to_string(),
index: 0,
scroll: 0,
size: Measure::new(),
})
}
}