Skip to content

Commit

Permalink
Fix file icon showing in custom tree views
Browse files Browse the repository at this point in the history
Fixes #146479
  • Loading branch information
alexr00 committed Apr 4, 2022
1 parent 1f2fdee commit a9c3c0e
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/vs/workbench/browser/parts/views/treeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import { ILogService } from 'vs/platform/log/common/log';
import { Mimes } from 'vs/base/common/mime';
import { IActivityService, NumberBadge } from 'vs/workbench/services/activity/common/activity';
import { IDataTransfer } from 'vs/workbench/common/dnd';
import { ThemeSettings } from 'vs/workbench/services/themes/common/workbenchThemeService';

export class TreeViewPane extends ViewPane {

Expand Down Expand Up @@ -1018,13 +1019,14 @@ class TreeRenderer extends Disposable implements ITreeRenderer<ITreeItem, FuzzyS
templateData.actionBar.clear();
templateData.icon.style.color = '';

if (resource || this.isFileKindThemeIcon(node.themeIcon)) {

if (resource) {
const fileDecorations = this.configurationService.getValue<{ colors: boolean; badges: boolean }>('explorer.decorations');
const labelResource = resource ? resource : URI.parse('missing:_icon_resource');
templateData.resourceLabel.setResource({ name: label, description, resource: labelResource }, {
fileKind: this.getFileKind(node),
title,
hideIcon: !!iconUrl || !!node.themeIcon,
hideIcon: !!iconUrl || this.shouldShowThemeIcon(!!resource, node.themeIcon),
fileDecorations,
extraClasses: ['custom-view-tree-node-item-resourceLabel'],
matches: matches ? matches : createMatches(element.filterData),
Expand All @@ -1047,7 +1049,7 @@ class TreeRenderer extends Disposable implements ITreeRenderer<ITreeItem, FuzzyS
let iconClass: string | undefined;
// If there is a resource for this tree item then we should respect the file icon theme's choice about
// whether to show a folder icon.
if (node.themeIcon && (!resource || !this.isFolderThemeIcon(node.themeIcon) || this.themeService.getFileIconTheme().hasFolderIcons)) {
if (this.shouldShowThemeIcon(!!resource, node.themeIcon)) {
iconClass = ThemeIcon.asClassName(node.themeIcon);
if (node.themeIcon.color) {
templateData.icon.style.color = this.themeService.getColorTheme().getColor(node.themeIcon.color.id)?.toString() ?? '';
Expand Down Expand Up @@ -1080,6 +1082,27 @@ class TreeRenderer extends Disposable implements ITreeRenderer<ITreeItem, FuzzyS
container.parentElement!.classList.toggle('align-icon-with-twisty', this.aligner.alignIconWithTwisty(treeItem));
}

private shouldShowThemeIcon(hasResource: boolean, icon: ThemeIcon | undefined): icon is ThemeIcon {
if (!icon) {
return false;
}

if (hasResource && (this.isFileKindThemeIcon(icon) || !this.shouldShowFileIcons())) {
return false;
} else if (hasResource && (this.isFolderThemeIcon(icon) || !this.shouldShowFolderIcons())) {
return false;
}
return true;
}

private shouldShowFileIcons(): boolean {
return this.configurationService.getValue(ThemeSettings.FILE_ICON_THEME);
}

private shouldShowFolderIcons(): boolean {
return this.themeService.getFileIconTheme().hasFolderIcons && this.shouldShowFileIcons();
}

private isFolderThemeIcon(icon: ThemeIcon | undefined): boolean {
return icon?.id === FolderThemeIcon.id;
}
Expand Down

0 comments on commit a9c3c0e

Please sign in to comment.