From 821b3edd3a1bd47d51b4a3d0dcd592c6d296259b Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 7 Nov 2017 14:22:35 -0500 Subject: [PATCH] Converts ResourceType to enum Removes ExplorerNode.resourceType --- src/views/branchHistoryNode.ts | 6 ++-- src/views/branchesNode.ts | 6 ++-- src/views/commitFileNode.ts | 5 +++- src/views/commitNode.ts | 3 +- src/views/explorerNode.ts | 56 ++++++++++++++++++-------------------- src/views/fileHistoryNode.ts | 4 +-- src/views/folderNode.ts | 3 +- src/views/historyNode.ts | 4 +-- src/views/remoteNode.ts | 4 +-- src/views/remotesNode.ts | 4 +-- src/views/repositoriesNode.ts | 4 +-- src/views/repositoryNode.ts | 4 +-- src/views/stashFileNode.ts | 6 ++-- src/views/stashNode.ts | 4 +-- src/views/stashesNode.ts | 4 +-- src/views/statusFileCommitsNode.ts | 4 +-- src/views/statusFilesNode.ts | 3 +- src/views/statusNode.ts | 4 +-- src/views/statusUpstreamNode.ts | 4 +-- 19 files changed, 54 insertions(+), 78 deletions(-) diff --git a/src/views/branchHistoryNode.ts b/src/views/branchHistoryNode.ts index 822f735..91f3244 100644 --- a/src/views/branchHistoryNode.ts +++ b/src/views/branchHistoryNode.ts @@ -9,8 +9,6 @@ import { GitBranch, GitUri } from '../gitService'; export class BranchHistoryNode extends ExplorerNode { - readonly resourceType: ResourceType = 'gitlens:branch-history'; - maxCount: number | undefined = undefined; constructor( @@ -38,7 +36,9 @@ export class BranchHistoryNode extends ExplorerNode { name += ` ${GlyphChars.Space}${GlyphChars.ArrowLeftRight}${GlyphChars.Space} ${this.branch.tracking}`; } const item = new TreeItem(`${this.branch!.current ? `${GlyphChars.Check} ${GlyphChars.Space}` : ''}${name}`, TreeItemCollapsibleState.Collapsed); - item.contextValue = this.branch.tracking ? `${this.resourceType}:remote` : this.resourceType; + item.contextValue = this.branch.tracking + ? ResourceType.RemoteBranchHistory + : ResourceType.BranchHistory; item.iconPath = { dark: this.explorer.context.asAbsolutePath('images/dark/icon-branch.svg'), diff --git a/src/views/branchesNode.ts b/src/views/branchesNode.ts index 12f53e7..fbdff24 100644 --- a/src/views/branchesNode.ts +++ b/src/views/branchesNode.ts @@ -8,8 +8,6 @@ import { GitUri, Repository } from '../gitService'; export class BranchesNode extends ExplorerNode { - readonly resourceType: ResourceType = 'gitlens:branches'; - constructor( uri: GitUri, private readonly repo: Repository, @@ -31,8 +29,8 @@ export class BranchesNode extends ExplorerNode { const remotes = await this.repo.getRemotes(); item.contextValue = (remotes !== undefined && remotes.length > 0) - ? `${this.resourceType}:remote` - : this.resourceType; + ? ResourceType.RemoteBranches + : ResourceType.Branches; item.iconPath = { dark: this.explorer.context.asAbsolutePath('images/dark/icon-branch.svg'), diff --git a/src/views/commitFileNode.ts b/src/views/commitFileNode.ts index b8bc212..c060090 100644 --- a/src/views/commitFileNode.ts +++ b/src/views/commitFileNode.ts @@ -20,7 +20,6 @@ export class CommitFileNode extends ExplorerNode { readonly priority: boolean = false; readonly repoPath: string; - readonly resourceType: ResourceType = 'gitlens:commit-file'; constructor( public readonly status: IGitStatusFile, @@ -97,6 +96,10 @@ export class CommitFileNode extends ExplorerNode { this._label = undefined; } + protected get resourceType(): ResourceType { + return ResourceType.CommitFile; + } + protected getCommitTemplate() { return this.explorer.config.commitFormat; } diff --git a/src/views/commitNode.ts b/src/views/commitNode.ts index 8883105..a87bde9 100644 --- a/src/views/commitNode.ts +++ b/src/views/commitNode.ts @@ -13,7 +13,6 @@ import * as path from 'path'; export class CommitNode extends ExplorerNode { readonly repoPath: string; - readonly resourceType: ResourceType = 'gitlens:commit'; constructor( public readonly commit: GitLogCommit, @@ -56,7 +55,7 @@ export class CommitNode extends ExplorerNode { dataFormat: this.explorer.git.config.defaultDateFormat } as ICommitFormatOptions), TreeItemCollapsibleState.Collapsed); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.Commit; item.iconPath = { dark: this.explorer.context.asAbsolutePath('images/dark/icon-commit.svg'), light: this.explorer.context.asAbsolutePath('images/light/icon-commit.svg') diff --git a/src/views/explorerNode.ts b/src/views/explorerNode.ts index 789355a..8b94dc7 100644 --- a/src/views/explorerNode.ts +++ b/src/views/explorerNode.ts @@ -4,35 +4,36 @@ import { GlyphChars } from '../constants'; import { GitUri } from '../gitService'; import { RefreshNodeCommandArgs } from './gitExplorer'; -export declare type ResourceType = - 'gitlens:branches' | - 'gitlens:branch-history' | - 'gitlens:commit' | - 'gitlens:commit-file' | - 'gitlens:file-history' | - 'gitlens:folder' | - 'gitlens:history' | - 'gitlens:message' | - 'gitlens:pager' | - 'gitlens:remote' | - 'gitlens:remotes' | - 'gitlens:repositories' | - 'gitlens:repository' | - 'gitlens:stash' | - 'gitlens:stash-file' | - 'gitlens:stashes' | - 'gitlens:status' | - 'gitlens:status-file' | - 'gitlens:status-files' | - 'gitlens:status-file-commits' | - 'gitlens:status-upstream'; +export enum ResourceType { + Branches = 'gitlens:branches', + RemoteBranches = 'gitlens:branches:remote', + BranchHistory = 'gitlens:branch-history', + RemoteBranchHistory = 'gitlens:branch-history:remote', + Commit = 'gitlens:commit', + CommitFile = 'gitlens:commit-file', + FileHistory = 'gitlens:file-history', + Folder = 'gitlens:folder', + History = 'gitlens:history', + Message = 'gitlens:message', + Pager = 'gitlens:pager', + Remote = 'gitlens:remote', + Remotes = 'gitlens:remotes', + Repositories = 'gitlens:repositories', + Repository = 'gitlens:repository', + Stash = 'gitlens:stash', + StashFile = 'gitlens:stash-file', + Stashes = 'gitlens:stashes', + Status = 'gitlens:status', + StatusFile = 'gitlens:status-file', + StatusFiles = 'gitlens:status-files', + StatusFileCommits = 'gitlens:status-file-commits', + StatusUpstream = 'gitlens:status-upstream' +} // let id = 0; export abstract class ExplorerNode extends Disposable { - abstract readonly resourceType: ResourceType; - protected children: ExplorerNode[] | undefined; protected disposable: Disposable | undefined; // protected readonly id: number; @@ -70,8 +71,6 @@ export abstract class ExplorerNode extends Disposable { export class MessageNode extends ExplorerNode { - readonly resourceType: ResourceType = 'gitlens:message'; - constructor( private readonly message: string ) { @@ -84,14 +83,13 @@ export class MessageNode extends ExplorerNode { getTreeItem(): TreeItem | Promise { const item = new TreeItem(this.message, TreeItemCollapsibleState.None); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.Message; return item; } } export class PagerNode extends ExplorerNode { - readonly resourceType: ResourceType = 'gitlens:pager'; args: RefreshNodeCommandArgs = {}; constructor( @@ -108,7 +106,7 @@ export class PagerNode extends ExplorerNode { getTreeItem(): TreeItem | Promise { const item = new TreeItem(this.message, TreeItemCollapsibleState.None); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.Pager; item.command = this.getCommand(); item.iconPath = { dark: this.context.asAbsolutePath('images/dark/icon-unfold.svg'), diff --git a/src/views/fileHistoryNode.ts b/src/views/fileHistoryNode.ts index 37526ff..530d817 100644 --- a/src/views/fileHistoryNode.ts +++ b/src/views/fileHistoryNode.ts @@ -9,8 +9,6 @@ import { Logger } from '../logger'; export class FileHistoryNode extends ExplorerNode { - readonly resourceType: ResourceType = 'gitlens:file-history'; - constructor( uri: GitUri, private readonly repo: Repository, @@ -32,7 +30,7 @@ export class FileHistoryNode extends ExplorerNode { this.updateSubscription(); const item = new TreeItem(`${this.uri.getFormattedPath()}`, TreeItemCollapsibleState.Expanded); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.FileHistory; item.iconPath = { dark: this.explorer.context.asAbsolutePath('images/dark/icon-history.svg'), diff --git a/src/views/folderNode.ts b/src/views/folderNode.ts index 1db3e06..4a28b9a 100644 --- a/src/views/folderNode.ts +++ b/src/views/folderNode.ts @@ -17,7 +17,6 @@ export interface IFileExplorerNode extends ExplorerNode { export class FolderNode extends ExplorerNode { readonly priority: boolean = true; - readonly resourceType: ResourceType = 'gitlens:folder'; constructor( public readonly repoPath: string, @@ -64,7 +63,7 @@ export class FolderNode extends ExplorerNode { async getTreeItem(): Promise { // TODO: Change this to expanded once https://github.com/Microsoft/vscode/issues/30918 is fixed const item = new TreeItem(this.label, TreeItemCollapsibleState.Collapsed); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.Folder; return item; } diff --git a/src/views/historyNode.ts b/src/views/historyNode.ts index 07806c1..8242e27 100644 --- a/src/views/historyNode.ts +++ b/src/views/historyNode.ts @@ -7,8 +7,6 @@ import { GitExplorer } from './gitExplorer'; export class HistoryNode extends ExplorerNode { - readonly resourceType: ResourceType = 'gitlens:history'; - constructor( uri: GitUri, private readonly repo: Repository, @@ -28,7 +26,7 @@ export class HistoryNode extends ExplorerNode { getTreeItem(): TreeItem { const item = new TreeItem(`${this.uri.getFormattedPath()}`, TreeItemCollapsibleState.Expanded); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.History; item.iconPath = { dark: this.explorer.context.asAbsolutePath('images/dark/icon-history.svg'), diff --git a/src/views/remoteNode.ts b/src/views/remoteNode.ts index 91891c1..0be14a3 100644 --- a/src/views/remoteNode.ts +++ b/src/views/remoteNode.ts @@ -9,8 +9,6 @@ import { GitRemote, GitRemoteType, GitUri, Repository } from '../gitService'; export class RemoteNode extends ExplorerNode { - readonly resourceType: ResourceType = 'gitlens:remote'; - constructor( public readonly remote: GitRemote, uri: GitUri, @@ -49,7 +47,7 @@ export class RemoteNode extends ExplorerNode { const label = `${this.remote.name} ${GlyphChars.Space}${separator}${GlyphChars.Space} ${(this.remote.provider !== undefined) ? this.remote.provider.name : this.remote.domain} ${GlyphChars.Space}${GlyphChars.Dot}${GlyphChars.Space} ${this.remote.path}`; const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.Remote; // item.iconPath = { // dark: this.context.asAbsolutePath('images/dark/icon-remote.svg'), diff --git a/src/views/remotesNode.ts b/src/views/remotesNode.ts index 9a19f7a..de084d6 100644 --- a/src/views/remotesNode.ts +++ b/src/views/remotesNode.ts @@ -8,8 +8,6 @@ import { RemoteNode } from './remoteNode'; export class RemotesNode extends ExplorerNode { - readonly resourceType: ResourceType = 'gitlens:remotes'; - constructor( uri: GitUri, private readonly repo: Repository, @@ -28,7 +26,7 @@ export class RemotesNode extends ExplorerNode { getTreeItem(): TreeItem { const item = new TreeItem(`Remotes`, TreeItemCollapsibleState.Collapsed); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.Remotes; item.iconPath = { dark: this.explorer.context.asAbsolutePath('images/dark/icon-remote.svg'), diff --git a/src/views/repositoriesNode.ts b/src/views/repositoriesNode.ts index 7470449..e21eab4 100644 --- a/src/views/repositoriesNode.ts +++ b/src/views/repositoriesNode.ts @@ -7,8 +7,6 @@ import { RepositoryNode } from './repositoryNode'; export class RepositoriesNode extends ExplorerNode { - readonly resourceType: ResourceType = 'gitlens:repositories'; - constructor( private readonly repositories: Repository[], private readonly explorer: GitExplorer @@ -27,7 +25,7 @@ export class RepositoriesNode extends ExplorerNode { getTreeItem(): TreeItem { const item = new TreeItem(`Repositories`, TreeItemCollapsibleState.Expanded); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.Repositories; return item; } } \ No newline at end of file diff --git a/src/views/repositoryNode.ts b/src/views/repositoryNode.ts index e91162c..954e43f 100644 --- a/src/views/repositoryNode.ts +++ b/src/views/repositoryNode.ts @@ -13,8 +13,6 @@ import { Logger } from '../logger'; export class RepositoryNode extends ExplorerNode { - readonly resourceType: ResourceType = 'gitlens:repository'; - constructor( uri: GitUri, private readonly repo: Repository, @@ -40,7 +38,7 @@ export class RepositoryNode extends ExplorerNode { this.updateSubscription(); const item = new TreeItem(`Repository ${Strings.pad(GlyphChars.Dash, 1, 1)} ${this.repo.name || this.uri.repoPath}`, TreeItemCollapsibleState.Expanded); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.Repository; return item; } diff --git a/src/views/stashFileNode.ts b/src/views/stashFileNode.ts index 179f7a0..1ff8472 100644 --- a/src/views/stashFileNode.ts +++ b/src/views/stashFileNode.ts @@ -6,8 +6,6 @@ import { GitLogCommit, IGitStatusFile } from '../gitService'; export class StashFileNode extends CommitFileNode { - readonly resourceType: ResourceType = 'gitlens:stash-file'; - constructor( status: IGitStatusFile, commit: GitLogCommit, @@ -16,6 +14,10 @@ export class StashFileNode extends CommitFileNode { super(status, commit, explorer, CommitFileNodeDisplayAs.File); } + protected get resourceType(): ResourceType { + return ResourceType.StashFile; + } + protected getCommitTemplate() { return this.explorer.config.stashFormat; } diff --git a/src/views/stashNode.ts b/src/views/stashNode.ts index 40e1f01..7184bdc 100644 --- a/src/views/stashNode.ts +++ b/src/views/stashNode.ts @@ -8,8 +8,6 @@ import { StashFileNode } from './stashFileNode'; export class StashNode extends ExplorerNode { - readonly resourceType: ResourceType = 'gitlens:stash'; - constructor( public readonly commit: GitStashCommit, private readonly explorer: GitExplorer @@ -41,7 +39,7 @@ export class StashNode extends ExplorerNode { truncateMessageAtNewLine: true, dataFormat: this.explorer.git.config.defaultDateFormat } as ICommitFormatOptions), TreeItemCollapsibleState.Collapsed); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.Stash; return item; } } \ No newline at end of file diff --git a/src/views/stashesNode.ts b/src/views/stashesNode.ts index b862929..960bd02 100644 --- a/src/views/stashesNode.ts +++ b/src/views/stashesNode.ts @@ -8,8 +8,6 @@ import { StashNode } from './stashNode'; export class StashesNode extends ExplorerNode { - readonly resourceType: ResourceType = 'gitlens:stashes'; - constructor( uri: GitUri, private readonly repo: Repository, @@ -27,7 +25,7 @@ export class StashesNode extends ExplorerNode { getTreeItem(): TreeItem { const item = new TreeItem(`Stashes`, TreeItemCollapsibleState.Collapsed); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.Stashes; item.iconPath = { dark: this.explorer.context.asAbsolutePath('images/dark/icon-stash.svg'), diff --git a/src/views/statusFileCommitsNode.ts b/src/views/statusFileCommitsNode.ts index afce748..ec32725 100644 --- a/src/views/statusFileCommitsNode.ts +++ b/src/views/statusFileCommitsNode.ts @@ -9,8 +9,6 @@ import * as path from 'path'; export class StatusFileCommitsNode extends ExplorerNode { - readonly resourceType: ResourceType = 'gitlens:status-file-commits'; - constructor( public readonly repoPath: string, public readonly status: IGitStatusFile, @@ -27,7 +25,7 @@ export class StatusFileCommitsNode extends ExplorerNode { async getTreeItem(): Promise { const item = new TreeItem(this.label, TreeItemCollapsibleState.Collapsed); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.StatusFileCommits; const icon = getGitStatusIcon(this.status.status); item.iconPath = { diff --git a/src/views/statusFilesNode.ts b/src/views/statusFilesNode.ts index ccb28aa..1284ade 100644 --- a/src/views/statusFilesNode.ts +++ b/src/views/statusFilesNode.ts @@ -12,7 +12,6 @@ import * as path from 'path'; export class StatusFilesNode extends ExplorerNode { readonly repoPath: string; - readonly resourceType: ResourceType = 'gitlens:status-files'; maxCount: number | undefined = undefined; @@ -88,7 +87,7 @@ export class StatusFilesNode extends ExplorerNode { const label = `${files} file${files > 1 ? 's' : ''} changed`; // ${this.status.upstream === undefined ? '' : ` (ahead of ${this.status.upstream})`}`; const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.StatusFiles; item.iconPath = { dark: this.explorer.context.asAbsolutePath(`images/dark/icon-diff.svg`), light: this.explorer.context.asAbsolutePath(`images/light/icon-diff.svg`) diff --git a/src/views/statusNode.ts b/src/views/statusNode.ts index 13797b7..18e8393 100644 --- a/src/views/statusNode.ts +++ b/src/views/statusNode.ts @@ -8,8 +8,6 @@ import { StatusUpstreamNode } from './statusUpstreamNode'; export class StatusNode extends ExplorerNode { - readonly resourceType: ResourceType = 'gitlens:status'; - constructor( uri: GitUri, private readonly repo: Repository, @@ -96,7 +94,7 @@ export class StatusNode extends ExplorerNode { } const item = new TreeItem(label, (hasChildren || hasWorkingChanges) ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.None); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.Status; item.iconPath = { dark: this.explorer.context.asAbsolutePath(`images/dark/icon-repo${iconSuffix}.svg`), diff --git a/src/views/statusUpstreamNode.ts b/src/views/statusUpstreamNode.ts index 49724d8..4166c34 100644 --- a/src/views/statusUpstreamNode.ts +++ b/src/views/statusUpstreamNode.ts @@ -8,8 +8,6 @@ import { GitStatus, GitUri } from '../gitService'; export class StatusUpstreamNode extends ExplorerNode { - readonly resourceType: ResourceType = 'gitlens:status-upstream'; - constructor( public readonly status: GitStatus, public readonly direction: 'ahead' | 'behind', @@ -47,7 +45,7 @@ export class StatusUpstreamNode extends ExplorerNode { : `${this.status.state.behind} commit${this.status.state.behind > 1 ? 's' : ''} (behind ${this.status.upstream})`; const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed); - item.contextValue = this.resourceType; + item.contextValue = ResourceType.StatusUpstream; item.iconPath = { dark: this.explorer.context.asAbsolutePath(`images/dark/icon-${this.direction === 'ahead' ? 'upload' : 'download'}.svg`),