From 55cf883581debc8bf31d4ecb07966603af6ac226 Mon Sep 17 00:00:00 2001 From: ChristianVisintin Date: Sat, 28 Nov 2020 12:05:15 +0100 Subject: [PATCH] FileExplorer dirstack --- src/ui/activities/filetransfer_activity.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/ui/activities/filetransfer_activity.rs b/src/ui/activities/filetransfer_activity.rs index 334bde5..668277e 100644 --- a/src/ui/activities/filetransfer_activity.rs +++ b/src/ui/activities/filetransfer_activity.rs @@ -120,6 +120,7 @@ enum InputMode { struct FileExplorer { pub index: usize, pub files: Vec, + dirstack: VecDeque, } impl FileExplorer { @@ -130,8 +131,29 @@ impl FileExplorer { FileExplorer { index: 0, files: Vec::new(), + dirstack: VecDeque::with_capacity(16) } } + + /// ### pushd + /// + /// push directory to stack + pub fn pushd(&mut self, dir: &Path) { + // Check if stack overflows the size + if self.dirstack.len() + 1 > 16 { + self.dirstack.pop_back(); // Start cleaning events from back + } + // Eventually push front the new record + self.dirstack.push_front(PathBuf::from(dir)); + } + + /// ### popd + /// + /// Pop directory from the stack and return the directory + pub fn popd(&mut self) -> Option { + self.dirstack.pop_front() + } + } /// ## FileExplorerTab