Browse Source

Converts ResourceType to enum

Removes ExplorerNode.resourceType
main
Eric Amodio 7 years ago
parent
commit
821b3edd3a
19 changed files with 54 additions and 78 deletions
  1. +3
    -3
      src/views/branchHistoryNode.ts
  2. +2
    -4
      src/views/branchesNode.ts
  3. +4
    -1
      src/views/commitFileNode.ts
  4. +1
    -2
      src/views/commitNode.ts
  5. +27
    -29
      src/views/explorerNode.ts
  6. +1
    -3
      src/views/fileHistoryNode.ts
  7. +1
    -2
      src/views/folderNode.ts
  8. +1
    -3
      src/views/historyNode.ts
  9. +1
    -3
      src/views/remoteNode.ts
  10. +1
    -3
      src/views/remotesNode.ts
  11. +1
    -3
      src/views/repositoriesNode.ts
  12. +1
    -3
      src/views/repositoryNode.ts
  13. +4
    -2
      src/views/stashFileNode.ts
  14. +1
    -3
      src/views/stashNode.ts
  15. +1
    -3
      src/views/stashesNode.ts
  16. +1
    -3
      src/views/statusFileCommitsNode.ts
  17. +1
    -2
      src/views/statusFilesNode.ts
  18. +1
    -3
      src/views/statusNode.ts
  19. +1
    -3
      src/views/statusUpstreamNode.ts

+ 3
- 3
src/views/branchHistoryNode.ts View File

@ -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'),

+ 2
- 4
src/views/branchesNode.ts View File

@ -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'),

+ 4
- 1
src/views/commitFileNode.ts View File

@ -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;
}

+ 1
- 2
src/views/commitNode.ts View File

@ -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')

+ 27
- 29
src/views/explorerNode.ts View File

@ -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<TreeItem> {
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<TreeItem> {
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'),

+ 1
- 3
src/views/fileHistoryNode.ts View File

@ -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'),

+ 1
- 2
src/views/folderNode.ts View File

@ -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<TreeItem> {
// 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;
}

+ 1
- 3
src/views/historyNode.ts View File

@ -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'),

+ 1
- 3
src/views/remoteNode.ts View File

@ -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'),

+ 1
- 3
src/views/remotesNode.ts View File

@ -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'),

+ 1
- 3
src/views/repositoriesNode.ts View File

@ -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;
}
}

+ 1
- 3
src/views/repositoryNode.ts View File

@ -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;
}

+ 4
- 2
src/views/stashFileNode.ts View File

@ -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;
}

+ 1
- 3
src/views/stashNode.ts View File

@ -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;
}
}

+ 1
- 3
src/views/stashesNode.ts View File

@ -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'),

+ 1
- 3
src/views/statusFileCommitsNode.ts View File

@ -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<TreeItem> {
const item = new TreeItem(this.label, TreeItemCollapsibleState.Collapsed);
item.contextValue = this.resourceType;
item.contextValue = ResourceType.StatusFileCommits;
const icon = getGitStatusIcon(this.status.status);
item.iconPath = {

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

@ -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`)

+ 1
- 3
src/views/statusNode.ts View File

@ -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`),

+ 1
- 3
src/views/statusUpstreamNode.ts View File

@ -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`),

Loading…
Cancel
Save