55
66import { IPanelService } from 'vs/workbench/services/panel/common/panelService' ;
77import { IActivityService , IActivity } from 'vs/workbench/services/activity/common/activity' ;
8- import { IDisposable , Disposable } from 'vs/base/common/lifecycle' ;
8+ import { IDisposable , Disposable , toDisposable } from 'vs/base/common/lifecycle' ;
99import { IActivityBarService } from 'vs/workbench/services/activityBar/browser/activityBarService' ;
1010import { registerSingleton } from 'vs/platform/instantiation/common/extensions' ;
1111import { IViewDescriptorService , ViewContainerLocation } from 'vs/workbench/common/views' ;
1212import { GLOBAL_ACTIVITY_ID , ACCOUNTS_ACTIIVTY_ID } from 'vs/workbench/common/activity' ;
13+ import { Event } from 'vs/base/common/event' ;
14+ import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
15+
16+ class ViewContainerActivityByView extends Disposable {
17+
18+ private activity : IActivity | undefined = undefined ;
19+ private activityDisposable : IDisposable = Disposable . None ;
20+
21+ constructor (
22+ private readonly viewId : string ,
23+ @IViewDescriptorService private readonly viewDescriptorService : IViewDescriptorService ,
24+ @IActivityService private readonly activityService : IActivityService ,
25+ ) {
26+ super ( ) ;
27+ this . _register ( Event . filter ( this . viewDescriptorService . onDidChangeContainer , e => e . views . some ( view => view . id === viewId ) ) ( ( ) => this . update ( ) ) ) ;
28+ this . _register ( Event . filter ( this . viewDescriptorService . onDidChangeLocation , e => e . views . some ( view => view . id === viewId ) ) ( ( ) => this . update ( ) ) ) ;
29+ }
30+
31+ setActivity ( activity : IActivity ) : void {
32+ this . activity = activity ;
33+ this . update ( ) ;
34+ }
35+
36+ clearActivity ( ) : void {
37+ this . activity = undefined ;
38+ this . update ( ) ;
39+ }
40+
41+ private update ( ) : void {
42+ this . activityDisposable . dispose ( ) ;
43+ const container = this . viewDescriptorService . getViewContainerByViewId ( this . viewId ) ;
44+ if ( container && this . activity ) {
45+ this . activityDisposable = this . activityService . showViewContainerActivity ( container . id , this . activity ) ;
46+ }
47+ }
48+
49+ dispose ( ) {
50+ this . activityDisposable . dispose ( ) ;
51+ }
52+ }
53+
54+ interface IViewActivity {
55+ id : number ;
56+ readonly activity : ViewContainerActivityByView ;
57+ }
1358
1459export class ActivityService implements IActivityService {
1560
1661 public _serviceBrand : undefined ;
1762
63+ private viewActivities = new Map < string , IViewActivity > ( ) ;
64+
1865 constructor (
1966 @IPanelService private readonly panelService : IPanelService ,
2067 @IActivityBarService private readonly activityBarService : IActivityBarService ,
2168 @IViewDescriptorService private readonly viewDescriptorService : IViewDescriptorService ,
69+ @IInstantiationService private readonly instantiationService : IInstantiationService
2270 ) { }
2371
2472 showViewContainerActivity ( viewContainerId : string , { badge, clazz, priority } : IActivity ) : IDisposable {
@@ -35,6 +83,30 @@ export class ActivityService implements IActivityService {
3583 return Disposable . None ;
3684 }
3785
86+ showViewActivity ( viewId : string , activity : IActivity ) : IDisposable {
87+ let maybeItem = this . viewActivities . get ( viewId ) ;
88+
89+ if ( maybeItem ) {
90+ maybeItem . id ++ ;
91+ } else {
92+ maybeItem = {
93+ id : 1 ,
94+ activity : this . instantiationService . createInstance ( ViewContainerActivityByView , viewId )
95+ } ;
96+ }
97+
98+ const id = maybeItem . id ;
99+ maybeItem . activity . setActivity ( activity ) ;
100+
101+ const item = maybeItem ;
102+ return toDisposable ( ( ) => {
103+ if ( item . id === id ) {
104+ item . activity . dispose ( ) ;
105+ this . viewActivities . delete ( viewId ) ;
106+ }
107+ } ) ;
108+ }
109+
38110 showAccountsActivity ( { badge, clazz, priority } : IActivity ) : IDisposable {
39111 return this . activityBarService . showActivity ( ACCOUNTS_ACTIIVTY_ID , badge , clazz , priority ) ;
40112 }
0 commit comments