mirror of
https://github.com/danbulant/icon
synced 2026-07-06 11:30:35 +00:00
standalone_icon to quickly find a standalone icon
This commit is contained in:
parent
b989389b63
commit
ee9af9c9aa
1 changed files with 16 additions and 22 deletions
|
|
@ -112,9 +112,19 @@ impl IconLocations {
|
||||||
|
|
||||||
ThemeDescriptor::new_from_folders(
|
ThemeDescriptor::new_from_folders(
|
||||||
internal_name.to_string_lossy().into_owned(),
|
internal_name.to_string_lossy().into_owned(),
|
||||||
theme.clone()
|
theme.clone(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn standalone_icon<S>(&self, icon_name: S) -> Option<&IconFile>
|
||||||
|
where
|
||||||
|
S: AsRef<OsStr>,
|
||||||
|
{
|
||||||
|
let name = icon_name.as_ref();
|
||||||
|
|
||||||
|
self.standalone_icons.iter()
|
||||||
|
.find(|icon| icon.path.file_stem() == Some(name))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Anything that turns into an iterator of things that can become paths, can be turned into a `SearchDirectories`.
|
/// Anything that turns into an iterator of things that can become paths, can be turned into a `SearchDirectories`.
|
||||||
|
|
@ -158,35 +168,19 @@ impl Default for SearchDirectories {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::search_dir::SearchDirectories;
|
use crate::search_dir::SearchDirectories;
|
||||||
use crate::IconLocations;
|
|
||||||
|
|
||||||
// these tests assume certain applications are installed on the system they are ran on.
|
// these tests assume certain applications are installed on the system they are ran on.
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_find_htop_icon_outside_icontheme() {
|
fn test_find_standard_theme_and_icon() {
|
||||||
let dirs = SearchDirectories::default();
|
|
||||||
|
|
||||||
let IconLocations {
|
|
||||||
standalone_icons,
|
|
||||||
themes_directories,
|
|
||||||
} = dirs.find_icon_locations();
|
|
||||||
|
|
||||||
println!("{:?}", themes_directories);
|
|
||||||
|
|
||||||
assert!(
|
|
||||||
standalone_icons
|
|
||||||
.iter()
|
|
||||||
.any(|i| i.path.file_name().and_then(|s| s.to_str()) == Some("htop.png"))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_find_adwaita() {
|
|
||||||
let dirs = SearchDirectories::default();
|
let dirs = SearchDirectories::default();
|
||||||
|
|
||||||
let locations = dirs.find_icon_locations();
|
let locations = dirs.find_icon_locations();
|
||||||
let descriptor = locations.theme("Adwaita").unwrap();
|
|
||||||
|
|
||||||
|
let descriptor = locations.theme("Adwaita").unwrap();
|
||||||
assert_eq!(descriptor.index.name, "Adwaita");
|
assert_eq!(descriptor.index.name, "Adwaita");
|
||||||
|
|
||||||
|
let icon = locations.standalone_icon("htop").unwrap();
|
||||||
|
assert_eq!(icon.path.file_name(), Some("htop.png".as_ref()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue