提交 3490cfe9 编写于 作者: M Matt Bierner

Make sure we dismiss the zoom status bar entry when switching editors

上级 2155c063
......@@ -20,8 +20,7 @@ import { dispose } from 'vs/base/common/lifecycle';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IFileService } from 'vs/platform/files/common/files';
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
export interface IOpenCallbacks {
openInternal: (input: EditorInput, options: EditorOptions) => Promise<void>;
......@@ -53,8 +52,7 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
@IFileService private readonly fileService: IFileService,
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
@IStorageService storageService: IStorageService,
@IStatusbarService private readonly statusbarService: IStatusbarService,
@IContextMenuService private readonly contextMenuService: IContextMenuService
@IInstantiationService private readonly instantiationService: IInstantiationService,
) {
super(id, telemetryService, themeService, storageService);
......@@ -101,7 +99,7 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
openInternalClb: () => this.handleOpenInternalCallback(input, options),
openExternalClb: this.environmentService.configuration.remoteAuthority ? undefined : resource => this.callbacks.openExternal(resource),
metadataClb: meta => this.handleMetadataChanged(meta)
}, this.statusbarService, this.contextMenuService);
}, this.instantiationService);
}
private async handleOpenInternalCallback(input: EditorInput, options: EditorOptions): Promise<void> {
......
......@@ -19,6 +19,8 @@ import { memoize } from 'vs/base/common/decorators';
import * as platform from 'vs/base/common/platform';
import { IFileService } from 'vs/platform/files/common/files';
import { IStatusbarEntry, IStatusbarEntryAccessor, IStatusbarService, StatusbarAlignment } from 'vs/platform/statusbar/common/statusbar';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
export interface IResourceDescriptor {
readonly resource: URI;
......@@ -79,8 +81,7 @@ export class ResourceViewer {
container: HTMLElement,
scrollbar: DomScrollableElement,
delegate: ResourceViewerDelegate,
statusbarService: IStatusbarService,
contextMenuService: IContextMenuService
instantiationService: IInstantiationService,
): ResourceViewerContext {
// Ensure CSS class
......@@ -88,7 +89,7 @@ export class ResourceViewer {
// Images
if (ResourceViewer.isImageResource(descriptor)) {
return ImageView.create(container, descriptor, fileService, scrollbar, delegate, statusbarService, contextMenuService);
return ImageView.create(container, descriptor, fileService, scrollbar, delegate, instantiationService);
}
// Large Files
......@@ -120,11 +121,10 @@ class ImageView {
fileService: IFileService,
scrollbar: DomScrollableElement,
delegate: ResourceViewerDelegate,
statusbarService: IStatusbarService,
contextMenuService: IContextMenuService
instantiationService: IInstantiationService,
): ResourceViewerContext {
if (ImageView.shouldShowImageInline(descriptor)) {
return InlineImageView.create(container, descriptor, fileService, scrollbar, delegate, statusbarService, contextMenuService);
return InlineImageView.create(container, descriptor, fileService, scrollbar, delegate, instantiationService);
}
return LargeImageView.create(container, descriptor, delegate);
......@@ -237,15 +237,22 @@ type Scale = number | 'fit';
export class ZoomStatusbarItem extends Disposable {
private statusbarItem: IStatusbarEntryAccessor;
private statusbarItem?: IStatusbarEntryAccessor;
onSelectScale?: (scale: Scale) => void;
constructor(
private readonly contextMenuService: IContextMenuService,
private readonly statusbarService: IStatusbarService
@IEditorService editorService: IEditorService,
@IContextMenuService private readonly contextMenuService: IContextMenuService,
@IStatusbarService private readonly statusbarService: IStatusbarService,
) {
super();
this._register(editorService.onDidActiveEditorChange(() => {
if (this.statusbarItem) {
this.statusbarItem.dispose();
this.statusbarItem = undefined;
}
}));
}
updateStatusbar(scale: Scale, onSelectScale?: (scale: Scale) => void): void {
......@@ -263,7 +270,6 @@ export class ZoomStatusbarItem extends Disposable {
this._register(this.statusbarItem);
const element = document.getElementById('status.imageZoom')!;
this._register(DOM.addDisposableListener(element, DOM.EventType.CLICK, (e: MouseEvent) => {
this.contextMenuService.showContextMenu({
getAnchor: () => element,
......@@ -344,13 +350,11 @@ class InlineImageView {
fileService: IFileService,
scrollbar: DomScrollableElement,
delegate: ResourceViewerDelegate,
statusbarService: IStatusbarService,
contextMenuService: IContextMenuService
@IInstantiationService instantiationService: IInstantiationService,
) {
const disposables = new DisposableStore();
const zoomStatusbarItem = new ZoomStatusbarItem(contextMenuService, statusbarService);
disposables.add(zoomStatusbarItem);
const zoomStatusbarItem = disposables.add(instantiationService.createInstance(ZoomStatusbarItem));
const context: ResourceViewerContext = {
layout(dimension: DOM.Dimension) { },
......@@ -408,8 +412,8 @@ class InlineImageView {
});
InlineImageView.imageStateCache.set(cacheKey, { scale: scale, offsetX: newScrollLeft, offsetY: newScrollTop });
}
zoomStatusbarItem.updateStatusbar(scale, updateScale);
scrollbar.scanDomNode();
}
......
......@@ -16,8 +16,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IFileService } from 'vs/platform/files/common/files';
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
/**
* An implementation of editor for binary files like images.
......@@ -34,8 +33,7 @@ export class BinaryFileEditor extends BaseBinaryResourceEditor {
@IStorageService storageService: IStorageService,
@IFileService fileService: IFileService,
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
@IStatusbarService statusbarService: IStatusbarService,
@IContextMenuService contextMenuService: IContextMenuService
@IInstantiationService instantiationService: IInstantiationService,
) {
super(
BinaryFileEditor.ID,
......@@ -48,8 +46,7 @@ export class BinaryFileEditor extends BaseBinaryResourceEditor {
fileService,
environmentService,
storageService,
statusbarService,
contextMenuService
instantiationService,
);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册