Implement add to sidebar, fixes #112

This commit is contained in:
Jeremy Soller 2024-05-09 12:48:33 -06:00
parent a61e587b1c
commit 99c378873a
No known key found for this signature in database
GPG key ID: D02FD439211AF56F
3 changed files with 46 additions and 5 deletions

View file

@ -48,6 +48,25 @@ pub enum Favorite {
}
impl Favorite {
pub fn from_path(path: PathBuf) -> Self {
// Ensure that special folders are handled properly
for favorite in &[
Self::Home,
Self::Documents,
Self::Downloads,
Self::Music,
Self::Pictures,
Self::Videos,
] {
if let Some(favorite_path) = favorite.path_opt() {
if &favorite_path == &path {
return favorite.clone();
}
}
}
Self::Path(path)
}
pub fn path_opt(&self) -> Option<PathBuf> {
match self {
Self::Home => dirs::home_dir(),