@@ -11,6 +11,10 @@ import { URI } from 'vs/base/common/uri';
11
11
import { ILogService } from 'vs/platform/log/common/log' ;
12
12
import { ITimelineService , TimelineChangeEvent , TimelineOptions , TimelineProvidersChangeEvent , TimelineProvider , InternalTimelineOptions , TimelinePaneId } from './timeline' ;
13
13
import { IViewsService } from 'vs/workbench/common/views' ;
14
+ import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
15
+ import { IContextKey , IContextKeyService , RawContextKey } from 'vs/platform/contextkey/common/contextkey' ;
16
+
17
+ export const TimelineHasProviderContext = new RawContextKey < boolean > ( 'timelineHasProvider' , false ) ;
14
18
15
19
export class TimelineService implements ITimelineService {
16
20
declare readonly _serviceBrand : undefined ;
@@ -23,13 +27,30 @@ export class TimelineService implements ITimelineService {
23
27
private readonly _onDidChangeUri = new Emitter < URI > ( ) ;
24
28
readonly onDidChangeUri : Event < URI > = this . _onDidChangeUri . event ;
25
29
30
+ private excludedSources : Set < string > ;
31
+ private readonly hasProviderContext : IContextKey < boolean > ;
26
32
private readonly providers = new Map < string , TimelineProvider > ( ) ;
27
33
private readonly providerSubscriptions = new Map < string , IDisposable > ( ) ;
28
34
29
35
constructor (
30
36
@ILogService private readonly logService : ILogService ,
31
37
@IViewsService protected viewsService : IViewsService ,
38
+ @IConfigurationService protected configurationService : IConfigurationService ,
39
+ @IContextKeyService protected contextKeyService : IContextKeyService ,
32
40
) {
41
+ this . hasProviderContext = TimelineHasProviderContext . bindTo ( this . contextKeyService ) ;
42
+
43
+ this . excludedSources = new Set ( configurationService . getValue ( 'timeline.excludeSources' ) ) ;
44
+ configurationService . onDidChangeConfiguration ( e => {
45
+ if ( e . affectsConfiguration ( 'timeline.excludeSources' ) ) {
46
+ this . excludedSources = new Set ( this . configurationService . getValue ( 'timeline.excludeSources' ) ) ;
47
+
48
+ this . updateHasProviderContext ( ) ;
49
+ }
50
+ } , this ) ;
51
+
52
+ this . updateHasProviderContext ( ) ;
53
+
33
54
// let source = 'fast-source';
34
55
// this.registerTimelineProvider({
35
56
// scheme: '*',
@@ -213,6 +234,9 @@ export class TimelineService implements ITimelineService {
213
234
}
214
235
215
236
this . providers . set ( id , provider ) ;
237
+
238
+ this . updateHasProviderContext ( ) ;
239
+
216
240
if ( provider . onDidChange ) {
217
241
this . providerSubscriptions . set ( id , provider . onDidChange ( e => this . _onDidChangeTimeline . fire ( e ) ) ) ;
218
242
}
@@ -235,11 +259,24 @@ export class TimelineService implements ITimelineService {
235
259
236
260
this . providers . delete ( id ) ;
237
261
this . providerSubscriptions . delete ( id ) ;
262
+
263
+ this . updateHasProviderContext ( ) ;
264
+
238
265
this . _onDidChangeProviders . fire ( { removed : [ id ] } ) ;
239
266
}
240
267
241
268
setUri ( uri : URI ) {
242
269
this . viewsService . openView ( TimelinePaneId , true ) ;
243
270
this . _onDidChangeUri . fire ( uri ) ;
244
271
}
272
+
273
+ private updateHasProviderContext ( ) {
274
+ if ( this . providers . size === 0 ) {
275
+ this . hasProviderContext . set ( false ) ;
276
+ return ;
277
+ }
278
+
279
+ const hasProviders = [ ...this . providers . keys ( ) ] . some ( id => ! this . excludedSources . has ( id ) ) ;
280
+ this . hasProviderContext . set ( hasProviders ) ;
281
+ }
245
282
}
0 commit comments