5
5
6
6
import { Disposable , IDisposable , toDisposable , DisposableStore } from 'vs/base/common/lifecycle' ;
7
7
import { IViewDescriptorService , ViewContainer , IViewDescriptor , IView , ViewContainerLocation , IViewsService , IViewPaneContainer } from 'vs/workbench/common/views' ;
8
- import { FocusedViewContext , getVisbileViewContextKey , getEnabledViewContainerContextKey } from 'vs/workbench/common/contextkeys' ;
8
+ import { FocusedViewContext , getVisbileViewContextKey } from 'vs/workbench/common/contextkeys' ;
9
9
import { Registry } from 'vs/platform/registry/common/platform' ;
10
10
import { IStorageService } from 'vs/platform/storage/common/storage' ;
11
11
import { ContextKeyExpr , IContextKey , IContextKeyService , RawContextKey } from 'vs/platform/contextkey/common/contextkey' ;
@@ -50,6 +50,7 @@ export class ViewsService extends Disposable implements IViewsService {
50
50
private readonly _onDidChangeFocusedView = this . _register ( new Emitter < void > ( ) ) ;
51
51
readonly onDidChangeFocusedView = this . _onDidChangeFocusedView . event ;
52
52
53
+ private readonly enabledViewContainersContextKeys : Map < string , IContextKey < boolean > > ;
53
54
private readonly visibleViewContextKeys : Map < string , IContextKey < boolean > > ;
54
55
private readonly focusedViewContextKey : IContextKey < string > ;
55
56
@@ -63,6 +64,7 @@ export class ViewsService extends Disposable implements IViewsService {
63
64
super ( ) ;
64
65
65
66
this . viewDisposable = new Map < IViewDescriptor , IDisposable > ( ) ;
67
+ this . enabledViewContainersContextKeys = new Map < string , IContextKey < boolean > > ( ) ;
66
68
this . visibleViewContextKeys = new Map < string , IContextKey < boolean > > ( ) ;
67
69
this . viewPaneContainers = new Map < string , ViewPaneContainer > ( ) ;
68
70
@@ -126,6 +128,8 @@ export class ViewsService extends Disposable implements IViewsService {
126
128
this . onViewDescriptorsAdded ( added , viewContainer ) ;
127
129
this . onViewDescriptorsRemoved ( removed ) ;
128
130
} ) ) ;
131
+ this . updateViewContainerEnablementContextKey ( viewContainer ) ;
132
+ this . _register ( viewContainerModel . onDidChangeActiveViewDescriptors ( ( ) => this . updateViewContainerEnablementContextKey ( viewContainer ) ) ) ;
129
133
this . _register ( this . registerOpenViewContainerAction ( viewContainer ) ) ;
130
134
}
131
135
@@ -159,6 +163,15 @@ export class ViewsService extends Disposable implements IViewsService {
159
163
}
160
164
}
161
165
166
+ private updateViewContainerEnablementContextKey ( viewContainer : ViewContainer ) : void {
167
+ let contextKey = this . enabledViewContainersContextKeys . get ( viewContainer . id ) ;
168
+ if ( ! contextKey ) {
169
+ contextKey = this . contextKeyService . createKey ( getEnabledViewContainerContextKey ( viewContainer . id ) , false ) ;
170
+ this . enabledViewContainersContextKeys . set ( viewContainer . id , contextKey ) ;
171
+ }
172
+ contextKey . set ( ! ( viewContainer . hideIfEmpty && this . viewDescriptorService . getViewContainerModel ( viewContainer ) . activeViewDescriptors . length === 0 ) ) ;
173
+ }
174
+
162
175
private async openComposite ( compositeId : string , location : ViewContainerLocation , focus ?: boolean ) : Promise < IPaneComposite | undefined > {
163
176
return this . paneCompositeService . openPaneComposite ( compositeId , location , focus ) ;
164
177
}
@@ -643,6 +656,8 @@ export class ViewsService extends Disposable implements IViewsService {
643
656
}
644
657
}
645
658
659
+ function getEnabledViewContainerContextKey ( viewContainerId : string ) : string { return `viewContainer.${ viewContainerId } .enabled` ; }
660
+
646
661
function getPaneCompositeExtension ( viewContainerLocation : ViewContainerLocation ) : string {
647
662
switch ( viewContainerLocation ) {
648
663
case ViewContainerLocation . AuxiliaryBar :
0 commit comments