refactor: children count

This commit is contained in:
Jonatan Pettersson 2025-12-26 10:52:16 +01:00 • committed by Jacob Kauffmann
parent b1771b4c42
commit 79c34ff9ce

View file

@ -1776,6 +1776,15 @@ impl ItemMetadata {
_ => None, _ => None,
} }
} }
pub fn children_count(&self) -> Option<&usize> {
match &self {
ItemMetadata::Path { children_opt, .. } => children_opt.as_ref(),
#[cfg(feature = "gvfs")]
ItemMetadata::GvfsPath { children_opt, .. } => children_opt.as_ref(),
_ => None,
}
}
} }
#[derive(Debug)] #[derive(Debug)]
@ -2283,24 +2292,17 @@ impl Item {
} }
let mut file_metadata = None; let mut file_metadata = None;
let mut dir_children_count = None;
match &self.metadata { match &self.metadata {
ItemMetadata::Path { ItemMetadata::Path { metadata, .. } => {
metadata,
children_opt,
} => {
file_metadata = Some(metadata.clone()); file_metadata = Some(metadata.clone());
dir_children_count = *children_opt;
} }
#[cfg(feature = "gvfs")] #[cfg(feature = "gvfs")]
ItemMetadata::GvfsPath { children_opt, .. } => { ItemMetadata::GvfsPath { .. } => {
// grab the fs::metadata object for gvfs paths since this is run on-demand // grab the fs::metadata object for gvfs paths since this is run on-demand
if let Some(path) = self.path_opt() { if let Some(path) = self.path_opt() {
file_metadata = fs::metadata(path).ok(); file_metadata = fs::metadata(path).ok();
} }
dir_children_count = *children_opt;
} }
_ => { _ => {
//TODO: other metadata types //TODO: other metadata types
@ -2309,7 +2311,7 @@ impl Item {
if let Some(metadata) = file_metadata { if let Some(metadata) = file_metadata {
if metadata.is_dir() { if metadata.is_dir() {
if let Some(children) = dir_children_count { if let Some(children) = self.metadata.children_count() {
details = details.push(widget::text::body(fl!("items", items = children))); details = details.push(widget::text::body(fl!("items", items = children)));
} }
let size = match &self.dir_size { let size = match &self.dir_size {