mirror of https://github.com/bobwen-dev/hunter
don't rely on widget for cwd
This commit is contained in:
parent
4c1e75c058
commit
b9a873094a
|
@ -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)
|
||||
}));
|
||||
|
|
|
@ -271,7 +271,7 @@ impl File {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new_from_path(path: &Path) -> Result<File, Error> {
|
||||
pub fn new_from_path(path: &Path) -> HResult<File> {
|
||||
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<File> {
|
||||
let pathbuf = self.grand_parent()?;
|
||||
File::new_from_path(&pathbuf)
|
||||
}
|
||||
|
||||
pub fn is_dir(&self) -> bool {
|
||||
self.kind == Kind::Directory
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue