From 8f0b24b264c1d0f621ca7acfc041cfa64c073896 Mon Sep 17 00:00:00 2001 From: Derek Briggs Date: Thu, 20 Jul 2023 12:01:41 -0600 Subject: [PATCH] Add moar icons --- assets/icons/file_icons/chevron_down.svg | 3 +++ assets/icons/file_icons/chevron_left.svg | 3 +++ assets/icons/file_icons/chevron_right.svg | 3 +++ assets/icons/file_icons/chevron_up.svg | 3 +++ assets/icons/file_icons/file_types.json | 16 ++++++++---- assets/icons/file_icons/folder.svg | 2 +- .../{folder-open.svg => folder_open.svg} | 2 +- crates/project_panel/src/file_associations.rs | 25 ++++++++++++++++--- 8 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 assets/icons/file_icons/chevron_down.svg create mode 100644 assets/icons/file_icons/chevron_left.svg create mode 100644 assets/icons/file_icons/chevron_right.svg create mode 100644 assets/icons/file_icons/chevron_up.svg rename assets/icons/file_icons/{folder-open.svg => folder_open.svg} (89%) diff --git a/assets/icons/file_icons/chevron_down.svg b/assets/icons/file_icons/chevron_down.svg new file mode 100644 index 0000000000..b971555cfa --- /dev/null +++ b/assets/icons/file_icons/chevron_down.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/icons/file_icons/chevron_left.svg b/assets/icons/file_icons/chevron_left.svg new file mode 100644 index 0000000000..8e61beed5d --- /dev/null +++ b/assets/icons/file_icons/chevron_left.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/icons/file_icons/chevron_right.svg b/assets/icons/file_icons/chevron_right.svg new file mode 100644 index 0000000000..fcd9d83fc2 --- /dev/null +++ b/assets/icons/file_icons/chevron_right.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/icons/file_icons/chevron_up.svg b/assets/icons/file_icons/chevron_up.svg new file mode 100644 index 0000000000..171cdd61c0 --- /dev/null +++ b/assets/icons/file_icons/chevron_up.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/icons/file_icons/file_types.json b/assets/icons/file_icons/file_types.json index edc398a295..b53d263063 100644 --- a/assets/icons/file_icons/file_types.json +++ b/assets/icons/file_icons/file_types.json @@ -94,20 +94,26 @@ "code": { "icon": "icons/file_icons/code.svg" }, + "collapsed_chevron": { + "icon": "icons/file_icons/chevron_right.svg" + }, + "collapsed_folder": { + "icon": "icons/file_icons/folder.svg" + }, "default": { "icon": "icons/file_icons/file.svg" }, - "directory": { - "icon": "icons/file_icons/folder.svg" - }, "document": { "icon": "icons/file_icons/book.svg" }, "eslint": { "icon": "icons/file_icons/eslint.svg" }, - "expanded_directory": { - "icon": "icons/file_icons/folder-open.svg" + "expanded_chevron": { + "icon": "icons/file_icons/chevron_down.svg" + }, + "expanded_folder": { + "icon": "icons/file_icons/folder_open.svg" }, "image": { "icon": "icons/file_icons/image.svg" diff --git a/assets/icons/file_icons/folder.svg b/assets/icons/file_icons/folder.svg index 4ef944a69c..d890160100 100644 --- a/assets/icons/file_icons/folder.svg +++ b/assets/icons/file_icons/folder.svg @@ -1,5 +1,5 @@ - + diff --git a/assets/icons/file_icons/folder-open.svg b/assets/icons/file_icons/folder_open.svg similarity index 89% rename from assets/icons/file_icons/folder-open.svg rename to assets/icons/file_icons/folder_open.svg index 405d0b8308..bf64f6ee39 100644 --- a/assets/icons/file_icons/folder-open.svg +++ b/assets/icons/file_icons/folder_open.svg @@ -1,5 +1,5 @@ - + diff --git a/crates/project_panel/src/file_associations.rs b/crates/project_panel/src/file_associations.rs index 6e2e373d76..2694fa1697 100644 --- a/crates/project_panel/src/file_associations.rs +++ b/crates/project_panel/src/file_associations.rs @@ -17,8 +17,10 @@ pub struct FileAssociations { types: HashMap, } -const DIRECTORY_TYPE: &'static str = "directory"; -const EXPANDED_DIRECTORY_TYPE: &'static str = "expanded_directory"; +const COLLAPSED_DIRECTORY_TYPE: &'static str = "collapsed_folder"; +const EXPANDED_DIRECTORY_TYPE: &'static str = "expanded_folder"; +const COLLAPSED_CHEVRON_TYPE: &'static str = "collapsed_chevron"; +const EXPANDED_CHEVRON_TYPE: &'static str = "expanded_chevron"; pub const FILE_TYPES_ASSET: &'static str = "icons/file_icons/file_types.json"; pub fn init(assets: impl AssetSource, cx: &mut AppContext) { @@ -72,7 +74,24 @@ impl FileAssociations { let key = if expanded { EXPANDED_DIRECTORY_TYPE } else { - DIRECTORY_TYPE + COLLAPSED_DIRECTORY_TYPE + }; + + this.types + .get(key) + .map(|type_config| type_config.icon.clone()) + }) + .unwrap_or_else(|| Arc::from("".to_string())) + } + + pub fn get_chevron_icon(expanded: bool, cx: &AppContext) -> Arc { + iife!({ + let this = cx.has_global::().then(|| cx.global::())?; + + let key = if expanded { + EXPANDED_CHEVRON_TYPE + } else { + COLLAPSED_CHEVRON_TYPE }; this.types