Add support for named folder icons (#36351)

Adds a `named_directory_icons` field to the icon theme that can be used
to specify a collection of icons for collapsed and expanded folders
based on the folder name.

The `named_directory_icons` is a map from the folder name to a
`DirectoryIcons` object containing the paths to the expanded and
collapsed icons for that folder:

```json
{
  "named_directory_icons": {
    ".angular": {
      "collapsed": "./icons/folder_angular.svg",
      "expanded": "./icons/folder_angular_open.svg"
    }
  }
}

```

Closes #20295

Also referenced
https://github.com/zed-industries/zed/pull/23987#issuecomment-2638869213

Example using https://github.com/jacobtread/zed-vscode-icons/ which I've
ported over from a VSCode theme,

<img width="609" height="1307" alt="image"
src="https://github.com/user-attachments/assets/2d3c120a-b2f0-43fd-889d-641ad4bb9cee"
/>

Release Notes:

- Added support for icon themes to change the folder icon based on the
directory name.

---------

Co-authored-by: Marshall Bowers <git@maxdeviant.com>
This commit is contained in:
Jacob
2025-09-12 14:55:25 -04:00
committed by GitHub
co-authored by Marshall Bowers
parent 4c758bd0b7
commit 5f20b905a5
10 changed files with 79 additions and 17 deletions
+4 -1
View File
@@ -28,6 +28,8 @@ pub struct IconTheme {
pub appearance: Appearance,
/// The icons used for directories.
pub directory_icons: DirectoryIcons,
/// The icons used for named directories.
pub named_directory_icons: HashMap<String, DirectoryIcons>,
/// The icons used for chevrons.
pub chevron_icons: ChevronIcons,
/// The mapping of file stems to their associated icon keys.
@@ -39,7 +41,7 @@ pub struct IconTheme {
}
/// The icons used for directories.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct DirectoryIcons {
/// The path to the icon to use for a collapsed directory.
pub collapsed: Option<SharedString>,
@@ -392,6 +394,7 @@ static DEFAULT_ICON_THEME: LazyLock<Arc<IconTheme>> = LazyLock::new(|| {
collapsed: Some("icons/file_icons/folder.svg".into()),
expanded: Some("icons/file_icons/folder_open.svg".into()),
},
named_directory_icons: HashMap::default(),
chevron_icons: ChevronIcons {
collapsed: Some("icons/file_icons/chevron_right.svg".into()),
expanded: Some("icons/file_icons/chevron_down.svg".into()),
+2
View File
@@ -21,6 +21,8 @@ pub struct IconThemeContent {
#[serde(default)]
pub directory_icons: DirectoryIconsContent,
#[serde(default)]
pub named_directory_icons: HashMap<String, DirectoryIconsContent>,
#[serde(default)]
pub chevron_icons: ChevronIconsContent,
#[serde(default)]
pub file_stems: HashMap<String, String>,
+14
View File
@@ -298,6 +298,19 @@ impl ThemeRegistry {
let mut file_suffixes = default_icon_theme.file_suffixes.clone();
file_suffixes.extend(icon_theme.file_suffixes);
let mut named_directory_icons = default_icon_theme.named_directory_icons.clone();
named_directory_icons.extend(icon_theme.named_directory_icons.into_iter().map(
|(key, value)| {
(
key,
DirectoryIcons {
collapsed: value.collapsed.map(resolve_icon_path),
expanded: value.expanded.map(resolve_icon_path),
},
)
},
));
let icon_theme = IconTheme {
id: uuid::Uuid::new_v4().to_string(),
name: icon_theme.name.into(),
@@ -309,6 +322,7 @@ impl ThemeRegistry {
collapsed: icon_theme.directory_icons.collapsed.map(resolve_icon_path),
expanded: icon_theme.directory_icons.expanded.map(resolve_icon_path),
},
named_directory_icons,
chevron_icons: ChevronIcons {
collapsed: icon_theme.chevron_icons.collapsed.map(resolve_icon_path),
expanded: icon_theme.chevron_icons.expanded.map(resolve_icon_path),