Skip to content

Commit

Permalink
Add color to ThemeIcon (#106491)
Browse files Browse the repository at this point in the history
Part of #103120
  • Loading branch information
alexr00 authored Sep 16, 2020
1 parent c6cada9 commit 10c7db8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/vs/platform/theme/common/themeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<ThemeIcon>obj).id === 'string';
}

Expand Down
9 changes: 9 additions & 0 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions src/vs/workbench/api/common/extHostTreeViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ class ExtHostTreeView<T> 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),
Expand All @@ -567,7 +567,7 @@ class ExtHostTreeView<T> 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
};
Expand All @@ -581,6 +581,13 @@ class ExtHostTreeView<T> 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}`;
Expand Down
8 changes: 7 additions & 1 deletion src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/contrib/views/browser/treeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,9 @@ class TreeRenderer extends Disposable implements ITreeRenderer<ITreeItem, FuzzyS
let iconClass: string | undefined;
if (node.themeIcon && !this.isFileKindThemeIcon(node.themeIcon)) {
iconClass = ThemeIcon.asClassName(node.themeIcon);
if (node.themeIcon.themeColor) {
templateData.icon.style.color = this.themeService.getColorTheme().getColor(node.themeIcon.themeColor.id)?.toString() ?? '';
}
}
templateData.icon.className = iconClass ? `custom-view-tree-node-item-icon ${iconClass}` : '';
templateData.icon.style.backgroundImage = '';
Expand Down

0 comments on commit 10c7db8

Please sign in to comment.