1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
use std::{fs, path};
use crate::fs::JoshutoMetadata;
#[derive(Clone, Debug)]
pub struct JoshutoDirEntry {
name: String,
path: path::PathBuf,
pub metadata: JoshutoMetadata,
selected: bool,
marked: bool,
}
impl JoshutoDirEntry {
pub fn from(direntry: &fs::DirEntry) -> std::io::Result<Self> {
let name = match direntry.file_name().into_string() {
Ok(s) => s,
Err(_) => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
"Failed converting OsString to String",
));
}
};
let path = direntry.path();
let metadata = JoshutoMetadata::from(&path)?;
let dir_entry = JoshutoDirEntry {
name,
path,
metadata,
selected: false,
marked: false,
};
Ok(dir_entry)
}
pub fn file_name(&self) -> &str {
self.name.as_str()
}
pub fn file_path(&self) -> &path::PathBuf {
&self.path
}
/*
pub fn is_marked(&self) -> bool {
self.marked
}
pub fn set_marked(&mut self, marked: bool) {
self.marked = marked;
}
*/
pub fn is_selected(&self) -> bool {
self.selected
}
pub fn set_selected(&mut self, selected: bool) {
self.selected = selected;
}
}
|