提交 da1a21d1 编写于 作者: J Joao Moreno

git: countBadge config

上级 adb32aa4
......@@ -374,7 +374,10 @@
"title": "Git",
"properties": {
"git.path": {
"type": ["string", "null"],
"type": [
"string",
"null"
],
"description": "%config.path%",
"default": null,
"isExecutable": true
......@@ -393,6 +396,16 @@
"type": "boolean",
"description": "%config.enableLongCommitWarning%",
"default": true
},
"git.countBadge": {
"type": "string",
"enum": [
"all",
"tracked",
"off"
],
"description": "%config.countBadge%",
"default": "all"
}
}
}
......
......@@ -26,5 +26,6 @@
"config.path": "Path to the git executable",
"config.autorefresh": "Whether auto refreshing is enabled",
"config.autofetch": "Whether auto fetching is enabled",
"config.enableLongCommitWarning": "Whether long commit messages should be warned about"
"config.enableLongCommitWarning": "Whether long commit messages should be warned about",
"config.countBadge": "Controls the git badge counter"
}
\ No newline at end of file
......@@ -5,7 +5,7 @@
'use strict';
import { scm, Uri, Disposable, SCMProvider, SCMResourceGroup, Event, ProviderResult } from 'vscode';
import { scm, Uri, Disposable, SCMProvider, SCMResourceGroup, Event, ProviderResult, workspace } from 'vscode';
import { Model, Resource, ResourceGroup } from './model';
import { CommandCenter } from './commands';
......@@ -17,6 +17,16 @@ export class GitSCMProvider implements SCMProvider {
get onDidChange(): Event<SCMResourceGroup[]> { return this.model.onDidChange; }
get label(): string { return 'Git'; }
get count(): number {
const countBadge = workspace.getConfiguration('git').get<string>('countBadge');
switch (countBadge) {
case 'off': return 0;
case 'tracked': return this.model.indexGroup.resources.length;
default: return this.model.resources.reduce((r, g) => r + g.resources.length, 0);
}
}
constructor(private model: Model, private commandCenter: CommandCenter) {
scm.registerSCMProvider('git', this);
}
......
......@@ -133,8 +133,9 @@ declare module 'vscode' {
readonly label: string;
readonly resources: SCMResourceGroup[];
readonly onDidChange: Event<SCMResourceGroup[]>;
getOriginalResource?(uri: Uri, token: CancellationToken): ProviderResult<Uri>;
readonly count?: number | undefined;
getOriginalResource?(uri: Uri, token: CancellationToken): ProviderResult<Uri>;
open?(resource: SCMResource, token: CancellationToken): ProviderResult<void>;
drag?(resource: SCMResource, resourceGroup: SCMResourceGroup, token: CancellationToken): ProviderResult<void>;
}
......
......@@ -257,7 +257,7 @@ export type SCMRawResourceGroup = [string /*id*/, string /*label*/, SCMRawResour
export abstract class MainThreadSCMShape {
$register(id: string, features: SCMProviderFeatures): void { throw ni(); }
$unregister(id: string): void { throw ni(); }
$onChange(id: string, resources: SCMRawResourceGroup[]): void { throw ni(); }
$onChange(id: string, resources: SCMRawResourceGroup[], count: number | undefined): void { throw ni(); }
}
// -- extension host
......
......@@ -151,7 +151,7 @@ export class ExtHostSCM {
return [g.id, g.label, rawResources] as SCMRawResourceGroup;
});
this._proxy.$onChange(providerId, rawResourceGroups);
this._proxy.$onChange(providerId, rawResourceGroups, provider.count);
});
return new Disposable(() => {
......
......@@ -27,6 +27,9 @@ class MainThreadSCMProvider implements ISCMProvider {
get id(): string { return this._id; }
get label(): string { return this.features.label; }
private _count: number | undefined = undefined;
get count(): number | undefined { return this._count; }
constructor(
private _id: string,
private proxy: ExtHostSCMShape,
......@@ -68,7 +71,7 @@ class MainThreadSCMProvider implements ISCMProvider {
// }
}
$onChange(rawResourceGroups: SCMRawResourceGroup[]): void {
$onChange(rawResourceGroups: SCMRawResourceGroup[], count: number | undefined): void {
this._resources = rawResourceGroups.map(rawGroup => {
const [id, label, rawResources] = rawGroup;
......@@ -93,6 +96,7 @@ class MainThreadSCMProvider implements ISCMProvider {
return { id, label, resources };
});
this._count = count;
this._onDidChange.fire(this.resources);
}
......@@ -130,14 +134,14 @@ export class MainThreadSCM extends MainThreadSCMShape {
delete this.providers[id];
}
$onChange(id: string, rawResourceGroups: SCMRawResourceGroup[]): void {
$onChange(id: string, rawResourceGroups: SCMRawResourceGroup[], count: number | undefined): void {
const provider = this.providers[id];
if (!provider) {
return;
}
provider.$onChange(rawResourceGroups);
provider.$onChange(rawResourceGroups, count);
}
dispose(): void {
......
......@@ -41,8 +41,15 @@ export class StatusUpdater implements IWorkbenchContribution {
private update(): void {
const provider = this.scmService.activeProvider;
const count = provider ? provider.resources.reduce<number>((r, g) => r + g.resources.length, 0) : 0;
let count = 0;
if (provider) {
if (typeof provider.count === 'number') {
count = provider.count;
} else {
count = provider.resources.reduce<number>((r, g) => r + g.resources.length, 0);
}
}
if (count > 0) {
const badge = new NumberBadge(count, num => localize('scmPendingChangesBadge', '{0} pending changes', num));
......
......@@ -40,6 +40,7 @@ export interface ISCMProvider extends IDisposable {
readonly label: string;
readonly resources: ISCMResourceGroup[];
readonly onDidChange: Event<ISCMResourceGroup[]>;
readonly count?: number | undefined;
open(uri: ISCMResource): TPromise<void>;
drag(from: ISCMResource, to: ISCMResourceGroup): TPromise<void>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册