Adds new GitLens custom view

This commit is contained in:
Eric Amodio
2017-08-30 12:26:30 -04:00
parent ed58dc3b49
commit 9782a81e46
69 changed files with 983 additions and 644 deletions

View File

@@ -1,34 +1,60 @@
import { Strings } from '../system';
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { GlyphChars } from '../constants';
import { ExplorerNode, ResourceType } from './explorerNode';
import { GitService, GitUri } from '../gitService';
import { StatusUpstreamNode } from './statusUpstreamNode';
export class StatusNode extends ExplorerNode {
readonly resourceType: ResourceType = 'status';
readonly resourceType: ResourceType = 'gitlens:status';
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
super(uri);
}
async getChildren(): Promise<ExplorerNode[]> {
return [];
// const status = await this.git.getStatusForRepo(this.uri.repoPath!);
// if (status === undefined) return [];
const status = await this.git.getStatusForRepo(this.uri.repoPath!);
if (status === undefined) return [];
// return [...Iterables.map(status.files, b => new CommitFile(b, this.uri, this.context, this.git))];
const children = [];
if (status.state.behind) {
children.push(new StatusUpstreamNode(status, 'behind', this.git.config.gitExplorer.commitFormat, this.context, this.git));
}
if (status.state.ahead) {
children.push(new StatusUpstreamNode(status, 'ahead', this.git.config.gitExplorer.commitFormat, this.context, this.git));
}
return children;
}
async getTreeItem(): Promise<TreeItem> {
const status = await this.git.getStatusForRepo(this.uri.repoPath!);
let suffix = '';
if (status !== undefined) {
suffix = ` ${GlyphChars.Dash} ${GlyphChars.ArrowUp} ${status.state.ahead} ${GlyphChars.ArrowDown} ${status.state.behind} ${Strings.pad(GlyphChars.Dot, 1, 1)} ${status.branch} ${GlyphChars.ArrowLeftRight} ${status.upstream}`;
if (status === undefined) return new TreeItem('No repo status');
let hasChildren = false;
let label = '';
if (status.upstream) {
if (!status.state.ahead && !status.state.behind) {
label = `${status.branch} is up-to-date with ${status.upstream}`;
}
else {
label = `${status.branch} is not up-to-date with ${status.upstream}`;
hasChildren = true;
}
}
else {
label = `${status.branch} is up-to-date`;
}
const item = new TreeItem(`Status${suffix}`, TreeItemCollapsibleState.Collapsed);
const item = new TreeItem(label, hasChildren ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.None);
item.contextValue = this.resourceType;
item.iconPath = {
dark: this.context.asAbsolutePath('images/dark/icon-repo.svg'),
light: this.context.asAbsolutePath('images/light/icon-repo.svg')
};
return item;
}
}