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", "command": "gitlens.explorers.openFile",
"when": "viewItem =~ /gitlens:file\\b/",
"when": "viewItem =~ /gitlens:(file|history-file|status:file)\\b/",
"group": "inline" "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}`; icon = `${GlyphChars.Space}${GlyphChars.EnDash}${GlyphChars.Space.repeat(2)}${GlyphChars.Check}`;
} }
else { else {
icon = `${GlyphChars.Space}${GlyphChars.EnDash}${GlyphChars.Space.repeat(2)}${GlyphChars.EnDash}${
GlyphChars.Space
}`;
icon = '';
} }
return this._padOrTruncate(icon, this._options.tokenOptions!.working); 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 { export class CommitFileNode extends ExplorerRefNode {
readonly priority: boolean = false;
constructor( constructor(
public readonly file: GitFile, public readonly file: GitFile,
public commit: GitLogCommit, public commit: GitLogCommit,
@ -41,6 +39,10 @@ export class CommitFileNode extends ExplorerRefNode {
super(GitUri.fromFile(file, commit.repoPath, commit.sha), parent); super(GitUri.fromFile(file, commit.repoPath, commit.sha), parent);
} }
get priority(): number {
return 0;
}
get ref(): string { get ref(): string {
return this.commit.sha; return this.commit.sha;
} }
@ -132,7 +134,9 @@ export class CommitFileNode extends ExplorerRefNode {
} }
protected get resourceType(): ResourceType { 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; private _tooltip: string | undefined;

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

@ -19,6 +19,9 @@ export enum ResourceType {
Commits = 'gitlens:commits', Commits = 'gitlens:commits',
ComparisonResults = 'gitlens:results:comparison', ComparisonResults = 'gitlens:results:comparison',
FileHistory = 'gitlens:history-file', FileHistory = 'gitlens:history-file',
FileStaged = 'gitlens:file:staged',
FileStagedAndUnstaged = 'gitlens:file:staged:unstaged',
FileUnstaged = 'gitlens:file:unstaged',
Folder = 'gitlens:folder', Folder = 'gitlens:folder',
Message = 'gitlens:message', Message = 'gitlens:message',
Pager = 'gitlens:pager', Pager = 'gitlens:pager',
@ -34,9 +37,8 @@ export enum ResourceType {
Stash = 'gitlens:stash', Stash = 'gitlens:stash',
StashFile = 'gitlens:file:stash', StashFile = 'gitlens:file:stash',
Stashes = 'gitlens:stashes', Stashes = 'gitlens:stashes',
StatusFile = 'gitlens:file:status',
StatusFileCommits = 'gitlens:status:file:commits',
StatusFiles = 'gitlens:status:files', StatusFiles = 'gitlens:status:files',
StatusFileCommits = 'gitlens:status:file-commits',
StatusUpstream = 'gitlens:status:upstream', StatusUpstream = 'gitlens:status:upstream',
Tag = 'gitlens:tag', Tag = 'gitlens:tag',
Tags = 'gitlens:tags' 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 { export interface FileExplorerNode extends ExplorerNode {
folderName: string; folderName: string;
label?: string; label?: string;
priority: boolean;
priority: number;
relativePath?: string; relativePath?: string;
root?: Arrays.IHierarchicalItem<FileExplorerNode>; root?: Arrays.IHierarchicalItem<FileExplorerNode>;
} }
export class FolderNode extends ExplorerNode { export class FolderNode extends ExplorerNode {
readonly priority: boolean = true;
readonly priority: number = 1;
constructor( constructor(
public readonly repoPath: string, public readonly repoPath: string,
@ -60,7 +60,7 @@ export class FolderNode extends ExplorerNode {
children.sort((a, b) => { children.sort((a, b) => {
return ( return (
(a instanceof FolderNode ? -1 : 1) - (b instanceof FolderNode ? -1 : 1) || (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!) 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; this._label = undefined;
} }
get priority(): boolean {
return false;
get priority(): number {
return 0;
} }
getCommand(): Command | undefined { 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[]; children = (await root.getChildren()) as FileExplorerNode[];
} }
else { 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; return children;

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

@ -2,6 +2,7 @@
import * as path from 'path'; import * as path from 'path';
import { Command, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode'; import { Command, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
import { Commands, DiffWithPreviousCommandArgs } from '../../commands'; import { Commands, DiffWithPreviousCommandArgs } from '../../commands';
import { Container } from '../../container';
import { import {
GitFile, GitFile,
GitFileWithCommit, GitFileWithCommit,
@ -16,6 +17,9 @@ import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { ExplorerNode, ResourceType } from './explorerNode'; import { ExplorerNode, ResourceType } from './explorerNode';
export class StatusFileNode extends ExplorerNode { export class StatusFileNode extends ExplorerNode {
private readonly _hasStagedChanges: boolean = false;
private readonly _hasUnstagedChanges: boolean = false;
constructor( constructor(
public readonly repoPath: string, public readonly repoPath: string,
public readonly file: GitFile, public readonly file: GitFile,
@ -24,6 +28,17 @@ export class StatusFileNode extends ExplorerNode {
public readonly explorer: Explorer public readonly explorer: Explorer
) { ) {
super(GitUri.fromFile(file, repoPath, 'HEAD'), parent); 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[]> { async getChildren(): Promise<ExplorerNode[]> {
@ -45,36 +60,60 @@ export class StatusFileNode extends ExplorerNode {
async getTreeItem(): Promise<TreeItem> { async getTreeItem(): Promise<TreeItem> {
const item = new TreeItem(this.label, TreeItemCollapsibleState.None); 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( item.tooltip = StatusFileFormatter.fromTemplate(
'${file}\n${directory}/\n\n${status} in Index (staged)', '${file}\n${directory}/\n\n${status} in Index (staged)',
this.file this.file
); );
} }
else { else {
item.contextValue = ResourceType.FileUnstaged;
item.tooltip = StatusFileFormatter.fromTemplate( item.tooltip = StatusFileFormatter.fromTemplate(
'${file}\n${directory}/\n\n${status} in Working Tree', '${file}\n${directory}/\n\n${status} in Working Tree',
this.file 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(); item.command = this.getCommand();
} }
else { else {
item.collapsibleState = TreeItemCollapsibleState.Collapsed; 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( item.tooltip = StatusFileFormatter.fromTemplate(
`\${file}\n\${directory}/\n\n\${status} in ${this.getChangedIn()}`, `\${file}\n\${directory}/\n\n\${status} in ${this.getChangedIn()}`,
this.file 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 // Only cache the label for a single refresh
this._label = undefined; this._label = undefined;
@ -110,8 +149,11 @@ export class StatusFileNode extends ExplorerNode {
return this.commits[0]; 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; private _relativePath: string | undefined;
@ -125,20 +167,21 @@ export class StatusFileNode extends ExplorerNode {
private getChangedIn(): string { private getChangedIn(): string {
const changedIn = []; const changedIn = [];
let commits = 0; 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++; commits++;
changedIn.push('Index (staged)');
}
if (this.commits.length > commits) {
commits = this.commits.length - commits;
} }
if (commits > 0) { 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[]; children = (await root.getChildren()) as FileExplorerNode[];
} }
else { 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; return children;

Loading…
Cancel
Save