Extract out common status bar entry management code

This commit is contained in:
Matt Bierner
2019-11-21 20:46:21 -08:00
parent aaa01eac73
commit 71c3136106
4 changed files with 47 additions and 55 deletions

View File

@@ -5,7 +5,7 @@
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { Disposable } from './dispose';
import { PreviewStatusBarEntry } from './statusBarEntry';
const localize = nls.loadMessageBundle();
@@ -13,22 +13,18 @@ const selectZoomLevelCommandId = '_imagePreview.selectZoomLevel';
export type Scale = number | 'fit';
export class ZoomStatusBarEntry extends Disposable {
private readonly _entry: vscode.StatusBarItem;
export class ZoomStatusBarEntry extends PreviewStatusBarEntry {
private readonly _onDidChangeScale = this._register(new vscode.EventEmitter<{ scale: Scale }>());
public readonly onDidChangeScale = this._onDidChangeScale.event;
private _showOwner: string | undefined;
constructor() {
super();
this._entry = this._register(vscode.window.createStatusBarItem({
super({
id: 'imagePreview.zoom',
name: localize('zoomStatusBar.name', "Image Zoom"),
alignment: vscode.StatusBarAlignment.Right,
priority: 102 /* to the left of editor size entry (101) */,
}));
});
this._register(vscode.commands.registerCommand(selectZoomLevelCommandId, async () => {
type MyPickItem = vscode.QuickPickItem & { scale: Scale };
@@ -47,20 +43,11 @@ export class ZoomStatusBarEntry extends Disposable {
}
}));
this._entry.command = selectZoomLevelCommandId;
this.entry.command = selectZoomLevelCommandId;
}
public show(owner: string, scale: Scale) {
this._showOwner = owner;
this._entry.text = this.zoomLabel(scale);
this._entry.show();
}
public hide(owner: string) {
if (owner === this._showOwner) {
this._entry.hide();
this._showOwner = undefined;
}
this.showItem(owner, this.zoomLabel(scale));
}
private zoomLabel(scale: Scale): string {