mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-14 03:58:31 -05:00
Adds new file layouts to the custom view
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
'use strict';
|
||||
import { Arrays, Iterables, Objects } from '../system';
|
||||
import { ExtensionContext, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
|
||||
import { GitExplorerFilesLayout } from '../configuration';
|
||||
import { ExplorerNode, ResourceType, ShowAllNode } from './explorerNode';
|
||||
import { FolderNode, IFileExplorerNode } from './folderNode';
|
||||
import { GitBranch, GitLog, GitLogCommit, GitService, GitStatus, GitUri, IGitStatusFileWithCommit } from '../gitService';
|
||||
import { StatusFileCommitsNode } from './statusFileCommitsNode';
|
||||
import * as path from 'path';
|
||||
|
||||
export class StatusFilesNode extends ExplorerNode {
|
||||
|
||||
readonly repoPath: string;
|
||||
readonly resourceType: ResourceType = 'gitlens:status-files';
|
||||
|
||||
maxCount: number | undefined = undefined;
|
||||
@@ -19,14 +23,17 @@ export class StatusFilesNode extends ExplorerNode {
|
||||
public readonly branch?: GitBranch
|
||||
) {
|
||||
super(new GitUri(Uri.file(status.repoPath), { repoPath: status.repoPath, fileName: status.repoPath }));
|
||||
this.repoPath = status.repoPath;
|
||||
}
|
||||
|
||||
async getChildren(): Promise<ExplorerNode[]> {
|
||||
let statuses: IGitStatusFileWithCommit[] = [];
|
||||
|
||||
const repoPath = this.repoPath;
|
||||
|
||||
let log: GitLog | undefined;
|
||||
if (this.range !== undefined) {
|
||||
log = await this.git.getLogForRepo(this.status.repoPath, this.range, this.maxCount);
|
||||
log = await this.git.getLogForRepo(repoPath, this.range, this.maxCount);
|
||||
if (log !== undefined) {
|
||||
statuses = Array.from(Iterables.flatMap(log.commits.values(), c => {
|
||||
return c.fileStatuses.map(s => {
|
||||
@@ -38,22 +45,33 @@ export class StatusFilesNode extends ExplorerNode {
|
||||
|
||||
if (this.status.files.length !== 0 && this.includeWorkingTree) {
|
||||
statuses.splice(0, 0, ...this.status.files.map(s => {
|
||||
return { ...s, commit: new GitLogCommit('file', this.status.repoPath, GitService.uncommittedSha, s.fileName, 'You', new Date(), '', s.status, [s], s.originalFileName, 'HEAD', s.fileName) } as IGitStatusFileWithCommit;
|
||||
return {
|
||||
...s,
|
||||
commit: new GitLogCommit('file', repoPath, GitService.uncommittedSha, s.fileName, 'You', new Date(), '', s.status, [s], s.originalFileName, 'HEAD', s.fileName)
|
||||
} as IGitStatusFileWithCommit;
|
||||
}));
|
||||
}
|
||||
statuses.sort((a, b) => b.commit.date.getTime() - a.commit.date.getTime());
|
||||
|
||||
const groups = Arrays.groupBy(statuses, s => s.fileName);
|
||||
|
||||
const children: (StatusFileCommitsNode | ShowAllNode)[] = [
|
||||
...Iterables.map(Objects.values<IGitStatusFileWithCommit[]>(groups),
|
||||
statuses => new StatusFileCommitsNode(this.uri.repoPath!, statuses[statuses.length - 1], statuses.map(s => s.commit), this.context, this.git, this.branch))
|
||||
let children: IFileExplorerNode[] = [
|
||||
...Iterables.map(Objects.values(groups), statuses => new StatusFileCommitsNode(repoPath, statuses[statuses.length - 1], statuses.map(s => s.commit), this.context, this.git, this.branch))
|
||||
];
|
||||
|
||||
children.sort((a: StatusFileCommitsNode, b: StatusFileCommitsNode) => (a.commit.isUncommitted ? -1 : 1) - (b.commit.isUncommitted ? -1 : 1) || a.label!.localeCompare(b.label!));
|
||||
if (this.git.config.gitExplorer.files.layout !== GitExplorerFilesLayout.List) {
|
||||
const hierarchy = Arrays.makeHierarchical(children, n => n.uri.getRelativePath().split('/'),
|
||||
(...paths: string[]) => GitService.normalizePath(path.join(...paths)), this.git.config.gitExplorer.files.compact);
|
||||
|
||||
const root = new FolderNode(repoPath, '', undefined, hierarchy, this.git.config.gitExplorer);
|
||||
children = await root.getChildren() as IFileExplorerNode[];
|
||||
}
|
||||
else {
|
||||
children.sort((a, b) => (a.priority ? -1 : 1) - (b.priority ? -1 : 1) || a.label!.localeCompare(b.label!));
|
||||
}
|
||||
|
||||
if (log !== undefined && log.truncated) {
|
||||
children.push(new ShowAllNode('Show All Changes', this, this.context));
|
||||
(children as (IFileExplorerNode | ShowAllNode)[]).push(new ShowAllNode('Show All Changes', this, this.context));
|
||||
}
|
||||
return children;
|
||||
}
|
||||
@@ -62,7 +80,7 @@ export class StatusFilesNode extends ExplorerNode {
|
||||
let files = (this.status.files !== undefined && this.includeWorkingTree) ? this.status.files.length : 0;
|
||||
|
||||
if (this.status.upstream !== undefined) {
|
||||
const stats = await this.git.getChangedFilesCount(this.status.repoPath, `${this.status.upstream}...`);
|
||||
const stats = await this.git.getChangedFilesCount(this.repoPath, `${this.status.upstream}...`);
|
||||
if (stats !== undefined) {
|
||||
files += stats.files;
|
||||
}
|
||||
@@ -82,5 +100,4 @@ export class StatusFilesNode extends ExplorerNode {
|
||||
private get includeWorkingTree(): boolean {
|
||||
return this.git.config.gitExplorer.includeWorkingTree;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user