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 std::{path::Path, str};
|
||||||
|
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
|
@ -5,7 +6,7 @@ use collections::HashMap;
|
||||||
use gpui::{AppContext, AssetSource, Global, SharedString};
|
use gpui::{AppContext, AssetSource, Global, SharedString};
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use theme::ThemeSettings;
|
use theme::{IconTheme, ThemeRegistry, ThemeSettings};
|
||||||
use util::{maybe, paths::PathExt};
|
use util::{maybe, paths::PathExt};
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
|
@ -58,33 +59,51 @@ impl FileIcons {
|
||||||
.or_else(|| this.get_icon_for_type("default", cx))
|
.or_else(|| this.get_icon_for_type("default", cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_icon_for_type(&self, typ: &str, cx: &AppContext) -> Option<SharedString> {
|
fn default_icon_theme(cx: &AppContext) -> Option<Arc<IconTheme>> {
|
||||||
let theme_settings = ThemeSettings::get_global(cx);
|
let theme_registry = ThemeRegistry::global(cx);
|
||||||
|
theme_registry.default_icon_theme().ok()
|
||||||
|
}
|
||||||
|
|
||||||
theme_settings
|
pub fn get_icon_for_type(&self, typ: &str, cx: &AppContext) -> Option<SharedString> {
|
||||||
.active_icon_theme
|
fn get_icon_for_type(icon_theme: &Arc<IconTheme>, typ: &str) -> Option<SharedString> {
|
||||||
.file_icons
|
icon_theme
|
||||||
.get(typ)
|
.file_icons
|
||||||
.map(|icon_definition| icon_definition.path.clone())
|
.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> {
|
pub fn get_folder_icon(expanded: bool, cx: &AppContext) -> Option<SharedString> {
|
||||||
let icon_theme = &ThemeSettings::get_global(cx).active_icon_theme;
|
fn get_folder_icon(icon_theme: &Arc<IconTheme>, expanded: bool) -> Option<SharedString> {
|
||||||
|
if expanded {
|
||||||
if expanded {
|
icon_theme.directory_icons.expanded.clone()
|
||||||
icon_theme.directory_icons.expanded.clone()
|
} else {
|
||||||
} else {
|
icon_theme.directory_icons.collapsed.clone()
|
||||||
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> {
|
pub fn get_chevron_icon(expanded: bool, cx: &AppContext) -> Option<SharedString> {
|
||||||
let icon_theme = &ThemeSettings::get_global(cx).active_icon_theme;
|
fn get_chevron_icon(icon_theme: &Arc<IconTheme>, expanded: bool) -> Option<SharedString> {
|
||||||
|
if expanded {
|
||||||
if expanded {
|
icon_theme.chevron_icons.expanded.clone()
|
||||||
icon_theme.chevron_icons.expanded.clone()
|
} else {
|
||||||
} else {
|
icon_theme.chevron_icons.collapsed.clone()
|
||||||
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))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ use util::ResultExt;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
read_user_theme, refine_theme_family, Appearance, IconTheme, Theme, ThemeFamily,
|
read_user_theme, refine_theme_family, Appearance, IconTheme, Theme, ThemeFamily,
|
||||||
ThemeFamilyContent,
|
ThemeFamilyContent, DEFAULT_ICON_THEME_ID,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The metadata for a theme.
|
/// The metadata for a theme.
|
||||||
|
@ -206,6 +206,11 @@ impl ThemeRegistry {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the default icon theme.
|
||||||
|
pub fn default_icon_theme(&self) -> Result<Arc<IconTheme>> {
|
||||||
|
self.get_icon_theme(DEFAULT_ICON_THEME_ID)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the icon theme with the specified name.
|
/// Returns the icon theme with the specified name.
|
||||||
pub fn get_icon_theme(&self, name: &str) -> Result<Arc<IconTheme>> {
|
pub fn get_icon_theme(&self, name: &str) -> Result<Arc<IconTheme>> {
|
||||||
self.state
|
self.state
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue