Adds status icons to explorer views

Adds templating support to explorer views
This commit is contained in:
Eric Amodio
2017-06-25 23:41:03 -04:00
parent 6410a274d5
commit d193676502
26 changed files with 1646 additions and 1506 deletions

View File

@@ -303,10 +303,15 @@ export interface IConfig {
defaultDateFormat: string | null;
explorer: {
gitExplorer: {
commitFormat: string;
commitFileFormat: string;
// dateFormat: string | null;
};
stashExplorer: {
stashFormat: string;
stashFileFormat: string;
// dateFormat: string | null;
};

View File

@@ -72,4 +72,19 @@ const statusOcticonsMap = {
export function getGitStatusOcticon(status: GitStatusFileStatus, missing: string = GlyphChars.Space.repeat(4)): string {
return statusOcticonsMap[status] || missing;
}
const statusIconsMap = {
'!': 'icon-status-ignored.svg',
'?': 'icon-status-untracked.svg',
A: 'icon-status-added.svg',
C: 'icon-status-copied.svg',
D: 'icon-status-deleted.svg',
M: 'icon-status-modified.svg',
R: 'icon-status-renamed.svg',
U: 'icon-status-conflict.svg'
};
export function getGitStatusIcon(status: GitStatusFileStatus): string {
return statusIconsMap[status];
}

View File

@@ -2,13 +2,14 @@
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Commands, DiffWithPreviousCommandArgs } from '../commands';
import { ExplorerNode, ResourceType } from './explorerNode';
import { GitCommit, GitService, GitUri, IGitStatusFile } from '../gitService';
import { getGitStatusIcon, GitCommit, GitService, GitUri, IGitStatusFile, StatusFileFormatter } from '../gitService';
import * as path from 'path';
export class CommitFileNode extends ExplorerNode {
readonly resourceType: ResourceType = 'commit-file';
constructor(public status: IGitStatusFile, public commit: GitCommit, uri: GitUri, context: ExtensionContext, git: GitService) {
constructor(public status: IGitStatusFile, public commit: GitCommit, private template: string, uri: GitUri, context: ExtensionContext, git: GitService) {
super(uri, context, git);
}
@@ -24,8 +25,15 @@ export class CommitFileNode extends ExplorerNode {
}
}
const item = new TreeItem(`${GitUri.getFormattedPath(this.status.fileName)}`, TreeItemCollapsibleState.None);
const item = new TreeItem(StatusFileFormatter.fromTemplate(this.template, this.status), TreeItemCollapsibleState.None);
item.contextValue = this.resourceType;
const icon = getGitStatusIcon(this.status.status);
item.iconPath = {
dark: this.context.asAbsolutePath(path.join('images', 'dark', icon)),
light: this.context.asAbsolutePath(path.join('images', 'light', icon))
};
item.command = {
title: 'Compare File with Previous',
command: Commands.DiffWithPrevious,
@@ -41,6 +49,7 @@ export class CommitFileNode extends ExplorerNode {
} as DiffWithPreviousCommandArgs
]
};
return item;
}
}

View File

@@ -20,11 +20,11 @@ export class CommitNode extends ExplorerNode {
const commit = Iterables.first(log.commits.values());
if (commit === undefined) return [];
return [...Iterables.map(commit.fileStatuses, s => new CommitFileNode(s, commit, this.uri, this.context, this.git))];
return [...Iterables.map(commit.fileStatuses, s => new CommitFileNode(s, commit, this.git.config.gitExplorer.commitFileFormat, this.uri, this.context, this.git))];
}
getTreeItem(): TreeItem {
const label = CommitFormatter.fromTemplate(this.git.config.explorer.commitFormat, this.commit, this.git.config.defaultDateFormat);
const label = CommitFormatter.fromTemplate(this.git.config.gitExplorer.commitFormat, this.commit, this.git.config.defaultDateFormat);
const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed);
item.contextValue = this.resourceType;

View File

@@ -13,11 +13,11 @@ export class StashCommitNode extends ExplorerNode {
}
async getChildren(): Promise<CommitFileNode[]> {
return Promise.resolve((this.commit as GitStashCommit).fileStatuses.map(_ => new CommitFileNode(_, this.commit, this.uri, this.context, this.git)));
return Promise.resolve((this.commit as GitStashCommit).fileStatuses.map(_ => new CommitFileNode(_, this.commit, this.git.config.stashExplorer.stashFileFormat, this.uri, this.context, this.git)));
}
getTreeItem(): TreeItem {
const label = CommitFormatter.fromTemplate(this.git.config.explorer.stashFormat, this.commit, this.git.config.defaultDateFormat);
const label = CommitFormatter.fromTemplate(this.git.config.stashExplorer.stashFormat, this.commit, this.git.config.defaultDateFormat);
const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed);
item.contextValue = this.resourceType;