From e374f33c3f2bcb6538557d43f05e36eca2bb3542 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Tue, 3 Sep 2019 14:27:12 +0200 Subject: [PATCH] fixes #79037 --- .../contrib/scm/browser/scmViewlet.ts | 62 +++++-------------- 1 file changed, 14 insertions(+), 48 deletions(-) diff --git a/src/vs/workbench/contrib/scm/browser/scmViewlet.ts b/src/vs/workbench/contrib/scm/browser/scmViewlet.ts index 0c43cc990a5d8..c80ce4371c88a 100644 --- a/src/vs/workbench/contrib/scm/browser/scmViewlet.ts +++ b/src/vs/workbench/contrib/scm/browser/scmViewlet.ts @@ -20,7 +20,7 @@ import { CountBadge } from 'vs/base/browser/ui/countBadge/countBadge'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IContextViewService, IContextMenuService } from 'vs/platform/contextview/browser/contextView'; -import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; +import { IContextKeyService, ContextKeyExpr, IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { ICommandService } from 'vs/platform/commands/common/commands'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { MenuItemAction, IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions'; @@ -1030,9 +1030,10 @@ class MainPanelDescriptor implements IViewDescriptor { readonly name = MainPanel.TITLE; readonly ctorDescriptor: { ctor: any, arguments?: any[] }; readonly canToggleVisibility = true; - readonly hideByDefault = true; + readonly hideByDefault = false; readonly order = -1000; readonly workspace = true; + readonly when = ContextKeyExpr.or(ContextKeyExpr.equals('config.scm.alwaysShowProviders', true), ContextKeyExpr.and(ContextKeyExpr.notEquals('scm.providerCount', 0), ContextKeyExpr.notEquals('scm.providerCount', 1))); constructor(viewModel: IViewModel) { this.ctorDescriptor = { ctor: MainPanel, arguments: [viewModel] }; @@ -1043,13 +1044,12 @@ export class SCMViewlet extends ViewContainerViewlet implements IViewModel { private static readonly STATE_KEY = 'workbench.scm.views.state'; - private repositoryCount = 0; private el: HTMLElement; private message: HTMLElement; private menus: SCMMenus; private _repositories: ISCMRepository[] = []; - private mainPanelDescriptor = new MainPanelDescriptor(this); + private repositoryCountKey: IContextKey; private viewDescriptors: RepositoryViewDescriptor[] = []; private _onDidSplice = new Emitter>(); @@ -1103,9 +1103,6 @@ export class SCMViewlet extends ViewContainerViewlet implements IViewModel { } } - private readonly _onDidChangeRepositories = new Emitter(); - private readonly _onHaveChangedRepositories = Event.debounce(this._onDidChangeRepositories.event, () => null, 1000); - constructor( @IWorkbenchLayoutService layoutService: IWorkbenchLayoutService, @ITelemetryService telemetryService: ITelemetryService, @@ -1121,6 +1118,7 @@ export class SCMViewlet extends ViewContainerViewlet implements IViewModel { @IConfigurationService configurationService: IConfigurationService, @IExtensionService extensionService: IExtensionService, @IWorkspaceContextService protected contextService: IWorkspaceContextService, + @IContextKeyService contextKeyService: IContextKeyService, ) { super(VIEWLET_ID, SCMViewlet.STATE_KEY, true, configurationService, layoutService, telemetryService, storageService, instantiationService, themeService, contextMenuService, extensionService, contextService); @@ -1129,15 +1127,17 @@ export class SCMViewlet extends ViewContainerViewlet implements IViewModel { this.message = $('.empty-message', { tabIndex: 0 }, localize('no open repo', "No source control providers registered.")); + const viewsRegistry = Registry.as(Extensions.ViewsRegistry); + viewsRegistry.registerViews([new MainPanelDescriptor(this)], VIEW_CONTAINER); + this._register(configurationService.onDidChangeConfiguration(e => { - if (e.affectsConfiguration('scm.alwaysShowProviders')) { - this.onDidChangeRepositories(); + if (e.affectsConfiguration('scm.alwaysShowProviders') && configurationService.getValue('scm.alwaysShowProviders')) { + this.viewsModel.setVisible(MainPanel.ID, true); } })); - this._register(Event.once(this._onHaveChangedRepositories)(this.onAfterStartup, this)); + this.repositoryCountKey = contextKeyService.createKey('scm.providerCount', 0); this._register(this.viewsModel.onDidRemove(this.onDidHideView, this)); - this._register(contextService.onDidChangeWorkspaceFolders(this.onDidChangeWorkspaceFolders, this)); } create(parent: HTMLElement): void { @@ -1186,54 +1186,20 @@ export class SCMViewlet extends ViewContainerViewlet implements IViewModel { private onDidChangeRepositories(): void { const repositoryCount = this.repositories.length; - - const viewsRegistry = Registry.as(Extensions.ViewsRegistry); - if (this.repositoryCount === 0 && repositoryCount !== 0) { - viewsRegistry.registerViews([this.mainPanelDescriptor], VIEW_CONTAINER); - } else if (this.repositoryCount !== 0 && repositoryCount === 0) { - viewsRegistry.deregisterViews([this.mainPanelDescriptor], VIEW_CONTAINER); - } - - const alwaysShowProviders = this.configurationService.getValue('scm.alwaysShowProviders') || false; - - if (alwaysShowProviders && repositoryCount > 0) { - this.viewsModel.setVisible(MainPanel.ID, true); - } - toggleClass(this.el, 'empty', repositoryCount === 0); - this.repositoryCount = repositoryCount; - - this._onDidChangeRepositories.fire(); - } - - private onAfterStartup(): void { - if (this.repositoryCount > 0 && this.viewDescriptors.every(d => !this.viewsModel.isVisible(d.id))) { - this.viewsModel.setVisible(this.viewDescriptors[0].id, true); - } + this.repositoryCountKey.set(repositoryCount); } private onDidHideView(): void { nextTick(() => { - if (this.repositoryCount > 0 && this.viewDescriptors.every(d => !this.viewsModel.isVisible(d.id))) { - const alwaysShowProviders = this.configurationService.getValue('scm.alwaysShowProviders') || false; - this.viewsModel.setVisible(MainPanel.ID, alwaysShowProviders || this.repositoryCount > 1); + if (this.repositoryCountKey.get()! > 0 && this.viewDescriptors.every(d => !this.viewsModel.isVisible(d.id))) { this.viewsModel.setVisible(this.viewDescriptors[0].id, true); } }); } - private onDidChangeWorkspaceFolders(): void { - Event.once(this._onHaveChangedRepositories)(this.onHaveChangedWorkspaceFolders, this); - } - - private onHaveChangedWorkspaceFolders(): void { - if (this.repositoryCount > 1) { - this.viewsModel.setVisible(MainPanel.ID, true); - } - } - focus(): void { - if (this.repositoryCount === 0) { + if (this.repositoryCountKey.get()! === 0) { this.message.focus(); } else { const repository = this.visibleRepositories[0];