diff --git a/src/file_browser.rs b/src/file_browser.rs index cdc38b4..65aca45 100644 --- a/src/file_browser.rs +++ b/src/file_browser.rs @@ -137,6 +137,10 @@ impl FileBrowser { pub fn go_back(&mut self) -> HResult<()> { self.columns.pop_widget(); + if let Ok(new_cwd) = self.cwd.grand_parent_as_file() { + self.cwd = new_cwd; + } + self.refresh(); Ok(()) } @@ -156,12 +160,12 @@ impl FileBrowser { pub fn fix_left(&mut self) -> HResult<()> { if self.left_widget().is_err() { - let file = self.selected_file()?.clone(); - if let Some(grand_parent) = file.grand_parent() { + let cwd = self.selected_file()?.clone(); + if let Ok(grand_parent) = cwd.grand_parent_as_file() { let (coords, _, _) = self.columns.calculate_coordinates(); let left_view = WillBeWidget::new(Box::new(move |_| { let mut view - = ListView::new(Files::new_from_path(&grand_parent)?); + = ListView::new(Files::new_from_path(&grand_parent.path)?); view.set_coordinates(&coords); Ok(view) })); diff --git a/src/files.rs b/src/files.rs index c7896fb..f546a00 100644 --- a/src/files.rs +++ b/src/files.rs @@ -271,7 +271,7 @@ impl File { } } - pub fn new_from_path(path: &Path) -> Result { + pub fn new_from_path(path: &Path) -> HResult { let pathbuf = path.to_path_buf(); let name = path .file_name() @@ -353,6 +353,11 @@ impl File { Some(self.path.parent()?.parent()?.to_path_buf()) } + pub fn grand_parent_as_file(&self) -> HResult { + let pathbuf = self.grand_parent()?; + File::new_from_path(&pathbuf) + } + pub fn is_dir(&self) -> bool { self.kind == Kind::Directory }