
This PR adds the initial concept of an `IconTheme` and refactors `FileIcons` to use it to resolve the icons. The `IconTheme` will ultimately be used to allow users to select a different set of icons to use. Currently, however, this is just laying the foundation for that work. The association between file types and icons is now handled by the icon theme when we resolve file icons. This mapping has been moved out of `file_types.json` and into `icon_theme.rs`. Release Notes: - N/A
127 lines
4.6 KiB
Rust
127 lines
4.6 KiB
Rust
use collections::HashMap;
|
|
use gpui::SharedString;
|
|
|
|
use crate::Appearance;
|
|
|
|
/// A family of icon themes.
|
|
pub struct IconThemeFamily {
|
|
/// The unique ID for the icon theme family.
|
|
pub id: String,
|
|
/// The name of the icon theme family.
|
|
pub name: SharedString,
|
|
/// The author of the icon theme family.
|
|
pub author: SharedString,
|
|
/// The list of icon themes in the family.
|
|
pub themes: Vec<IconTheme>,
|
|
}
|
|
|
|
/// An icon theme.
|
|
#[derive(Debug, PartialEq)]
|
|
pub struct IconTheme {
|
|
/// The unique ID for the icon theme.
|
|
pub id: String,
|
|
/// The name of the icon theme.
|
|
pub name: SharedString,
|
|
/// The appearance of the icon theme (e.g., light or dark).
|
|
pub appearance: Appearance,
|
|
/// The mapping of file types to icon definitions.
|
|
pub file_icons: HashMap<String, IconDefinition>,
|
|
}
|
|
|
|
/// An icon definition.
|
|
#[derive(Debug, PartialEq)]
|
|
pub struct IconDefinition {
|
|
/// The path to the icon file.
|
|
pub path: SharedString,
|
|
}
|
|
|
|
/// A mapping of a file type identifier to its corresponding icon.
|
|
const FILE_ICONS: &[(&str, &str)] = &[
|
|
("astro", "icons/file_icons/astro.svg"),
|
|
("audio", "icons/file_icons/audio.svg"),
|
|
("bun", "icons/file_icons/bun.svg"),
|
|
("c", "icons/file_icons/c.svg"),
|
|
("code", "icons/file_icons/code.svg"),
|
|
("coffeescript", "icons/file_icons/coffeescript.svg"),
|
|
("collapsed_chevron", "icons/file_icons/chevron_right.svg"),
|
|
("collapsed_folder", "icons/file_icons/folder.svg"),
|
|
("cpp", "icons/file_icons/cpp.svg"),
|
|
("css", "icons/file_icons/css.svg"),
|
|
("dart", "icons/file_icons/dart.svg"),
|
|
("default", "icons/file_icons/file.svg"),
|
|
("diff", "icons/file_icons/diff.svg"),
|
|
("docker", "icons/file_icons/docker.svg"),
|
|
("document", "icons/file_icons/book.svg"),
|
|
("elixir", "icons/file_icons/elixir.svg"),
|
|
("elm", "icons/file_icons/elm.svg"),
|
|
("erlang", "icons/file_icons/erlang.svg"),
|
|
("eslint", "icons/file_icons/eslint.svg"),
|
|
("expanded_chevron", "icons/file_icons/chevron_down.svg"),
|
|
("expanded_folder", "icons/file_icons/folder_open.svg"),
|
|
("font", "icons/file_icons/font.svg"),
|
|
("fsharp", "icons/file_icons/fsharp.svg"),
|
|
("gleam", "icons/file_icons/gleam.svg"),
|
|
("go", "icons/file_icons/go.svg"),
|
|
("graphql", "icons/file_icons/graphql.svg"),
|
|
("haskell", "icons/file_icons/haskell.svg"),
|
|
("hcl", "icons/file_icons/hcl.svg"),
|
|
("heroku", "icons/file_icons/heroku.svg"),
|
|
("image", "icons/file_icons/image.svg"),
|
|
("java", "icons/file_icons/java.svg"),
|
|
("javascript", "icons/file_icons/javascript.svg"),
|
|
("julia", "icons/file_icons/julia.svg"),
|
|
("kotlin", "icons/file_icons/kotlin.svg"),
|
|
("lock", "icons/file_icons/lock.svg"),
|
|
("log", "icons/file_icons/info.svg"),
|
|
("lua", "icons/file_icons/lua.svg"),
|
|
("metal", "icons/file_icons/metal.svg"),
|
|
("nim", "icons/file_icons/nim.svg"),
|
|
("nix", "icons/file_icons/nix.svg"),
|
|
("ocaml", "icons/file_icons/ocaml.svg"),
|
|
("phoenix", "icons/file_icons/phoenix.svg"),
|
|
("php", "icons/file_icons/php.svg"),
|
|
("prettier", "icons/file_icons/prettier.svg"),
|
|
("prisma", "icons/file_icons/prisma.svg"),
|
|
("python", "icons/file_icons/python.svg"),
|
|
("r", "icons/file_icons/r.svg"),
|
|
("react", "icons/file_icons/react.svg"),
|
|
("roc", "icons/file_icons/roc.svg"),
|
|
("ruby", "icons/file_icons/ruby.svg"),
|
|
("rust", "icons/file_icons/rust.svg"),
|
|
("sass", "icons/file_icons/sass.svg"),
|
|
("scala", "icons/file_icons/scala.svg"),
|
|
("settings", "icons/file_icons/settings.svg"),
|
|
("storage", "icons/file_icons/database.svg"),
|
|
("swift", "icons/file_icons/swift.svg"),
|
|
("tcl", "icons/file_icons/tcl.svg"),
|
|
("template", "icons/file_icons/html.svg"),
|
|
("terminal", "icons/file_icons/terminal.svg"),
|
|
("terraform", "icons/file_icons/terraform.svg"),
|
|
("toml", "icons/file_icons/toml.svg"),
|
|
("typescript", "icons/file_icons/typescript.svg"),
|
|
("v", "icons/file_icons/v.svg"),
|
|
("vcs", "icons/file_icons/git.svg"),
|
|
("video", "icons/file_icons/video.svg"),
|
|
("vue", "icons/file_icons/vue.svg"),
|
|
("zig", "icons/file_icons/zig.svg"),
|
|
];
|
|
|
|
/// The ID of the default icon theme.
|
|
pub(crate) const DEFAULT_ICON_THEME_ID: &str = "zed";
|
|
|
|
/// Returns the default icon theme.
|
|
pub fn default_icon_theme() -> IconTheme {
|
|
IconTheme {
|
|
id: DEFAULT_ICON_THEME_ID.into(),
|
|
name: "Zed (Default)".into(),
|
|
appearance: Appearance::Dark,
|
|
file_icons: HashMap::from_iter(FILE_ICONS.into_iter().map(|(ty, path)| {
|
|
(
|
|
ty.to_string(),
|
|
IconDefinition {
|
|
path: (*path).into(),
|
|
},
|
|
)
|
|
})),
|
|
}
|
|
}
|