Closes #128258: Adds ThemeIcon support

This commit is contained in:
Eric Amodio
2021-07-08 18:48:00 -04:00
parent 7b064adcd5
commit 55868691ef
8 changed files with 50 additions and 29 deletions

View File

@@ -13,6 +13,7 @@ import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { ISplice, Sequence } from 'vs/base/common/sequence';
import { CancellationToken } from 'vs/base/common/cancellation';
import { MarshalledId } from 'vs/base/common/marshalling';
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
class MainThreadSCMResourceGroup implements ISCMResourceGroup {
@@ -204,11 +205,14 @@ class MainThreadSCMProvider implements ISCMProvider {
for (const [start, deleteCount, rawResources] of groupSlices) {
const resources = rawResources.map(rawResource => {
const [handle, sourceUri, icons, tooltip, strikeThrough, faded, contextValue, command] = rawResource;
const icon = icons[0];
const iconDark = icons[1] || icon;
const [light, dark] = icons;
const icon = ThemeIcon.isThemeIcon(light) ? light : URI.revive(light);
const iconDark = (ThemeIcon.isThemeIcon(dark) ? dark : URI.revive(dark)) || icon;
const decorations = {
icon: icon ? URI.revive(icon) : undefined,
iconDark: iconDark ? URI.revive(iconDark) : undefined,
icon: icon,
iconDark: iconDark,
tooltip,
strikeThrough,
faded

View File

@@ -1039,7 +1039,7 @@ export interface SCMGroupFeatures {
export type SCMRawResource = [
number /*handle*/,
UriComponents /*resourceUri*/,
UriComponents[] /*icons: light, dark*/,
[UriComponents | ThemeIcon | undefined, UriComponents | ThemeIcon | undefined] /*icons: light, dark*/,
string /*tooltip*/,
boolean /*strike through*/,
boolean /*faded*/,

View File

@@ -19,18 +19,23 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
import { MarshalledId } from 'vs/base/common/marshalling';
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
type ProviderHandle = number;
type GroupHandle = number;
type ResourceStateHandle = number;
function getIconResource(decorations?: vscode.SourceControlResourceThemableDecorations): vscode.Uri | undefined {
function getIconResource(decorations?: vscode.SourceControlResourceThemableDecorations): UriComponents | ThemeIcon | undefined {
if (!decorations) {
return undefined;
} else if (typeof decorations.iconPath === 'string') {
return URI.file(decorations.iconPath);
} else {
} else if (URI.isUri(decorations.iconPath)) {
return decorations.iconPath;
} else if (ThemeIcon.isThemeIcon(decorations.iconPath)) {
return decorations.iconPath;
} else {
return undefined;
}
}
@@ -43,8 +48,8 @@ function compareResourceThemableDecorations(a: vscode.SourceControlResourceThema
return 1;
}
const aPath = typeof a.iconPath === 'string' ? a.iconPath : a.iconPath.fsPath;
const bPath = typeof b.iconPath === 'string' ? b.iconPath : b.iconPath.fsPath;
const aPath = typeof a.iconPath === 'string' ? a.iconPath : URI.isUri(a.iconPath) ? a.iconPath.fsPath : (a.iconPath as vscode.ThemeIcon).id;
const bPath = typeof b.iconPath === 'string' ? b.iconPath : URI.isUri(b.iconPath) ? b.iconPath.fsPath : (b.iconPath as vscode.ThemeIcon).id;
return comparePaths(aPath, bPath);
}
@@ -368,12 +373,8 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
this._resourceStatesMap.set(handle, r);
const sourceUri = r.resourceUri;
const iconUri = getIconResource(r.decorations);
const lightIconUri = r.decorations && getIconResource(r.decorations.light) || iconUri;
const darkIconUri = r.decorations && getIconResource(r.decorations.dark) || iconUri;
const icons: UriComponents[] = [];
let command: ICommandDto | undefined;
let command: ICommandDto | undefined;
if (r.command) {
if (r.command.command === 'vscode.open' || r.command.command === 'vscode.diff') {
const disposables = new DisposableStore();
@@ -384,13 +385,10 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
}
}
if (lightIconUri) {
icons.push(lightIconUri);
}
if (darkIconUri && (darkIconUri.toString() !== lightIconUri?.toString())) {
icons.push(darkIconUri);
}
const icon = getIconResource(r.decorations);
const lightIcon = r.decorations && getIconResource(r.decorations.light) || icon;
const darkIcon = r.decorations && getIconResource(r.decorations.dark) || icon;
const icons: SCMRawResource[2] = [lightIcon, darkIcon];
const tooltip = (r.decorations && r.decorations.tooltip) || '';
const strikeThrough = r.decorations && !!r.decorations.strikeThrough;