mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Dirstack implementation for local
This commit is contained in:
@@ -131,7 +131,7 @@ impl FileExplorer {
|
|||||||
FileExplorer {
|
FileExplorer {
|
||||||
index: 0,
|
index: 0,
|
||||||
files: Vec::new(),
|
files: Vec::new(),
|
||||||
dirstack: VecDeque::with_capacity(16)
|
dirstack: VecDeque::with_capacity(16),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +153,6 @@ impl FileExplorer {
|
|||||||
pub fn popd(&mut self) -> Option<PathBuf> {
|
pub fn popd(&mut self) -> Option<PathBuf> {
|
||||||
self.dirstack.pop_front()
|
self.dirstack.pop_front()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ## FileExplorerTab
|
/// ## FileExplorerTab
|
||||||
@@ -658,35 +657,51 @@ impl FileTransferActivity {
|
|||||||
// Match selected file
|
// Match selected file
|
||||||
if let Some(entry) = self.local.files.get(self.local.index) {
|
if let Some(entry) = self.local.files.get(self.local.index) {
|
||||||
if let FsEntry::Directory(dir) = entry {
|
if let FsEntry::Directory(dir) = entry {
|
||||||
|
// Get current directory
|
||||||
|
let prev_dir: PathBuf = context.local.pwd();
|
||||||
// Change directory
|
// Change directory
|
||||||
if let Err(err) = context.local.change_wrkdir(dir.abs_path.clone())
|
match context.local.change_wrkdir(dir.abs_path.clone()) {
|
||||||
{
|
Ok(_) => self.local.pushd(prev_dir.as_path()), // Push prev_dir to stack
|
||||||
|
Err(err) => {
|
||||||
// Report err
|
// Report err
|
||||||
self.input_mode = InputMode::Popup(PopupType::Alert(
|
self.input_mode = InputMode::Popup(PopupType::Alert(
|
||||||
Color::Red,
|
Color::Red,
|
||||||
format!("Could not change working directory: {}", err),
|
format!("Could not change working directory: {}", err),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Update files
|
// Update files
|
||||||
self.local.files = context.local.list_dir();
|
self.local.files = context.local.list_dir();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Backspace => {
|
KeyCode::Backspace => {
|
||||||
// TODO: directory stack
|
// Go to previous directory
|
||||||
// Go previous directory
|
loop {
|
||||||
let wrkdir: PathBuf = context.local.pwd();
|
// Till a valid directory is found
|
||||||
if let Some(parent) = wrkdir.as_path().parent() {
|
match self.local.popd() {
|
||||||
// Change directory
|
Some(d) => {
|
||||||
if let Err(err) = context.local.change_wrkdir(PathBuf::from(parent)) {
|
match context.local.change_wrkdir(d) {
|
||||||
// Report err
|
Ok(_) => {
|
||||||
self.input_mode = InputMode::Popup(PopupType::Alert(
|
|
||||||
Color::Red,
|
|
||||||
format!("Could not change working directory: {}", err),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
// Update files
|
// Update files
|
||||||
self.local.files = context.local.list_dir();
|
self.local.files = context.local.list_dir();
|
||||||
|
// Break, directory has changed
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
// Report error
|
||||||
|
self.input_mode = InputMode::Popup(PopupType::Alert(
|
||||||
|
Color::Red,
|
||||||
|
format!(
|
||||||
|
"Could not change working directory: {}",
|
||||||
|
err
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => break, // Break if stack is empty
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Delete => {
|
KeyCode::Delete => {
|
||||||
|
|||||||
Reference in New Issue
Block a user