1use std::path::{Path, PathBuf};
2
3use crate::io::DrawMenu;
4use crate::{impl_content, impl_selectable};
5
6#[derive(Default, Clone)]
10pub struct History {
11 pub content: Vec<PathBuf>,
12 pub index: usize,
13}
14
15impl History {
16 pub fn new(start_dir: &std::path::Path) -> Self {
18 Self {
19 content: vec![start_dir.to_path_buf()],
20 index: 0,
21 }
22 }
23
24 pub fn push(&mut self, file: &Path) {
27 if !self.content.contains(&file.to_path_buf()) {
28 self.content.push(file.to_owned());
29 self.index = self.len() - 1;
30 }
31 }
33
34 pub fn drop_queue(&mut self) {
37 if self.is_empty() {
38 return;
39 }
40 let final_length = self.len() - self.index + 1;
41 self.content.truncate(final_length);
42 if self.is_empty() {
43 self.index = 0;
44 } else {
45 self.index = self.len() - 1;
46 }
47 }
48
49 #[must_use]
54 pub fn is_this_the_last(&self, path: &Path) -> bool {
55 if self.is_empty() {
56 return false;
57 }
58 self.content[self.len() - 1] == path
59 }
60}
61
62impl_content!(History, PathBuf);
63
64impl DrawMenu<PathBuf> for History {}