From 97e6e13b7749e84ecd75dbecbc33b6ef6a0ceff9 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 20 Oct 2020 23:36:57 -0400 Subject: [PATCH] Changes to use tree.message for no "items" --- src/views/branchesView.ts | 9 +++++++-- src/views/commitsView.ts | 17 ++++++++++++++--- src/views/contributorsView.ts | 9 +++++++-- src/views/remotesView.ts | 9 +++++++-- src/views/searchAndCompareView.ts | 8 ++++++++ src/views/stashesView.ts | 9 +++++++-- src/views/tagsView.ts | 18 ++++++++---------- src/views/viewBase.ts | 11 +++++++++++ 8 files changed, 69 insertions(+), 21 deletions(-) diff --git a/src/views/branchesView.ts b/src/views/branchesView.ts index d98e993..4e06573 100644 --- a/src/views/branchesView.ts +++ b/src/views/branchesView.ts @@ -31,7 +31,6 @@ import { BranchNode, BranchOrTagFolderNode, ContextValues, - MessageNode, RepositoryNode, SubscribeableViewNode, unknownGitUri, @@ -137,7 +136,13 @@ export class BranchesViewNode extends ViewNode { async getChildren(): Promise { if (this.children == null) { const repositories = await Container.git.getOrderedRepositories(); - if (repositories.length === 0) return [new MessageNode(this.view, this, 'No branches could be found.')]; + if (repositories.length === 0) { + this.view.message = 'No branches could be found.'; + + return []; + } + + this.view.message = undefined; const splat = repositories.length === 1; this.children = repositories.map( diff --git a/src/views/commitsView.ts b/src/views/commitsView.ts index 6776c8b..09b9e48 100644 --- a/src/views/commitsView.ts +++ b/src/views/commitsView.ts @@ -24,7 +24,6 @@ import { BranchNode, BranchTrackingStatusNode, ContextValues, - MessageNode, RepositoryNode, SubscribeableViewNode, unknownGitUri, @@ -50,7 +49,13 @@ export class CommitsRepositoryNode extends SubscribeableViewNode { async getChildren(): Promise { if (this.child == null) { const branch = await this.repo.getBranch(); - if (branch == null) return [new MessageNode(this.view, this, 'No commits could be found.')]; + if (branch == null) { + this.view.message = 'No commits could be found.'; + + return []; + } + + this.view.message = undefined; let authors; if (this.view.state.myCommitsOnly) { @@ -161,7 +166,13 @@ export class CommitsViewNode extends ViewNode { async getChildren(): Promise { if (this.children == null) { const repositories = await Container.git.getOrderedRepositories(); - if (repositories.length === 0) return [new MessageNode(this.view, this, 'No commits could be found.')]; + if (repositories.length === 0) { + this.view.message = 'No commits could be found.'; + + return []; + } + + this.view.message = undefined; const splat = repositories.length === 1; this.children = repositories.map( diff --git a/src/views/contributorsView.ts b/src/views/contributorsView.ts index d25c4c0..33e6073 100644 --- a/src/views/contributorsView.ts +++ b/src/views/contributorsView.ts @@ -8,7 +8,6 @@ import { GitUri } from '../git/gitUri'; import { ContextValues, ContributorsNode, - MessageNode, RepositoryNode, SubscribeableViewNode, unknownGitUri, @@ -110,7 +109,13 @@ export class ContributorsViewNode extends ViewNode { async getChildren(): Promise { if (this.children == null) { const repositories = await Container.git.getOrderedRepositories(); - if (repositories.length === 0) return [new MessageNode(this.view, this, 'No contributors could be found.')]; + if (repositories.length === 0) { + this.view.message = 'No contributors could be found.'; + + return []; + } + + this.view.message = undefined; const splat = repositories.length === 1; this.children = repositories.map( diff --git a/src/views/remotesView.ts b/src/views/remotesView.ts index 55c8798..f3570d8 100644 --- a/src/views/remotesView.ts +++ b/src/views/remotesView.ts @@ -26,7 +26,6 @@ import { BranchNode, BranchOrTagFolderNode, ContextValues, - MessageNode, RemoteNode, RemotesNode, RepositoryNode, @@ -127,7 +126,13 @@ export class RemotesViewNode extends ViewNode { async getChildren(): Promise { if (this.children == null) { const repositories = await Container.git.getOrderedRepositories(); - if (repositories.length === 0) return [new MessageNode(this.view, this, 'No remotes could be found.')]; + if (repositories.length === 0) { + this.view.message = 'No remotes could be found.'; + + return []; + } + + this.view.message = undefined; const splat = repositories.length === 1; this.children = repositories.map( diff --git a/src/views/searchAndCompareView.ts b/src/views/searchAndCompareView.ts index d549586..96f8c5a 100644 --- a/src/views/searchAndCompareView.ts +++ b/src/views/searchAndCompareView.ts @@ -52,6 +52,14 @@ export class SearchAndCompareViewNode extends ViewNode { } getChildren(): ViewNode[] { + if (this.children.length === 0) { + this.view.message = 'No search or comparison results could be found.'; + + return []; + } + + this.view.message = undefined; + return this.children.sort((a, b) => (a.pinned ? -1 : 1) - (b.pinned ? -1 : 1) || b.order - a.order); } diff --git a/src/views/stashesView.ts b/src/views/stashesView.ts index f859c82..ddeb700 100644 --- a/src/views/stashesView.ts +++ b/src/views/stashesView.ts @@ -14,7 +14,6 @@ import { GitReference, GitStashReference, Repository, RepositoryChange, Reposito import { GitUri } from '../git/gitUri'; import { ContextValues, - MessageNode, RepositoryNode, StashesNode, StashNode, @@ -111,7 +110,13 @@ export class StashesViewNode extends ViewNode { async getChildren(): Promise { if (this.children == null) { const repositories = await Container.git.getOrderedRepositories(); - if (repositories.length === 0) return [new MessageNode(this.view, this, 'No stashes could be found.')]; + if (repositories.length === 0) { + this.view.message = 'No stashes could be found.'; + + return []; + } + + this.view.message = undefined; const splat = repositories.length === 1; this.children = repositories.map( diff --git a/src/views/tagsView.ts b/src/views/tagsView.ts index 621b79a..6ccc608 100644 --- a/src/views/tagsView.ts +++ b/src/views/tagsView.ts @@ -12,15 +12,7 @@ import { configuration, TagsViewConfig, ViewBranchesLayout, ViewFilesLayout } fr import { Container } from '../container'; import { GitReference, GitTagReference, Repository, RepositoryChange, RepositoryChangeEvent } from '../git/git'; import { GitUri } from '../git/gitUri'; -import { - ContextValues, - MessageNode, - RepositoryNode, - SubscribeableViewNode, - TagsNode, - unknownGitUri, - ViewNode, -} from './nodes'; +import { ContextValues, RepositoryNode, SubscribeableViewNode, TagsNode, unknownGitUri, ViewNode } from './nodes'; import { debug, gate } from '../system'; import { ViewBase } from './viewBase'; import { BranchOrTagFolderNode } from './nodes/branchOrTagFolderNode'; @@ -115,7 +107,13 @@ export class TagsViewNode extends ViewNode { async getChildren(): Promise { if (this.children == null) { const repositories = await Container.git.getOrderedRepositories(); - if (repositories.length === 0) return [new MessageNode(this.view, this, 'No tags could be found.')]; + if (repositories.length === 0) { + this.view.message = 'No tags could be found.'; + + return []; + } + + this.view.message = undefined; const splat = repositories.length === 1; this.children = repositories.map( diff --git a/src/views/viewBase.ts b/src/views/viewBase.ts index 5878f00..9a91cec 100644 --- a/src/views/viewBase.ts +++ b/src/views/viewBase.ts @@ -182,6 +182,17 @@ export abstract class ViewBase< } } + private _message: string | undefined; + get message(): string | undefined { + return this._message; + } + set message(value: string | undefined) { + this._message = value; + if (this.tree != null) { + this.tree.message = value; + } + } + getQualifiedCommand(command: string) { return `${this.id}.${command}`; }