scm viewlet: themable icons

This commit is contained in:
Joao Moreno
2016-12-02 10:31:19 +01:00
parent a5812a5e0c
commit 9cd7423788
15 changed files with 147 additions and 58 deletions

View File

@@ -236,7 +236,11 @@ export interface SCMProviderFeatures {
supportsOriginalResource: boolean;
}
export type SCMRawResource = [string /*uri*/, string /*decoration icon*/, boolean /*strike through*/];
export type SCMRawResource = [
string /*uri*/,
string[] /*icons: light, dark*/,
boolean /*strike through*/
];
export type SCMRawResourceGroup = [string /*id*/, string /*label*/, SCMRawResource[]];
export abstract class MainThreadSCMShape {

View File

@@ -13,6 +13,16 @@ import { Disposable } from 'vs/workbench/api/node/extHostTypes';
import { MainContext, MainThreadSCMShape, SCMRawResource, SCMRawResourceGroup } from './extHost.protocol';
import * as vscode from 'vscode';
function getIconPath(decorations: vscode.SCMResourceThemableDecorations) {
if (!decorations) {
return void 0;
} else if (typeof decorations.iconPath === 'string') {
return URI.file(decorations.iconPath).toString();
} else if (decorations.iconPath) {
return `${decorations.iconPath}`;
}
}
export class ExtHostSCM {
private _proxy: MainThreadSCMShape;
@@ -49,20 +59,22 @@ export class ExtHostSCM {
const rawResourceGroups = resourceGroups.map(g => {
const rawResources = g.resources.map(r => {
const uri = r.uri.toString();
let strikeThrough = false;
let decorationIcon: string | undefined;
const iconPath = getIconPath(r.decorations);
const lightIconPath = r.decorations && getIconPath(r.decorations.light) || iconPath;
const darkIconPath = r.decorations && getIconPath(r.decorations.dark) || iconPath;
const icons: string[] = [];
if (r.decorations) {
if (typeof r.decorations.iconPath === 'string') {
decorationIcon = URI.file(r.decorations.iconPath).toString();
} else if (r.decorations.iconPath) {
decorationIcon = `${r.decorations.iconPath}`;
}
strikeThrough = !!r.decorations.strikeThrough;
if (lightIconPath || darkIconPath) {
icons.push(lightIconPath);
}
return [uri, decorationIcon, strikeThrough] as SCMRawResource;
if (darkIconPath !== lightIconPath) {
icons.push(darkIconPath);
}
const strikeThrough = r.decorations && !!r.decorations.strikeThrough;
return [uri, icons, strikeThrough] as SCMRawResource;
});
return [g.id, g.label, rawResources] as SCMRawResourceGroup;
});

View File

@@ -87,9 +87,14 @@ class MainThreadSCMProvider implements ISCMProvider {
const [id, label, rawResources] = rawGroup;
const resources = rawResources.map(rawResource => {
const [uri, decorationIcon, strikeThrough] = rawResource;
const [uri, icons, strikeThrough] = rawResource;
const icon = icons[0];
const iconDark = icons[1] || icon;
const decorations = {
icon: decorationIcon && URI.parse(decorationIcon),
icon: icon && URI.parse(icon),
iconDark: iconDark && URI.parse(iconDark),
strikeThrough
};