mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 10:58:34 -05:00
Reworks ExplorerNode base class
Adds TextExplorerNode for messages
This commit is contained in:
@@ -10,15 +10,15 @@ export class BranchHistoryNode extends ExplorerNode {
|
|||||||
|
|
||||||
readonly resourceType: ResourceType = 'branch-history';
|
readonly resourceType: ResourceType = 'branch-history';
|
||||||
|
|
||||||
constructor(public readonly branch: GitBranch, uri: GitUri, context: ExtensionContext, git: GitService) {
|
constructor(public readonly branch: GitBranch, uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||||
super(uri, context, git);
|
super(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChildren(): Promise<CommitNode[]> {
|
async getChildren(): Promise<CommitNode[]> {
|
||||||
const log = await this.git.getLogForRepo(this.uri.repoPath!, this.branch.name);
|
const log = await this.git.getLogForRepo(this.uri.repoPath!, this.branch.name);
|
||||||
if (log === undefined) return [];
|
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 {
|
getTreeItem(): TreeItem {
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ export class BranchesNode extends ExplorerNode {
|
|||||||
|
|
||||||
readonly resourceType: ResourceType = 'branches';
|
readonly resourceType: ResourceType = 'branches';
|
||||||
|
|
||||||
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
|
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||||
super(uri, context, git);
|
super(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChildren(): Promise<BranchHistoryNode[]> {
|
async getChildren(): Promise<BranchHistoryNode[]> {
|
||||||
const branches = await this.git.getBranches(this.uri.repoPath!);
|
const branches = await this.git.getBranches(this.uri.repoPath!);
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ export class CommitFileNode extends ExplorerNode {
|
|||||||
|
|
||||||
readonly resourceType: ResourceType = 'commit-file';
|
readonly resourceType: ResourceType = 'commit-file';
|
||||||
|
|
||||||
constructor(public readonly status: IGitStatusFile, public commit: GitCommit, private template: string, context: ExtensionContext, git: GitService) {
|
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 }), context, git);
|
super(new GitUri(Uri.file(path.resolve(commit.repoPath, status.fileName)), { repoPath: commit.repoPath, fileName: status.fileName, sha: commit.sha }));
|
||||||
}
|
}
|
||||||
|
|
||||||
getChildren(): Promise<ExplorerNode[]> {
|
getChildren(): Promise<ExplorerNode[]> {
|
||||||
|
|||||||
@@ -9,9 +9,8 @@ export class CommitNode extends ExplorerNode {
|
|||||||
|
|
||||||
readonly resourceType: ResourceType = 'commit';
|
readonly resourceType: ResourceType = 'commit';
|
||||||
|
|
||||||
constructor(public readonly commit: GitCommit, context: ExtensionContext, git: GitService) {
|
constructor(public readonly commit: GitCommit, private template: string, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||||
super(new GitUri(commit.uri, commit), context, git);
|
super(new GitUri(commit.uri, commit));
|
||||||
this.commit = commit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChildren(): Promise<ExplorerNode[]> {
|
async getChildren(): Promise<ExplorerNode[]> {
|
||||||
@@ -25,7 +24,7 @@ export class CommitNode extends ExplorerNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getTreeItem(): TreeItem {
|
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);
|
const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed);
|
||||||
item.contextValue = this.resourceType;
|
item.contextValue = this.resourceType;
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Command, Event, ExtensionContext, TreeItem } from 'vscode';
|
import { Command, Event, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||||
import { GitService, GitUri } from '../gitService';
|
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 {
|
export abstract class ExplorerNode {
|
||||||
|
|
||||||
abstract readonly resourceType: ResourceType;
|
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 getChildren(): ExplorerNode[] | Promise<ExplorerNode[]>;
|
||||||
abstract getTreeItem(): TreeItem | Promise<TreeItem>;
|
abstract getTreeItem(): TreeItem | Promise<TreeItem>;
|
||||||
@@ -20,4 +20,23 @@ export abstract class ExplorerNode {
|
|||||||
onDidChangeTreeData?: Event<ExplorerNode>;
|
onDidChangeTreeData?: Event<ExplorerNode>;
|
||||||
|
|
||||||
refresh?(): void;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
import { Iterables } from '../system';
|
import { Iterables } from '../system';
|
||||||
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||||
import { CommitNode } from './commitNode';
|
import { CommitNode } from './commitNode';
|
||||||
import { ExplorerNode, ResourceType } from './explorerNode';
|
import { ExplorerNode, ResourceType, TextExplorerNode } from './explorerNode';
|
||||||
import { GitService, GitUri } from '../gitService';
|
import { GitService, GitUri } from '../gitService';
|
||||||
|
|
||||||
export class FileHistoryNode extends ExplorerNode {
|
export class FileHistoryNode extends ExplorerNode {
|
||||||
@@ -10,15 +10,15 @@ export class FileHistoryNode extends ExplorerNode {
|
|||||||
static readonly rootType: ResourceType = 'file-history';
|
static readonly rootType: ResourceType = 'file-history';
|
||||||
readonly resourceType: ResourceType = 'file-history';
|
readonly resourceType: ResourceType = 'file-history';
|
||||||
|
|
||||||
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
|
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||||
super(uri, context, git);
|
super(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChildren(): Promise<CommitNode[]> {
|
async getChildren(): Promise<CommitNode[]> {
|
||||||
const log = await this.git.getLogForFile(this.uri.repoPath, this.uri.fsPath, this.uri.sha);
|
const log = await this.git.getLogForFile(this.uri.repoPath, this.uri.fsPath, this.uri.sha);
|
||||||
if (log === undefined) return [];
|
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 {
|
getTreeItem(): TreeItem {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ export class RepositoryNode extends ExplorerNode {
|
|||||||
static readonly rootType: ResourceType = 'repository';
|
static readonly rootType: ResourceType = 'repository';
|
||||||
readonly resourceType: ResourceType = 'repository';
|
readonly resourceType: ResourceType = 'repository';
|
||||||
|
|
||||||
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
|
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||||
super(uri, context, git);
|
super(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChildren(): Promise<ExplorerNode[]> {
|
async getChildren(): Promise<ExplorerNode[]> {
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ export class StashCommitNode extends ExplorerNode {
|
|||||||
return this._onDidChangeTreeData.event;
|
return this._onDidChangeTreeData.event;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(public readonly commit: GitStashCommit, context: ExtensionContext, git: GitService) {
|
constructor(public readonly commit: GitStashCommit, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||||
super(new GitUri(commit.uri, commit), context, git);
|
super(new GitUri(commit.uri, commit));
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChildren(): Promise<CommitFileNode[]> {
|
async getChildren(): Promise<CommitFileNode[]> {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Iterables } from '../system';
|
import { Iterables } from '../system';
|
||||||
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||||
import { ExplorerNode, ResourceType } from './explorerNode';
|
import { ExplorerNode, ResourceType, TextExplorerNode } from './explorerNode';
|
||||||
import { GitService, GitUri } from '../gitService';
|
import { GitService, GitUri } from '../gitService';
|
||||||
import { StashCommitNode } from './stashCommitNode';
|
import { StashCommitNode } from './stashCommitNode';
|
||||||
|
|
||||||
@@ -10,8 +10,8 @@ export class StashNode extends ExplorerNode {
|
|||||||
static readonly rootType: ResourceType = 'stash-history';
|
static readonly rootType: ResourceType = 'stash-history';
|
||||||
readonly resourceType: ResourceType = 'stash-history';
|
readonly resourceType: ResourceType = 'stash-history';
|
||||||
|
|
||||||
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
|
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||||
super(uri, context, git);
|
super(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChildren(): Promise<StashCommitNode[]> {
|
async getChildren(): Promise<StashCommitNode[]> {
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ export class StatusNode extends ExplorerNode {
|
|||||||
|
|
||||||
readonly resourceType: ResourceType = 'status';
|
readonly resourceType: ResourceType = 'status';
|
||||||
|
|
||||||
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
|
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||||
super(uri, context, git);
|
super(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChildren(): Promise<ExplorerNode[]> {
|
async getChildren(): Promise<ExplorerNode[]> {
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
Reference in New Issue
Block a user