mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode a234f13c45b40a0929777cb440ee011b7549eed2 (#8911)
* Merge from vscode a234f13c45b40a0929777cb440ee011b7549eed2 * update distro * fix layering * update distro * fix tests
This commit is contained in:
@@ -73,6 +73,8 @@ class Preview extends Disposable {
|
||||
private _imageBinarySize: number | undefined;
|
||||
private _imageZoom: Scale | undefined;
|
||||
|
||||
private readonly emptyPngDataUri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAEElEQVR42gEFAPr/AP///wAI/AL+Sr4t6gAAAABJRU5ErkJggg==';
|
||||
|
||||
constructor(
|
||||
private readonly extensionRoot: vscode.Uri,
|
||||
private readonly resource: vscode.Uri,
|
||||
@@ -108,6 +110,12 @@ class Preview extends Disposable {
|
||||
this.update();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'reopen-as-text':
|
||||
{
|
||||
vscode.commands.executeCommand('vscode.openWith', resource, 'default', webviewEditor.viewColumn);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -165,9 +173,9 @@ class Preview extends Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
private render() {
|
||||
private async render() {
|
||||
if (this._previewState !== PreviewState.Disposed) {
|
||||
this.webviewEditor.webview.html = this.getWebiewContents();
|
||||
this.webviewEditor.webview.html = await this.getWebiewContents();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,11 +199,11 @@ class Preview extends Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
private getWebiewContents(): string {
|
||||
private async getWebiewContents(): Promise<string> {
|
||||
const version = Date.now().toString();
|
||||
const settings = {
|
||||
isMac: process.platform === 'darwin',
|
||||
src: this.getResourcePath(this.webviewEditor, this.resource, version),
|
||||
src: await this.getResourcePath(this.webviewEditor, this.resource, version),
|
||||
};
|
||||
|
||||
const nonce = Date.now().toString();
|
||||
@@ -218,28 +226,28 @@ class Preview extends Disposable {
|
||||
</head>
|
||||
<body class="container image scale-to-fit loading">
|
||||
<div class="loading-indicator"></div>
|
||||
<div class="image-load-error-message">${localize('preview.imageLoadError', "An error occurred while loading the image")}</div>
|
||||
<div class="image-load-error">
|
||||
<p>${localize('preview.imageLoadError', "An error occurred while loading the image.")}</p>
|
||||
<a href="#" class="open-file-link">${localize('preview.imageLoadErrorLink', "Open file using VS Code's standard text/binary editor?")}</a>
|
||||
</div>
|
||||
<script src="${escapeAttribute(this.extensionResource('/media/main.js'))}" nonce="${nonce}"></script>
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
|
||||
private getResourcePath(webviewEditor: vscode.WebviewPanel, resource: vscode.Uri, version: string) {
|
||||
switch (resource.scheme) {
|
||||
case 'data':
|
||||
return resource.toString(true);
|
||||
|
||||
case 'git':
|
||||
// Show blank image
|
||||
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAEElEQVR42gEFAPr/AP///wAI/AL+Sr4t6gAAAABJRU5ErkJggg==';
|
||||
|
||||
default:
|
||||
// Avoid adding cache busting if there is already a query string
|
||||
if (resource.query) {
|
||||
return webviewEditor.webview.asWebviewUri(resource).toString(true);
|
||||
}
|
||||
return webviewEditor.webview.asWebviewUri(resource).with({ query: `version=${version}` }).toString(true);
|
||||
private async getResourcePath(webviewEditor: vscode.WebviewPanel, resource: vscode.Uri, version: string): Promise<string> {
|
||||
if (resource.scheme === 'gitfs') {
|
||||
const stat = await vscode.workspace.fs.stat(resource);
|
||||
if (stat.size === 0) {
|
||||
return this.emptyPngDataUri;
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid adding cache busting if there is already a query string
|
||||
if (resource.query) {
|
||||
return webviewEditor.webview.asWebviewUri(resource).toString(true);
|
||||
}
|
||||
return webviewEditor.webview.asWebviewUri(resource).with({ query: `version=${version}` }).toString(true);
|
||||
}
|
||||
|
||||
private extensionResource(path: string) {
|
||||
|
||||
Reference in New Issue
Block a user