未验证 提交 10c7db89 编写于 作者: A Alex Ross 提交者: GitHub

Add color to ThemeIcon (#106491)

Part of #103120
上级 c6cada99
...@@ -25,10 +25,11 @@ export function themeColorFromId(id: ColorIdentifier) { ...@@ -25,10 +25,11 @@ export function themeColorFromId(id: ColorIdentifier) {
// theme icon // theme icon
export interface ThemeIcon { export interface ThemeIcon {
readonly id: string; readonly id: string;
readonly themeColor?: ThemeColor;
} }
export namespace ThemeIcon { 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'; return obj && typeof obj === 'object' && typeof (<ThemeIcon>obj).id === 'string';
} }
......
...@@ -2266,6 +2266,15 @@ declare module 'vscode' { ...@@ -2266,6 +2266,15 @@ declare module 'vscode' {
*/ */
description?: string | undefined; 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 //#endregion
} }
...@@ -1123,6 +1123,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I ...@@ -1123,6 +1123,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
TextEditorSelectionChangeKind: extHostTypes.TextEditorSelectionChangeKind, TextEditorSelectionChangeKind: extHostTypes.TextEditorSelectionChangeKind,
ThemeColor: extHostTypes.ThemeColor, ThemeColor: extHostTypes.ThemeColor,
ThemeIcon: extHostTypes.ThemeIcon, ThemeIcon: extHostTypes.ThemeIcon,
ThemeIcon2: extHostTypes.ThemeIcon,
TreeItem: extHostTypes.TreeItem, TreeItem: extHostTypes.TreeItem,
TreeItem2: extHostTypes.TreeItem, TreeItem2: extHostTypes.TreeItem,
TreeItemCollapsibleState: extHostTypes.TreeItemCollapsibleState, TreeItemCollapsibleState: extHostTypes.TreeItemCollapsibleState,
......
...@@ -556,7 +556,7 @@ class ExtHostTreeView<T> extends Disposable { ...@@ -556,7 +556,7 @@ class ExtHostTreeView<T> extends Disposable {
const disposable = new DisposableStore(); const disposable = new DisposableStore();
const handle = this.createHandle(element, extensionTreeItem, parent); const handle = this.createHandle(element, extensionTreeItem, parent);
const icon = this.getLightIconPath(extensionTreeItem); const icon = this.getLightIconPath(extensionTreeItem);
const item = { const item: ITreeItem = {
handle, handle,
parentHandle: parent ? parent.item.handle : undefined, parentHandle: parent ? parent.item.handle : undefined,
label: toTreeItemLabel(extensionTreeItem.label, this.extension), label: toTreeItemLabel(extensionTreeItem.label, this.extension),
...@@ -567,7 +567,7 @@ class ExtHostTreeView<T> extends Disposable { ...@@ -567,7 +567,7 @@ class ExtHostTreeView<T> extends Disposable {
contextValue: extensionTreeItem.contextValue, contextValue: extensionTreeItem.contextValue,
icon, icon,
iconDark: this.getDarkIconPath(extensionTreeItem) || 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, collapsibleState: isUndefinedOrNull(extensionTreeItem.collapsibleState) ? TreeItemCollapsibleState.None : extensionTreeItem.collapsibleState,
accessibilityInformation: extensionTreeItem.accessibilityInformation accessibilityInformation: extensionTreeItem.accessibilityInformation
}; };
...@@ -581,6 +581,13 @@ class ExtHostTreeView<T> extends Disposable { ...@@ -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 { private createHandle(element: T, { id, label, resourceUri }: vscode.TreeItem, parent: TreeNode | Root, returnFirst?: boolean): TreeItemHandle {
if (id) { if (id) {
return `${ExtHostTreeView.ID_HANDLE_PREFIX}/${id}`; return `${ExtHostTreeView.ID_HANDLE_PREFIX}/${id}`;
......
...@@ -2172,9 +2172,15 @@ export class ThemeIcon { ...@@ -2172,9 +2172,15 @@ export class ThemeIcon {
static Folder: ThemeIcon; static Folder: ThemeIcon;
readonly id: string; readonly id: string;
readonly themeColor?: ThemeColor;
constructor(id: string) { constructor(id: string, color?: ThemeColor) {
this.id = id; this.id = id;
this.themeColor = color;
}
with(color: ThemeColor): ThemeIcon {
return new ThemeIcon(this.id, color);
} }
} }
ThemeIcon.File = new ThemeIcon('file'); ThemeIcon.File = new ThemeIcon('file');
......
...@@ -806,6 +806,9 @@ class TreeRenderer extends Disposable implements ITreeRenderer<ITreeItem, FuzzyS ...@@ -806,6 +806,9 @@ class TreeRenderer extends Disposable implements ITreeRenderer<ITreeItem, FuzzyS
let iconClass: string | undefined; let iconClass: string | undefined;
if (node.themeIcon && !this.isFileKindThemeIcon(node.themeIcon)) { if (node.themeIcon && !this.isFileKindThemeIcon(node.themeIcon)) {
iconClass = ThemeIcon.asClassName(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.className = iconClass ? `custom-view-tree-node-item-icon ${iconClass}` : '';
templateData.icon.style.backgroundImage = ''; templateData.icon.style.backgroundImage = '';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册