From 10c7db89ee42b83420573f7b1f4c9655e6687d08 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Wed, 16 Sep 2020 11:20:52 +0200 Subject: [PATCH] Add color to ThemeIcon (#106491) Part of #103120 --- src/vs/platform/theme/common/themeService.ts | 3 ++- src/vs/vscode.proposed.d.ts | 9 +++++++++ src/vs/workbench/api/common/extHost.api.impl.ts | 1 + src/vs/workbench/api/common/extHostTreeViews.ts | 11 +++++++++-- src/vs/workbench/api/common/extHostTypes.ts | 8 +++++++- src/vs/workbench/contrib/views/browser/treeView.ts | 3 +++ 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/vs/platform/theme/common/themeService.ts b/src/vs/platform/theme/common/themeService.ts index e936a4eb05a..889bf4a9c92 100644 --- a/src/vs/platform/theme/common/themeService.ts +++ b/src/vs/platform/theme/common/themeService.ts @@ -25,10 +25,11 @@ export function themeColorFromId(id: ColorIdentifier) { // theme icon export interface ThemeIcon { readonly id: string; + readonly themeColor?: ThemeColor; } export namespace ThemeIcon { - export function isThemeIcon(obj: any): obj is ThemeIcon { + export function isThemeIcon(obj: any): obj is ThemeIcon | { id: string } { return obj && typeof obj === 'object' && typeof (obj).id === 'string'; } diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 10e23905a66..2f273359c4e 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -2266,6 +2266,15 @@ declare module 'vscode' { */ description?: string | undefined; } + //#endregion + //#region https://github.com/microsoft/vscode/issues/103120 @alexr00 + export class ThemeIcon2 extends ThemeIcon { + /** + * Returns a new `ThemeIcon` that will use the specified `ThemeColor` + * @param color The `ThemeColor` to use for the icon. + */ + with(color: ThemeColor): ThemeIcon2; + } //#endregion } diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 0d62aba5cec..eaadfc5f6e4 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -1123,6 +1123,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I TextEditorSelectionChangeKind: extHostTypes.TextEditorSelectionChangeKind, ThemeColor: extHostTypes.ThemeColor, ThemeIcon: extHostTypes.ThemeIcon, + ThemeIcon2: extHostTypes.ThemeIcon, TreeItem: extHostTypes.TreeItem, TreeItem2: extHostTypes.TreeItem, TreeItemCollapsibleState: extHostTypes.TreeItemCollapsibleState, diff --git a/src/vs/workbench/api/common/extHostTreeViews.ts b/src/vs/workbench/api/common/extHostTreeViews.ts index d2c41045553..bc284a4f34c 100644 --- a/src/vs/workbench/api/common/extHostTreeViews.ts +++ b/src/vs/workbench/api/common/extHostTreeViews.ts @@ -556,7 +556,7 @@ class ExtHostTreeView extends Disposable { const disposable = new DisposableStore(); const handle = this.createHandle(element, extensionTreeItem, parent); const icon = this.getLightIconPath(extensionTreeItem); - const item = { + const item: ITreeItem = { handle, parentHandle: parent ? parent.item.handle : undefined, label: toTreeItemLabel(extensionTreeItem.label, this.extension), @@ -567,7 +567,7 @@ class ExtHostTreeView extends Disposable { contextValue: extensionTreeItem.contextValue, icon, iconDark: this.getDarkIconPath(extensionTreeItem) || icon, - themeIcon: extensionTreeItem.iconPath instanceof ThemeIcon ? { id: extensionTreeItem.iconPath.id } : undefined, + themeIcon: this.getThemeIcon(extensionTreeItem), collapsibleState: isUndefinedOrNull(extensionTreeItem.collapsibleState) ? TreeItemCollapsibleState.None : extensionTreeItem.collapsibleState, accessibilityInformation: extensionTreeItem.accessibilityInformation }; @@ -581,6 +581,13 @@ class ExtHostTreeView extends Disposable { }; } + private getThemeIcon(extensionTreeItem: vscode.TreeItem2): ThemeIcon | undefined { + if ((extensionTreeItem.iconPath instanceof ThemeIcon) && extensionTreeItem.iconPath.themeColor) { + checkProposedApiEnabled(this.extension); + } + return extensionTreeItem.iconPath instanceof ThemeIcon ? extensionTreeItem.iconPath : undefined; + } + private createHandle(element: T, { id, label, resourceUri }: vscode.TreeItem, parent: TreeNode | Root, returnFirst?: boolean): TreeItemHandle { if (id) { return `${ExtHostTreeView.ID_HANDLE_PREFIX}/${id}`; diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index 8f4b93a8ac1..503512e25c7 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -2172,9 +2172,15 @@ export class ThemeIcon { static Folder: ThemeIcon; readonly id: string; + readonly themeColor?: ThemeColor; - constructor(id: string) { + constructor(id: string, color?: ThemeColor) { this.id = id; + this.themeColor = color; + } + + with(color: ThemeColor): ThemeIcon { + return new ThemeIcon(this.id, color); } } ThemeIcon.File = new ThemeIcon('file'); diff --git a/src/vs/workbench/contrib/views/browser/treeView.ts b/src/vs/workbench/contrib/views/browser/treeView.ts index 9f919e9cd1f..695f7ff8883 100644 --- a/src/vs/workbench/contrib/views/browser/treeView.ts +++ b/src/vs/workbench/contrib/views/browser/treeView.ts @@ -806,6 +806,9 @@ class TreeRenderer extends Disposable implements ITreeRenderer