Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add full support: SourceControlResourceThemableDecorations.iconPath #12

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/git/src/browser/git-scm-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ export class GitScmProvider implements ScmProvider {
decorations: {
letter: GitFileStatus.toAbbreviation(change.status, change.staged),
color: GitFileStatus.getColor(change.status, change.staged),
tooltip: GitFileStatus.toString(change.status)
tooltip: GitFileStatus.toString(change.status),
strikeThrough: GitFileStatus.toStrikethrough(change.status)
},
open: async () => this.open(change, { mode: 'reveal' })
});
Expand Down
4 changes: 4 additions & 0 deletions packages/git/src/common/git-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ export namespace GitFileStatus {
}
}

export function toStrikethrough(status: GitFileStatus): boolean {
return status === GitFileStatus.Deleted;
}

}

/**
Expand Down
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
16 changes: 10 additions & 6 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 @@ -435,7 +440,7 @@ class SsmResourceGroupImpl implements theia.SourceControlResourceGroup {
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[] = [];
const icons: ScmRawResource['icons'] = [lightIconUri, darkIconUri];
let command: Command | undefined;

if (r.command) {
Expand Down Expand Up @@ -467,7 +472,6 @@ class SsmResourceGroupImpl implements theia.SourceControlResourceGroup {
handle, sourceUri, letter: (r as any).letter, colorId: (r as any).color.id, icons,
tooltip, strikeThrough, faded, contextValue, command
} as ScmRawResource;

return { rawResource, handle };
});

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 @@ -10718,7 +10718,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
5 changes: 5 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,13 @@ export interface ScmResource {
}

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

export interface ScmCommand {
Expand Down
5 changes: 3 additions & 2 deletions packages/scm/src/browser/scm-tree-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ export class ScmResourceComponent extends ScmElement<ScmResourceComponent.Props>
const color = decoration && decoration.colorId ? `var(${colors.toCssVariableName(decoration.colorId)})` : '';
const letter = decoration && decoration.letter || '';
const tooltip = decoration && decoration.tooltip || '';
const textDecoration = treeNode.decorations?.strikeThrough === true ? 'line-through' : 'normal';
const relativePath = parentPath.relative(resourceUri.parent);
const path = relativePath ? relativePath.fsPath() : labelProvider.getLongName(resourceUri.parent);
const title = tooltip.length !== 0
Expand All @@ -554,8 +555,8 @@ export class ScmResourceComponent extends ScmElement<ScmResourceComponent.Props>
<span className={icon + ' file-icon'} />
{this.props.renderExpansionToggle()}
<div className={`noWrapInfo ${TREE_NODE_SEGMENT_GROW_CLASS}`} >
<span className='name'>{caption}</span>
<span className='path'>{path}</span>
<span className='name' style={{ textDecoration }}>{caption}</span>
<span className='path' style={{ textDecoration }}>{path}</span>
</div>
<ScmInlineActions {...{
hover,
Expand Down