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

SCM - fix statistics tooltip localization #197896

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 25 additions & 33 deletions src/vs/workbench/contrib/scm/browser/scmViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,9 @@ class HistoryItemGroupRenderer implements ICompressibleTreeRenderer<SCMHistoryIt

interface HistoryItemTemplate {
readonly iconContainer: HTMLElement;
// readonly avatarImg: HTMLImageElement;
readonly iconLabel: IconLabel;
readonly label: IconLabel;
readonly statsContainer: HTMLElement;
readonly statsLabel: IconLabel;
// readonly timestampContainer: HTMLElement;
// readonly timestamp: HTMLSpanElement;
readonly disposables: IDisposable;
}

Expand All @@ -759,12 +756,7 @@ class HistoryItemRenderer implements ICompressibleTreeRenderer<SCMHistoryItemTre
const statsContainer = append(element, $('.stats-container'));
const statsLabel = new IconLabel(statsContainer, { supportIcons: true });

// const avatarImg = append(iconContainer, $('img.avatar')) as HTMLImageElement;

// const timestampContainer = append(iconLabel.element, $('.timestamp-container'));
// const timestamp = append(timestampContainer, $('span.timestamp'));

return { iconContainer, iconLabel, statsContainer, statsLabel, disposables: new DisposableStore() };
return { iconContainer, label: iconLabel, statsContainer, statsLabel, disposables: new DisposableStore() };
}

renderElement(node: ITreeNode<SCMHistoryItemTreeElement, void>, index: number, templateData: HistoryItemTemplate, height: number | undefined): void {
Expand All @@ -775,47 +767,47 @@ class HistoryItemRenderer implements ICompressibleTreeRenderer<SCMHistoryItemTre
templateData.iconContainer.classList.add(...ThemeIcon.asClassNameArray(historyItem.icon));
}

// if (commit.authorAvatar) {
// templateData.avatarImg.src = commit.authorAvatar;
// templateData.avatarImg.style.display = 'block';
// templateData.iconContainer.classList.remove(...ThemeIcon.asClassNameArray(Codicon.account));
// } else {
// templateData.avatarImg.style.display = 'none';
// templateData.iconContainer.classList.add(...ThemeIcon.asClassNameArray(Codicon.account));
// }
templateData.label.setLabel(historyItem.label, historyItem.description);
this.renderStatistics(node, index, templateData, height);
}

renderCompressedElements(node: ITreeNode<ICompressedTreeNode<SCMHistoryItemTreeElement>, void>, index: number, templateData: HistoryItemTemplate, height: number | undefined): void {
throw new Error('Should never happen since node is incompressible');
}

templateData.iconLabel.setLabel(historyItem.label, historyItem.description);
private renderStatistics(node: ITreeNode<SCMHistoryItemTreeElement, void>, index: number, templateData: HistoryItemTemplate, height: number | undefined): void {
const historyItem = node.element;

if (historyItem.statistics?.files || historyItem.statistics?.insertions || historyItem.statistics?.deletions) {
const statsLabelTitle: string[] = [];

const filesLabel = historyItem.statistics?.files ? `${historyItem.statistics.files}$(files)` : '';
if (filesLabel !== '') {
statsLabelTitle.push(`${historyItem.statistics.files} ${historyItem.statistics.files === 1 ? 'file' : 'files'} changed`);
const insertionsLabel = historyItem.statistics?.insertions ? ` ${historyItem.statistics.insertions}$(diff-added)` : '';
const deletionsLabel = historyItem.statistics?.deletions ? ` ${historyItem.statistics.deletions}$(diff-removed)` : '';

if (historyItem.statistics?.files) {
const filesDescription = historyItem.statistics.files === 1 ?
localize('fileChanged', "file changed") : localize('filesChanged', "files changed");
statsLabelTitle.push(`${historyItem.statistics.files} ${filesDescription}`);
}

const insertionsLabel = historyItem.statistics?.insertions ? ` ${historyItem.statistics.insertions}$(diff-added)` : '';
if (insertionsLabel !== '') {
statsLabelTitle.push(`${historyItem.statistics.insertions} insertions(+)`);
if (historyItem.statistics?.insertions) {
const insertionsDescription = localize('insertions', "insertions{0}", '(+)');
statsLabelTitle.push(`${historyItem.statistics.insertions} ${insertionsDescription}`);
}

const deletionsLabel = historyItem.statistics?.deletions ? ` ${historyItem.statistics.deletions}$(diff-removed)` : '';
if (deletionsLabel !== '') {
statsLabelTitle.push(`${historyItem.statistics.deletions} deletions(-)`);
if (historyItem.statistics?.deletions) {
const deletionsDescription = localize('deletions', "deletions{0}", '(-)');
statsLabelTitle.push(`${historyItem.statistics.deletions} ${deletionsDescription}`);
}

templateData.statsLabel.setLabel(`${filesLabel}${insertionsLabel}${deletionsLabel}`, undefined, { title: statsLabelTitle.join(', ') });
templateData.statsContainer.style.display = '';
} else {
templateData.statsContainer.style.display = 'none';
}

// templateData.timestampContainer.classList.toggle('timestamp-duplicate', commit.hideTimestamp === true);
// templateData.timestamp.textContent = fromNow(commit.timestamp);
}

renderCompressedElements(node: ITreeNode<ICompressedTreeNode<SCMHistoryItemTreeElement>, void>, index: number, templateData: HistoryItemTemplate, height: number | undefined): void {
throw new Error('Should never happen since node is incompressible');
}
disposeTemplate(templateData: HistoryItemTemplate): void {
templateData.disposables.dispose();
}
Expand Down