mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 11:10:48 +00:00
#114144 fix remote explorer icon flickering
This commit is contained in:
parent
d03490f353
commit
e12a9d74a6
1 changed files with 70 additions and 48 deletions
|
@ -23,9 +23,9 @@ import { IStorageService, StorageScope, IStorageValueChangeEvent, StorageTarget
|
|||
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { ToggleCompositePinnedAction, ICompositeBarColors, ActivityAction, ICompositeActivity } from 'vs/workbench/browser/parts/compositeBarActions';
|
||||
import { IViewDescriptorService, ViewContainer, TEST_VIEW_CONTAINER_ID, IViewContainerModel, ViewContainerLocation, IViewsService } from 'vs/workbench/common/views';
|
||||
import { IViewDescriptorService, ViewContainer, IViewContainerModel, ViewContainerLocation, IViewsService } from 'vs/workbench/common/views';
|
||||
import { IContextKeyService, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { assertIsDefined } from 'vs/base/common/types';
|
||||
import { assertIsDefined, isString } from 'vs/base/common/types';
|
||||
import { IActivityBarService } from 'vs/workbench/services/activityBar/browser/activityBarService';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
|
||||
|
@ -49,6 +49,7 @@ interface IPlaceholderViewContainer {
|
|||
readonly name?: string;
|
||||
readonly iconUrl?: UriComponents;
|
||||
readonly themeIcon?: ThemeIcon;
|
||||
readonly isBuiltin?: boolean;
|
||||
readonly views?: { when?: string; }[];
|
||||
}
|
||||
|
||||
|
@ -66,6 +67,7 @@ interface ICachedViewContainer {
|
|||
readonly pinned: boolean;
|
||||
readonly order?: number;
|
||||
visible: boolean;
|
||||
isBuiltin?: boolean;
|
||||
views?: { when?: string; }[];
|
||||
}
|
||||
|
||||
|
@ -116,6 +118,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
|
|||
private readonly keyboardNavigationDisposables = this._register(new DisposableStore());
|
||||
|
||||
private readonly location = ViewContainerLocation.Sidebar;
|
||||
private hasExtensionsRegistered: boolean = false;
|
||||
|
||||
constructor(
|
||||
@IInstantiationService private readonly instantiationService: IInstantiationService,
|
||||
|
@ -319,7 +322,22 @@ export class ActivitybarPart extends Part implements IActivityBarService {
|
|||
}
|
||||
|
||||
private onDidRegisterExtensions(): void {
|
||||
this.removeNotExistingComposites();
|
||||
this.hasExtensionsRegistered = true;
|
||||
|
||||
// show/hide/remove composites
|
||||
for (const { id } of this.cachedViewContainers) {
|
||||
const viewContainer = this.getViewContainer(id);
|
||||
if (viewContainer) {
|
||||
this.showOrHideViewContainer(viewContainer);
|
||||
} else {
|
||||
if (this.viewDescriptorService.isViewContainerRemovedPermanently(id)) {
|
||||
this.removeComposite(id);
|
||||
} else {
|
||||
this.hideComposite(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.saveCachedViewContainers();
|
||||
}
|
||||
|
||||
|
@ -331,7 +349,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
|
|||
this.compositeBar.addComposite(viewContainer);
|
||||
this.compositeBar.activateComposite(viewContainer.id);
|
||||
|
||||
if (viewContainer.hideIfEmpty) {
|
||||
if (this.shouldBeHidden(viewContainer)) {
|
||||
const viewContainerModel = this.viewDescriptorService.getViewContainerModel(viewContainer);
|
||||
if (viewContainerModel.activeViewDescriptors.length === 0) {
|
||||
// Update the composite bar by hiding
|
||||
|
@ -675,32 +693,27 @@ export class ActivitybarPart extends Part implements IActivityBarService {
|
|||
|
||||
private onDidRegisterViewContainers(viewContainers: ReadonlyArray<ViewContainer>): void {
|
||||
for (const viewContainer of viewContainers) {
|
||||
this.compositeBar.addComposite(viewContainer);
|
||||
|
||||
// Pin it by default if it is new
|
||||
const cachedViewContainer = this.cachedViewContainers.filter(({ id }) => id === viewContainer.id)[0];
|
||||
const visibleViewContainer = this.viewsService.getVisibleViewContainer(this.location);
|
||||
const isActive = visibleViewContainer?.id === viewContainer.id;
|
||||
|
||||
if (isActive || !this.shouldBeHidden(viewContainer.id, cachedViewContainer)) {
|
||||
this.compositeBar.addComposite(viewContainer);
|
||||
|
||||
// Pin it by default if it is new
|
||||
if (!cachedViewContainer) {
|
||||
this.compositeBar.pin(viewContainer.id);
|
||||
}
|
||||
|
||||
if (isActive) {
|
||||
this.compositeBar.activateComposite(viewContainer.id);
|
||||
}
|
||||
if (!cachedViewContainer) {
|
||||
this.compositeBar.pin(viewContainer.id);
|
||||
}
|
||||
|
||||
// Active
|
||||
const visibleViewContainer = this.viewsService.getVisibleViewContainer(this.location);
|
||||
if (visibleViewContainer?.id === viewContainer.id) {
|
||||
this.compositeBar.activateComposite(viewContainer.id);
|
||||
}
|
||||
}
|
||||
|
||||
for (const viewContainer of viewContainers) {
|
||||
const viewContainerModel = this.viewDescriptorService.getViewContainerModel(viewContainer);
|
||||
this.updateActivity(viewContainer, viewContainerModel);
|
||||
this.onDidChangeActiveViews(viewContainer, viewContainerModel);
|
||||
this.showOrHideViewContainer(viewContainer);
|
||||
|
||||
const disposables = new DisposableStore();
|
||||
disposables.add(viewContainerModel.onDidChangeContainerInfo(() => this.updateActivity(viewContainer, viewContainerModel)));
|
||||
disposables.add(viewContainerModel.onDidChangeActiveViewDescriptors(() => this.onDidChangeActiveViews(viewContainer, viewContainerModel)));
|
||||
disposables.add(viewContainerModel.onDidChangeActiveViewDescriptors(() => this.showOrHideViewContainer(viewContainer)));
|
||||
|
||||
this.viewContainerDisposables.set(viewContainer.id, disposables);
|
||||
}
|
||||
|
@ -755,36 +768,43 @@ export class ActivitybarPart extends Part implements IActivityBarService {
|
|||
return { id, name, cssClass, iconUrl, keybindingId };
|
||||
}
|
||||
|
||||
private onDidChangeActiveViews(viewContainer: ViewContainer, viewContainerModel: IViewContainerModel): void {
|
||||
if (viewContainerModel.activeViewDescriptors.length) {
|
||||
this.compositeBar.addComposite(viewContainer);
|
||||
} else if (viewContainer.hideIfEmpty) {
|
||||
private showOrHideViewContainer(viewContainer: ViewContainer): void {
|
||||
if (this.shouldBeHidden(viewContainer)) {
|
||||
this.hideComposite(viewContainer.id);
|
||||
} else {
|
||||
this.compositeBar.addComposite(viewContainer);
|
||||
}
|
||||
}
|
||||
|
||||
private shouldBeHidden(viewContainerId: string, cachedViewContainer?: ICachedViewContainer): boolean {
|
||||
const viewContainer = this.getViewContainer(viewContainerId);
|
||||
if (!viewContainer || !viewContainer.hideIfEmpty) {
|
||||
return false;
|
||||
}
|
||||
private shouldBeHidden(viewContainerOrId: string | ViewContainer, cachedViewContainer?: ICachedViewContainer): boolean {
|
||||
const viewContainer = isString(viewContainerOrId) ? this.getViewContainer(viewContainerOrId) : viewContainerOrId;
|
||||
const viewContainerId = isString(viewContainerOrId) ? viewContainerOrId : viewContainerOrId.id;
|
||||
|
||||
return cachedViewContainer?.views && cachedViewContainer.views.length
|
||||
? cachedViewContainer.views.every(({ when }) => !!when && !this.contextKeyService.contextMatchesRules(ContextKeyExpr.deserialize(when)))
|
||||
: viewContainerId === TEST_VIEW_CONTAINER_ID /* Hide Test view container for the first time or it had no views registered before */;
|
||||
}
|
||||
|
||||
private removeNotExistingComposites(): void {
|
||||
const viewContainers = this.getViewContainers();
|
||||
for (const { id } of this.cachedViewContainers) {
|
||||
if (viewContainers.every(viewContainer => viewContainer.id !== id)) {
|
||||
if (this.viewDescriptorService.isViewContainerRemovedPermanently(id)) {
|
||||
this.removeComposite(id);
|
||||
} else {
|
||||
this.hideComposite(id);
|
||||
if (viewContainer) {
|
||||
if (viewContainer.hideIfEmpty) {
|
||||
if (this.viewDescriptorService.getViewContainerModel(viewContainer).activeViewDescriptors.length > 0) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check Cache
|
||||
if (!this.hasExtensionsRegistered) {
|
||||
cachedViewContainer = cachedViewContainer || this.cachedViewContainers.find(({ id }) => id === viewContainerId);
|
||||
|
||||
// Show builtin ViewContainer if not registered yet
|
||||
if (!viewContainer && cachedViewContainer?.isBuiltin) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cachedViewContainer?.views?.length) {
|
||||
return cachedViewContainer.views.every(({ when }) => !!when && !this.contextKeyService.contextMatchesRules(ContextKeyExpr.deserialize(when)));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private hideComposite(compositeId: string): void {
|
||||
|
@ -876,7 +896,6 @@ export class ActivitybarPart extends Part implements IActivityBarService {
|
|||
|
||||
private getViewContainer(id: string): ViewContainer | undefined {
|
||||
const viewContainer = this.viewDescriptorService.getViewContainerById(id);
|
||||
|
||||
return viewContainer && this.viewDescriptorService.getViewContainerLocation(viewContainer) === this.location ? viewContainer : undefined;
|
||||
}
|
||||
|
||||
|
@ -941,10 +960,11 @@ export class ActivitybarPart extends Part implements IActivityBarService {
|
|||
views,
|
||||
pinned: compositeItem.pinned,
|
||||
order: compositeItem.order,
|
||||
visible: compositeItem.visible
|
||||
visible: compositeItem.visible,
|
||||
isBuiltin: !viewContainer.extensionId
|
||||
});
|
||||
} else {
|
||||
state.push({ id: compositeItem.id, pinned: compositeItem.pinned, order: compositeItem.order, visible: false });
|
||||
state.push({ id: compositeItem.id, pinned: compositeItem.pinned, order: compositeItem.order, visible: false, isBuiltin: false });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -962,6 +982,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
|
|||
cachedViewContainer.icon = placeholderViewContainer.themeIcon ? placeholderViewContainer.themeIcon :
|
||||
placeholderViewContainer.iconUrl ? URI.revive(placeholderViewContainer.iconUrl) : undefined;
|
||||
cachedViewContainer.views = placeholderViewContainer.views;
|
||||
cachedViewContainer.isBuiltin = placeholderViewContainer.isBuiltin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -977,11 +998,12 @@ export class ActivitybarPart extends Part implements IActivityBarService {
|
|||
order
|
||||
})));
|
||||
|
||||
this.setPlaceholderViewContainers(cachedViewContainers.map(({ id, icon, name, views }) => (<IPlaceholderViewContainer>{
|
||||
this.setPlaceholderViewContainers(cachedViewContainers.map(({ id, icon, name, views, isBuiltin }) => (<IPlaceholderViewContainer>{
|
||||
id,
|
||||
iconUrl: URI.isUri(icon) ? icon : undefined,
|
||||
themeIcon: ThemeIcon.isThemeIcon(icon) ? icon : undefined,
|
||||
name,
|
||||
isBuiltin,
|
||||
views
|
||||
})));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue