Browse Source

Reworks ExplorerNode base class

Adds TextExplorerNode for messages
main
Eric Amodio 7 years ago
parent
commit
bcd83566a1
10 changed files with 49 additions and 31 deletions
  1. +4
    -4
      src/views/branchHistoryNode.ts
  2. +3
    -3
      src/views/branchesNode.ts
  3. +2
    -2
      src/views/commitFileNode.ts
  4. +3
    -4
      src/views/commitNode.ts
  5. +23
    -4
      src/views/explorerNode.ts
  6. +4
    -4
      src/views/fileHistoryNode.ts
  7. +2
    -2
      src/views/repositoryNode.ts
  8. +2
    -2
      src/views/stashCommitNode.ts
  9. +3
    -3
      src/views/stashNode.ts
  10. +3
    -3
      src/views/statusNode.ts

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

@ -10,15 +10,15 @@ export class BranchHistoryNode extends ExplorerNode {
readonly resourceType: ResourceType = 'branch-history';
constructor(public readonly branch: GitBranch, uri: GitUri, context: ExtensionContext, git: GitService) {
super(uri, context, git);
}
constructor(public readonly branch: GitBranch, uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
super(uri);
}
async getChildren(): Promise<CommitNode[]> {
const log = await this.git.getLogForRepo(this.uri.repoPath!, this.branch.name);
if (log === undefined) return [];
return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.context, this.git))];
return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.git.config.gitExplorer.commitFormat, this.context, this.git))];
}
getTreeItem(): TreeItem {

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

@ -9,9 +9,9 @@ export class BranchesNode extends ExplorerNode {
readonly resourceType: ResourceType = 'branches';
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
super(uri, context, git);
}
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
super(uri);
}
async getChildren(): Promise<BranchHistoryNode[]> {
const branches = await this.git.getBranches(this.uri.repoPath!);

+ 2
- 2
src/views/commitFileNode.ts View File

@ -9,8 +9,8 @@ export class CommitFileNode extends ExplorerNode {
readonly resourceType: ResourceType = 'commit-file';
constructor(public readonly status: IGitStatusFile, public commit: GitCommit, private template: string, context: ExtensionContext, git: GitService) {
super(new GitUri(Uri.file(path.resolve(commit.repoPath, status.fileName)), { repoPath: commit.repoPath, fileName: status.fileName, sha: commit.sha }), context, git);
constructor(public readonly status: IGitStatusFile, public commit: GitCommit, private template: string, protected readonly context: ExtensionContext, protected readonly git: GitService) {
super(new GitUri(Uri.file(path.resolve(commit.repoPath, status.fileName)), { repoPath: commit.repoPath, fileName: status.fileName, sha: commit.sha }));
}
getChildren(): Promise<ExplorerNode[]> {

+ 3
- 4
src/views/commitNode.ts View File

@ -9,9 +9,8 @@ export class CommitNode extends ExplorerNode {
readonly resourceType: ResourceType = 'commit';
constructor(public readonly commit: GitCommit, context: ExtensionContext, git: GitService) {
super(new GitUri(commit.uri, commit), context, git);
this.commit = commit;
constructor(public readonly commit: GitCommit, private template: string, protected readonly context: ExtensionContext, protected readonly git: GitService) {
super(new GitUri(commit.uri, commit));
}
async getChildren(): Promise<ExplorerNode[]> {
@ -25,7 +24,7 @@ export class CommitNode extends ExplorerNode {
}
getTreeItem(): TreeItem {
const label = CommitFormatter.fromTemplate(this.git.config.gitExplorer.commitFormat, this.commit, this.git.config.defaultDateFormat);
const label = CommitFormatter.fromTemplate(this.template, this.commit, this.git.config.defaultDateFormat);
const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed);
item.contextValue = this.resourceType;

+ 23
- 4
src/views/explorerNode.ts View File

@ -1,14 +1,14 @@
'use strict';
import { Command, Event, ExtensionContext, TreeItem } from 'vscode';
import { GitService, GitUri } from '../gitService';
import { Command, Event, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { GitUri } from '../gitService';
export declare type ResourceType = 'status' | 'branches' | 'repository' | 'branch-history' | 'file-history' | 'stash-history' | 'commit' | 'stash-commit' | 'commit-file';
export declare type ResourceType = 'text' | 'status' | 'branches' | 'repository' | 'branch-history' | 'file-history' | 'stash-history' | 'commit' | 'stash-commit' | 'commit-file';
export abstract class ExplorerNode {
abstract readonly resourceType: ResourceType;
constructor(public readonly uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) { }
constructor(public readonly uri: GitUri) { }
abstract getChildren(): ExplorerNode[] | Promise<ExplorerNode[]>;
abstract getTreeItem(): TreeItem | Promise<TreeItem>;
@ -20,4 +20,23 @@ export abstract class ExplorerNode {
onDidChangeTreeData?: Event<ExplorerNode>;
refresh?(): void;
}
export class TextExplorerNode extends ExplorerNode {
readonly resourceType: ResourceType = 'text';
constructor(private text: string) {
super(new GitUri());
}
getChildren(): ExplorerNode[] | Promise<ExplorerNode[]> {
return [];
}
getTreeItem(): TreeItem | Promise<TreeItem> {
const item = new TreeItem(this.text, TreeItemCollapsibleState.None);
item.contextValue = this.resourceType;
return item;
}
}

+ 4
- 4
src/views/fileHistoryNode.ts View File

@ -2,7 +2,7 @@
import { Iterables } from '../system';
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { CommitNode } from './commitNode';
import { ExplorerNode, ResourceType } from './explorerNode';
import { ExplorerNode, ResourceType, TextExplorerNode } from './explorerNode';
import { GitService, GitUri } from '../gitService';
export class FileHistoryNode extends ExplorerNode {
@ -10,15 +10,15 @@ export class FileHistoryNode extends ExplorerNode {
static readonly rootType: ResourceType = 'file-history';
readonly resourceType: ResourceType = 'file-history';
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
super(uri, context, git);
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
super(uri);
}
async getChildren(): Promise<CommitNode[]> {
const log = await this.git.getLogForFile(this.uri.repoPath, this.uri.fsPath, this.uri.sha);
if (log === undefined) return [];
return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.context, this.git))];
return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.git.config.gitExplorer.commitFormat, this.context, this.git))];
}
getTreeItem(): TreeItem {

+ 2
- 2
src/views/repositoryNode.ts View File

@ -11,8 +11,8 @@ export class RepositoryNode extends ExplorerNode {
static readonly rootType: ResourceType = 'repository';
readonly resourceType: ResourceType = 'repository';
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
super(uri, context, git);
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
super(uri);
}
async getChildren(): Promise<ExplorerNode[]> {

+ 2
- 2
src/views/stashCommitNode.ts View File

@ -13,8 +13,8 @@ export class StashCommitNode extends ExplorerNode {
return this._onDidChangeTreeData.event;
}
constructor(public readonly commit: GitStashCommit, context: ExtensionContext, git: GitService) {
super(new GitUri(commit.uri, commit), context, git);
constructor(public readonly commit: GitStashCommit, protected readonly context: ExtensionContext, protected readonly git: GitService) {
super(new GitUri(commit.uri, commit));
}
async getChildren(): Promise<CommitFileNode[]> {

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

@ -1,7 +1,7 @@
'use strict';
import { Iterables } from '../system';
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ExplorerNode, ResourceType } from './explorerNode';
import { ExplorerNode, ResourceType, TextExplorerNode } from './explorerNode';
import { GitService, GitUri } from '../gitService';
import { StashCommitNode } from './stashCommitNode';
@ -10,8 +10,8 @@ export class StashNode extends ExplorerNode {
static readonly rootType: ResourceType = 'stash-history';
readonly resourceType: ResourceType = 'stash-history';
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
super(uri, context, git);
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
super(uri);
}
async getChildren(): Promise<StashCommitNode[]> {

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

@ -8,9 +8,9 @@ export class StatusNode extends ExplorerNode {
readonly resourceType: ResourceType = 'status';
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
super(uri, context, git);
}
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
super(uri);
}
async getChildren(): Promise<ExplorerNode[]> {
return [];

||||||
x
 
000:0
Loading…
Cancel
Save