file_icons: Fall back to the default icon theme for icons (#23196)
This PR updates the various `FileIcons` methods to fall back to the default icon theme if the active icon theme does not have the desired icon. Release Notes: - N/A
This commit is contained in:
parent
904b367882
commit
a8526d9143
2 changed files with 45 additions and 21 deletions
|
@ -1,3 +1,4 @@
|
|||
use std::sync::Arc;
|
||||
use std::{path::Path, str};
|
||||
|
||||
use collections::HashMap;
|
||||
|
@ -5,7 +6,7 @@ use collections::HashMap;
|
|||
use gpui::{AppContext, AssetSource, Global, SharedString};
|
||||
use serde_derive::Deserialize;
|
||||
use settings::Settings;
|
||||
use theme::ThemeSettings;
|
||||
use theme::{IconTheme, ThemeRegistry, ThemeSettings};
|
||||
use util::{maybe, paths::PathExt};
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
|
@ -58,33 +59,51 @@ impl FileIcons {
|
|||
.or_else(|| this.get_icon_for_type("default", cx))
|
||||
}
|
||||
|
||||
pub fn get_icon_for_type(&self, typ: &str, cx: &AppContext) -> Option<SharedString> {
|
||||
let theme_settings = ThemeSettings::get_global(cx);
|
||||
fn default_icon_theme(cx: &AppContext) -> Option<Arc<IconTheme>> {
|
||||
let theme_registry = ThemeRegistry::global(cx);
|
||||
theme_registry.default_icon_theme().ok()
|
||||
}
|
||||
|
||||
theme_settings
|
||||
.active_icon_theme
|
||||
.file_icons
|
||||
.get(typ)
|
||||
.map(|icon_definition| icon_definition.path.clone())
|
||||
pub fn get_icon_for_type(&self, typ: &str, cx: &AppContext) -> Option<SharedString> {
|
||||
fn get_icon_for_type(icon_theme: &Arc<IconTheme>, typ: &str) -> Option<SharedString> {
|
||||
icon_theme
|
||||
.file_icons
|
||||
.get(typ)
|
||||
.map(|icon_definition| icon_definition.path.clone())
|
||||
}
|
||||
|
||||
get_icon_for_type(&ThemeSettings::get_global(cx).active_icon_theme, typ).or_else(|| {
|
||||
Self::default_icon_theme(cx).and_then(|icon_theme| get_icon_for_type(&icon_theme, typ))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_folder_icon(expanded: bool, cx: &AppContext) -> Option<SharedString> {
|
||||
let icon_theme = &ThemeSettings::get_global(cx).active_icon_theme;
|
||||
|
||||
if expanded {
|
||||
icon_theme.directory_icons.expanded.clone()
|
||||
} else {
|
||||
icon_theme.directory_icons.collapsed.clone()
|
||||
fn get_folder_icon(icon_theme: &Arc<IconTheme>, expanded: bool) -> Option<SharedString> {
|
||||
if expanded {
|
||||
icon_theme.directory_icons.expanded.clone()
|
||||
} else {
|
||||
icon_theme.directory_icons.collapsed.clone()
|
||||
}
|
||||
}
|
||||
|
||||
get_folder_icon(&ThemeSettings::get_global(cx).active_icon_theme, expanded).or_else(|| {
|
||||
Self::default_icon_theme(cx)
|
||||
.and_then(|icon_theme| get_folder_icon(&icon_theme, expanded))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_chevron_icon(expanded: bool, cx: &AppContext) -> Option<SharedString> {
|
||||
let icon_theme = &ThemeSettings::get_global(cx).active_icon_theme;
|
||||
|
||||
if expanded {
|
||||
icon_theme.chevron_icons.expanded.clone()
|
||||
} else {
|
||||
icon_theme.chevron_icons.collapsed.clone()
|
||||
fn get_chevron_icon(icon_theme: &Arc<IconTheme>, expanded: bool) -> Option<SharedString> {
|
||||
if expanded {
|
||||
icon_theme.chevron_icons.expanded.clone()
|
||||
} else {
|
||||
icon_theme.chevron_icons.collapsed.clone()
|
||||
}
|
||||
}
|
||||
|
||||
get_chevron_icon(&ThemeSettings::get_global(cx).active_icon_theme, expanded).or_else(|| {
|
||||
Self::default_icon_theme(cx)
|
||||
.and_then(|icon_theme| get_chevron_icon(&icon_theme, expanded))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue