Skip to content

Commit 52e557f

Browse files
committed
API proposal for tree item icon color
Part of microsoft#103120
1 parent 12fc18b commit 52e557f

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/vs/vscode.proposed.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,11 @@ declare module 'vscode' {
972972
*/
973973
tooltip?: string | MarkdownString | /* for compilation */ any;
974974

975+
/**
976+
* When `iconPath` is a [ThemeColor](#ThemeColor) `iconColor` will be used to set the color of the icon.
977+
*/
978+
iconColor?: ThemeColor;
979+
975980
/**
976981
* @param label Label describing this item
977982
* @param collapsibleState [TreeItemCollapsibleState](#TreeItemCollapsibleState) of the tree item. Default is [TreeItemCollapsibleState.None](#TreeItemCollapsibleState.None)

src/vs/workbench/api/common/extHostTreeViews.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ExtHostTreeViewsShape, MainThreadTreeViewsShape } from './extHost.proto
1313
import { ITreeItem, TreeViewItemHandleArg, ITreeItemLabel, IRevealOptions } from 'vs/workbench/common/views';
1414
import { ExtHostCommands, CommandsConverter } from 'vs/workbench/api/common/extHostCommands';
1515
import { asPromise } from 'vs/base/common/async';
16-
import { TreeItemCollapsibleState, ThemeIcon, MarkdownString as MarkdownStringType } from 'vs/workbench/api/common/extHostTypes';
16+
import { TreeItemCollapsibleState, ThemeIcon, MarkdownString as MarkdownStringType, ThemeColor } from 'vs/workbench/api/common/extHostTypes';
1717
import { isUndefinedOrNull, isString } from 'vs/base/common/types';
1818
import { equals, coalesce } from 'vs/base/common/arrays';
1919
import { ILogService } from 'vs/platform/log/common/log';
@@ -550,6 +550,7 @@ class ExtHostTreeView<T> extends Disposable {
550550
icon,
551551
iconDark: this.getDarkIconPath(extensionTreeItem) || icon,
552552
themeIcon: extensionTreeItem.iconPath instanceof ThemeIcon ? { id: extensionTreeItem.iconPath.id } : undefined,
553+
iconColor: this.getIconColor(extensionTreeItem),
553554
collapsibleState: isUndefinedOrNull(extensionTreeItem.collapsibleState) ? TreeItemCollapsibleState.None : extensionTreeItem.collapsibleState,
554555
accessibilityInformation: extensionTreeItem.accessibilityInformation
555556
};
@@ -563,6 +564,11 @@ class ExtHostTreeView<T> extends Disposable {
563564
};
564565
}
565566

567+
private getIconColor(extensionTreeItem: vscode.TreeItem2): ThemeColor | undefined {
568+
checkProposedApiEnabled(this.extension);
569+
return (extensionTreeItem.iconPath instanceof ThemeIcon) ? <ThemeColor>extensionTreeItem.iconColor : undefined;
570+
}
571+
566572
private createHandle(element: T, { id, label, resourceUri }: vscode.TreeItem, parent: TreeNode | Root, returnFirst?: boolean): TreeItemHandle {
567573
if (id) {
568574
return `${ExtHostTreeView.ID_HANDLE_PREFIX}/${id}`;

src/vs/workbench/common/views.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { RawContextKey, ContextKeyExpression } from 'vs/platform/contextkey/comm
1010
import { localize } from 'vs/nls';
1111
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
1212
import { IDisposable, Disposable, toDisposable } from 'vs/base/common/lifecycle';
13-
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
13+
import { ThemeColor, ThemeIcon } from 'vs/platform/theme/common/themeService';
1414
import { getOrSet } from 'vs/base/common/map';
1515
import { Registry } from 'vs/platform/registry/common/platform';
1616
import { IKeybindings } from 'vs/platform/keybinding/common/keybindingsRegistry';
@@ -644,6 +644,8 @@ export interface ITreeItem {
644644

645645
themeIcon?: ThemeIcon;
646646

647+
iconColor?: ThemeColor;
648+
647649
resourceUri?: UriComponents;
648650

649651
tooltip?: string | IMarkdownString;
@@ -666,6 +668,7 @@ export class ResolvableTreeItem implements ITreeItem {
666668
icon?: UriComponents;
667669
iconDark?: UriComponents;
668670
themeIcon?: ThemeIcon;
671+
iconColor?: ThemeColor;
669672
resourceUri?: UriComponents;
670673
tooltip?: string | IMarkdownString;
671674
contextValue?: string;

src/vs/workbench/contrib/views/browser/treeView.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,9 @@ class TreeRenderer extends Disposable implements ITreeRenderer<ITreeItem, FuzzyS
792792
let iconClass: string | undefined;
793793
if (node.themeIcon && !this.isFileKindThemeIcon(node.themeIcon)) {
794794
iconClass = ThemeIcon.asClassName(node.themeIcon);
795+
if (node.iconColor) {
796+
templateData.icon.style.color = this.themeService.getColorTheme().getColor(node.iconColor.id)?.toString() ?? '';
797+
}
795798
}
796799
templateData.icon.className = iconClass ? `custom-view-tree-node-item-icon ${iconClass}` : '';
797800
templateData.icon.style.backgroundImage = '';

0 commit comments

Comments
 (0)