diff --git a/assets/settings/default.json b/assets/settings/default.json index 5cf5f59f76..e1f2d93270 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -99,6 +99,8 @@ "project_panel": { // Whether to show the git status in the project panel. "git_status": true, + // Whether to show file icons in the project panel. + "file_icons": true, // Where to dock project panel. Can be 'left' or 'right'. "dock": "left", // Default width of the project panel. diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index f416422fa2..60f14d9fa7 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -755,19 +755,13 @@ impl LanguageRegistry { self.get_or_load_language(|config| UniCase::new(config.name.as_ref()) == name) } - pub fn icon_for_suffix( - self: &Arc, - suffix: &str, - ) -> Option> { + pub fn icon_for_suffix(self: &Arc, suffix: &str) -> Option> { let state = self.state.read(); - state.available_languages + state + .available_languages .iter() - .find(|langauge| { - langauge.config.path_suffixes.iter().any(|s| s == suffix) - }) - .map(|language| { - language.config.icon_path.clone() - }) + .find(|langauge| langauge.config.path_suffixes.iter().any(|s| s == suffix)) + .map(|language| language.config.icon_path.clone()) .flatten() } diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 1158f2fa56..80c098baa6 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -2475,8 +2475,7 @@ impl Project { } pub fn icon_for_path(&self, path: &Path) -> Option> { - self.languages - .icon_for_suffix(path.extension()?.to_str()?) + self.languages.icon_for_suffix(path.extension()?.to_str()?) } fn detect_language_for_buffer( diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index ce86b1e768..06c6c1540c 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -1168,7 +1168,10 @@ impl ProjectPanel { } let end_ix = range.end.min(ix + visible_worktree_entries.len()); - let git_status_setting = settings::get::(cx).git_status; + let (git_status_setting, show_file_icons) = { + let settings = settings::get::(cx); + (settings.git_status, settings.file_icons) + }; if let Some(worktree) = self.project.read(cx).worktree_for_id(*worktree_id, cx) { let snapshot = worktree.read(cx).snapshot(); let root_name = OsStr::new(snapshot.root_name()); @@ -1182,14 +1185,16 @@ impl ProjectPanel { for entry in visible_worktree_entries[entry_range].iter() { let status = git_status_setting.then(|| entry.git_status).flatten(); - let icon = match entry.kind { - EntryKind::File(_) => self - .project - .read(cx) - .icon_for_path(&entry.path) - .or_else(|| Some(TEXT_FILE_ASSET.into())), - _ => None, - }; + let icon = show_file_icons + .then(|| match entry.kind { + EntryKind::File(_) => self + .project + .read(cx) + .icon_for_path(&entry.path) + .or_else(|| Some(TEXT_FILE_ASSET.into())), + _ => None, + }) + .flatten(); let mut details = EntryDetails { filename: entry @@ -1283,14 +1288,20 @@ impl ProjectPanel { Svg::new(icon.to_string()) .with_color(style.icon_color) .constrained() + .with_max_width(style.file_icon_size) + .with_max_height(style.file_icon_size) + .aligned() + .constrained() + .with_width(style.file_icon_size) } else { - Empty::new().constrained() + Empty::new() + .constrained() + .with_max_width(style.directory_icon_size) + .with_max_height(style.directory_icon_size) + .aligned() + .constrained() + .with_width(style.directory_icon_size) } - .with_max_width(style.file_icon_size) - .with_max_height(style.file_icon_size) - .aligned() - .constrained() - .with_width(style.file_icon_size) }) .with_child(if show_editor && editor.is_some() { ChildView::new(editor.as_ref().unwrap(), cx) diff --git a/crates/project_panel/src/project_panel_settings.rs b/crates/project_panel/src/project_panel_settings.rs index 1d6c590710..f0d60d7f4f 100644 --- a/crates/project_panel/src/project_panel_settings.rs +++ b/crates/project_panel/src/project_panel_settings.rs @@ -13,6 +13,7 @@ pub enum ProjectPanelDockPosition { #[derive(Deserialize, Debug)] pub struct ProjectPanelSettings { pub git_status: bool, + pub file_icons: bool, pub dock: ProjectPanelDockPosition, pub default_width: f32, } @@ -20,6 +21,7 @@ pub struct ProjectPanelSettings { #[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)] pub struct ProjectPanelSettingsContent { pub git_status: Option, + pub file_icons: Option, pub dock: Option, pub default_width: Option, }