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 push(&mut self, file: &Path) {
19 if !self.content.contains(&file.to_path_buf()) {
20 self.content.push(file.to_owned());
21 self.index = self.len() - 1;
22 }
23 }
25
26 pub fn drop_queue(&mut self) {
29 if self.is_empty() {
30 return;
31 }
32 let final_length = self.len() - self.index + 1;
33 self.content.truncate(final_length);
34 if self.is_empty() {
35 self.index = 0;
36 } else {
37 self.index = self.len() - 1;
38 }
39 }
40
41 #[must_use]
46 pub fn is_this_the_last(&self, path: &Path) -> bool {
47 if self.is_empty() {
48 return false;
49 }
50 self.content[self.len() - 1] == path
51 }
52}
53
54impl_selectable!(History);
55impl_content!(History, PathBuf);
56
57impl DrawMenu<PathBuf> for History {}