Skip to content

Commit 208d549

Browse files
committed
Reworks ExplorerNode base class
Adds TextExplorerNode for messages
1 parent 6518279 commit 208d549

File tree

10 files changed

+49
-31
lines changed

10 files changed

+49
-31
lines changed

src/views/branchHistoryNode.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ export class BranchHistoryNode extends ExplorerNode {
1010

1111
readonly resourceType: ResourceType = 'branch-history';
1212

13-
constructor(public readonly branch: GitBranch, uri: GitUri, context: ExtensionContext, git: GitService) {
14-
super(uri, context, git);
15-
}
13+
constructor(public readonly branch: GitBranch, uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
14+
super(uri);
15+
}
1616

1717
async getChildren(): Promise<CommitNode[]> {
1818
const log = await this.git.getLogForRepo(this.uri.repoPath!, this.branch.name);
1919
if (log === undefined) return [];
2020

21-
return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.context, this.git))];
21+
return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.git.config.gitExplorer.commitFormat, this.context, this.git))];
2222
}
2323

2424
getTreeItem(): TreeItem {

src/views/branchesNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ export class BranchesNode extends ExplorerNode {
99

1010
readonly resourceType: ResourceType = 'branches';
1111

12-
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
13-
super(uri, context, git);
14-
}
12+
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
13+
super(uri);
14+
}
1515

1616
async getChildren(): Promise<BranchHistoryNode[]> {
1717
const branches = await this.git.getBranches(this.uri.repoPath!);

src/views/commitFileNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export class CommitFileNode extends ExplorerNode {
99

1010
readonly resourceType: ResourceType = 'commit-file';
1111

12-
constructor(public readonly status: IGitStatusFile, public commit: GitCommit, private template: string, context: ExtensionContext, git: GitService) {
13-
super(new GitUri(Uri.file(path.resolve(commit.repoPath, status.fileName)), { repoPath: commit.repoPath, fileName: status.fileName, sha: commit.sha }), context, git);
12+
constructor(public readonly status: IGitStatusFile, public commit: GitCommit, private template: string, protected readonly context: ExtensionContext, protected readonly git: GitService) {
13+
super(new GitUri(Uri.file(path.resolve(commit.repoPath, status.fileName)), { repoPath: commit.repoPath, fileName: status.fileName, sha: commit.sha }));
1414
}
1515

1616
getChildren(): Promise<ExplorerNode[]> {

src/views/commitNode.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ export class CommitNode extends ExplorerNode {
99

1010
readonly resourceType: ResourceType = 'commit';
1111

12-
constructor(public readonly commit: GitCommit, context: ExtensionContext, git: GitService) {
13-
super(new GitUri(commit.uri, commit), context, git);
14-
this.commit = commit;
12+
constructor(public readonly commit: GitCommit, private template: string, protected readonly context: ExtensionContext, protected readonly git: GitService) {
13+
super(new GitUri(commit.uri, commit));
1514
}
1615

1716
async getChildren(): Promise<ExplorerNode[]> {
@@ -25,7 +24,7 @@ export class CommitNode extends ExplorerNode {
2524
}
2625

2726
getTreeItem(): TreeItem {
28-
const label = CommitFormatter.fromTemplate(this.git.config.gitExplorer.commitFormat, this.commit, this.git.config.defaultDateFormat);
27+
const label = CommitFormatter.fromTemplate(this.template, this.commit, this.git.config.defaultDateFormat);
2928

3029
const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed);
3130
item.contextValue = this.resourceType;

src/views/explorerNode.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
2-
import { Command, Event, ExtensionContext, TreeItem } from 'vscode';
3-
import { GitService, GitUri } from '../gitService';
2+
import { Command, Event, TreeItem, TreeItemCollapsibleState } from 'vscode';
3+
import { GitUri } from '../gitService';
44

5-
export declare type ResourceType = 'status' | 'branches' | 'repository' | 'branch-history' | 'file-history' | 'stash-history' | 'commit' | 'stash-commit' | 'commit-file';
5+
export declare type ResourceType = 'text' | 'status' | 'branches' | 'repository' | 'branch-history' | 'file-history' | 'stash-history' | 'commit' | 'stash-commit' | 'commit-file';
66

77
export abstract class ExplorerNode {
88

99
abstract readonly resourceType: ResourceType;
1010

11-
constructor(public readonly uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) { }
11+
constructor(public readonly uri: GitUri) { }
1212

1313
abstract getChildren(): ExplorerNode[] | Promise<ExplorerNode[]>;
1414
abstract getTreeItem(): TreeItem | Promise<TreeItem>;
@@ -20,4 +20,23 @@ export abstract class ExplorerNode {
2020
onDidChangeTreeData?: Event<ExplorerNode>;
2121

2222
refresh?(): void;
23+
}
24+
25+
export class TextExplorerNode extends ExplorerNode {
26+
27+
readonly resourceType: ResourceType = 'text';
28+
29+
constructor(private text: string) {
30+
super(new GitUri());
31+
}
32+
33+
getChildren(): ExplorerNode[] | Promise<ExplorerNode[]> {
34+
return [];
35+
}
36+
37+
getTreeItem(): TreeItem | Promise<TreeItem> {
38+
const item = new TreeItem(this.text, TreeItemCollapsibleState.None);
39+
item.contextValue = this.resourceType;
40+
return item;
41+
}
2342
}

src/views/fileHistoryNode.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
import { Iterables } from '../system';
33
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
44
import { CommitNode } from './commitNode';
5-
import { ExplorerNode, ResourceType } from './explorerNode';
5+
import { ExplorerNode, ResourceType, TextExplorerNode } from './explorerNode';
66
import { GitService, GitUri } from '../gitService';
77

88
export class FileHistoryNode extends ExplorerNode {
99

1010
static readonly rootType: ResourceType = 'file-history';
1111
readonly resourceType: ResourceType = 'file-history';
1212

13-
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
14-
super(uri, context, git);
13+
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
14+
super(uri);
1515
}
1616

1717
async getChildren(): Promise<CommitNode[]> {
1818
const log = await this.git.getLogForFile(this.uri.repoPath, this.uri.fsPath, this.uri.sha);
1919
if (log === undefined) return [];
2020

21-
return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.context, this.git))];
21+
return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.git.config.gitExplorer.commitFormat, this.context, this.git))];
2222
}
2323

2424
getTreeItem(): TreeItem {

src/views/repositoryNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export class RepositoryNode extends ExplorerNode {
1111
static readonly rootType: ResourceType = 'repository';
1212
readonly resourceType: ResourceType = 'repository';
1313

14-
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
15-
super(uri, context, git);
14+
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
15+
super(uri);
1616
}
1717

1818
async getChildren(): Promise<ExplorerNode[]> {

src/views/stashCommitNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export class StashCommitNode extends ExplorerNode {
1313
return this._onDidChangeTreeData.event;
1414
}
1515

16-
constructor(public readonly commit: GitStashCommit, context: ExtensionContext, git: GitService) {
17-
super(new GitUri(commit.uri, commit), context, git);
16+
constructor(public readonly commit: GitStashCommit, protected readonly context: ExtensionContext, protected readonly git: GitService) {
17+
super(new GitUri(commit.uri, commit));
1818
}
1919

2020
async getChildren(): Promise<CommitFileNode[]> {

src/views/stashNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
import { Iterables } from '../system';
33
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
4-
import { ExplorerNode, ResourceType } from './explorerNode';
4+
import { ExplorerNode, ResourceType, TextExplorerNode } from './explorerNode';
55
import { GitService, GitUri } from '../gitService';
66
import { StashCommitNode } from './stashCommitNode';
77

@@ -10,8 +10,8 @@ export class StashNode extends ExplorerNode {
1010
static readonly rootType: ResourceType = 'stash-history';
1111
readonly resourceType: ResourceType = 'stash-history';
1212

13-
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
14-
super(uri, context, git);
13+
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
14+
super(uri);
1515
}
1616

1717
async getChildren(): Promise<StashCommitNode[]> {

src/views/statusNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ export class StatusNode extends ExplorerNode {
88

99
readonly resourceType: ResourceType = 'status';
1010

11-
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
12-
super(uri, context, git);
13-
}
11+
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
12+
super(uri);
13+
}
1414

1515
async getChildren(): Promise<ExplorerNode[]> {
1616
return [];

0 commit comments

Comments
 (0)