@@ -12,7 +12,7 @@ import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
1212import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey' ;
1313import { Event , Emitter } from 'vs/base/common/event' ;
1414import { firstIndex , move } from 'vs/base/common/arrays' ;
15- import { isUndefinedOrNull , isUndefined } from 'vs/base/common/types' ;
15+ import { isUndefinedOrNull , isUndefined , isString } from 'vs/base/common/types' ;
1616import { MenuId , registerAction2 , Action2 } from 'vs/platform/actions/common/actions' ;
1717import { localize } from 'vs/nls' ;
1818import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry' ;
@@ -22,9 +22,19 @@ import { toggleClass, addClass } from 'vs/base/browser/dom';
2222import { registerSingleton } from 'vs/platform/instantiation/common/extensions' ;
2323import { IPaneComposite } from 'vs/workbench/common/panecomposite' ;
2424import { IPanelService } from 'vs/workbench/services/panel/common/panelService' ;
25- import type { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
26- import { PaneComposite } from 'vs/workbench/browser/panecomposite' ;
25+ import { ServicesAccessor , IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
2726import { VIEW_ID as SEARCH_VIEW_ID } from 'vs/workbench/services/search/common/search' ;
27+ import { ViewPaneContainer } from 'vs/workbench/browser/parts/views/viewPaneContainer' ;
28+ import { PaneCompositePanel , PanelRegistry , PanelDescriptor , Extensions as PanelExtensions } from 'vs/workbench/browser/panel' ;
29+ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
30+ import { IThemeService } from 'vs/platform/theme/common/themeService' ;
31+ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView' ;
32+ import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions' ;
33+ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace' ;
34+ import { Viewlet , ViewletDescriptor , ViewletRegistry , Extensions as ViewletExtensions } from 'vs/workbench/browser/viewlet' ;
35+ import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
36+ import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService' ;
37+ import { URI } from 'vs/base/common/uri' ;
2838
2939export interface IViewState {
3040 visibleGlobal : boolean | undefined ;
@@ -451,10 +461,14 @@ export class ViewsService extends Disposable implements IViewsService {
451461 private readonly viewContainersRegistry : IViewContainersRegistry ;
452462 private readonly viewDisposable : Map < IViewDescriptor , IDisposable > ;
453463
464+ private readonly _onDidChangeViewVisibility : Emitter < { id : string , visible : boolean } > = this . _register ( new Emitter < { id : string , visible : boolean } > ( ) ) ;
465+ readonly onDidChangeViewVisibility : Event < { id : string , visible : boolean } > = this . _onDidChangeViewVisibility . event ;
466+
454467 constructor (
455468 @IViewDescriptorService private readonly viewDescriptorService : IViewDescriptorService ,
456469 @IPanelService private readonly panelService : IPanelService ,
457- @IViewletService private readonly viewletService : IViewletService
470+ @IViewletService private readonly viewletService : IViewletService ,
471+ @IInstantiationService private readonly instantiationService : IInstantiationService ,
458472 ) {
459473 super ( ) ;
460474
@@ -466,11 +480,11 @@ export class ViewsService extends Disposable implements IViewsService {
466480 this . viewDisposable . clear ( ) ;
467481 } ) ) ;
468482
469- this . viewContainersRegistry . all . forEach ( viewContainer => this . onViewContainerRegistered ( viewContainer ) ) ;
470- this . _register ( this . viewContainersRegistry . onDidRegister ( ( { viewContainer } ) => this . onViewContainerRegistered ( viewContainer ) ) ) ;
483+ this . viewContainersRegistry . all . forEach ( viewContainer => this . onDidRegisterViewContainer ( viewContainer , this . viewContainersRegistry . getViewContainerLocation ( viewContainer ) ) ) ;
484+ this . _register ( this . viewContainersRegistry . onDidRegister ( ( { viewContainer, viewContainerLocation } ) => this . onDidRegisterViewContainer ( viewContainer , viewContainerLocation ) ) ) ;
471485 }
472486
473- private onViewContainerRegistered ( viewContainer : ViewContainer ) : void {
487+ private onDidRegisterViewContainer ( viewContainer : ViewContainer , location : ViewContainerLocation ) : void {
474488 const viewDescriptorCollection = this . viewDescriptorService . getViewDescriptors ( viewContainer ) ;
475489 this . onViewsAdded ( viewDescriptorCollection . allViewDescriptors , viewContainer ) ;
476490 this . _register ( viewDescriptorCollection . onDidChangeViews ( ( { added, removed } ) => {
@@ -577,20 +591,20 @@ export class ViewsService extends Disposable implements IViewsService {
577591 return undefined ;
578592 }
579593
580- getActiveViewWithId ( id : string ) : IView | null {
594+ getActiveViewWithId < T extends IView > ( id : string ) : T | null {
581595 const viewContainer = this . viewDescriptorService . getViewContainer ( id ) ;
582596 if ( viewContainer ) {
583597 const location = this . viewContainersRegistry . getViewContainerLocation ( viewContainer ) ;
584598
585599 if ( location === ViewContainerLocation . Sidebar ) {
586600 const activeViewlet = this . viewletService . getActiveViewlet ( ) ;
587601 if ( activeViewlet ?. getId ( ) === viewContainer . id ) {
588- return activeViewlet . getViewPaneContainer ( ) . getView ( id ) ?? null ;
602+ return activeViewlet . getViewPaneContainer ( ) . getView ( id ) as T ?? null ;
589603 }
590604 } else if ( location === ViewContainerLocation . Panel ) {
591605 const activePanel = this . panelService . getActivePanel ( ) ;
592- if ( activePanel ?. getId ( ) === viewContainer . id && activePanel instanceof PaneComposite ) {
593- return activePanel . getViewPaneContainer ( ) . getView ( id ) ?? null ;
606+ if ( activePanel ?. getId ( ) === viewContainer . id ) {
607+ return ( activePanel as IPaneComposite ) . getViewPaneContainer ( ) . getView ( id ) as T ?? null ;
594608 }
595609 }
596610 }
@@ -613,6 +627,14 @@ export class ViewsService extends Disposable implements IViewsService {
613627
614628 return null ;
615629 }
630+
631+ createContainer ( container : ViewContainer ) : ViewPaneContainer {
632+ const viewPaneContainer : ViewPaneContainer = this . _register ( ( this . instantiationService as any ) . createInstance ( container . ctorDescriptor ! . ctor , ...( container . ctorDescriptor ! . staticArguments || [ ] ) ) ) ;
633+ this . _register ( viewPaneContainer . onDidAddViews ( views => views . forEach ( view => this . _onDidChangeViewVisibility . fire ( { id : view . id , visible : view . isBodyVisible ( ) } ) ) ) ) ;
634+ this . _register ( viewPaneContainer . onDidChangeViewVisibility ( view => this . _onDidChangeViewVisibility . fire ( { id : view . id , visible : view . isBodyVisible ( ) } ) ) ) ;
635+ this . _register ( viewPaneContainer . onDidRemoveViews ( views => views . forEach ( view => this . _onDidChangeViewVisibility . fire ( { id : view . id , visible : false } ) ) ) ) ;
636+ return viewPaneContainer ;
637+ }
616638}
617639
618640export function createFileIconThemableTreeContainerScope ( container : HTMLElement , themeService : IWorkbenchThemeService ) : IDisposable {
@@ -629,3 +651,74 @@ export function createFileIconThemableTreeContainerScope(container: HTMLElement,
629651}
630652
631653registerSingleton ( IViewsService , ViewsService ) ;
654+
655+ // Viewlets & Panels
656+ ( function registerViewletsAndPanels ( ) : void {
657+ const registerPanel = ( viewContainer : ViewContainer ) : void => {
658+ class PaneContainerPanel extends PaneCompositePanel {
659+ constructor (
660+ @ITelemetryService telemetryService : ITelemetryService ,
661+ @IStorageService storageService : IStorageService ,
662+ @IInstantiationService instantiationService : IInstantiationService ,
663+ @IThemeService themeService : IThemeService ,
664+ @IContextMenuService contextMenuService : IContextMenuService ,
665+ @IExtensionService extensionService : IExtensionService ,
666+ @IWorkspaceContextService contextService : IWorkspaceContextService ,
667+ @IViewsService viewsService : ViewsService
668+ ) {
669+ super ( viewContainer . id , viewsService . createContainer ( viewContainer ) , telemetryService , storageService , instantiationService , themeService , contextMenuService , extensionService , contextService ) ;
670+ }
671+ }
672+ Registry . as < PanelRegistry > ( PanelExtensions . Panels ) . registerPanel ( PanelDescriptor . create (
673+ PaneContainerPanel ,
674+ viewContainer . id ,
675+ viewContainer . name ,
676+ isString ( viewContainer . icon ) ? viewContainer . icon : undefined ,
677+ viewContainer . order ,
678+ viewContainer . focusCommand ?. id ,
679+ ) ) ;
680+ } ;
681+
682+ const registerViewlet = ( viewContainer : ViewContainer ) : void => {
683+ class PaneContainerViewlet extends Viewlet {
684+ constructor (
685+ @IConfigurationService configurationService : IConfigurationService ,
686+ @IWorkbenchLayoutService layoutService : IWorkbenchLayoutService ,
687+ @ITelemetryService telemetryService : ITelemetryService ,
688+ @IWorkspaceContextService contextService : IWorkspaceContextService ,
689+ @IStorageService storageService : IStorageService ,
690+ @IInstantiationService instantiationService : IInstantiationService ,
691+ @IThemeService themeService : IThemeService ,
692+ @IContextMenuService contextMenuService : IContextMenuService ,
693+ @IExtensionService extensionService : IExtensionService
694+ ) {
695+ super ( viewContainer . id , ( instantiationService as any ) . createInstance ( viewContainer . ctorDescriptor ! . ctor , ...( viewContainer . ctorDescriptor ! . staticArguments || [ ] ) ) , telemetryService , storageService , instantiationService , themeService , contextMenuService , extensionService , contextService , layoutService , configurationService ) ;
696+ }
697+ }
698+ const viewletDescriptor = ViewletDescriptor . create (
699+ PaneContainerViewlet ,
700+ viewContainer . id ,
701+ viewContainer . name ,
702+ isString ( viewContainer . icon ) ? viewContainer . icon : undefined ,
703+ viewContainer . order ,
704+ viewContainer . icon instanceof URI ? viewContainer . icon : undefined
705+ ) ;
706+
707+ Registry . as < ViewletRegistry > ( ViewletExtensions . Viewlets ) . registerViewlet ( viewletDescriptor ) ;
708+ } ;
709+
710+ const viewContainerRegistry = Registry . as < IViewContainersRegistry > ( ViewExtensions . ViewContainersRegistry ) ;
711+ viewContainerRegistry . getViewContainers ( ViewContainerLocation . Panel ) . forEach ( viewContainer => registerPanel ( viewContainer ) ) ;
712+ viewContainerRegistry . onDidRegister ( ( { viewContainer, viewContainerLocation } ) => {
713+ switch ( viewContainerLocation ) {
714+ case ViewContainerLocation . Panel :
715+ registerPanel ( viewContainer ) ;
716+ return ;
717+ case ViewContainerLocation . Sidebar :
718+ if ( viewContainer . ctorDescriptor ) {
719+ registerViewlet ( viewContainer ) ;
720+ }
721+ return ;
722+ }
723+ } ) ;
724+ } ) ( ) ;
0 commit comments