Skip to content

Commit

Permalink
Adds indicator if view auto-refresh is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Jan 18, 2021
1 parent 4c573e7 commit 0afba2c
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export enum GlyphChars {
SpaceThinnest = '\u200A',
SquareWithBottomShadow = '\u274F',
SquareWithTopShadow = '\u2750',
Warning = '\u26a0',
ZeroWidthSpace = '\u200b',
}

Expand Down
7 changes: 6 additions & 1 deletion src/views/branchesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ViewFilesLayout,
ViewShowBranchComparison,
} from '../configuration';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import {
GitBranchReference,
Expand All @@ -34,7 +35,7 @@ import {
unknownGitUri,
ViewNode,
} from './nodes';
import { debug, gate } from '../system';
import { debug, gate, Strings } from '../system';
import { ViewBase } from './viewBase';

export class BranchesRepositoryNode extends RepositoryFolderNode<BranchesView, BranchesNode> {
Expand Down Expand Up @@ -85,6 +86,10 @@ export class BranchesViewNode extends ViewNode<BranchesView> {
if (this.children.length === 1) {
const [child] = this.children;

if (!child.repo.supportsChangeEvents) {
this.view.description = `${Strings.pad(GlyphChars.Warning, 0, 2)}Auto-refresh unavailable`;
}

const branches = await child.repo.getBranches({ filter: b => !b.remote });
if (branches.length === 0) {
this.view.message = 'No branches could be found.';
Expand Down
22 changes: 17 additions & 5 deletions src/views/commitsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ export class CommitsRepositoryNode extends RepositoryFolderNode<CommitsView, Bra
item.contextValue = `${ContextValues.RepositoryFolder}${this.repo.starred ? '+starred' : ''}`;

if (branch != null) {
const lastFetched = (await this.repo?.getLastFetched()) ?? 0;
const lastFetched = (await this.repo.getLastFetched()) ?? 0;

const status = branch?.getTrackingStatus();
item.description = `${status ? `${status}${Strings.pad(GlyphChars.Dot, 1, 1)}` : ''}${branch.name}${
item.description = `${this.repo.supportsChangeEvents ? '' : Strings.pad(GlyphChars.Warning, 1, 2)}${
status ? `${status}${Strings.pad(GlyphChars.Dot, 1, 1)}` : ''
}${branch.name}${
lastFetched
? `${Strings.pad(GlyphChars.Dot, 1, 1)}Last fetched ${Repository.formatLastFetched(lastFetched)}`
: ''
Expand Down Expand Up @@ -126,6 +128,10 @@ export class CommitsRepositoryNode extends RepositoryFolderNode<CommitsView, Bra
suffix: ` $(git-branch) ${branch.tracking}${providerName ? ` on ${providerName}` : ''}`,
})}`
: `hasn't been published to ${providerName ?? 'a remote'}`
}${
this.repo.supportsChangeEvents
? ''
: `\n\n${GlyphChars.Warning} Unable to automatically detect repository changes`
}`,
true,
);
Expand Down Expand Up @@ -213,14 +219,20 @@ export class CommitsViewNode extends ViewNode<CommitsView> {

const branch = await child.repo.getBranch();
if (branch != null) {
const lastFetched = (await child.repo?.getLastFetched()) ?? 0;
const lastFetched = (await child.repo.getLastFetched()) ?? 0;

const status = branch.getTrackingStatus();
this.view.description = `${status ? `${status} ${GlyphChars.Dot} ` : ''}${branch.name}${
branch.rebasing ? ' (Rebasing)' : ''
}${lastFetched ? ` ${GlyphChars.Dot} Last fetched ${Repository.formatLastFetched(lastFetched)}` : ''}`;
}${lastFetched ? ` ${GlyphChars.Dot} Last fetched ${Repository.formatLastFetched(lastFetched)}` : ''}${
child.repo.supportsChangeEvents
? ''
: `${Strings.pad(GlyphChars.Warning, 3, 2)}Auto-refresh unavailable`
}`;
} else {
this.view.description = undefined;
this.view.description = child.repo.supportsChangeEvents
? undefined
: `${Strings.pad(GlyphChars.Warning, 1, 2)}Auto-refresh unavailable`;
}

return child.getChildren();
Expand Down
7 changes: 6 additions & 1 deletion src/views/contributorsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import { commands, ConfigurationChangeEvent, Disposable, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Avatars } from '../avatars';
import { configuration, ContributorsViewConfig, ViewFilesLayout } from '../configuration';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { RepositoryChange, RepositoryChangeEvent } from '../git/git';
import { GitUri } from '../git/gitUri';
import { ContributorsNode, RepositoryFolderNode, unknownGitUri, ViewNode } from './nodes';
import { debug, gate } from '../system';
import { debug, gate, Strings } from '../system';
import { ViewBase } from './viewBase';

export class ContributorsRepositoryNode extends RepositoryFolderNode<ContributorsView, ContributorsNode> {
Expand Down Expand Up @@ -64,6 +65,10 @@ export class ContributorsViewNode extends ViewNode<ContributorsView> {
if (this.children.length === 1) {
const [child] = this.children;

if (!child.repo.supportsChangeEvents) {
this.view.description = `${Strings.pad(GlyphChars.Warning, 0, 2)}Auto-refresh unavailable`;
}

const contributors = await child.repo.getContributors();
if (contributors.length === 0) {
this.view.message = 'No contributors could be found.';
Expand Down
6 changes: 4 additions & 2 deletions src/views/nodes/repositoryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,10 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
}

if (!this.repo.supportsChangeEvents) {
description = `<!>${description ? ` ${GlyphChars.Space}${description}` : ''}`;
tooltip += '\n\n<!> Unable to automatically detect repository changes';
description = `${Strings.pad(GlyphChars.Warning, 1, 0)}${
description ? Strings.pad(description, 2, 0) : ''
}`;
tooltip += `\n\n${GlyphChars.Warning} Unable to automatically detect repository changes`;
}

const item = new TreeItem(label, TreeItemCollapsibleState.Expanded);
Expand Down
8 changes: 7 additions & 1 deletion src/views/nodes/viewNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
import { Command, Disposable, Event, TreeItem, TreeItemCollapsibleState, TreeViewVisibilityChangeEvent } from 'vscode';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import {
GitFile,
Expand All @@ -11,7 +12,7 @@ import {
} from '../../git/git';
import { GitUri } from '../../git/gitUri';
import { Logger } from '../../logger';
import { debug, Functions, gate, log, logName } from '../../system';
import { debug, Functions, gate, log, logName, Strings } from '../../system';
import { TreeViewNodeCollapsibleStateChangeEvent, View } from '../viewBase';

export enum ContextValues {
Expand Down Expand Up @@ -352,8 +353,13 @@ export abstract class RepositoryFolderNode<
expand ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed,
);
item.contextValue = `${ContextValues.RepositoryFolder}${this.repo.starred ? '+starred' : ''}`;
item.description = this.repo.supportsChangeEvents ? undefined : Strings.pad(GlyphChars.Warning, 1, 0);
item.tooltip = `${
this.repo.formattedName ? `${this.repo.formattedName}\n${this.uri.repoPath}` : this.uri.repoPath ?? ''
}${
this.repo.supportsChangeEvents
? ''
: `\n\n${GlyphChars.Warning} Unable to automatically detect repository changes`
}`;

return item;
Expand Down
7 changes: 6 additions & 1 deletion src/views/remotesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
window,
} from 'vscode';
import { configuration, RemotesViewConfig, ViewBranchesLayout, ViewFilesLayout } from '../configuration';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import {
GitBranch,
Expand All @@ -31,7 +32,7 @@ import {
unknownGitUri,
ViewNode,
} from './nodes';
import { debug, gate } from '../system';
import { debug, gate, Strings } from '../system';
import { ViewBase } from './viewBase';

export class RemotesRepositoryNode extends RepositoryFolderNode<RemotesView, RemotesNode> {
Expand Down Expand Up @@ -80,6 +81,10 @@ export class RemotesViewNode extends ViewNode<RemotesView> {
if (this.children.length === 1) {
const [child] = this.children;

if (!child.repo.supportsChangeEvents) {
this.view.description = `${Strings.pad(GlyphChars.Warning, 0, 2)}Auto-refresh unavailable`;
}

const remotes = await child.repo.getRemotes();
if (remotes.length === 0) {
this.view.message = 'No remotes could be found.';
Expand Down
7 changes: 6 additions & 1 deletion src/views/stashesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import {
window,
} from 'vscode';
import { configuration, StashesViewConfig, ViewFilesLayout } from '../configuration';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitReference, GitStashReference, RepositoryChange, RepositoryChangeEvent } from '../git/git';
import { GitUri } from '../git/gitUri';
import { RepositoryFolderNode, RepositoryNode, StashesNode, StashNode, unknownGitUri, ViewNode } from './nodes';
import { debug, gate } from '../system';
import { debug, gate, Strings } from '../system';
import { ViewBase } from './viewBase';

export class StashesRepositoryNode extends RepositoryFolderNode<StashesView, StashesNode> {
Expand Down Expand Up @@ -62,6 +63,10 @@ export class StashesViewNode extends ViewNode<StashesView> {
if (this.children.length === 1) {
const [child] = this.children;

if (!child.repo.supportsChangeEvents) {
this.view.description = `${Strings.pad(GlyphChars.Warning, 0, 2)}Auto-refresh unavailable`;
}

const stash = await child.repo.getStash();
if (stash == null) {
this.view.message = 'No stashes could be found.';
Expand Down
17 changes: 14 additions & 3 deletions src/views/tagsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ import {
window,
} from 'vscode';
import { configuration, TagsViewConfig, ViewBranchesLayout, ViewFilesLayout } from '../configuration';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitReference, GitTagReference, RepositoryChange, RepositoryChangeEvent } from '../git/git';
import { GitUri } from '../git/gitUri';
import { RepositoryFolderNode, RepositoryNode, TagsNode, unknownGitUri, ViewNode } from './nodes';
import { debug, gate } from '../system';
import {
BranchOrTagFolderNode,
RepositoryFolderNode,
RepositoryNode,
TagsNode,
unknownGitUri,
ViewNode,
} from './nodes';
import { debug, gate, Strings } from '../system';
import { ViewBase } from './viewBase';
import { BranchOrTagFolderNode } from './nodes/branchOrTagFolderNode';

export class TagsRepositoryNode extends RepositoryFolderNode<TagsView, TagsNode> {
async getChildren(): Promise<ViewNode[]> {
Expand Down Expand Up @@ -63,6 +70,10 @@ export class TagsViewNode extends ViewNode<TagsView> {
if (this.children.length === 1) {
const [child] = this.children;

if (!child.repo.supportsChangeEvents) {
this.view.description = `${Strings.pad(GlyphChars.Warning, 0, 2)}Auto-refresh unavailable`;
}

const tags = await child.repo.getTags();
if (tags.length === 0) {
this.view.message = 'No tags could be found.';
Expand Down

0 comments on commit 0afba2c

Please sign in to comment.