Browse Source

Adds reset support to view & node refresh

main
Eric Amodio 6 years ago
parent
commit
c50bec867a
12 changed files with 66 additions and 53 deletions
  1. +3
    -3
      src/views/compareView.ts
  2. +3
    -3
      src/views/fileHistoryView.ts
  3. +3
    -3
      src/views/lineHistoryView.ts
  4. +1
    -1
      src/views/nodes/common.ts
  5. +11
    -6
      src/views/nodes/fileHistoryTrackerNode.ts
  6. +12
    -6
      src/views/nodes/lineHistoryTrackerNode.ts
  7. +20
    -13
      src/views/nodes/repositoriesNode.ts
  8. +2
    -2
      src/views/nodes/viewNode.ts
  9. +3
    -3
      src/views/repositoriesView.ts
  10. +3
    -3
      src/views/searchView.ts
  11. +4
    -9
      src/views/viewBase.ts
  12. +1
    -1
      src/views/viewCommands.ts

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

@ -4,7 +4,7 @@ import { CompareViewConfig, configuration, ViewFilesLayout, ViewsConfig } from '
import { CommandContext, setCommandContext, WorkspaceState } from '../constants';
import { Container } from '../container';
import { CompareNode, CompareResultsNode, NamedRef, ViewNode } from './nodes';
import { RefreshReason, ViewBase } from './viewBase';
import { ViewBase } from './viewBase';
export class CompareView extends ViewBase<CompareNode> {
constructor() {
@ -24,7 +24,7 @@ export class CompareView extends ViewBase {
protected registerCommands() {
void Container.viewCommands;
commands.registerCommand(this.getQualifiedCommand('clear'), () => this.clear(), this);
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(), this);
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this);
commands.registerCommand(
this.getQualifiedCommand('setFilesLayoutToAuto'),
() => this.setFilesLayout(ViewFilesLayout.Auto),
@ -66,7 +66,7 @@ export class CompareView extends ViewBase {
}
if (!configuration.initializing(e) && this._root !== undefined) {
void this.refresh(RefreshReason.ConfigurationChanged);
void this.refresh(true);
}
}

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

@ -5,7 +5,7 @@ import { CommandContext, setCommandContext } from '../constants';
import { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { FileHistoryTrackerNode } from './nodes';
import { RefreshReason, ViewBase } from './viewBase';
import { ViewBase } from './viewBase';
export class FileHistoryView extends ViewBase<FileHistoryTrackerNode> {
constructor() {
@ -22,7 +22,7 @@ export class FileHistoryView extends ViewBase {
protected registerCommands() {
void Container.viewCommands;
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(), this);
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this);
commands.registerCommand(this.getQualifiedCommand('changeBase'), () => this.changeBase(), this);
commands.registerCommand(
this.getQualifiedCommand('setEditorFollowingOn'),
@ -65,7 +65,7 @@ export class FileHistoryView extends ViewBase {
}
if (!configuration.initializing(e) && this._root !== undefined) {
void this.refresh(RefreshReason.ConfigurationChanged);
void this.refresh(true);
}
}

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

@ -4,7 +4,7 @@ import { configuration, LineHistoryViewConfig, ViewsConfig } from '../configurat
import { CommandContext, setCommandContext } from '../constants';
import { Container } from '../container';
import { LineHistoryTrackerNode } from './nodes';
import { RefreshReason, ViewBase } from './viewBase';
import { ViewBase } from './viewBase';
export class LineHistoryView extends ViewBase<LineHistoryTrackerNode> {
constructor() {
@ -21,7 +21,7 @@ export class LineHistoryView extends ViewBase {
protected registerCommands() {
void Container.viewCommands;
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(), this);
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this);
commands.registerCommand(this.getQualifiedCommand('changeBase'), () => this.changeBase(), this);
commands.registerCommand(
this.getQualifiedCommand('setEditorFollowingOn'),
@ -64,7 +64,7 @@ export class LineHistoryView extends ViewBase {
}
if (!configuration.initializing(e) && this._root !== undefined) {
void this.refresh(RefreshReason.ConfigurationChanged);
void this.refresh(true);
}
}

+ 1
- 1
src/views/nodes/common.ts View File

@ -166,7 +166,7 @@ export abstract class PagerNode extends ViewNode {
return {
title: 'Refresh',
command: 'gitlens.views.refreshNode',
arguments: [this.parent, this._args]
arguments: [this.parent, false, this._args]
} as Command;
}
}

+ 11
- 6
src/views/nodes/fileHistoryTrackerNode.ts View File

@ -27,11 +27,11 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode
}
@debug()
resetChild() {
if (this._child !== undefined) {
this._child.dispose();
this._child = undefined;
}
private resetChild() {
if (this._child === undefined) return;
this._child.dispose();
this._child = undefined;
}
async getChildren(): Promise<ViewNode[]> {
@ -84,7 +84,12 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode
@gate()
@debug()
async refresh() {
async refresh(reset: boolean = false) {
if (reset) {
this._uri = unknownGitUri;
this.resetChild();
}
const editor = window.activeTextEditor;
if (editor == null || !Container.git.isTrackable(editor.document.uri)) {
if (

+ 12
- 6
src/views/nodes/lineHistoryTrackerNode.ts View File

@ -28,11 +28,11 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode
}
@debug()
resetChild() {
if (this._child !== undefined) {
this._child.dispose();
this._child = undefined;
}
private resetChild() {
if (this._child === undefined) return;
this._child.dispose();
this._child = undefined;
}
async getChildren(): Promise<ViewNode[]> {
@ -84,7 +84,13 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode
@gate()
@debug()
async refresh() {
async refresh(reset: boolean = false) {
if (reset) {
this._uri = unknownGitUri;
this._selection = undefined;
this.resetChild();
}
const editor = window.activeTextEditor;
if (editor == null || !Container.git.isTrackable(editor.document.uri)) {
if (

+ 20
- 13
src/views/nodes/repositoriesNode.ts View File

@ -5,7 +5,6 @@ import { GitUri } from '../../git/gitService';
import { Logger } from '../../logger';
import { debug, Functions, gate } from '../../system';
import { RepositoriesView } from '../repositoriesView';
import { RefreshReason } from '../viewBase';
import { MessageNode } from './common';
import { RepositoryNode } from './repositoryNode';
import { ResourceType, SubscribeableViewNode, unknownGitUri, ViewNode } from './viewNode';
@ -20,14 +19,19 @@ export class RepositoriesNode extends SubscribeableViewNode {
dispose() {
super.dispose();
if (this._children !== undefined) {
for (const child of this._children) {
if (child instanceof RepositoryNode) {
child.dispose();
}
this.resetChildren();
}
@debug()
private resetChildren() {
if (this._children === undefined) return;
for (const child of this._children) {
if (child instanceof RepositoryNode) {
child.dispose();
}
this._children = undefined;
}
this._children = undefined;
}
async getChildren(): Promise<ViewNode[]> {
@ -59,9 +63,17 @@ export class RepositoriesNode extends SubscribeableViewNode {
@gate()
@debug()
async refresh(reason?: RefreshReason) {
async refresh(reset: boolean = false) {
if (this._children === undefined) return;
if (reset) {
this.resetChildren();
await this.unsubscribe();
void this.ensureSubscription();
return;
}
const repositories = await Container.git.getOrderedRepositories();
if (repositories.length === 0 && (this._children === undefined || this._children.length === 0)) return;
@ -93,11 +105,6 @@ export class RepositoriesNode extends SubscribeableViewNode {
this._children = children;
// Reset our subscription if the configuration changed
if (reason === RefreshReason.ConfigurationChanged) {
await this.unsubscribe();
}
void this.ensureSubscription();
}

+ 2
- 2
src/views/nodes/viewNode.ts View File

@ -3,7 +3,7 @@ import { Command, Disposable, Event, TreeItem, TreeItemCollapsibleState, TreeVie
import { GitUri } from '../../git/gitService';
import { Logger } from '../../logger';
import { debug, gate, logName } from '../../system';
import { RefreshReason, TreeViewNodeStateChangeEvent, View } from '../viewBase';
import { TreeViewNodeStateChangeEvent, View } from '../viewBase';
export enum ResourceType {
ActiveFileHistory = 'gitlens:history:active:file',
@ -97,7 +97,7 @@ export abstract class ViewNode {
@gate()
@debug()
refresh(reason?: RefreshReason): void | boolean | Promise<void> | Promise<boolean> {}
refresh(reset: boolean = false): void | boolean | Promise<void> | Promise<boolean> {}
@gate()
@debug()

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

@ -4,7 +4,7 @@ import { configuration, RepositoriesViewConfig, ViewFilesLayout, ViewsConfig } f
import { CommandContext, setCommandContext, WorkspaceState } from '../constants';
import { Container } from '../container';
import { RepositoriesNode } from './nodes';
import { RefreshReason, ViewBase } from './viewBase';
import { ViewBase } from './viewBase';
export class RepositoriesView extends ViewBase<RepositoriesNode> {
constructor() {
@ -27,7 +27,7 @@ export class RepositoriesView extends ViewBase {
protected registerCommands() {
void Container.viewCommands;
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(), this);
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this);
commands.registerCommand(
this.getQualifiedCommand('setFilesLayoutToAuto'),
() => this.setFilesLayout(ViewFilesLayout.Auto),
@ -74,7 +74,7 @@ export class RepositoriesView extends ViewBase {
}
if (!configuration.initializing(e) && this._root !== undefined) {
void this.refresh(RefreshReason.ConfigurationChanged);
void this.refresh(true);
}
}

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

@ -6,7 +6,7 @@ import { Container } from '../container';
import { GitLog, GitRepoSearchBy } from '../git/gitService';
import { Functions, Strings } from '../system';
import { SearchNode, SearchResultsCommitsNode, ViewNode } from './nodes';
import { RefreshReason, ViewBase } from './viewBase';
import { ViewBase } from './viewBase';
interface SearchQueryResult {
label: string;
@ -31,7 +31,7 @@ export class SearchView extends ViewBase {
protected registerCommands() {
void Container.viewCommands;
commands.registerCommand(this.getQualifiedCommand('clear'), () => this.clear(), this);
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(), this);
commands.registerCommand(this.getQualifiedCommand('refresh'), () => this.refresh(true), this);
commands.registerCommand(
this.getQualifiedCommand('setFilesLayoutToAuto'),
() => this.setFilesLayout(ViewFilesLayout.Auto),
@ -69,7 +69,7 @@ export class SearchView extends ViewBase {
}
if (!configuration.initializing(e) && this._root !== undefined) {
void this.refresh(RefreshReason.ConfigurationChanged);
void this.refresh(true);
}
}

+ 4
- 9
src/views/viewBase.ts View File

@ -26,11 +26,6 @@ import { RepositoriesView } from './repositoriesView';
import { SearchView } from './searchView';
import { RefreshNodeCommandArgs } from './viewCommands';
export enum RefreshReason {
ConfigurationChanged = 'ConfigurationChanged',
VisibilityChanged = 'VisibilityChanged'
}
export type View = RepositoriesView | FileHistoryView | LineHistoryView | CompareView | SearchView;
export interface TreeViewNodeStateChangeEvent<T> extends TreeViewExpansionEvent<T> {
@ -144,9 +139,9 @@ export abstract class ViewBase> implements TreeData
}
@debug()
async refresh(reason?: RefreshReason) {
async refresh(reset: boolean = false) {
if (this._root !== undefined) {
await this._root.refresh(reason);
await this._root.refresh(reset);
}
this.triggerNodeChange();
@ -155,7 +150,7 @@ export abstract class ViewBase> implements TreeData
@debug({
args: { 0: (n: ViewNode) => n.toString() }
})
async refreshNode(node: ViewNode, args?: RefreshNodeCommandArgs) {
async refreshNode(node: ViewNode, reset: boolean = false, args?: RefreshNodeCommandArgs) {
if (args !== undefined) {
if (isPageable(node)) {
if (args.maxCount === undefined || args.maxCount === 0) {
@ -167,7 +162,7 @@ export abstract class ViewBase> implements TreeData
}
}
const cancel = await node.refresh();
const cancel = await node.refresh(reset);
if (cancel === true) return;
this.triggerNodeChange(node);

+ 1
- 1
src/views/viewCommands.ts View File

@ -52,7 +52,7 @@ export class ViewCommands implements Disposable {
constructor() {
commands.registerCommand(
'gitlens.views.refreshNode',
(node: ViewNode, args?: RefreshNodeCommandArgs) => node.view.refreshNode(node, args),
(node: ViewNode, args?: RefreshNodeCommandArgs) => node.view.refreshNode(node, true, args),
this
);
commands.registerCommand(

Loading…
Cancel
Save