Path: blob/main/extensions/media-preview/src/imagePreview/zoomStatusBarEntry.ts
4774 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as vscode from 'vscode';6import { PreviewStatusBarEntry as OwnedStatusBarEntry } from '../ownedStatusBarEntry';789const selectZoomLevelCommandId = '_imagePreview.selectZoomLevel';1011export type Scale = number | 'fit';1213export class ZoomStatusBarEntry extends OwnedStatusBarEntry {1415private readonly _onDidChangeScale = this._register(new vscode.EventEmitter<{ scale: Scale }>());16public readonly onDidChangeScale = this._onDidChangeScale.event;1718constructor() {19super('status.imagePreview.zoom', vscode.l10n.t("Image Zoom"), vscode.StatusBarAlignment.Right, 102 /* to the left of editor size entry (101) */);2021this._register(vscode.commands.registerCommand(selectZoomLevelCommandId, async () => {22type MyPickItem = vscode.QuickPickItem & { scale: Scale };2324const scales: Scale[] = [10, 5, 2, 1, 0.5, 0.2, 'fit'];25const options = scales.map((scale): MyPickItem => ({26label: this.zoomLabel(scale),27scale28}));2930const pick = await vscode.window.showQuickPick(options, {31placeHolder: vscode.l10n.t("Select zoom level")32});33if (pick) {34this._onDidChangeScale.fire({ scale: pick.scale });35}36}));3738this.entry.command = selectZoomLevelCommandId;39}4041public show(owner: unknown, scale: Scale) {42this.showItem(owner, this.zoomLabel(scale));43}4445private zoomLabel(scale: Scale): string {46return scale === 'fit'47? vscode.l10n.t("Whole Image")48: `${Math.round(scale * 100)}%`;49}50}515253