Skip to content

Commit

Permalink
fixes #79037
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Sep 3, 2019
1 parent 99bc09c commit e374f33
Showing 1 changed file with 14 additions and 48 deletions.
62 changes: 14 additions & 48 deletions src/vs/workbench/contrib/scm/browser/scmViewlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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] };
Expand All @@ -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<number>;
private viewDescriptors: RepositoryViewDescriptor[] = [];

private _onDidSplice = new Emitter<ISpliceEvent<ISCMRepository>>();
Expand Down Expand Up @@ -1103,9 +1103,6 @@ export class SCMViewlet extends ViewContainerViewlet implements IViewModel {
}
}

private readonly _onDidChangeRepositories = new Emitter<void>();
private readonly _onHaveChangedRepositories = Event.debounce(this._onDidChangeRepositories.event, () => null, 1000);

constructor(
@IWorkbenchLayoutService layoutService: IWorkbenchLayoutService,
@ITelemetryService telemetryService: ITelemetryService,
Expand All @@ -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);

Expand All @@ -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<IViewsRegistry>(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<boolean>('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 {
Expand Down Expand Up @@ -1186,54 +1186,20 @@ export class SCMViewlet extends ViewContainerViewlet implements IViewModel {

private onDidChangeRepositories(): void {
const repositoryCount = this.repositories.length;

const viewsRegistry = Registry.as<IViewsRegistry>(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<boolean>('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<boolean>('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];
Expand Down

0 comments on commit e374f33

Please sign in to comment.