diff --git a/src/vs/workbench/api/electron-browser/mainThreadWebview.ts b/src/vs/workbench/api/electron-browser/mainThreadWebview.ts index 8d3058803ca906f3b4c613784aaab59dcf9640cd..e671f1e86b33c9a0ce5f7feaf60a7047d2878ebe 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadWebview.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadWebview.ts @@ -2,7 +2,6 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as dom from 'vs/base/browser/dom'; import { dispose, IDisposable } from 'vs/base/common/lifecycle'; import * as map from 'vs/base/common/map'; import URI, { UriComponents } from 'vs/base/common/uri'; @@ -30,39 +29,6 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv private static revivalPool = 0; - private static _styleElement?: HTMLStyleElement; - - private static _icons = new Map(); - - private static updateStyleElement( - webview: WebviewEditorInput, - iconPath: { light: URI, dark: URI } | undefined - ) { - const id = webview.getId(); - if (!this._styleElement) { - this._styleElement = dom.createStyleSheet(); - this._styleElement.className = 'webview-icons'; - } - - if (!iconPath) { - this._icons.delete(id); - } else { - this._icons.set(id, iconPath); - } - - const cssRules: string[] = []; - this._icons.forEach((value, key) => { - const webviewSelector = `.show-file-icons .webview-${key}-name-file-icon::before`; - if (URI.isUri(value)) { - cssRules.push(`${webviewSelector} { content: ""; background-image: url(${value.toString()}); }`); - } else { - cssRules.push(`${webviewSelector} { content: ""; background-image: url(${value.light.toString()}); }`); - cssRules.push(`.vs-dark ${webviewSelector} { content: ""; background-image: url(${value.dark.toString()}); }`); - } - }); - this._styleElement.innerHTML = cssRules.join('\n'); - } - private _toDispose: IDisposable[] = []; private readonly _proxy: ExtHostWebviewsShape; @@ -132,7 +98,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv public $setIconPath(handle: WebviewPanelHandle, value: { light: UriComponents, dark: UriComponents } | undefined): void { const webview = this.getWebview(handle); - MainThreadWebviews.updateStyleElement(webview, reviveWebviewIcon(value)); + webview.iconPath = reviveWebviewIcon(value); } public $setHtml(handle: WebviewPanelHandle, value: string): void { @@ -225,10 +191,6 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv onMessage: message => this._proxy.$onMessage(handle, message), onDispose: () => { const cleanUp = () => { - const webview = this._webviews.get(handle); - if (webview) { - MainThreadWebviews.updateStyleElement(webview, undefined); - } this._webviews.delete(handle); }; this._proxy.$onDidDisposeWebviewPanel(handle).then( diff --git a/src/vs/workbench/parts/webview/electron-browser/webviewEditorInput.ts b/src/vs/workbench/parts/webview/electron-browser/webviewEditorInput.ts index 07f44326ef7c1a758b1ec438542b18f329857ccd..638ea70b328d09c607e44a8ab5ce983c3c7fc687 100644 --- a/src/vs/workbench/parts/webview/electron-browser/webviewEditorInput.ts +++ b/src/vs/workbench/parts/webview/electron-browser/webviewEditorInput.ts @@ -2,7 +2,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ - +import * as dom from 'vs/base/browser/dom'; import { Emitter } from 'vs/base/common/event'; import { dispose, IDisposable } from 'vs/base/common/lifecycle'; import URI from 'vs/base/common/uri'; @@ -14,12 +14,47 @@ import * as vscode from 'vscode'; import { WebviewEvents, WebviewInputOptions, WebviewReviver } from './webviewEditorService'; import { WebviewElement } from './webviewElement'; + export class WebviewEditorInput extends EditorInput { private static handlePool = 0; + + private static _styleElement?: HTMLStyleElement; + + private static _icons = new Map(); + + private static updateStyleElement( + id: number, + iconPath: { light: URI, dark: URI } | undefined + ) { + if (!this._styleElement) { + this._styleElement = dom.createStyleSheet(); + this._styleElement.className = 'webview-icons'; + } + + if (!iconPath) { + this._icons.delete(id); + } else { + this._icons.set(id, iconPath); + } + + const cssRules: string[] = []; + this._icons.forEach((value, key) => { + const webviewSelector = `.show-file-icons .webview-${key}-name-file-icon::before`; + if (URI.isUri(value)) { + cssRules.push(`${webviewSelector} { content: ""; background-image: url(${value.toString()}); }`); + } else { + cssRules.push(`${webviewSelector} { content: ""; background-image: url(${value.light.toString()}); }`); + cssRules.push(`.vs-dark ${webviewSelector} { content: ""; background-image: url(${value.dark.toString()}); }`); + } + }); + this._styleElement.innerHTML = cssRules.join('\n'); + } + public static readonly typeId = 'workbench.editors.webviewInput'; private _name: string; + private _iconPath?: { light: URI, dark: URI }; private _options: WebviewInputOptions; private _html: string = ''; private _currentWebviewHtml: string = ''; @@ -109,6 +144,15 @@ export class WebviewEditorInput extends EditorInput { this._onDidChangeLabel.fire(); } + public get iconPath() { + return this._iconPath; + } + + public set iconPath(value: { light: URI, dark: URI } | undefined) { + this._iconPath = value; + WebviewEditorInput.updateStyleElement(this._id, value); + } + public matches(other: IEditorInput): boolean { return other && other === this; } diff --git a/src/vs/workbench/parts/webview/electron-browser/webviewEditorInputFactory.ts b/src/vs/workbench/parts/webview/electron-browser/webviewEditorInputFactory.ts index 0bb8b9fbd71dbe4dc0558d3345c8b0e7dfb497d3..fc973d684795ea5088ac2b16349791296572cc65 100644 --- a/src/vs/workbench/parts/webview/electron-browser/webviewEditorInputFactory.ts +++ b/src/vs/workbench/parts/webview/electron-browser/webviewEditorInputFactory.ts @@ -15,6 +15,7 @@ interface SerializedWebview { readonly options: WebviewInputOptions; readonly extensionLocation: string; readonly state: any; + readonly iconPath: { light: string, dark: string } | undefined; } export class WebviewEditorInputFactory implements IEditorInputFactory { @@ -43,7 +44,8 @@ export class WebviewEditorInputFactory implements IEditorInputFactory { title: input.getName(), options: input.options, extensionLocation: input.extensionLocation.toString(), - state: input.state + state: input.state, + iconPath: input.iconPath ? { light: input.iconPath.light.toString(), dark: input.iconPath.dark.toString(), } : undefined, }; return JSON.stringify(data); } @@ -54,6 +56,7 @@ export class WebviewEditorInputFactory implements IEditorInputFactory { ): WebviewEditorInput { const data: SerializedWebview = JSON.parse(serializedEditorInput); const extensionLocation = URI.parse(data.extensionLocation); - return this._webviewService.reviveWebview(data.viewType, data.title, data.state, data.options, extensionLocation); + const iconPath = data.iconPath ? { light: URI.parse(data.iconPath.light), dark: URI.parse(data.iconPath.dark) } : undefined; + return this._webviewService.reviveWebview(data.viewType, data.title, iconPath, data.state, data.options, extensionLocation); } } diff --git a/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts b/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts index 3c4228078b61ebe2c22e1121dbd0052133288e0a..99695243653cdb2680e538e1ea3914939aa01c7b 100644 --- a/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts +++ b/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts @@ -36,6 +36,7 @@ export interface IWebviewEditorService { reviveWebview( viewType: string, title: string, + iconPath: { light: URI, dark: URI } | undefined, state: any, options: WebviewInputOptions, extensionLocation: URI @@ -126,6 +127,7 @@ export class WebviewEditorService implements IWebviewEditorService { reviveWebview( viewType: string, title: string, + iconPath: { light: URI, dark: URI } | undefined, state: any, options: WebviewInputOptions, extensionLocation: URI @@ -148,7 +150,7 @@ export class WebviewEditorService implements IWebviewEditorService { }); } }); - + webviewInput.iconPath = iconPath; return webviewInput; }