3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { Disposable , DisposableStore , IDisposable , toDisposable } from '../../../../base/common/lifecycle.js' ;
6
+ import { Disposable , DisposableStore , toDisposable } from '../../../../base/common/lifecycle.js' ;
7
7
import { Event , Emitter } from '../../../../base/common/event.js' ;
8
8
import { ISCMService , ISCMProvider , ISCMInput , ISCMRepository , IInputValidator , ISCMInputChangeEvent , SCMInputChangeReason , InputValidationType , IInputValidation } from './scm.js' ;
9
9
import { ILogService } from '../../../../platform/log/common/log.js' ;
@@ -17,6 +17,7 @@ import { Iterable } from '../../../../base/common/iterator.js';
17
17
import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.js' ;
18
18
import { Schemas } from '../../../../base/common/network.js' ;
19
19
import { IUriIdentityService } from '../../../../platform/uriIdentity/common/uriIdentity.js' ;
20
+ import { runOnChange } from '../../../../base/common/observable.js' ;
20
21
21
22
class SCMInput extends Disposable implements ISCMInput {
22
23
@@ -188,7 +189,7 @@ class SCMRepository implements ISCMRepository {
188
189
constructor (
189
190
public readonly id : string ,
190
191
public readonly provider : ISCMProvider ,
191
- private disposable : IDisposable ,
192
+ private readonly disposables : DisposableStore ,
192
193
inputHistory : SCMInputHistory
193
194
) {
194
195
this . input = new SCMInput ( this , inputHistory ) ;
@@ -204,7 +205,7 @@ class SCMRepository implements ISCMRepository {
204
205
}
205
206
206
207
dispose ( ) : void {
207
- this . disposable . dispose ( ) ;
208
+ this . disposables . dispose ( ) ;
208
209
this . provider . dispose ( ) ;
209
210
}
210
211
}
@@ -355,6 +356,7 @@ export class SCMService implements ISCMService {
355
356
356
357
private inputHistory : SCMInputHistory ;
357
358
private providerCount : IContextKey < number > ;
359
+ private historyProviderCount : IContextKey < number > ;
358
360
359
361
private readonly _onDidAddProvider = new Emitter < ISCMRepository > ( ) ;
360
362
readonly onDidAddRepository : Event < ISCMRepository > = this . _onDidAddProvider . event ;
@@ -370,7 +372,9 @@ export class SCMService implements ISCMService {
370
372
@IUriIdentityService private readonly uriIdentityService : IUriIdentityService
371
373
) {
372
374
this . inputHistory = new SCMInputHistory ( storageService , workspaceContextService ) ;
375
+
373
376
this . providerCount = contextKeyService . createKey ( 'scm.providerCount' , 0 ) ;
377
+ this . historyProviderCount = contextKeyService . createKey ( 'scm.historyProviderCount' , 0 ) ;
374
378
}
375
379
376
380
registerSCMProvider ( provider : ISCMProvider ) : ISCMRepository {
@@ -380,17 +384,33 @@ export class SCMService implements ISCMService {
380
384
throw new Error ( `SCM Provider ${ provider . id } already exists.` ) ;
381
385
}
382
386
383
- const disposable = toDisposable ( ( ) => {
387
+ const disposables = new DisposableStore ( ) ;
388
+
389
+ const historyProviderCount = ( ) => {
390
+ return Array . from ( this . _repositories . values ( ) )
391
+ . filter ( r => ! ! r . provider . historyProvider ) . length ;
392
+ } ;
393
+
394
+ disposables . add ( toDisposable ( ( ) => {
384
395
this . _repositories . delete ( provider . id ) ;
385
396
this . _onDidRemoveProvider . fire ( repository ) ;
397
+
386
398
this . providerCount . set ( this . _repositories . size ) ;
387
- } ) ;
399
+ this . historyProviderCount . set ( historyProviderCount ( ) ) ;
400
+ } ) ) ;
388
401
389
- const repository = new SCMRepository ( provider . id , provider , disposable , this . inputHistory ) ;
402
+ const repository = new SCMRepository ( provider . id , provider , disposables , this . inputHistory ) ;
390
403
this . _repositories . set ( provider . id , repository ) ;
391
- this . _onDidAddProvider . fire ( repository ) ;
404
+
405
+ disposables . add ( runOnChange ( provider . historyProvider , ( ) => {
406
+ this . historyProviderCount . set ( historyProviderCount ( ) ) ;
407
+ } ) ) ;
392
408
393
409
this . providerCount . set ( this . _repositories . size ) ;
410
+ this . historyProviderCount . set ( historyProviderCount ( ) ) ;
411
+
412
+ this . _onDidAddProvider . fire ( repository ) ;
413
+
394
414
return repository ;
395
415
}
396
416
0 commit comments