mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
git: countBadge config
This commit is contained in:
@@ -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"
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Vendored
+2
-1
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user