Browse Source

Removes working status placeholders if not changed in working tree

Adds better sorting of working tree file changes
Changes non-working tree file changes back to use status icons
main
Eric Amodio 6 years ago
parent
commit
9eaac0ed54
9 changed files with 84 additions and 37 deletions
  1. +1
    -1
      package.json
  2. +1
    -3
      src/git/formatters/statusFormatter.ts
  3. +7
    -3
      src/views/nodes/commitFileNode.ts
  4. +4
    -2
      src/views/nodes/explorerNode.ts
  5. +3
    -3
      src/views/nodes/folderNode.ts
  6. +2
    -2
      src/views/nodes/resultsFileNode.ts
  7. +1
    -1
      src/views/nodes/resultsFilesNode.ts
  8. +64
    -21
      src/views/nodes/statusFileNode.ts
  9. +1
    -1
      src/views/nodes/statusFilesNode.ts

+ 1
- 1
package.json View File

@ -3196,7 +3196,7 @@
},
{
"command": "gitlens.explorers.openFile",
"when": "viewItem =~ /gitlens:file\\b/",
"when": "viewItem =~ /gitlens:(file|history-file|status:file)\\b/",
"group": "inline"
},
{

+ 1
- 3
src/git/formatters/statusFormatter.ts View File

@ -61,9 +61,7 @@ export class StatusFileFormatter extends Formatter
icon = `${GlyphChars.Space}${GlyphChars.EnDash}${GlyphChars.Space.repeat(2)}${GlyphChars.Check}`;
}
else {
icon = `${GlyphChars.Space}${GlyphChars.EnDash}${GlyphChars.Space.repeat(2)}${GlyphChars.EnDash}${
GlyphChars.Space
}`;
icon = '';
}
return this._padOrTruncate(icon, this._options.tokenOptions!.working);
}

+ 7
- 3
src/views/nodes/commitFileNode.ts View File

@ -28,8 +28,6 @@ export enum CommitFileNodeDisplayAs {
}
export class CommitFileNode extends ExplorerRefNode {
readonly priority: boolean = false;
constructor(
public readonly file: GitFile,
public commit: GitLogCommit,
@ -41,6 +39,10 @@ export class CommitFileNode extends ExplorerRefNode {
super(GitUri.fromFile(file, commit.repoPath, commit.sha), parent);
}
get priority(): number {
return 0;
}
get ref(): string {
return this.commit.sha;
}
@ -132,7 +134,9 @@ export class CommitFileNode extends ExplorerRefNode {
}
protected get resourceType(): ResourceType {
return ResourceType.CommitFile;
if (!this.commit.isUncommitted) return ResourceType.CommitFile;
return this.commit.isStagedUncommitted ? ResourceType.FileStaged : ResourceType.FileUnstaged;
}
private _tooltip: string | undefined;

+ 4
- 2
src/views/nodes/explorerNode.ts View File

@ -19,6 +19,9 @@ export enum ResourceType {
Commits = 'gitlens:commits',
ComparisonResults = 'gitlens:results:comparison',
FileHistory = 'gitlens:history-file',
FileStaged = 'gitlens:file:staged',
FileStagedAndUnstaged = 'gitlens:file:staged:unstaged',
FileUnstaged = 'gitlens:file:unstaged',
Folder = 'gitlens:folder',
Message = 'gitlens:message',
Pager = 'gitlens:pager',
@ -34,9 +37,8 @@ export enum ResourceType {
Stash = 'gitlens:stash',
StashFile = 'gitlens:file:stash',
Stashes = 'gitlens:stashes',
StatusFile = 'gitlens:file:status',
StatusFileCommits = 'gitlens:status:file:commits',
StatusFiles = 'gitlens:status:files',
StatusFileCommits = 'gitlens:status:file-commits',
StatusUpstream = 'gitlens:status:upstream',
Tag = 'gitlens:tag',
Tags = 'gitlens:tags'

+ 3
- 3
src/views/nodes/folderNode.ts View File

@ -9,13 +9,13 @@ import { ExplorerNode, ResourceType } from './explorerNode';
export interface FileExplorerNode extends ExplorerNode {
folderName: string;
label?: string;
priority: boolean;
priority: number;
relativePath?: string;
root?: Arrays.IHierarchicalItem<FileExplorerNode>;
}
export class FolderNode extends ExplorerNode {
readonly priority: boolean = true;
readonly priority: number = 1;
constructor(
public readonly repoPath: string,
@ -60,7 +60,7 @@ export class FolderNode extends ExplorerNode {
children.sort((a, b) => {
return (
(a instanceof FolderNode ? -1 : 1) - (b instanceof FolderNode ? -1 : 1) ||
(a.priority ? -1 : 1) - (b.priority ? -1 : 1) ||
a.priority - b.priority ||
a.label!.localeCompare(b.label!)
);
});

+ 2
- 2
src/views/nodes/resultsFileNode.ts View File

@ -65,8 +65,8 @@ export class ResultsFileNode extends ExplorerNode {
this._label = undefined;
}
get priority(): boolean {
return false;
get priority(): number {
return 0;
}
getCommand(): Command | undefined {

+ 1
- 1
src/views/nodes/resultsFilesNode.ts View File

@ -49,7 +49,7 @@ export class ResultsFilesNode extends ExplorerNode {
children = (await root.getChildren()) as FileExplorerNode[];
}
else {
children.sort((a, b) => (a.priority ? -1 : 1) - (b.priority ? -1 : 1) || a.label!.localeCompare(b.label!));
children.sort((a, b) => a.priority - b.priority || a.label!.localeCompare(b.label!));
}
return children;

+ 64
- 21
src/views/nodes/statusFileNode.ts View File

@ -2,6 +2,7 @@
import * as path from 'path';
import { Command, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
import { Commands, DiffWithPreviousCommandArgs } from '../../commands';
import { Container } from '../../container';
import {
GitFile,
GitFileWithCommit,
@ -16,6 +17,9 @@ import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { ExplorerNode, ResourceType } from './explorerNode';
export class StatusFileNode extends ExplorerNode {
private readonly _hasStagedChanges: boolean = false;
private readonly _hasUnstagedChanges: boolean = false;
constructor(
public readonly repoPath: string,
public readonly file: GitFile,
@ -24,6 +28,17 @@ export class StatusFileNode extends ExplorerNode {
public readonly explorer: Explorer
) {
super(GitUri.fromFile(file, repoPath, 'HEAD'), parent);
for (const c of this.commits) {
if (c.isStagedUncommitted) {
this._hasStagedChanges = true;
}
else if (c.isUncommitted) {
this._hasUnstagedChanges = true;
}
if (this._hasStagedChanges && this._hasUnstagedChanges) break;
}
}
async getChildren(): Promise<ExplorerNode[]> {
@ -45,36 +60,60 @@ export class StatusFileNode extends ExplorerNode {
async getTreeItem(): Promise<TreeItem> {
const item = new TreeItem(this.label, TreeItemCollapsibleState.None);
if (this.commits.length === 1 && this.commit.isUncommitted) {
item.contextValue = ResourceType.StatusFile;
if (this.commit.isStagedUncommitted) {
if ((this._hasStagedChanges || this._hasUnstagedChanges) && this.commits.length === 1) {
if (this._hasStagedChanges) {
item.contextValue = ResourceType.FileStaged;
item.tooltip = StatusFileFormatter.fromTemplate(
'${file}\n${directory}/\n\n${status} in Index (staged)',
this.file
);
}
else {
item.contextValue = ResourceType.FileUnstaged;
item.tooltip = StatusFileFormatter.fromTemplate(
'${file}\n${directory}/\n\n${status} in Working Tree',
this.file
);
}
// Use the file icon and decorations
item.resourceUri = Uri.file(path.resolve(this.repoPath, this.file.fileName));
item.iconPath = ThemeIcon.File;
item.command = this.getCommand();
}
else {
item.collapsibleState = TreeItemCollapsibleState.Collapsed;
item.contextValue = ResourceType.StatusFileCommits;
if (this._hasStagedChanges || this._hasUnstagedChanges) {
if (this._hasStagedChanges && this._hasUnstagedChanges) {
item.contextValue = ResourceType.FileStagedAndUnstaged;
}
else if (this._hasStagedChanges) {
item.contextValue = ResourceType.FileStaged;
}
else {
item.contextValue = ResourceType.FileUnstaged;
}
// Use the file icon and decorations
item.resourceUri = Uri.file(path.resolve(this.repoPath, this.file.fileName));
item.iconPath = ThemeIcon.File;
}
else {
item.contextValue = ResourceType.StatusFileCommits;
const icon = GitFile.getStatusIcon(this.file.status);
item.iconPath = {
dark: Container.context.asAbsolutePath(path.join('images', 'dark', icon)),
light: Container.context.asAbsolutePath(path.join('images', 'light', icon))
};
}
item.tooltip = StatusFileFormatter.fromTemplate(
`\${file}\n\${directory}/\n\n\${status} in ${this.getChangedIn()}`,
this.file
);
}
// Use the file icon and decorations
item.resourceUri = Uri.file(path.resolve(this.repoPath, this.file.fileName));
item.iconPath = ThemeIcon.File;
// Only cache the label for a single refresh
this._label = undefined;
@ -110,8 +149,11 @@ export class StatusFileNode extends ExplorerNode {
return this.commits[0];
}
get priority(): boolean {
return this.commit.isUncommitted;
get priority(): number {
if (this._hasStagedChanges && !this._hasUnstagedChanges) return -3;
if (this._hasStagedChanges) return -2;
if (this._hasUnstagedChanges) return -1;
return 0;
}
private _relativePath: string | undefined;
@ -125,20 +167,21 @@ export class StatusFileNode extends ExplorerNode {
private getChangedIn(): string {
const changedIn = [];
let commits = 0;
for (const c of this.commits) {
if (c.isUncommitted) {
if (c.isStagedUncommitted) {
changedIn.push('Index (staged)');
}
else {
changedIn.push('Working Tree');
}
continue;
}
if (this._hasUnstagedChanges) {
commits++;
changedIn.push('Working Tree');
}
if (this._hasStagedChanges) {
commits++;
changedIn.push('Index (staged)');
}
if (this.commits.length > commits) {
commits = this.commits.length - commits;
}
if (commits > 0) {

+ 1
- 1
src/views/nodes/statusFilesNode.ts View File

@ -102,7 +102,7 @@ export class StatusFilesNode extends ExplorerNode {
children = (await root.getChildren()) as FileExplorerNode[];
}
else {
children.sort((a, b) => (a.priority ? -1 : 1) - (b.priority ? -1 : 1) || a.label!.localeCompare(b.label!));
children.sort((a, b) => a.priority - b.priority || a.label!.localeCompare(b.label!));
}
return children;

Loading…
Cancel
Save