Browse Source

Adds rudimentary "paging" to custom view branch history

main
Eric Amodio 7 years ago
parent
commit
77ae37c54c
6 changed files with 77 additions and 19 deletions
  1. +4
    -0
      images/dark/icon-sync.svg
  2. +4
    -0
      images/light/icon-sync.svg
  3. +8
    -3
      src/views/branchHistoryNode.ts
  4. +46
    -5
      src/views/explorerNode.ts
  5. +14
    -1
      src/views/gitExplorer.ts
  6. +1
    -10
      src/views/stashNode.ts

+ 4
- 0
images/dark/icon-sync.svg View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<svg width="16" height="22" version="1.1" xmlns="http://www.w3.org/2000/svg">
<path fill="#C5C5C5" d="m12.24,10.4c0.19,1.28 -0.2,2.62 -1.2,3.6c-1.47,1.45 -3.74,1.63 -5.41,0.54l1.17,-1.14l-4.3,-0.6l0.6,4.2l1.31,-1.26c2.36,1.74 5.7,1.57 7.84,-0.54c1.24,-1.23 1.81,-2.85 1.74,-4.46l-1.75,-0.34l0,0zm-7.28,-2.4c1.47,-1.45 3.74,-1.63 5.41,-0.54l-1.17,1.14l4.3,0.6l-0.6,-4.2l-1.31,1.26c-2.36,-1.74 -5.7,-1.57 -7.85,0.54c-1.24,1.23 -1.8,2.85 -1.73,4.46l1.75,0.35c-0.19,-1.28 0.2,-2.63 1.2,-3.61l0,0z" />
</svg>

+ 4
- 0
images/light/icon-sync.svg View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<svg width="16" height="22" version="1.1" xmlns="http://www.w3.org/2000/svg">
<path fill="#424242" d="m12.24,10.4c0.19,1.28 -0.2,2.62 -1.2,3.6c-1.47,1.45 -3.74,1.63 -5.41,0.54l1.17,-1.14l-4.3,-0.6l0.6,4.2l1.31,-1.26c2.36,1.74 5.7,1.57 7.84,-0.54c1.24,-1.23 1.81,-2.85 1.74,-4.46l-1.75,-0.34l0,0zm-7.28,-2.4c1.47,-1.45 3.74,-1.63 5.41,-0.54l-1.17,1.14l4.3,0.6l-0.6,-4.2l-1.31,1.26c-2.36,-1.74 -5.7,-1.57 -7.85,0.54c-1.24,1.23 -1.8,2.85 -1.73,4.46l1.75,0.35c-0.19,-1.28 0.2,-2.63 1.2,-3.61l0,0z" />
</svg>

+ 8
- 3
src/views/branchHistoryNode.ts View File

@ -3,22 +3,27 @@ import { Iterables } from '../system';
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { CommitNode } from './commitNode';
import { GlyphChars } from '../constants';
import { ExplorerNode, ResourceType } from './explorerNode';
import { ExplorerNode, ResourceType, ShowAllCommitsNode } from './explorerNode';
import { GitBranch, GitService, GitUri } from '../gitService';
export class BranchHistoryNode extends ExplorerNode {
readonly resourceType: ResourceType = 'gitlens:branch-history';
maxCount: number | undefined = undefined;
constructor(public readonly branch: GitBranch, uri: GitUri, private readonly template: string, protected readonly context: ExtensionContext, protected readonly git: GitService) {
super(uri);
}
async getChildren(): Promise<ExplorerNode[]> {
const log = await this.git.getLogForRepo(this.uri.repoPath!, this.branch.name, 0);
const log = await this.git.getLogForRepo(this.uri.repoPath!, this.branch.name, this.maxCount);
if (log === undefined) return [];
return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.template, this.context, this.git))];
const children = Iterables.map(log.commits.values(), c => new CommitNode(c, this.template, this.context, this.git));
if (!log.truncated) return [...children];
return [...children, new ShowAllCommitsNode(this, this.context)];
}
async getTreeItem(): Promise<TreeItem> {

+ 46
- 5
src/views/explorerNode.ts View File

@ -1,6 +1,8 @@
'use strict';
import { Command, Event, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Command, ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { GlyphChars } from '../constants';
import { GitUri } from '../gitService';
import { RefreshNodeCommandArgs } from './gitExplorer';
export declare type ResourceType =
'gitlens:branches' |
@ -10,6 +12,7 @@ export declare type ResourceType =
'gitlens:file-history' |
'gitlens:history' |
'gitlens:message' |
'gitlens:pager' |
'gitlens:remote' |
'gitlens:remotes' |
'gitlens:repository' |
@ -31,10 +34,6 @@ export abstract class ExplorerNode {
getCommand(): Command | undefined {
return undefined;
}
onDidChangeTreeData?: Event<ExplorerNode>;
refresh?(): void;
}
export class MessageNode extends ExplorerNode {
@ -54,4 +53,46 @@ export class MessageNode extends ExplorerNode {
item.contextValue = this.resourceType;
return item;
}
}
export class PagerNode extends ExplorerNode {
readonly resourceType: ResourceType = 'gitlens:pager';
args: RefreshNodeCommandArgs = {};
constructor(private message: string, private node: ExplorerNode, protected readonly context: ExtensionContext) {
super(new GitUri());
}
getChildren(): ExplorerNode[] | Promise<ExplorerNode[]> {
return [];
}
getTreeItem(): TreeItem | Promise<TreeItem> {
const item = new TreeItem(this.message, TreeItemCollapsibleState.None);
item.contextValue = this.resourceType;
item.command = this.getCommand();
item.iconPath = {
dark: this.context.asAbsolutePath('images/dark/icon-sync.svg'),
light: this.context.asAbsolutePath('images/light/icon-sync.svg')
};
return item;
}
getCommand(): Command | undefined {
return {
title: 'Refresh',
command: 'gitlens.gitExplorer.refreshNode',
arguments: [this.node, this.args]
} as Command;
}
}
export class ShowAllCommitsNode extends PagerNode {
args: RefreshNodeCommandArgs = { maxCount: 0 };
constructor(node: ExplorerNode, context: ExtensionContext) {
super(`Show All Commits ${GlyphChars.Space}${GlyphChars.Dash}${GlyphChars.Space} this may take a while`, node, context);
}
}

+ 14
- 1
src/views/gitExplorer.ts View File

@ -5,7 +5,7 @@ import { Commands, DiffWithPreviousCommandArgs, DiffWithWorkingCommandArgs, open
import { UriComparer } from '../comparers';
import { ExtensionKey, IConfig } from '../configuration';
import { CommandContext, setCommandContext } from '../constants';
import { CommitFileNode, CommitNode, ExplorerNode, HistoryNode, MessageNode, RepositoryNode, StashNode } from './explorerNodes';
import { BranchHistoryNode, CommitFileNode, CommitNode, ExplorerNode, HistoryNode, MessageNode, RepositoryNode, StashNode } from './explorerNodes';
import { GitService, GitUri, RepoChangedReasons } from '../gitService';
export * from './explorerNodes';
@ -23,6 +23,10 @@ export interface OpenFileRevisionCommandArgs {
showOptions?: TextDocumentShowOptions;
}
export interface RefreshNodeCommandArgs {
maxCount?: number;
}
export class GitExplorer implements TreeDataProvider<ExplorerNode> {
private _config: IConfig;
@ -38,6 +42,7 @@ export class GitExplorer implements TreeDataProvider {
commands.registerCommand('gitlens.gitExplorer.switchToHistoryView', () => this.switchTo(GitExplorerView.History), this);
commands.registerCommand('gitlens.gitExplorer.switchToRepositoryView', () => this.switchTo(GitExplorerView.Repository), this);
commands.registerCommand('gitlens.gitExplorer.refresh', this.refresh, this);
commands.registerCommand('gitlens.gitExplorer.refreshNode', this.refreshNode, this);
commands.registerCommand('gitlens.gitExplorer.openChanges', this.openChanges, this);
commands.registerCommand('gitlens.gitExplorer.openChangesWithWorking', this.openChangesWithWorking, this);
commands.registerCommand('gitlens.gitExplorer.openFile', this.openFile, this);
@ -133,6 +138,14 @@ export class GitExplorer implements TreeDataProvider {
this._onDidChangeTreeData.fire(node);
}
refreshNode(node: ExplorerNode, args: RefreshNodeCommandArgs) {
if (node instanceof BranchHistoryNode) {
node.maxCount = args.maxCount;
}
this.refresh(node);
}
switchTo(view: GitExplorerView) {
if (this._view === view) return;

+ 1
- 10
src/views/stashNode.ts View File

@ -1,5 +1,5 @@
'use strict';
import { Event, EventEmitter, ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ExplorerNode, ResourceType } from './explorerNode';
import { CommitFormatter, GitService, GitStashCommit, GitUri, ICommitFormatOptions } from '../gitService';
import { StashFileNode } from './stashFileNode';
@ -8,11 +8,6 @@ export class StashNode extends ExplorerNode {
readonly resourceType: ResourceType = 'gitlens:stash';
private _onDidChangeTreeData = new EventEmitter<ExplorerNode>();
public get onDidChangeTreeData(): Event<ExplorerNode> {
return this._onDidChangeTreeData.event;
}
constructor(public readonly commit: GitStashCommit, protected readonly context: ExtensionContext, protected readonly git: GitService) {
super(new GitUri(commit.uri, commit));
}
@ -29,8 +24,4 @@ export class StashNode extends ExplorerNode {
item.contextValue = this.resourceType;
return item;
}
refresh() {
this._onDidChangeTreeData.fire();
}
}

Loading…
Cancel
Save