Skip to content

Commit

Permalink
Adds view reference to all ViewNodes
Browse files Browse the repository at this point in the history
Normalizes ctor parameters for ViewNodes
  • Loading branch information
eamodio committed Nov 8, 2018
1 parent 933cd10 commit 5e30864
Show file tree
Hide file tree
Showing 33 changed files with 242 additions and 227 deletions.
14 changes: 7 additions & 7 deletions src/views/nodes/branchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import { MessageNode, ShowMoreNode } from './common';
import { insertDateMarkers } from './helpers';
import { PageableViewNode, ResourceType, ViewNode, ViewRefNode } from './viewNode';

export class BranchNode extends ViewRefNode implements PageableViewNode {
export class BranchNode extends ViewRefNode<RepositoriesView> implements PageableViewNode {
readonly supportsPaging: boolean = true;
maxCount: number | undefined;

private _children: ViewNode[] | undefined;

constructor(
public readonly branch: GitBranch,
uri: GitUri,
view: RepositoriesView,
parent: ViewNode,
public readonly view: RepositoriesView,
public readonly branch: GitBranch,
private readonly _markCurrent: boolean = true
) {
super(uri, parent);
super(uri, view, parent);
}

get id(): string {
Expand Down Expand Up @@ -54,7 +54,7 @@ export class BranchNode extends ViewRefNode implements PageableViewNode {
maxCount: this.maxCount || this.view.config.defaultItemLimit,
ref: this.ref
});
if (log === undefined) return [new MessageNode(this, 'No commits could be found.')];
if (log === undefined) return [new MessageNode(this.view, this, 'No commits could be found.')];

const branches = await Container.git.getBranches(this.uri.repoPath);
// Get the sha length, since `git branch` can return variable length shas
Expand All @@ -75,14 +75,14 @@ export class BranchNode extends ViewRefNode implements PageableViewNode {
...insertDateMarkers(
Iterables.map(
log.commits.values(),
c => new CommitNode(c, this, this.view, this.branch, getBranchTips)
c => new CommitNode(this.view, this, c, this.branch, getBranchTips)
),
this
)
];

if (log.truncated) {
children.push(new ShowMoreNode('Commits', this, this.view));
children.push(new ShowMoreNode(this.view, this, 'Commits'));
}

this._children = children;
Expand Down
10 changes: 5 additions & 5 deletions src/views/nodes/branchOrTagFolderNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import { ResourceType, ViewNode } from './viewNode';

export class BranchOrTagFolderNode extends ViewNode {
constructor(
view: View,
parent: ViewNode,
public readonly type: 'branch' | 'remote-branch' | 'tag',
public readonly repoPath: string,
public readonly folderName: string,
public readonly relativePath: string | undefined,
public readonly root: Arrays.IHierarchicalItem<BranchNode | TagNode>,
parent: ViewNode,
public readonly view: View,
private readonly _expanded: boolean = false
) {
super(GitUri.fromRepoPath(repoPath), parent);
super(GitUri.fromRepoPath(repoPath), view, parent);
}

get id(): string {
Expand All @@ -38,13 +38,13 @@ export class BranchOrTagFolderNode extends ViewNode {
folder.descendants.some(n => n instanceof BranchNode && n.current);
children.push(
new BranchOrTagFolderNode(
this.view,
this,
this.type,
this.repoPath,
folder.name,
folder.relativePath,
folder,
this,
this.view,
expanded
)
);
Expand Down
12 changes: 6 additions & 6 deletions src/views/nodes/branchesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import { BranchNode } from './branchNode';
import { BranchOrTagFolderNode } from './branchOrTagFolderNode';
import { ResourceType, ViewNode } from './viewNode';

export class BranchesNode extends ViewNode {
export class BranchesNode extends ViewNode<RepositoriesView> {
private _children: ViewNode[] | undefined;

constructor(
uri: GitUri,
public readonly repo: Repository,
view: RepositoriesView,
parent: ViewNode,
public readonly view: RepositoriesView
public readonly repo: Repository
) {
super(uri, parent);
super(uri, view, parent);
}

get id(): string {
Expand All @@ -36,7 +36,7 @@ export class BranchesNode extends ViewNode {
const branchNodes = [
...Iterables.filterMap(
branches,
b => (b.remote ? undefined : new BranchNode(b, this.uri, this, this.view))
b => (b.remote ? undefined : new BranchNode(this.uri, this.view, this, b))
)
];
if (this.view.config.branches.layout === ViewBranchesLayout.List) return branchNodes;
Expand All @@ -48,7 +48,7 @@ export class BranchesNode extends ViewNode {
this.view.config.files.compact
);

const root = new BranchOrTagFolderNode('branch', this.repo.path, '', undefined, hierarchy, this, this.view);
const root = new BranchOrTagFolderNode(this.view, this, 'branch', this.repo.path, '', undefined, hierarchy);
this._children = await root.getChildren();
}
return this._children;
Expand Down
6 changes: 3 additions & 3 deletions src/views/nodes/commitFileNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ export enum CommitFileNodeDisplayAs {

export class CommitFileNode extends ViewRefNode {
constructor(
view: View,
parent: ViewNode,
public readonly file: GitFile,
public commit: GitLogCommit,
parent: ViewNode,
public readonly view: View,
private readonly _displayAs: CommitFileNodeDisplayAs,
private readonly _selection?: Selection
) {
super(GitUri.fromFile(file, commit.repoPath, commit.sha), parent);
super(GitUri.fromFile(file, commit.repoPath, commit.sha), view, parent);
}

get priority(): number {
Expand Down
10 changes: 5 additions & 5 deletions src/views/nodes/commitNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import { ResourceType, ViewNode, ViewRefNode } from './viewNode';

export class CommitNode extends ViewRefNode {
constructor(
public readonly commit: GitLogCommit,
view: View,
parent: ViewNode,
public readonly view: View,
public readonly commit: GitLogCommit,
public readonly branch?: GitBranch,
private readonly getBranchTips?: (sha: string) => string | undefined
) {
super(commit.toGitUri(), parent);
super(commit.toGitUri(), view, parent);
}

get ref(): string {
Expand All @@ -32,7 +32,7 @@ export class CommitNode extends ViewRefNode {
let children: FileNode[] = [
...Iterables.map(
commit.files,
s => new CommitFileNode(s, commit.toFileCommit(s), this, this.view, CommitFileNodeDisplayAs.File)
s => new CommitFileNode(this.view, this, s, commit.toFileCommit(s), CommitFileNodeDisplayAs.File)
)
];

Expand All @@ -44,7 +44,7 @@ export class CommitNode extends ViewRefNode {
this.view.config.files.compact
);

const root = new FolderNode(this.repoPath, '', undefined, hierarchy, this, this.view);
const root = new FolderNode(this.view, this, this.repoPath, '', hierarchy);
children = (await root.getChildren()) as FileNode[];
}
else {
Expand Down
27 changes: 15 additions & 12 deletions src/views/nodes/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ResourceType, unknownGitUri, ViewNode } from './viewNode';

export class MessageNode extends ViewNode {
constructor(
view: View,
parent: ViewNode,
private readonly _message: string,
private readonly _tooltip?: string,
Expand All @@ -19,7 +20,7 @@ export class MessageNode extends ViewNode {
}
| ThemeIcon
) {
super(unknownGitUri, parent);
super(unknownGitUri, view, parent);
}

getChildren(): ViewNode[] | Promise<ViewNode[]> {
Expand All @@ -37,6 +38,7 @@ export class MessageNode extends ViewNode {

export class CommandMessageNode extends MessageNode {
constructor(
view: View,
parent: ViewNode,
private readonly _command: Command,
message: string,
Expand All @@ -50,7 +52,7 @@ export class CommandMessageNode extends MessageNode {
}
| ThemeIcon
) {
super(parent, message, tooltip, iconPath);
super(view, parent, message, tooltip, iconPath);
}

getTreeItem(): TreeItem | Promise<TreeItem> {
Expand All @@ -69,6 +71,7 @@ export class CommandMessageNode extends MessageNode {

export class UpdateableMessageNode extends ViewNode {
constructor(
view: View,
parent: ViewNode,
public readonly id: string,
private _message: string,
Expand All @@ -82,7 +85,7 @@ export class UpdateableMessageNode extends ViewNode {
}
| ThemeIcon
) {
super(unknownGitUri, parent);
super(unknownGitUri, view, parent);
}

getChildren(): ViewNode[] | Promise<ViewNode[]> {
Expand Down Expand Up @@ -134,11 +137,11 @@ export abstract class PagerNode extends ViewNode {
protected _args: RefreshNodeCommandArgs = {};

constructor(
protected readonly message: string,
protected readonly parent: ViewNode,
protected readonly view: View
view: View,
parent: ViewNode,
protected readonly message: string
) {
super(unknownGitUri, parent);
super(unknownGitUri, view, parent);
}

getChildren(): ViewNode[] | Promise<ViewNode[]> {
Expand All @@ -160,19 +163,19 @@ export abstract class PagerNode extends ViewNode {
return {
title: 'Refresh',
command: this.view.getQualifiedCommand('refreshNode'),
arguments: [this.parent, this._args]
arguments: [this._parent, this._args]
} as Command;
}
}

export class ShowMoreNode extends PagerNode {
constructor(type: string, parent: ViewNode, view: View, maxCount: number = Container.config.advanced.maxListItems) {
constructor(view: View, parent: ViewNode, type: string, maxCount: number = Container.config.advanced.maxListItems) {
super(
view,
parent,
maxCount === 0
? `Show All ${type} ${GlyphChars.Space}${GlyphChars.Dash}${GlyphChars.Space} this may take a while`
: `Show More ${type}`,
parent,
view
: `Show More ${type}`
);
this._args.maxCount = maxCount;
}
Expand Down
24 changes: 8 additions & 16 deletions src/views/nodes/fileHistoryNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
import { Disposable, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import {
GitCommitType,
Expand All @@ -12,16 +11,16 @@ import {
RepositoryFileSystemChangeEvent
} from '../../git/gitService';
import { Logger } from '../../logger';
import { debug, gate, Iterables, log } from '../../system';
import { FileHistoryView } from '../fileHistoryView';
import { debug, Iterables } from '../../system';
import { View } from '../viewBase';
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { MessageNode } from './common';
import { insertDateMarkers } from './helpers';
import { ResourceType, SubscribeableViewNode, ViewNode } from './viewNode';

export class FileHistoryNode extends SubscribeableViewNode<FileHistoryView> {
constructor(uri: GitUri, parent: ViewNode, view: FileHistoryView) {
super(uri, parent, view);
export class FileHistoryNode extends SubscribeableViewNode {
constructor(uri: GitUri, view: View, parent: ViewNode) {
super(uri, view, parent);
}

async getChildren(): Promise<ViewNode[]> {
Expand Down Expand Up @@ -67,7 +66,7 @@ export class FileHistoryNode extends SubscribeableViewNode<FileHistoryView> {
previousSha,
status.originalFileName || status.fileName
);
children.push(new CommitFileNode(status, commit, this, this.view, displayAs));
children.push(new CommitFileNode(this.view, this, status, commit, displayAs));
}
}

Expand All @@ -79,14 +78,14 @@ export class FileHistoryNode extends SubscribeableViewNode<FileHistoryView> {
...insertDateMarkers(
Iterables.map(
log.commits.values(),
c => new CommitFileNode(c.files[0], c, this, this.view, displayAs)
c => new CommitFileNode(this.view, this, c.files[0], c, displayAs)
),
this
)
);
}

if (children.length === 0) return [new MessageNode(this, 'No file history could be found.')];
if (children.length === 0) return [new MessageNode(this.view, this, 'No file history could be found.')];
return children;
}

Expand Down Expand Up @@ -120,13 +119,6 @@ export class FileHistoryNode extends SubscribeableViewNode<FileHistoryView> {
return item;
}

@gate()
@log()
changeBase(ref: string | undefined) {
this.uri.sha = ref;
return this.triggerChange();
}

@debug()
protected async subscribe() {
const repo = await Container.git.getRepository(this.uri);
Expand Down
24 changes: 16 additions & 8 deletions src/views/nodes/fileHistoryTrackerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import { FileHistoryNode } from './fileHistoryNode';
import { ResourceType, SubscribeableViewNode, unknownGitUri, ViewNode } from './viewNode';

export class FileHistoryTrackerNode extends SubscribeableViewNode<FileHistoryView> {
private _base: string | undefined;
private _baseRef: string | undefined;
private _child: FileHistoryNode | undefined;

constructor(view: FileHistoryView) {
super(unknownGitUri, undefined, view);
super(unknownGitUri, view);
}

dispose() {
Expand All @@ -37,11 +37,18 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode<FileHistoryVie
async getChildren(): Promise<ViewNode[]> {
if (this._child === undefined) {
if (this.uri === unknownGitUri) {
return [new MessageNode(this, 'There are no editors open that can provide file history information.')];
return [
new MessageNode(
this.view,
this,
'There are no editors open that can provide file history information.'
)
];
}

const fileUri = new GitUri(this.uri, { ...this.uri, sha: this.uri.sha || this._base } as GitCommitish);
this._child = new FileHistoryNode(fileUri, this, this.view);
const uri = this.uri;
const fileUri = new GitUri(uri, { ...uri, sha: this._baseRef || uri.sha } as GitCommitish);
this._child = new FileHistoryNode(fileUri, this.view, this);
}

return [this._child];
Expand All @@ -62,15 +69,16 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode<FileHistoryVie
const pick = await new BranchesAndTagsQuickPick(this.uri.repoPath!).show(
`Change the file history base to${GlyphChars.Ellipsis}`,
{
checked: this._base
checked: this._baseRef
}
);
if (pick === undefined || pick instanceof CommandQuickPickItem) return;

this._base = pick.current ? undefined : pick.name;
this._baseRef = pick.current ? undefined : pick.name;
if (this._child === undefined) return;

await this._child.changeBase(this._base);
this._uri = unknownGitUri;
await this.triggerChange();
}

@gate()
Expand Down

0 comments on commit 5e30864

Please sign in to comment.