Skip to content

Commit

Permalink
#49054 Do not hide in built viewlets
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Mar 8, 2019
1 parent 53c5277 commit fa93b07
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
15 changes: 6 additions & 9 deletions src/vs/workbench/browser/parts/activitybar/activitybarPart.ts
Expand Up @@ -34,8 +34,6 @@ import { isUndefinedOrNull } from 'vs/base/common/types';
import { IActivityBarService } from 'vs/workbench/services/activityBar/browser/activityBarService';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';

const SCM_VIEWLET_ID = 'workbench.view.scm';

interface ICachedViewlet {
id: string;
iconUrl?: UriComponents;
Expand Down Expand Up @@ -136,7 +134,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
for (const viewlet of this.viewletService.getViewlets()) {
this.enableCompositeActions(viewlet);
const viewContainer = this.getViewContainer(viewlet.id);
if (viewContainer) {
if (viewContainer && viewContainer.hideIfEmpty) {
const viewDescriptors = this.viewsService.getViewDescriptors(viewContainer);
if (viewDescriptors) {
this.onDidChangeActiveViews(viewlet, viewDescriptors);
Expand Down Expand Up @@ -167,7 +165,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
const viewletDescriptor = this.viewletService.getViewlet(viewlet.getId());
if (viewletDescriptor) {
const viewContainer = this.getViewContainer(viewletDescriptor.id);
if (viewContainer) {
if (viewContainer && viewContainer.hideIfEmpty) {
const viewDescriptors = this.viewsService.getViewDescriptors(viewContainer);
if (viewDescriptors && viewDescriptors.activeViewDescriptors.length === 0) {
this.removeComposite(viewletDescriptor.id, true); // Update the composite bar by hiding
Expand Down Expand Up @@ -313,6 +311,10 @@ export class ActivitybarPart extends Part implements IActivityBarService {
}

private shouldBeHidden(viewletId: string, cachedViewlet: ICachedViewlet): boolean {
const viewContainer = this.getViewContainer(viewletId);
if (!viewContainer || !viewContainer.hideIfEmpty) {
return false;
}
return cachedViewlet && cachedViewlet.views && cachedViewlet.views.length
? cachedViewlet.views.every(({ when }) => !!when && !this.contextKeyService.contextMatchesRules(ContextKeyExpr.deserialize(when)))
: viewletId === TEST_VIEW_CONTAINER_ID /* Hide Test viewlet for the first time or it had no views registered before */;
Expand Down Expand Up @@ -488,11 +490,6 @@ export class ActivitybarPart extends Part implements IActivityBarService {
}

private getViewContainer(viewletId: string): ViewContainer | undefined {
// TODO: @Joao Remove this after moving SCM Viewlet to ViewContainerViewlet - https://github.com/Microsoft/vscode/issues/49054
if (viewletId === SCM_VIEWLET_ID) {
return undefined;
}

const viewContainerRegistry = Registry.as<IViewContainersRegistry>(ViewContainerExtensions.ViewContainersRegistry);
return viewContainerRegistry.get(viewletId);
}
Expand Down
7 changes: 4 additions & 3 deletions src/vs/workbench/common/views.ts
Expand Up @@ -67,7 +67,7 @@ export interface IViewContainersRegistry {
}

export class ViewContainer {
protected constructor(readonly id: string, readonly extensionId: ExtensionIdentifier) { }
protected constructor(readonly id: string, readonly hideIfEmpty: boolean, readonly extensionId?: ExtensionIdentifier) { }
}

class ViewContainersRegistryImpl implements IViewContainersRegistry {
Expand All @@ -84,15 +84,16 @@ class ViewContainersRegistryImpl implements IViewContainersRegistry {
return values(this.viewContainers);
}

registerViewContainer(id: string, extensionId: ExtensionIdentifier): ViewContainer {
registerViewContainer(id: string, extensionId?: ExtensionIdentifier): ViewContainer {
const existing = this.viewContainers.get(id);
if (existing) {
return existing;
}
const hideIfEmpty = id === TEST_VIEW_CONTAINER_ID || !!extensionId;

const viewContainer = new class extends ViewContainer {
constructor() {
super(id, extensionId);
super(id, hideIfEmpty, extensionId);
}
};
this.viewContainers.set(id, viewContainer);
Expand Down

0 comments on commit fa93b07

Please sign in to comment.