basalt_tui/explorer/
item.rs1use std::path::PathBuf;
2
3use basalt_core::obsidian::{Note, VaultEntry};
4
5#[derive(Debug, Clone, PartialEq)]
6pub enum Item {
7 File(Note),
8 Directory {
9 name: String,
10 path: PathBuf,
11 expanded: bool,
12 items: Vec<Item>,
13 },
14}
15
16impl Item {
17 pub(crate) fn name(&self) -> &str {
18 match self {
19 Self::Directory { name, .. } => name.as_str(),
20 Self::File(note) => note.name(),
21 }
22 }
23
24 pub(crate) fn is_dir(&self) -> bool {
25 matches!(self, Self::Directory { .. })
26 }
27}
28
29impl From<VaultEntry> for Item {
30 fn from(value: VaultEntry) -> Self {
31 match value {
32 VaultEntry::File(note) => Self::File(note),
33 VaultEntry::Directory {
34 name,
35 entries,
36 path,
37 } => Self::Directory {
38 name,
39 path,
40 expanded: false,
41 items: entries.into_iter().map(|item| item.into()).collect(),
42 },
43 }
44 }
45}