diff --git a/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts b/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts index 48355bed0f7..f93b7a83500 100644 --- a/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts +++ b/src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts @@ -73,6 +73,7 @@ export class StatusUpdater implements ext.IWorkbenchContribution this.progressBadgeDelayer = new async.Delayer(200); this.toDispose = []; + this.toDispose.push(this.configurationService.onDidUpdateConfiguration(e => this.onGitServiceChange())); this.toDispose.push(this.gitService.addBulkListener2(e => this.onGitServiceChange())); } @@ -90,25 +91,24 @@ export class StatusUpdater implements ext.IWorkbenchContribution } private showChangesBadge(): void { - const config = this.configurationService.getConfiguration('git'); + this.progressBadgeDelayer.cancel(); - // only use the filter version of the map callback if filtering by file status is really necessary - var mapper = (g1: git.IStatusGroup) => { - return g1.all().filter((f1: git.IFileStatus) => { - return f1.getStatus() !== git.Status.UNTRACKED; - }).length; - }; + const { countBadge } = this.configurationService.getConfiguration('git'); - // no need to filter by file status if we count both tracked and untracked files - if (config.countUntracked) { - mapper = (g1: git.IStatusGroup) => g1.all().length; + if (countBadge === 'off') { + return; } - var count = this.gitService.getModel().getStatus().getGroups().map(mapper).reduce((a, b) => a + b, 0); + const filter = countBadge === 'tracked' + ? s => s.getStatus() !== git.Status.UNTRACKED + : () => true; - var badge = new NumberBadge(count, (num)=>{ return nls.localize('gitPendingChangesBadge', '{0} pending changes', num); }); + const statuses = this.gitService.getModel().getStatus().getGroups() + .map(g => g.all()) + .reduce((r, g) => r.concat(g), []) + .filter(filter); - this.progressBadgeDelayer.cancel(); + const badge = new NumberBadge(statuses.length, num => nls.localize('gitPendingChangesBadge', '{0} pending changes', num)); this.activityService.showActivity('workbench.view.git', badge, 'git-viewlet-label'); } @@ -564,10 +564,11 @@ export function registerContributions(): void { description: nls.localize('confirmSync', "Confirm before synchronizing git repositories."), default: false }, - 'git.countUntracked': { - type: 'boolean', - description: nls.localize('countUntracked', "Count untracked files in the changes badge."), - default: true + 'git.countBadge': { + type: 'string', + enum: ['all', 'tracked', 'off'], + default: 'all', + description: nls.localize('countBadge', "Controls the git badge counter."), } } }); diff --git a/src/vs/workbench/parts/git/common/git.ts b/src/vs/workbench/parts/git/common/git.ts index b00d9a1f3f1..609e70a7b52 100644 --- a/src/vs/workbench/parts/git/common/git.ts +++ b/src/vs/workbench/parts/git/common/git.ts @@ -240,7 +240,7 @@ export interface IGitConfiguration { enableLongCommitWarning: boolean; allowLargeRepositories: boolean; confirmSync: boolean; - countUntracked: boolean; + countBadge: string; } // Service interfaces