Skip to content

Commit

Permalink
Changes to use tree.message for no "items"
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Oct 21, 2020
1 parent 2ea859f commit 97e6e13
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 21 deletions.
9 changes: 7 additions & 2 deletions src/views/branchesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
BranchNode,
BranchOrTagFolderNode,
ContextValues,
MessageNode,
RepositoryNode,
SubscribeableViewNode,
unknownGitUri,
Expand Down Expand Up @@ -137,7 +136,13 @@ export class BranchesViewNode extends ViewNode<BranchesView> {
async getChildren(): Promise<ViewNode[]> {
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(
Expand Down
17 changes: 14 additions & 3 deletions src/views/commitsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
BranchNode,
BranchTrackingStatusNode,
ContextValues,
MessageNode,
RepositoryNode,
SubscribeableViewNode,
unknownGitUri,
Expand All @@ -50,7 +49,13 @@ export class CommitsRepositoryNode extends SubscribeableViewNode<CommitsView> {
async getChildren(): Promise<ViewNode[]> {
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) {
Expand Down Expand Up @@ -161,7 +166,13 @@ export class CommitsViewNode extends ViewNode<CommitsView> {
async getChildren(): Promise<ViewNode[]> {
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(
Expand Down
9 changes: 7 additions & 2 deletions src/views/contributorsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { GitUri } from '../git/gitUri';
import {
ContextValues,
ContributorsNode,
MessageNode,
RepositoryNode,
SubscribeableViewNode,
unknownGitUri,
Expand Down Expand Up @@ -110,7 +109,13 @@ export class ContributorsViewNode extends ViewNode<ContributorsView> {
async getChildren(): Promise<ViewNode[]> {
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(
Expand Down
9 changes: 7 additions & 2 deletions src/views/remotesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
BranchNode,
BranchOrTagFolderNode,
ContextValues,
MessageNode,
RemoteNode,
RemotesNode,
RepositoryNode,
Expand Down Expand Up @@ -127,7 +126,13 @@ export class RemotesViewNode extends ViewNode<RemotesView> {
async getChildren(): Promise<ViewNode[]> {
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(
Expand Down
8 changes: 8 additions & 0 deletions src/views/searchAndCompareView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ export class SearchAndCompareViewNode extends ViewNode<SearchAndCompareView> {
}

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);
}

Expand Down
9 changes: 7 additions & 2 deletions src/views/stashesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { GitReference, GitStashReference, Repository, RepositoryChange, Reposito
import { GitUri } from '../git/gitUri';
import {
ContextValues,
MessageNode,
RepositoryNode,
StashesNode,
StashNode,
Expand Down Expand Up @@ -111,7 +110,13 @@ export class StashesViewNode extends ViewNode<StashesView> {
async getChildren(): Promise<ViewNode[]> {
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(
Expand Down
18 changes: 8 additions & 10 deletions src/views/tagsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -115,7 +107,13 @@ export class TagsViewNode extends ViewNode<TagsView> {
async getChildren(): Promise<ViewNode[]> {
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(
Expand Down
11 changes: 11 additions & 0 deletions src/views/viewBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
Expand Down

0 comments on commit 97e6e13

Please sign in to comment.