Skip to content

Commit fa45ed2

Browse files
authored
1 parent d6b684a commit fa45ed2

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/vs/workbench/services/views/browser/viewDescriptorService.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
4747

4848
private readonly viewContainerModels = this._register(new DisposableMap<ViewContainer, { viewContainerModel: ViewContainerModel; disposables: DisposableStore } & IDisposable>());
4949
private readonly viewsVisibilityActionDisposables = this._register(new DisposableMap<ViewContainer, IDisposable>());
50+
private canRegisterViewsVisibilityActions: boolean = false;
5051
private readonly activeViewContextKeys: Map<string, IContextKey<boolean>>;
5152
private readonly movableViewContextKeys: Map<string, IContextKey<boolean>>;
5253
private readonly defaultViewLocationContextKeys: Map<string, IContextKey<boolean>>;
@@ -202,7 +203,10 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
202203
this.saveViewCustomizations();
203204

204205
// Register visibility actions for all views
205-
this.registerViewsVisibilityActions();
206+
for (const [key, value] of this.viewContainerModels) {
207+
this.registerViewsVisibilityActions(key, value);
208+
}
209+
this.canRegisterViewsVisibilityActions = true;
206210
}
207211

208212
private onDidRegisterViews(views: { views: IViewDescriptor[]; viewContainer: ViewContainer }[]): void {
@@ -697,7 +701,8 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
697701

698702
disposables.add(this.registerResetViewContainerAction(viewContainer));
699703

700-
this.viewContainerModels.set(viewContainer, { viewContainerModel: viewContainerModel, disposables, dispose: () => disposables.dispose() });
704+
const value = { viewContainerModel: viewContainerModel, disposables, dispose: () => disposables.dispose() };
705+
this.viewContainerModels.set(viewContainer, value);
701706

702707
// Register all views that were statically registered to this container
703708
// Potentially, this is registering something that was handled by another container
@@ -712,13 +717,18 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
712717
viewsToRegister.forEach(viewDescriptor => this.getOrCreateMovableViewContextKey(viewDescriptor).set(!!viewDescriptor.canMoveView));
713718
});
714719
}
720+
721+
if (this.canRegisterViewsVisibilityActions) {
722+
this.registerViewsVisibilityActions(viewContainer, value);
723+
}
715724
}
716725

717726
return viewContainerModel;
718727
}
719728

720729
private onDidDeregisterViewContainer(viewContainer: ViewContainer): void {
721730
this.viewContainerModels.deleteAndDispose(viewContainer);
731+
this.viewsVisibilityActionDisposables.deleteAndDispose(viewContainer);
722732
}
723733

724734
private onDidChangeActiveViews({ added, removed }: { added: ReadonlyArray<IViewDescriptor>; removed: ReadonlyArray<IViewDescriptor> }): void {
@@ -735,16 +745,14 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
735745
});
736746
}
737747

738-
private registerViewsVisibilityActions(): void {
739-
for (const [viewContainer, { viewContainerModel, disposables }] of this.viewContainerModels) {
740-
this.viewsVisibilityActionDisposables.set(viewContainer, this.registerViewsVisibilityActionsForContainer(viewContainerModel));
741-
disposables.add(Event.any(
742-
viewContainerModel.onDidChangeActiveViewDescriptors,
743-
viewContainerModel.onDidAddVisibleViewDescriptors,
744-
viewContainerModel.onDidRemoveVisibleViewDescriptors,
745-
viewContainerModel.onDidMoveVisibleViewDescriptors
746-
)(e => this.viewsVisibilityActionDisposables.set(viewContainer, this.registerViewsVisibilityActionsForContainer(viewContainerModel))));
747-
}
748+
private registerViewsVisibilityActions(viewContainer: ViewContainer, { viewContainerModel, disposables }: { viewContainerModel: ViewContainerModel; disposables: DisposableStore }): void {
749+
this.viewsVisibilityActionDisposables.set(viewContainer, this.registerViewsVisibilityActionsForContainer(viewContainerModel));
750+
disposables.add(Event.any(
751+
viewContainerModel.onDidChangeActiveViewDescriptors,
752+
viewContainerModel.onDidAddVisibleViewDescriptors,
753+
viewContainerModel.onDidRemoveVisibleViewDescriptors,
754+
viewContainerModel.onDidMoveVisibleViewDescriptors
755+
)(e => this.viewsVisibilityActionDisposables.set(viewContainer, this.registerViewsVisibilityActionsForContainer(viewContainerModel))));
748756
}
749757

750758
private registerViewsVisibilityActionsForContainer(viewContainerModel: ViewContainerModel): IDisposable {

0 commit comments

Comments
 (0)