mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-15 01:25:42 -05:00
Closes #139 - adds changed files node to repository status
Reworks commit-file nodes
This commit is contained in:
68
src/views/statusFileCommitsNode.ts
Normal file
68
src/views/statusFileCommitsNode.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
'use strict';
|
||||
import { Command, ExtensionContext, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
|
||||
import { Commands, DiffWithPreviousCommandArgs } from '../commands';
|
||||
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
|
||||
import { ExplorerNode, ResourceType } from './explorerNode';
|
||||
import { getGitStatusIcon, GitBranch, GitLogCommit, GitService, GitUri, IGitStatusFile, StatusFileFormatter } from '../gitService';
|
||||
import * as path from 'path';
|
||||
|
||||
export class StatusFileCommitsNode extends ExplorerNode {
|
||||
|
||||
readonly resourceType: ResourceType = 'gitlens:status-file-commits';
|
||||
|
||||
constructor(
|
||||
repoPath: string,
|
||||
public readonly status: IGitStatusFile,
|
||||
public commits: GitLogCommit[],
|
||||
protected readonly context: ExtensionContext,
|
||||
protected readonly git: GitService,
|
||||
public readonly branch?: GitBranch
|
||||
) {
|
||||
super(new GitUri(Uri.file(path.resolve(repoPath, status.fileName)), { repoPath: repoPath, fileName: status.fileName, sha: 'HEAD' }));
|
||||
}
|
||||
|
||||
async getChildren(): Promise<ExplorerNode[]> {
|
||||
return this.commits.map(c => new CommitFileNode(this.status, c, this.context, this.git, CommitFileNodeDisplayAs.Commit, this.branch));
|
||||
}
|
||||
|
||||
async getTreeItem(): Promise<TreeItem> {
|
||||
const item = new TreeItem(StatusFileFormatter.fromTemplate(this.git.config.gitExplorer.commitFileFormat, this.status), TreeItemCollapsibleState.Collapsed);
|
||||
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))
|
||||
};
|
||||
|
||||
if (this.commits.length === 1 && this.commits[0].isUncommitted) {
|
||||
item.collapsibleState = TreeItemCollapsibleState.None;
|
||||
item.contextValue = 'gitlens:status-file' as ResourceType;
|
||||
item.command = this.getCommand();
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
get commit() {
|
||||
return this.commits[0];
|
||||
}
|
||||
|
||||
getCommand(): Command | undefined {
|
||||
return {
|
||||
title: 'Compare File with Previous Revision',
|
||||
command: Commands.DiffWithPrevious,
|
||||
arguments: [
|
||||
GitUri.fromFileStatus(this.status, this.uri.repoPath!),
|
||||
{
|
||||
commit: this.commit,
|
||||
line: 0,
|
||||
showOptions: {
|
||||
preserveFocus: true,
|
||||
preview: true
|
||||
}
|
||||
} as DiffWithPreviousCommandArgs
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user