mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
wip: midi import/export browser, pt.4
This commit is contained in:
parent
a4febb8a0d
commit
bd354bbc67
3 changed files with 47 additions and 14 deletions
|
|
@ -266,18 +266,30 @@ impl<T: PhrasesControl> Command<T> for FileBrowserCommand {
|
||||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||||
use FileBrowserCommand::*;
|
use FileBrowserCommand::*;
|
||||||
match state.phrases_mode_mut().clone() {
|
match state.phrases_mode_mut().clone() {
|
||||||
Some(PhrasesMode::Import(index, browser)) => {
|
Some(PhrasesMode::Import(index, browser)) => match self {
|
||||||
todo!()
|
Cancel => {
|
||||||
|
*state.phrases_mode_mut() = None;
|
||||||
|
},
|
||||||
|
Chdir(cwd) => {
|
||||||
|
*state.phrases_mode_mut() = Some(PhrasesMode::Import(
|
||||||
|
index, FileBrowser::new(Some(cwd))?
|
||||||
|
));
|
||||||
|
},
|
||||||
|
_ => todo!(),
|
||||||
|
_ => unreachable!()
|
||||||
},
|
},
|
||||||
Some(PhrasesMode::Export(index, browser)) => {
|
Some(PhrasesMode::Export(index, browser)) => match self {
|
||||||
todo!()
|
Cancel => {
|
||||||
},
|
*state.phrases_mode_mut() = None;
|
||||||
_ => match self {
|
},
|
||||||
Begin => {
|
Chdir(cwd) => {
|
||||||
todo!()
|
*state.phrases_mode_mut() = Some(PhrasesMode::Export(
|
||||||
|
index, FileBrowser::new(Some(cwd))?
|
||||||
|
));
|
||||||
},
|
},
|
||||||
_ => unreachable!()
|
_ => unreachable!()
|
||||||
}
|
},
|
||||||
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,15 @@ impl<'a, T: PhrasesViewState> Content for PhrasesView<'a, T> {
|
||||||
impl Content for FileBrowser {
|
impl Content for FileBrowser {
|
||||||
type Engine = Tui;
|
type Engine = Tui;
|
||||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||||
"todo: file browser"
|
Stack::down(|add|{
|
||||||
|
for (_, name) in self.dirs.iter() {
|
||||||
|
add(&name.as_str())?;
|
||||||
|
}
|
||||||
|
for (_, name) in self.files.iter() {
|
||||||
|
add(&name.as_str())?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -172,8 +172,8 @@ pub enum PhrasesMode {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct FileBrowser {
|
pub struct FileBrowser {
|
||||||
pub cwd: PathBuf,
|
pub cwd: PathBuf,
|
||||||
pub dirs: Vec<PathBuf>,
|
pub dirs: Vec<(OsString, String)>,
|
||||||
pub files: Vec<PathBuf>,
|
pub files: Vec<(OsString, String)>,
|
||||||
pub filter: String,
|
pub filter: String,
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
pub scroll: usize,
|
pub scroll: usize,
|
||||||
|
|
@ -183,10 +183,23 @@ pub struct FileBrowser {
|
||||||
impl FileBrowser {
|
impl FileBrowser {
|
||||||
pub fn new (cwd: Option<PathBuf>) -> Usually<Self> {
|
pub fn new (cwd: Option<PathBuf>) -> Usually<Self> {
|
||||||
let cwd = if let Some(cwd) = cwd { cwd } else { std::env::current_dir()? };
|
let cwd = if let Some(cwd) = cwd { cwd } else { std::env::current_dir()? };
|
||||||
|
let mut dirs = vec![];
|
||||||
|
let mut files = vec![];
|
||||||
|
for entry in std::fs::read_dir(&cwd)? {
|
||||||
|
let entry = entry?;
|
||||||
|
let name = entry.file_name();
|
||||||
|
let decoded = name.clone().into_string().unwrap_or_else(|_|"<unreadable>".to_string());
|
||||||
|
let meta = entry.metadata()?;
|
||||||
|
if meta.is_dir() {
|
||||||
|
dirs.push((name, format!("📁 {decoded}")));
|
||||||
|
} else if meta.is_file() {
|
||||||
|
files.push((name, format!("📄 {decoded}")));
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
cwd,
|
cwd,
|
||||||
dirs: vec![/*todo*/],
|
dirs,
|
||||||
files: vec![/*todo*/],
|
files,
|
||||||
filter: "".to_string(),
|
filter: "".to_string(),
|
||||||
index: 0,
|
index: 0,
|
||||||
scroll: 0,
|
scroll: 0,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue