mirror of
https://github.com/bobwen-dev/hunter
synced 2025-04-12 00:55:41 +02:00
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<()> {
|
pub fn go_back(&mut self) -> HResult<()> {
|
||||||
self.columns.pop_widget();
|
self.columns.pop_widget();
|
||||||
|
|
||||||
|
if let Ok(new_cwd) = self.cwd.grand_parent_as_file() {
|
||||||
|
self.cwd = new_cwd;
|
||||||
|
}
|
||||||
|
|
||||||
self.refresh();
|
self.refresh();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -156,12 +160,12 @@ impl FileBrowser {
|
|||||||
|
|
||||||
pub fn fix_left(&mut self) -> HResult<()> {
|
pub fn fix_left(&mut self) -> HResult<()> {
|
||||||
if self.left_widget().is_err() {
|
if self.left_widget().is_err() {
|
||||||
let file = self.selected_file()?.clone();
|
let cwd = self.selected_file()?.clone();
|
||||||
if let Some(grand_parent) = file.grand_parent() {
|
if let Ok(grand_parent) = cwd.grand_parent_as_file() {
|
||||||
let (coords, _, _) = self.columns.calculate_coordinates();
|
let (coords, _, _) = self.columns.calculate_coordinates();
|
||||||
let left_view = WillBeWidget::new(Box::new(move |_| {
|
let left_view = WillBeWidget::new(Box::new(move |_| {
|
||||||
let mut view
|
let mut view
|
||||||
= ListView::new(Files::new_from_path(&grand_parent)?);
|
= ListView::new(Files::new_from_path(&grand_parent.path)?);
|
||||||
view.set_coordinates(&coords);
|
view.set_coordinates(&coords);
|
||||||
Ok(view)
|
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 pathbuf = path.to_path_buf();
|
||||||
let name = path
|
let name = path
|
||||||
.file_name()
|
.file_name()
|
||||||
@ -353,6 +353,11 @@ impl File {
|
|||||||
Some(self.path.parent()?.parent()?.to_path_buf())
|
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 {
|
pub fn is_dir(&self) -> bool {
|
||||||
self.kind == Kind::Directory
|
self.kind == Kind::Directory
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user