From 73614cbca3282f38de302ba30e9e82890e74e738 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 16 Sep 2018 03:25:27 -0400 Subject: [PATCH] Renames StatusFileNode to ResultsFileNode --- README.md | 2 +- package.json | 2 +- src/views/explorerCommands.ts | 16 +++--- src/views/nodes.ts | 2 +- src/views/nodes/resultsFileNode.ts | 101 ++++++++++++++++++++++++++++++++++++ src/views/nodes/resultsFilesNode.ts | 4 +- src/views/nodes/statusFileNode.ts | 101 ------------------------------------ 7 files changed, 114 insertions(+), 114 deletions(-) create mode 100644 src/views/nodes/resultsFileNode.ts delete mode 100644 src/views/nodes/statusFileNode.ts diff --git a/README.md b/README.md index c26947c..120492e 100644 --- a/README.md +++ b/README.md @@ -693,7 +693,7 @@ See also [Explorer Settings](#explorer-settings 'Jump to the Explorer settings') | `gitlens.explorers.defaultItemLimit` | Specifies the default number of items to show in an explorer list. Use 0 to specify no limit | | `gitlens.explorers.stashFileFormat` | Specifies the format of a stashed file in the _Repositories_ and _Results_ explorers
Available tokens
${directory} - directory name
${file} - file name
${filePath} - formatted file name and path
${path} - full file path | | `gitlens.explorers.stashFormat` | Specifies the format of stashed changes in the _Repositories_ and _Results_ explorers
Available tokens
${id} - commit id
${author} - commit author
${message} - commit message
${ago} - relative commit date (e.g. 1 day ago)
${date} - formatted commit date (format specified by `gitlens.statusBar.dateFormat`)
${agoOrDate} - commit date specified by `gitlens.defaultDateStyle`
${authorAgo} - commit author, relative commit date
${authorAgoOrDate} - commit author, commit date specified by `gitlens.defaultDateStyle`
See https://github.com/eamodio/vscode-gitlens/wiki/Advanced-Formatting for advanced formatting | -| `gitlens.explorers.statusFileFormat` | Specifies the format of the status of a working or committed file in the _Repositories_ and _Results_ explorers
Available tokens
${directory} - directory name
${file} - file name
${filePath} - formatted file name and path
${path} - full file path
${working} - optional indicator if the file is uncommitted | +| `gitlens.explorers.statusFileFormat` | Specifies the format of the status of a working or committed file in the _Repositories_ explorer
Available tokens
${directory} - directory name
${file} - file name
${filePath} - formatted file name and path
${path} - full file path
${working} - optional indicator if the file is uncommitted | ### Code Lens Settings diff --git a/package.json b/package.json index e7e845a..050ed11 100644 --- a/package.json +++ b/package.json @@ -476,7 +476,7 @@ "gitlens.explorers.statusFileFormat": { "type": "string", "default": "${working }${filePath}", - "description": "Specifies the format of the status of a working or committed file in the `Repositories` and `Results` explorers\nAvailable tokens\n ${directory} - directory name\n ${file} - file name\n ${filePath} - formatted file name and path\n ${path} - full file path\n ${working} - optional indicator if the file is uncommitted", + "description": "Specifies the format of the status of a working or committed file in the `Repositories` explorer\nAvailable tokens\n ${directory} - directory name\n ${file} - file name\n ${filePath} - formatted file name and path\n ${path} - full file path\n ${working} - optional indicator if the file is uncommitted", "scope": "window" }, "gitlens.repositoriesExplorer.autoRefresh": { diff --git a/src/views/explorerCommands.ts b/src/views/explorerCommands.ts index 8942a36..7ebc5ca 100644 --- a/src/views/explorerCommands.ts +++ b/src/views/explorerCommands.ts @@ -25,10 +25,10 @@ import { ExplorerRefNode, RemoteNode, RepositoryNode, + ResultsFileNode, StashFileNode, StashNode, StatusFileCommitsNode, - StatusFileNode, StatusUpstreamNode, TagNode } from './nodes'; @@ -124,7 +124,7 @@ export class ExplorerCommands implements Disposable { return node.push(); } - private async applyChanges(node: CommitFileNode | StashFileNode | StatusFileNode) { + private async applyChanges(node: CommitFileNode | StashFileNode | ResultsFileNode) { await this.openFile(node); if (node.uri.sha !== undefined && node.uri.sha !== 'HEAD') { @@ -220,7 +220,7 @@ export class ExplorerCommands implements Disposable { void commands.executeCommand(BuiltInCommands.FocusFilesExplorer); } - private openChanges(node: CommitFileNode | StashFileNode | StatusFileNode) { + private openChanges(node: CommitFileNode | StashFileNode | ResultsFileNode) { const command = node.getCommand(); if (command === undefined || command.arguments === undefined) return; @@ -229,7 +229,7 @@ export class ExplorerCommands implements Disposable { return commands.executeCommand(command.command, uri, args); } - private async openChangesWithWorking(node: CommitFileNode | StashFileNode | StatusFileNode) { + private async openChangesWithWorking(node: CommitFileNode | StashFileNode | ResultsFileNode) { const args: DiffWithWorkingCommandArgs = { showOptions: { preserveFocus: true, @@ -237,7 +237,7 @@ export class ExplorerCommands implements Disposable { } }; - if (node instanceof StatusFileNode) { + if (node instanceof ResultsFileNode) { args.commit = await Container.git.getLogCommitForFile(node.repoPath, node.uri.fsPath, { ref: node.uri.sha, firstIfNotFound: true, @@ -248,17 +248,17 @@ export class ExplorerCommands implements Disposable { return commands.executeCommand(Commands.DiffWithWorking, node.uri, args); } - private openFile(node: CommitFileNode | StashFileNode | StatusFileNode) { + private openFile(node: CommitFileNode | StashFileNode | ResultsFileNode) { return openEditor(node.uri, { preserveFocus: true, preview: false }); } private openFileRevision( - node: CommitFileNode | StashFileNode | StatusFileNode, + node: CommitFileNode | StashFileNode | ResultsFileNode, options: OpenFileRevisionCommandArgs = { showOptions: { preserveFocus: true, preview: false } } ) { let uri = options.uri; if (uri == null) { - if (node instanceof StatusFileNode) { + if (node instanceof ResultsFileNode) { uri = GitUri.toRevisionUri(node.uri); } else { diff --git a/src/views/nodes.ts b/src/views/nodes.ts index 95c293c..84d19bd 100644 --- a/src/views/nodes.ts +++ b/src/views/nodes.ts @@ -21,7 +21,7 @@ export * from './nodes/stashesNode'; export * from './nodes/stashFileNode'; export * from './nodes/stashNode'; export * from './nodes/statusFileCommitsNode'; -export * from './nodes/statusFileNode'; +export * from './nodes/resultsFileNode'; export * from './nodes/statusFilesNode'; export * from './nodes/resultsFilesNode'; export * from './nodes/statusUpstreamNode'; diff --git a/src/views/nodes/resultsFileNode.ts b/src/views/nodes/resultsFileNode.ts new file mode 100644 index 0000000..8001fb0 --- /dev/null +++ b/src/views/nodes/resultsFileNode.ts @@ -0,0 +1,101 @@ +'use strict'; +import * as path from 'path'; +import { Command, TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { Commands, DiffWithCommandArgs } from '../../commands'; +import { Container } from '../../container'; +import { GitFile, GitUri, IStatusFormatOptions, StatusFileFormatter } from '../../git/gitService'; +import { Explorer } from '../explorer'; +import { ExplorerNode, ResourceType } from './explorerNode'; + +export class ResultsFileNode extends ExplorerNode { + constructor( + public readonly repoPath: string, + private readonly _file: GitFile, + private readonly _ref1: string, + private readonly _ref2: string, + parent: ExplorerNode, + public readonly explorer: Explorer + ) { + super(GitUri.fromFile(_file, repoPath, _ref1 ? _ref1 : _ref2 ? _ref2 : undefined), parent); + } + + getChildren(): ExplorerNode[] { + return []; + } + + getTreeItem(): TreeItem { + const item = new TreeItem(this.label, TreeItemCollapsibleState.None); + item.contextValue = ResourceType.StatusFile; + item.tooltip = StatusFileFormatter.fromTemplate('${file}\n${directory}/\n\n${status}', this._file); + + const statusIcon = GitFile.getStatusIcon(this._file.status); + item.iconPath = { + dark: Container.context.asAbsolutePath(path.join('images', 'dark', statusIcon)), + light: Container.context.asAbsolutePath(path.join('images', 'light', statusIcon)) + }; + + item.command = this.getCommand(); + return item; + } + + private _folderName: string | undefined; + get folderName() { + if (this._folderName === undefined) { + this._folderName = path.dirname(this.uri.getRelativePath()); + } + return this._folderName; + } + + private _label: string | undefined; + get label() { + if (this._label === undefined) { + this._label = StatusFileFormatter.fromTemplate('${filePath}', this._file, { + relativePath: this.relativePath + } as IStatusFormatOptions); + } + return this._label; + } + + private _relativePath: string | undefined; + get relativePath(): string | undefined { + return this._relativePath; + } + set relativePath(value: string | undefined) { + this._relativePath = value; + this._label = undefined; + } + + get priority(): boolean { + return false; + } + + getCommand(): Command | undefined { + return { + title: 'Open Changes', + command: Commands.DiffWith, + arguments: [ + this.uri, + { + lhs: { + sha: this._ref1, + uri: this.uri + }, + rhs: { + sha: this._ref2, + uri: + this._file.status === 'R' + ? GitUri.fromFile(this._file, this.uri.repoPath!, this._ref2, true) + : this.uri + }, + repoPath: this.uri.repoPath!, + + line: 0, + showOptions: { + preserveFocus: true, + preview: true + } + } as DiffWithCommandArgs + ] + }; + } +} diff --git a/src/views/nodes/resultsFilesNode.ts b/src/views/nodes/resultsFilesNode.ts index dbc2117..3f1b0c1 100644 --- a/src/views/nodes/resultsFilesNode.ts +++ b/src/views/nodes/resultsFilesNode.ts @@ -8,7 +8,7 @@ import { Arrays, Iterables, Strings } from '../../system'; import { Explorer } from '../explorer'; import { ExplorerNode, ResourceType } from './explorerNode'; import { FileExplorerNode, FolderNode } from './folderNode'; -import { StatusFileNode } from './statusFileNode'; +import { ResultsFileNode } from './resultsFileNode'; export interface FilesQueryResults { label: string; @@ -33,7 +33,7 @@ export class ResultsFilesNode extends ExplorerNode { let children: FileExplorerNode[] = [ ...Iterables.map( diff, - s => new StatusFileNode(this.repoPath, s, this._ref1, this._ref2, this, this.explorer) + s => new ResultsFileNode(this.repoPath, s, this._ref1, this._ref2, this, this.explorer) ) ]; diff --git a/src/views/nodes/statusFileNode.ts b/src/views/nodes/statusFileNode.ts deleted file mode 100644 index 2684a3d..0000000 --- a/src/views/nodes/statusFileNode.ts +++ /dev/null @@ -1,101 +0,0 @@ -'use strict'; -import * as path from 'path'; -import { Command, TreeItem, TreeItemCollapsibleState } from 'vscode'; -import { Commands, DiffWithCommandArgs } from '../../commands'; -import { Container } from '../../container'; -import { GitFile, GitStatusFile, GitUri, IStatusFormatOptions, StatusFileFormatter } from '../../git/gitService'; -import { Explorer } from '../explorer'; -import { ExplorerNode, ResourceType } from './explorerNode'; - -export class StatusFileNode extends ExplorerNode { - constructor( - public readonly repoPath: string, - private readonly _file: GitStatusFile, - private readonly _ref1: string, - private readonly _ref2: string, - parent: ExplorerNode, - public readonly explorer: Explorer - ) { - super(GitUri.fromFile(_file, repoPath, _ref1 ? _ref1 : _ref2 ? _ref2 : undefined), parent); - } - - getChildren(): ExplorerNode[] { - return []; - } - - getTreeItem(): TreeItem { - const item = new TreeItem(this.label, TreeItemCollapsibleState.None); - item.contextValue = ResourceType.StatusFile; - item.tooltip = StatusFileFormatter.fromTemplate('${file}\n${directory}/\n\n${status}', this._file); - - const statusIcon = GitFile.getStatusIcon(this._file.status); - item.iconPath = { - dark: Container.context.asAbsolutePath(path.join('images', 'dark', statusIcon)), - light: Container.context.asAbsolutePath(path.join('images', 'light', statusIcon)) - }; - - item.command = this.getCommand(); - return item; - } - - private _folderName: string | undefined; - get folderName() { - if (this._folderName === undefined) { - this._folderName = path.dirname(this.uri.getRelativePath()); - } - return this._folderName; - } - - private _label: string | undefined; - get label() { - if (this._label === undefined) { - this._label = StatusFileFormatter.fromTemplate(this.explorer.config.statusFileFormat, this._file, { - relativePath: this.relativePath - } as IStatusFormatOptions); - } - return this._label; - } - - private _relativePath: string | undefined; - get relativePath(): string | undefined { - return this._relativePath; - } - set relativePath(value: string | undefined) { - this._relativePath = value; - this._label = undefined; - } - - get priority(): boolean { - return false; - } - - getCommand(): Command | undefined { - return { - title: 'Open Changes', - command: Commands.DiffWith, - arguments: [ - this.uri, - { - lhs: { - sha: this._ref1, - uri: this.uri - }, - rhs: { - sha: this._ref2, - uri: - this._file.status === 'R' - ? GitUri.fromFile(this._file, this.uri.repoPath!, this._ref2, true) - : this.uri - }, - repoPath: this.uri.repoPath!, - - line: 0, - showOptions: { - preserveFocus: true, - preview: true - } - } as DiffWithCommandArgs - ] - }; - } -}