implement passable #[command]
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
i do not exist 2026-08-09 09:23:24 +03:00
parent 68236a7210
commit ae496987c8
7 changed files with 458 additions and 172 deletions

View file

@ -1,6 +1,17 @@
use crate::*;
def_command!(FileBrowserCommand: |sampler: Sampler|{
impl App {
/// Return reference to content browser if open.
///
/// ```
/// assert_eq!(tek::App::default().browser(), None);
/// ```
pub fn browser (&self) -> Option<&Browse> {
if let Dialog::Browse(_, ref b) = self.dialog { Some(b) } else { None }
}
}
def_command!(FileBrowserCommand: |_browse: Browse|{
//("begin" [] Some(Self::Begin))
//("cancel" [] Some(Self::Cancel))
//("confirm" [] Some(Self::Confirm))
@ -539,3 +550,20 @@ def_command!(CropCommand: |pool: Pool| {
Ok(None)
}
});
pub fn scan (dir: &PathBuf) -> Usually<(Vec<OsString>, Vec<OsString>)> {
let (mut subdirs, mut files) = std::fs::read_dir(dir)?
.fold((vec!["..".into()], vec![]), |(mut subdirs, mut files), entry|{
let entry = entry.expect("failed to read drectory entry");
let meta = entry.metadata().expect("failed to read entry metadata");
if meta.is_file() {
files.push(entry.file_name());
} else if meta.is_dir() {
subdirs.push(entry.file_name());
}
(subdirs, files)
});
subdirs.sort();
files.sort();
Ok((subdirs, files))
}