Skip to content

Commit

Permalink
Add full support: SourceControlResourceThemable
Browse files Browse the repository at this point in the history
Decorations.iconPath

The SourceControlResourceThemableDecorations.iconPath now accept
ThemeIcons (similarly as per VS Code API).
  • Loading branch information
Estelle Foisy committed Dec 15, 2022
1 parent dc81358 commit faf52d5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ export interface SourceControlGroupFeatures {
export interface ScmRawResource {
handle: number,
sourceUri: UriComponents,
icons: UriComponents[],
icons: [UriComponents | ThemeIcon | undefined, UriComponents | ThemeIcon | undefined],
tooltip: string,
strikeThrough: boolean,
faded: boolean,
Expand Down
10 changes: 6 additions & 4 deletions packages/plugin-ext/src/main/browser/scm-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { URI as vscodeURI } from '@theia/core/shared/vscode-uri';
import { Splice } from '../../common/arrays';
import { UriComponents } from '../../common/uri-components';
import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
import { ThemeIcon } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService';

export class PluginScmResourceGroup implements ScmResourceGroup {

Expand Down Expand Up @@ -222,13 +223,14 @@ export class PluginScmProvider implements ScmProvider {
const { start, deleteCount, rawResources } = groupSlice;
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 : vscodeURI.revive(light);
const iconDark = (ThemeIcon.isThemeIcon(dark) ? dark : vscodeURI.revive(dark)) || icon;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const colorVariable = (rawResource as any).colorId && this.colors.toCssVariableName((rawResource as any).colorId);
const decorations = {
icon: icon ? vscodeURI.revive(icon) : undefined,
iconDark: iconDark ? vscodeURI.revive(iconDark) : undefined,
icon: icon,
iconDark: iconDark,
tooltip,
strikeThrough,
// TODO remove the letter and colorId fields when the FileDecorationProvider is applied, see https://github.com/eclipse-theia/theia/pull/8911
Expand Down
34 changes: 16 additions & 18 deletions packages/plugin-ext/src/plugin/scm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,22 @@ import { RPCProtocol } from '../common/rpc-protocol';
import { URI } from './types-impl';
import { ScmCommandArg } from '../common/plugin-api-rpc';
import { sep } from '@theia/core/lib/common/paths';
import { ThemeIcon } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService';
type ProviderHandle = number;
type GroupHandle = number;
type ResourceStateHandle = number;

function getIconResource(decorations?: theia.SourceControlResourceThemableDecorations): theia.Uri | undefined {
function getIconResource(decorations?: theia.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;
}
}

Expand Down Expand Up @@ -111,8 +116,8 @@ function compareResourceThemableDecorations(a: theia.SourceControlResourceThemab
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 ThemeIcon).id;
const bPath = typeof b.iconPath === 'string' ? b.iconPath : URI.isUri(b.iconPath) ? b.iconPath.fsPath : (b.iconPath as ThemeIcon).id;
return comparePaths(aPath, bPath);
}

Expand Down Expand Up @@ -423,7 +428,7 @@ class SsmResourceGroupImpl implements theia.SourceControlResourceGroup {
}

takeResourceStateSnapshot(): ScmRawResourceSplice[] {
const snapshot = [...this._resourceStates];
const snapshot = [...this._resourceStates].sort(compareResourceStates);
const diffs = sortedDiff(this.resourceSnapshot, snapshot, compareResourceStates);

const splices = diffs.map<Splice<{ rawResource: ScmRawResource, handle: number }>>(diff => {
Expand All @@ -432,12 +437,8 @@ class SsmResourceGroupImpl implements theia.SourceControlResourceGroup {
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: Command | undefined;

let command: Command | undefined;
if (r.command) {
if (r.command.command === 'theia.open' || r.command.command === 'theia.diff') {
const disposables = new DisposableCollection();
Expand All @@ -448,13 +449,10 @@ class SsmResourceGroupImpl implements theia.SourceControlResourceGroup {
}
}

if (lightIconUri) {
icons.push(lightIconUri);
}

if (darkIconUri && (darkIconUri.toString() !== lightIconUri?.toString())) {
icons.push(darkIconUri);
}
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: ScmRawResource['icons'] = [lightIconUri, darkIconUri];

const tooltip = (r.decorations && r.decorations.tooltip) || '';
const strikeThrough = r.decorations && !!r.decorations.strikeThrough;
Expand All @@ -464,7 +462,7 @@ class SsmResourceGroupImpl implements theia.SourceControlResourceGroup {
// TODO remove the letter and colorId fields when the FileDecorationProvider is applied, see https://github.com/eclipse-theia/theia/pull/8911
const rawResource = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
handle, sourceUri, letter: (r as any).letter, colorId: (r as any).color.id, icons,
handle, sourceUri, icons,
tooltip, strikeThrough, faded, contextValue, command
} as ScmRawResource;

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10710,7 +10710,7 @@ export module '@theia/plugin' {
* The icon path for a specific
* {@link SourceControlResourceState source control resource state}.
*/
readonly iconPath?: string | Uri;
readonly iconPath?: string | Uri | ThemeIcon;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/scm/src/browser/scm-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import { Disposable, Event } from '@theia/core/lib/common';
import URI from '@theia/core/lib/common/uri';
// eslint-disable-next-line import/no-extraneous-dependencies
import { ThemeIcon } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService';

export interface ScmProvider extends Disposable {
readonly id: string;
Expand Down Expand Up @@ -58,10 +60,14 @@ export interface ScmResource {
}

export interface ScmResourceDecorations {
icon?: URI | ThemeIcon;
iconDark?: URI | ThemeIcon;
tooltip?: string;
source?: string;
letter?: string;
color?: string;
strikeThrough?: boolean;
faded?: boolean;
}

export interface ScmCommand {
Expand Down

0 comments on commit faf52d5

Please sign in to comment.