mirror of https://github.com/bobwen-dev/hunter
add flaceholder for empty dir
This commit is contained in:
parent
ea77d6f45a
commit
23e699234a
|
@ -38,32 +38,34 @@ impl FileBrowser {
|
|||
}
|
||||
|
||||
pub fn enter_dir(&mut self) {
|
||||
let fileview = self.columns.get_main_widget();
|
||||
let file = self.selected_file();
|
||||
|
||||
let path = fileview.selected_file().path();
|
||||
match Files::new_from_path(&path) {
|
||||
match file.read_dir() {
|
||||
Ok(files) => {
|
||||
std::env::set_current_dir(path).unwrap();
|
||||
std::env::set_current_dir(&file.path).unwrap();
|
||||
let view = ListView::new(files);
|
||||
self.columns.push_widget(view);
|
||||
self.update_preview();
|
||||
}
|
||||
Err(_) => {
|
||||
//self.show_status(&format!("Can't open this path: {}", err));
|
||||
},
|
||||
|
||||
Err(ref err) if err.description() == "placeholder".to_string() =>
|
||||
self.show_status("No! Can't open this!"),
|
||||
_ => {
|
||||
let status = std::process::Command::new("xdg-open")
|
||||
.args(dbg!(path.file_name()))
|
||||
.args(dbg!(file.path.file_name()))
|
||||
.status();
|
||||
|
||||
match status {
|
||||
Ok(status) => {
|
||||
self.show_status(&format!("\"{}\" exited with {}", "xdg-open", status))
|
||||
}
|
||||
Err(err) => {
|
||||
self.show_status(&format!("Can't run this \"{}\": {}", "xdg-open", err))
|
||||
}
|
||||
Ok(status) =>
|
||||
self.show_status(&format!("\"{}\" exited with {}",
|
||||
"xdg-open", status)),
|
||||
Err(err) =>
|
||||
self.show_status(&format!("Can't run this \"{}\": {}",
|
||||
"xdg-open", err))
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn go_back(&mut self) {
|
||||
|
@ -87,6 +89,7 @@ impl FileBrowser {
|
|||
}
|
||||
|
||||
pub fn update_preview(&mut self) {
|
||||
if self.columns.get_main_widget().content.len() == 0 { return }
|
||||
let file = self.columns.get_main_widget().selected_file().clone();
|
||||
let preview = &mut self.columns.preview;
|
||||
preview.set_file(&file);
|
||||
|
@ -103,6 +106,14 @@ impl FileBrowser {
|
|||
self.columns.get_main_widget().content.directory.clone()
|
||||
}
|
||||
|
||||
pub fn selected_file(&self) -> &File {
|
||||
self.main_column().selected_file()
|
||||
}
|
||||
|
||||
pub fn main_column(&self) -> &ListView<Files> {
|
||||
self.columns.get_main_widget()
|
||||
}
|
||||
|
||||
pub fn quit_with_dir(&self) {
|
||||
let cwd = self.cwd().path;
|
||||
|
||||
|
|
26
src/files.rs
26
src/files.rs
|
@ -77,6 +77,11 @@ impl Files {
|
|||
};
|
||||
|
||||
files.sort();
|
||||
|
||||
if files.files.len() == 0 {
|
||||
files.files = vec![File::new_placeholder(&path)?];
|
||||
}
|
||||
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
|
@ -133,6 +138,7 @@ pub enum Kind {
|
|||
File,
|
||||
Link,
|
||||
Pipe,
|
||||
Placeholder
|
||||
}
|
||||
|
||||
impl std::fmt::Display for SortBy {
|
||||
|
@ -203,6 +209,13 @@ impl File {
|
|||
Ok(File::new(&name, pathbuf, kind, size as usize, mtime, color))
|
||||
}
|
||||
|
||||
pub fn new_placeholder(path: &Path) -> Result<File, Box<Error>> {
|
||||
let mut file = File::new_from_path(path)?;
|
||||
file.name = "<empty>".to_string();
|
||||
file.kind = Kind::Placeholder;
|
||||
Ok(file)
|
||||
}
|
||||
|
||||
pub fn calculate_size(&self) -> (usize, String) {
|
||||
let mut unit = 0;
|
||||
let mut size = self.size.unwrap();
|
||||
|
@ -236,6 +249,19 @@ impl File {
|
|||
self.kind == Kind::Directory
|
||||
}
|
||||
|
||||
pub fn read_dir(&self) -> Result<Files, Box<Error>> {
|
||||
match self.kind {
|
||||
Kind::Placeholder => {
|
||||
let e: Box<Error>
|
||||
= From::from("placeholder".to_string());
|
||||
Err(e)
|
||||
},
|
||||
_ => Files::new_from_path(&self.path)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
pub fn path(&self) -> PathBuf {
|
||||
self.path.clone()
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ where
|
|||
let ysize = self.coordinates.ysize() as usize;
|
||||
let mut offset = 0;
|
||||
|
||||
while position + 1 > ysize + offset {
|
||||
while position >= ysize - 2 + offset {
|
||||
offset += 1
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue