44 *--------------------------------------------------------------------------------------------*/
55
66import { ViewContainerLocation , IViewDescriptorService , ViewContainer , IViewsRegistry , IViewContainersRegistry , IViewDescriptor , Extensions as ViewExtensions } from 'vs/workbench/common/views' ;
7- import { IContextKey , RawContextKey , IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
7+ import { IContextKey , RawContextKey , IContextKeyService , ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey' ;
88import { IStorageService , StorageScope , IWorkspaceStorageChangeEvent } from 'vs/platform/storage/common/storage' ;
99import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions' ;
1010import { Registry } from 'vs/platform/registry/common/platform' ;
@@ -18,6 +18,8 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1818import { generateUuid } from 'vs/base/common/uuid' ;
1919import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
2020import { ViewContainerModel } from 'vs/workbench/services/views/common/viewContainerModel' ;
21+ import { registerAction2 , Action2 , MenuId } from 'vs/platform/actions/common/actions' ;
22+ import { localize } from 'vs/nls' ;
2123
2224interface ICachedViewContainerInfo {
2325 containerId : string ;
@@ -44,6 +46,7 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
4446 private readonly activeViewContextKeys : Map < string , IContextKey < boolean > > ;
4547 private readonly movableViewContextKeys : Map < string , IContextKey < boolean > > ;
4648 private readonly defaultViewLocationContextKeys : Map < string , IContextKey < boolean > > ;
49+ private readonly defaultViewContainerLocationContextKeys : Map < string , IContextKey < boolean > > ;
4750
4851 private readonly viewsRegistry : IViewsRegistry ;
4952 private readonly viewContainersRegistry : IViewContainersRegistry ;
@@ -103,6 +106,7 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
103106 this . activeViewContextKeys = new Map < string , IContextKey < boolean > > ( ) ;
104107 this . movableViewContextKeys = new Map < string , IContextKey < boolean > > ( ) ;
105108 this . defaultViewLocationContextKeys = new Map < string , IContextKey < boolean > > ( ) ;
109+ this . defaultViewContainerLocationContextKeys = new Map < string , IContextKey < boolean > > ( ) ;
106110
107111 this . viewContainersRegistry = Registry . as < IViewContainersRegistry > ( ViewExtensions . ViewContainersRegistry ) ;
108112 this . viewsRegistry = Registry . as < IViewsRegistry > ( ViewExtensions . ViewsRegistry ) ;
@@ -297,6 +301,9 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
297301 if ( from !== to ) {
298302 this . cachedViewContainerInfo . set ( viewContainer . id , to ) ;
299303
304+ const defaultLocation = this . isGeneratedContainerId ( viewContainer . id ) ? true : this . getViewContainerLocation ( viewContainer ) === this . getDefaultViewContainerLocation ( viewContainer ) ;
305+ this . getOrCreateDefaultViewContainerLocationContextKey ( viewContainer ) . set ( defaultLocation ) ;
306+
300307 this . _onDidChangeContainerLocation . fire ( { viewContainer, from, to } ) ;
301308
302309 const views = this . getViewsByContainer ( viewContainer ) ;
@@ -590,6 +597,8 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
590597 }
591598
592599 private onDidRegisterViewContainer ( viewContainer : ViewContainer ) : void {
600+ const defaultLocation = this . isGeneratedContainerId ( viewContainer . id ) ? true : this . getViewContainerLocation ( viewContainer ) === this . getDefaultViewContainerLocation ( viewContainer ) ;
601+ this . getOrCreateDefaultViewContainerLocationContextKey ( viewContainer ) . set ( defaultLocation ) ;
593602 this . getOrRegisterViewContainerModel ( viewContainer ) ;
594603 }
595604
@@ -603,6 +612,8 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
603612 this . onDidChangeActiveViews ( { added : viewContainerModel . activeViewDescriptors , removed : [ ] } ) ;
604613 viewContainerModel . onDidChangeActiveViewDescriptors ( changed => this . onDidChangeActiveViews ( changed ) , this , disposables ) ;
605614
615+ disposables . add ( this . registerResetViewContainerAction ( viewContainer ) ) ;
616+
606617 this . viewContainerModels . set ( viewContainer , { viewContainerModel : viewContainerModel , disposable : disposables } ) ;
607618
608619 // Register all views that were statically registered to this container
@@ -632,6 +643,33 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
632643 removed . forEach ( viewDescriptor => this . getOrCreateActiveViewContextKey ( viewDescriptor ) . set ( false ) ) ;
633644 }
634645
646+ private registerResetViewContainerAction ( viewContainer : ViewContainer ) : IDisposable {
647+ const that = this ;
648+ return registerAction2 ( class ResetViewLocationAction extends Action2 {
649+ constructor ( ) {
650+ super ( {
651+ id : `${ viewContainer . id } .resetViewContainerLocation` ,
652+ title : {
653+ original : 'Reset Location' ,
654+ value : localize ( 'resetViewLocation' , "Reset Location" )
655+ } ,
656+ menu : [ {
657+ id : MenuId . ViewContainerTitleContext ,
658+ when : ContextKeyExpr . or (
659+ ContextKeyExpr . and (
660+ ContextKeyExpr . equals ( 'container' , viewContainer . id ) ,
661+ ContextKeyExpr . equals ( `${ viewContainer . id } .defaultViewContainerLocation` , false )
662+ )
663+ )
664+ } ] ,
665+ } ) ;
666+ }
667+ run ( ) : void {
668+ that . moveViewContainerToLocation ( viewContainer , that . getDefaultViewContainerLocation ( viewContainer ) ) ;
669+ }
670+ } ) ;
671+ }
672+
635673 private addViews ( container : ViewContainer , views : IViewDescriptor [ ] ) : void {
636674 // Update in memory cache
637675 views . forEach ( view => {
@@ -679,6 +717,16 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
679717 }
680718 return contextKey ;
681719 }
720+
721+ private getOrCreateDefaultViewContainerLocationContextKey ( viewContainer : ViewContainer ) : IContextKey < boolean > {
722+ const defaultViewContainerLocationContextKeyId = `${ viewContainer . id } .defaultViewContainerLocation` ;
723+ let contextKey = this . defaultViewContainerLocationContextKeys . get ( defaultViewContainerLocationContextKeyId ) ;
724+ if ( ! contextKey ) {
725+ contextKey = new RawContextKey ( defaultViewContainerLocationContextKeyId , false ) . bindTo ( this . contextKeyService ) ;
726+ this . defaultViewContainerLocationContextKeys . set ( defaultViewContainerLocationContextKeyId , contextKey ) ;
727+ }
728+ return contextKey ;
729+ }
682730}
683731
684732registerSingleton ( IViewDescriptorService , ViewDescriptorService ) ;
0 commit comments