Skip to content

Commit 77ae37c

Browse files
committed
Adds rudimentary "paging" to custom view branch history
1 parent e20ec55 commit 77ae37c

File tree

6 files changed

+77
-19
lines changed

6 files changed

+77
-19
lines changed

images/dark/icon-sync.svg

Lines changed: 4 additions & 0 deletions
Loading

images/light/icon-sync.svg

Lines changed: 4 additions & 0 deletions
Loading

src/views/branchHistoryNode.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,27 @@ import { Iterables } from '../system';
33
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
44
import { CommitNode } from './commitNode';
55
import { GlyphChars } from '../constants';
6-
import { ExplorerNode, ResourceType } from './explorerNode';
6+
import { ExplorerNode, ResourceType, ShowAllCommitsNode } from './explorerNode';
77
import { GitBranch, GitService, GitUri } from '../gitService';
88

99
export class BranchHistoryNode extends ExplorerNode {
1010

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

13+
maxCount: number | undefined = undefined;
14+
1315
constructor(public readonly branch: GitBranch, uri: GitUri, private readonly template: string, protected readonly context: ExtensionContext, protected readonly git: GitService) {
1416
super(uri);
1517
}
1618

1719
async getChildren(): Promise<ExplorerNode[]> {
18-
const log = await this.git.getLogForRepo(this.uri.repoPath!, this.branch.name, 0);
20+
const log = await this.git.getLogForRepo(this.uri.repoPath!, this.branch.name, this.maxCount);
1921
if (log === undefined) return [];
2022

21-
return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.template, this.context, this.git))];
23+
const children = Iterables.map(log.commits.values(), c => new CommitNode(c, this.template, this.context, this.git));
24+
if (!log.truncated) return [...children];
25+
26+
return [...children, new ShowAllCommitsNode(this, this.context)];
2227
}
2328

2429
async getTreeItem(): Promise<TreeItem> {

src/views/explorerNode.ts

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
2-
import { Command, Event, TreeItem, TreeItemCollapsibleState } from 'vscode';
2+
import { Command, ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
3+
import { GlyphChars } from '../constants';
34
import { GitUri } from '../gitService';
5+
import { RefreshNodeCommandArgs } from './gitExplorer';
46

57
export declare type ResourceType =
68
'gitlens:branches' |
@@ -10,6 +12,7 @@ export declare type ResourceType =
1012
'gitlens:file-history' |
1113
'gitlens:history' |
1214
'gitlens:message' |
15+
'gitlens:pager' |
1316
'gitlens:remote' |
1417
'gitlens:remotes' |
1518
'gitlens:repository' |
@@ -31,10 +34,6 @@ export abstract class ExplorerNode {
3134
getCommand(): Command | undefined {
3235
return undefined;
3336
}
34-
35-
onDidChangeTreeData?: Event<ExplorerNode>;
36-
37-
refresh?(): void;
3837
}
3938

4039
export class MessageNode extends ExplorerNode {
@@ -54,4 +53,46 @@ export class MessageNode extends ExplorerNode {
5453
item.contextValue = this.resourceType;
5554
return item;
5655
}
56+
}
57+
58+
export class PagerNode extends ExplorerNode {
59+
60+
readonly resourceType: ResourceType = 'gitlens:pager';
61+
args: RefreshNodeCommandArgs = {};
62+
63+
constructor(private message: string, private node: ExplorerNode, protected readonly context: ExtensionContext) {
64+
super(new GitUri());
65+
}
66+
67+
getChildren(): ExplorerNode[] | Promise<ExplorerNode[]> {
68+
return [];
69+
}
70+
71+
getTreeItem(): TreeItem | Promise<TreeItem> {
72+
const item = new TreeItem(this.message, TreeItemCollapsibleState.None);
73+
item.contextValue = this.resourceType;
74+
item.command = this.getCommand();
75+
item.iconPath = {
76+
dark: this.context.asAbsolutePath('images/dark/icon-sync.svg'),
77+
light: this.context.asAbsolutePath('images/light/icon-sync.svg')
78+
};
79+
return item;
80+
}
81+
82+
getCommand(): Command | undefined {
83+
return {
84+
title: 'Refresh',
85+
command: 'gitlens.gitExplorer.refreshNode',
86+
arguments: [this.node, this.args]
87+
} as Command;
88+
}
89+
}
90+
91+
export class ShowAllCommitsNode extends PagerNode {
92+
93+
args: RefreshNodeCommandArgs = { maxCount: 0 };
94+
95+
constructor(node: ExplorerNode, context: ExtensionContext) {
96+
super(`Show All Commits ${GlyphChars.Space}${GlyphChars.Dash}${GlyphChars.Space} this may take a while`, node, context);
97+
}
5798
}

src/views/gitExplorer.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Commands, DiffWithPreviousCommandArgs, DiffWithWorkingCommandArgs, open
55
import { UriComparer } from '../comparers';
66
import { ExtensionKey, IConfig } from '../configuration';
77
import { CommandContext, setCommandContext } from '../constants';
8-
import { CommitFileNode, CommitNode, ExplorerNode, HistoryNode, MessageNode, RepositoryNode, StashNode } from './explorerNodes';
8+
import { BranchHistoryNode, CommitFileNode, CommitNode, ExplorerNode, HistoryNode, MessageNode, RepositoryNode, StashNode } from './explorerNodes';
99
import { GitService, GitUri, RepoChangedReasons } from '../gitService';
1010

1111
export * from './explorerNodes';
@@ -23,6 +23,10 @@ export interface OpenFileRevisionCommandArgs {
2323
showOptions?: TextDocumentShowOptions;
2424
}
2525

26+
export interface RefreshNodeCommandArgs {
27+
maxCount?: number;
28+
}
29+
2630
export class GitExplorer implements TreeDataProvider<ExplorerNode> {
2731

2832
private _config: IConfig;
@@ -38,6 +42,7 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
3842
commands.registerCommand('gitlens.gitExplorer.switchToHistoryView', () => this.switchTo(GitExplorerView.History), this);
3943
commands.registerCommand('gitlens.gitExplorer.switchToRepositoryView', () => this.switchTo(GitExplorerView.Repository), this);
4044
commands.registerCommand('gitlens.gitExplorer.refresh', this.refresh, this);
45+
commands.registerCommand('gitlens.gitExplorer.refreshNode', this.refreshNode, this);
4146
commands.registerCommand('gitlens.gitExplorer.openChanges', this.openChanges, this);
4247
commands.registerCommand('gitlens.gitExplorer.openChangesWithWorking', this.openChangesWithWorking, this);
4348
commands.registerCommand('gitlens.gitExplorer.openFile', this.openFile, this);
@@ -133,6 +138,14 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
133138
this._onDidChangeTreeData.fire(node);
134139
}
135140

141+
refreshNode(node: ExplorerNode, args: RefreshNodeCommandArgs) {
142+
if (node instanceof BranchHistoryNode) {
143+
node.maxCount = args.maxCount;
144+
}
145+
146+
this.refresh(node);
147+
}
148+
136149
switchTo(view: GitExplorerView) {
137150
if (this._view === view) return;
138151

src/views/stashNode.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
import { Event, EventEmitter, ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
2+
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
33
import { ExplorerNode, ResourceType } from './explorerNode';
44
import { CommitFormatter, GitService, GitStashCommit, GitUri, ICommitFormatOptions } from '../gitService';
55
import { StashFileNode } from './stashFileNode';
@@ -8,11 +8,6 @@ export class StashNode extends ExplorerNode {
88

99
readonly resourceType: ResourceType = 'gitlens:stash';
1010

11-
private _onDidChangeTreeData = new EventEmitter<ExplorerNode>();
12-
public get onDidChangeTreeData(): Event<ExplorerNode> {
13-
return this._onDidChangeTreeData.event;
14-
}
15-
1611
constructor(public readonly commit: GitStashCommit, protected readonly context: ExtensionContext, protected readonly git: GitService) {
1712
super(new GitUri(commit.uri, commit));
1813
}
@@ -29,8 +24,4 @@ export class StashNode extends ExplorerNode {
2924
item.contextValue = this.resourceType;
3025
return item;
3126
}
32-
33-
refresh() {
34-
this._onDidChangeTreeData.fire();
35-
}
3627
}

0 commit comments

Comments
 (0)