Rename WebviewEditor to WebviewPanel

This commit is contained in:
Matt Bierner 2018-04-12 12:06:07 -07:00
parent 5ff2ccfc28
commit a2346c606d
8 changed files with 84 additions and 84 deletions

View file

@ -20,7 +20,7 @@ export class MarkdownPreview {
public static viewType = 'markdown.preview';
private readonly editor: vscode.WebviewEditor;
private readonly editor: vscode.WebviewPanel;
private throttleTimer: any;
private line: number | undefined = undefined;
private readonly disposables: vscode.Disposable[] = [];
@ -32,7 +32,7 @@ export class MarkdownPreview {
public static async revive(
webview: vscode.WebviewEditor,
webview: vscode.WebviewPanel,
state: any,
contentProvider: MarkdownContentProvider,
previewConfigurations: MarkdownPreviewConfigurationManager,
@ -69,7 +69,7 @@ export class MarkdownPreview {
topmostLineMonitor: MarkdownFileTopmostLineMonitor,
contributions: MarkdownContributions
): MarkdownPreview {
const webview = vscode.window.createWebviewEditor(
const webview = vscode.window.createWebviewPanel(
MarkdownPreview.viewType,
MarkdownPreview.getPreviewTitle(resource, locked),
previewColumn, {
@ -90,7 +90,7 @@ export class MarkdownPreview {
}
private constructor(
webview: vscode.WebviewEditor,
webview: vscode.WebviewPanel,
private _resource: vscode.Uri,
public locked: boolean,
private readonly contentProvider: MarkdownContentProvider,
@ -155,7 +155,7 @@ export class MarkdownPreview {
private readonly _onDisposeEmitter = new vscode.EventEmitter<void>();
public readonly onDispose = this._onDisposeEmitter.event;
private readonly _onDidChangeViewStateEmitter = new vscode.EventEmitter<vscode.WebviewEditorOnDidChangeViewStateEvent>();
private readonly _onDidChangeViewStateEmitter = new vscode.EventEmitter<vscode.WebviewPanelOnDidChangeViewStateEvent>();
public readonly onDidChangeViewState = this._onDidChangeViewStateEmitter.event;
public get resource(): vscode.Uri {
@ -231,7 +231,7 @@ export class MarkdownPreview {
return this._resource.fsPath === resource.fsPath;
}
public isWebviewOf(webview: vscode.WebviewEditor): boolean {
public isWebviewOf(webview: vscode.WebviewPanel): boolean {
return this.editor === webview;
}

View file

@ -14,7 +14,7 @@ import { isMarkdownFile } from '../util/file';
import { MarkdownPreviewConfigurationManager } from './previewConfig';
import { MarkdownContributions } from '../markdownExtensions';
export class MarkdownPreviewManager implements vscode.WebviewEditorSerializer {
export class MarkdownPreviewManager implements vscode.WebviewPanelSerializer {
private static readonly markdownPreviewActiveContextKey = 'markdownPreviewFocus';
private readonly topmostLineMonitor = new MarkdownFileTopmostLineMonitor();
@ -36,7 +36,7 @@ export class MarkdownPreviewManager implements vscode.WebviewEditorSerializer {
}
}, null, this.disposables);
this.disposables.push(vscode.window.registerWebviewEditorSerializer(MarkdownPreview.viewType, this));
this.disposables.push(vscode.window.registerWebviewPanelSerializer(MarkdownPreview.viewType, this));
}
public dispose(): void {
@ -88,8 +88,8 @@ export class MarkdownPreviewManager implements vscode.WebviewEditorSerializer {
}
}
public async deserializeWebviewEditor(
webview: vscode.WebviewEditor,
public async deserializeWebviewPanel(
webview: vscode.WebviewPanel,
state: any
): Promise<void> {
const preview = await MarkdownPreview.revive(
@ -103,8 +103,8 @@ export class MarkdownPreviewManager implements vscode.WebviewEditorSerializer {
this.registerPreview(preview);
}
public async serializeWebviewEditor(
webview: vscode.WebviewEditor,
public async serializeWebviewPanel(
webview: vscode.WebviewPanel,
): Promise<any> {
const preview = this.previews.find(preview => preview.isWebviewOf(webview));
return preview ? preview.state : undefined;

View file

@ -640,66 +640,66 @@ declare module 'vscode' {
}
/**
* Content settings for a webview editor.
* Content settings for a webview panel.
*/
export interface WebviewEditorOptions {
export interface WebviewPanelOptions {
/**
* Should the find widget be enabled in the editor?
* Should the find widget be enabled in the panel?
*
* Defaults to false.
*/
readonly enableFindWidget?: boolean;
/**
* Should the webview editor's content (iframe) be kept around even when the editor
* Should the webview panel's content (iframe) be kept around even when the panel
* is no longer visible?
*
* Normally the editor's html context is created when the editor becomes visible
* Normally the webview panels's html context is created when the panel becomes visible
* and destroyed when it is is hidden. Apps that have complex state
* or UI can set the `retainContextWhenHidden` to make VS Code keep the webview
* context around, even when the webview moves to a background tab. When
* the editor becomes visible again, the context is automatically restored
* the panel becomes visible again, the context is automatically restored
* in the exact same state it was in originally.
*
* `retainContextWhenHidden` has a high memory overhead and should only be used if
* your editor's context cannot be quickly saved and restored.
* your panel's context cannot be quickly saved and restored.
*/
readonly retainContextWhenHidden?: boolean;
}
/**
* An editor that contains a webview.
* A panel that contains a webview.
*/
interface WebviewEditor {
interface WebviewPanel {
/**
* The type of the webview editor, such as `'markdown.preview'`.
* The type of the webview panel, such as `'markdown.preview'`.
*/
readonly viewType: string;
/**
* The webview belonging to the editor.
* The webview belonging to the panel.
*/
readonly webview: Webview;
/**
* Content settings for the webview editor.
* Content settings for the webview panel.
*/
readonly options: WebviewEditorOptions;
readonly options: WebviewPanelOptions;
/**
* The column in which the editor is showing.
* The column in which the panel is showing.
*/
readonly viewColumn?: ViewColumn;
/**
* Fired when the editor's view state changes.
* Fired when the panel's view state changes.
*/
readonly onDidChangeViewState: Event<WebviewEditorOnDidChangeViewStateEvent>;
readonly onDidChangeViewState: Event<WebviewPanelOnDidChangeViewStateEvent>;
/**
* Fired when the editor is disposed.
* Fired when the panel is disposed.
*
* This may be because the user closed the editor or because `.dispose()` was
* This may be because the user closed the panel or because `.dispose()` was
* called on it.
*
* Trying to use the webview after it has been disposed throws an exception.
@ -707,77 +707,77 @@ declare module 'vscode' {
readonly onDidDispose: Event<void>;
/**
* Shows the webview editor in a given column.
* Shows the webview panel in a given column.
*
* A webview may only be in a single column at a time. If it is already showing, this
* A webview panel may only be in a single column at a time. If it is already showing, this
* command moves it to a new column.
*/
reveal(viewColumn: ViewColumn): void;
/**
* Dispose of the webview editor.
* Dispose of the webview panel.
*
* This closes the webview if it showing and disposes of the resources owned by the webview.
* Webview are also disposed when the user closes the webview editor. Both cases fire `onDispose`
* Webview are also disposed when the user closes the webview panel. Both cases fire `onDispose`
* event.
*/
dispose(): any;
}
export interface WebviewEditorOnDidChangeViewStateEvent {
export interface WebviewPanelOnDidChangeViewStateEvent {
readonly viewColumn: ViewColumn;
readonly active: boolean;
}
/**
* Save and restore webview editors that have been persisted when vscode shuts down.
* Save and restore webview panels that have been persisted when vscode shuts down.
*/
interface WebviewEditorSerializer {
interface WebviewPanelSerializer {
/**
* Save a webview editors's `state`.
* Save a webview panels's `state`.
*
* Called before shutdown. Webview editor may or may not be visible.
* Called before shutdown. webview panel may or may not be visible.
*
* @param webviewEditor Webview editor to serialize.
* @param webviewPanel webview Panel to serialize.
*
* @returns JSON serializable state blob.
*/
serializeWebviewEditor(webviewEditor: WebviewEditor): Thenable<any>;
serializeWebviewPanel(webviewPanel: WebviewPanel): Thenable<any>;
/**
* Restore a webview editor from its `state`.
* Restore a webview panel from its `state`.
*
* Called when a serialized webview first becomes active.
*
* @param webviewEditor Webview editor to restore. The serializer should take ownership of this editor.
* @param webviewPanel Webview panel to restore. The serializer should take ownership of this panel.
* @param state Persisted state.
*/
deserializeWebviewEditor(webviewEditor: WebviewEditor, state: any): Thenable<void>;
deserializeWebviewPanel(webviewPanel: WebviewPanel, state: any): Thenable<void>;
}
namespace window {
/**
* Create and show a new webview editor.
* Create and show a new webview panel.
*
* @param viewType Identifies the type of the webview editor.
* @param viewType Identifies the type of the webview panel.
* @param title Title of the webview.
* @param column Editor column to show the new webview editor in.
* @param editorOptions Settings for the webview editor.
* @param column Editor column to show the new webview panel in.
* @param options Settings for the new webview panel.
*/
export function createWebviewEditor(viewType: string, title: string, column: ViewColumn, options: WebviewEditorOptions & WebviewOptions): WebviewEditor;
export function createWebviewPanel(viewType: string, title: string, column: ViewColumn, options: WebviewPanelOptions & WebviewOptions): WebviewPanel;
/**
* Registers a webview editor serializer.
* Registers a webview panel serializer.
*
* Extensions that support reviving should have an `"onView:viewType"` activation method and
* make sure that `registerWebviewEditorSerializer` is called during activation.
* make sure that [registerWebviewPanelSerializer](#registerWebviewPanelSerializer) is called during activation.
*
* Only a single serializer may be registered at a time for a given `viewType`.
*
* @param viewType Type of the webview editor that can be serialized.
* @param viewType Type of the webview panel that can be serialized.
* @param reviver Webview serializer.
*/
export function registerWebviewEditorSerializer(viewType: string, reviver: WebviewEditorSerializer): Disposable;
export function registerWebviewPanelSerializer(viewType: string, reviver: WebviewPanelSerializer): Disposable;
}
//#endregion
@ -829,7 +829,7 @@ declare module 'vscode' {
export namespace workspace {
/**
* Fetches all task available in the systems. This includes tasks
* Fetches all task available in the systems. Thisweweb includes tasks
* from `tasks.json` files as well as tasks from task providers
* contributed through extensions.
*/

View file

@ -447,11 +447,11 @@ export function createApiFactory(
registerDecorationProvider: proposedApiFunction(extension, (provider: vscode.DecorationProvider) => {
return extHostDecorations.registerDecorationProvider(provider, extension.id);
}),
createWebviewEditor: proposedApiFunction(extension, (viewType: string, title: string, column: vscode.ViewColumn, options: vscode.WebviewEditorOptions & vscode.WebviewOptions) => {
createWebviewPanel: proposedApiFunction(extension, (viewType: string, title: string, column: vscode.ViewColumn, options: vscode.WebviewPanelOptions & vscode.WebviewOptions) => {
return extHostWebviews.createWebview(viewType, title, column, options, extension.extensionFolderPath);
}),
registerWebviewEditorSerializer: proposedApiFunction(extension, (viewType: string, serializer: vscode.WebviewEditorSerializer) => {
return extHostWebviews.registerWebviewEditorSerializer(viewType, serializer);
registerWebviewPanelSerializer: proposedApiFunction(extension, (viewType: string, serializer: vscode.WebviewPanelSerializer) => {
return extHostWebviews.registerWebviewPanelSerializer(viewType, serializer);
})
};

View file

@ -350,7 +350,7 @@ export interface MainThreadTelemetryShape extends IDisposable {
export type WebviewHandle = string;
export interface MainThreadWebviewsShape extends IDisposable {
$createWebview(handle: WebviewHandle, viewType: string, title: string, column: EditorPosition, options: vscode.WebviewEditorOptions & vscode.WebviewOptions, extensionFolderPath: string): void;
$createWebview(handle: WebviewHandle, viewType: string, title: string, column: EditorPosition, options: vscode.WebviewPanelOptions & vscode.WebviewOptions, extensionFolderPath: string): void;
$disposeWebview(handle: WebviewHandle): void;
$reveal(handle: WebviewHandle, column: EditorPosition): void;
$setTitle(handle: WebviewHandle, value: string): void;

View file

@ -22,8 +22,8 @@ export class ExtHostWebview implements vscode.Webview {
public readonly onMessageEmitter = new Emitter<any>();
public readonly onDidReceiveMessage: Event<any> = this.onMessageEmitter.event;
public readonly onDidChangeViewStateEmitter = new Emitter<vscode.WebviewEditorOnDidChangeViewStateEvent>();
public readonly onDidChangeViewState: Event<vscode.WebviewEditorOnDidChangeViewStateEvent> = this.onDidChangeViewStateEmitter.event;
public readonly onDidChangeViewStateEmitter = new Emitter<vscode.WebviewPanelOnDidChangeViewStateEvent>();
public readonly onDidChangeViewState: Event<vscode.WebviewPanelOnDidChangeViewStateEvent> = this.onDidChangeViewStateEmitter.event;
constructor(
handle: WebviewHandle,
@ -89,11 +89,11 @@ export class ExtHostWebview implements vscode.Webview {
}
}
export class ExtHostWebviewEditor implements vscode.WebviewEditor {
export class ExtHostWebviewPanel implements vscode.WebviewPanel {
private readonly _handle: WebviewHandle;
private readonly _viewType: string;
private readonly _options: vscode.WebviewEditorOptions;
private readonly _options: vscode.WebviewPanelOptions;
private readonly _proxy: MainThreadWebviewsShape;
private _isDisposed: boolean = false;
private _viewColumn: vscode.ViewColumn;
@ -102,8 +102,8 @@ export class ExtHostWebviewEditor implements vscode.WebviewEditor {
public readonly onDisposeEmitter = new Emitter<void>();
public readonly onDidDispose: Event<void> = this.onDisposeEmitter.event;
public readonly onDidChangeViewStateEmitter = new Emitter<vscode.WebviewEditorOnDidChangeViewStateEvent>();
public readonly onDidChangeViewState: Event<vscode.WebviewEditorOnDidChangeViewStateEvent> = this.onDidChangeViewStateEmitter.event;
public readonly onDidChangeViewStateEmitter = new Emitter<vscode.WebviewPanelOnDidChangeViewStateEvent>();
public readonly onDidChangeViewState: Event<vscode.WebviewPanelOnDidChangeViewStateEvent> = this.onDidChangeViewStateEmitter.event;
private _webview: ExtHostWebview;
@ -113,7 +113,7 @@ export class ExtHostWebviewEditor implements vscode.WebviewEditor {
viewType: string,
title: string,
viewColumn: vscode.ViewColumn,
editorOptions: vscode.WebviewEditorOptions,
editorOptions: vscode.WebviewPanelOptions,
webviewOptions: vscode.WebviewOptions
) {
this._handle = handle;
@ -192,8 +192,8 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
private readonly _proxy: MainThreadWebviewsShape;
private readonly _webviews = new Map<WebviewHandle, ExtHostWebviewEditor>();
private readonly _serializers = new Map<string, vscode.WebviewEditorSerializer>();
private readonly _webviews = new Map<WebviewHandle, ExtHostWebviewPanel>();
private readonly _serializers = new Map<string, vscode.WebviewPanelSerializer>();
constructor(
mainContext: IMainContext
@ -205,20 +205,20 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
viewType: string,
title: string,
viewColumn: vscode.ViewColumn,
options: vscode.WebviewEditorOptions & vscode.WebviewOptions,
options: vscode.WebviewPanelOptions & vscode.WebviewOptions,
extensionFolderPath: string
): vscode.WebviewEditor {
): vscode.WebviewPanel {
const handle = ExtHostWebviews.webviewHandlePool++ + '';
this._proxy.$createWebview(handle, viewType, title, typeConverters.fromViewColumn(viewColumn), options, extensionFolderPath);
const webview = new ExtHostWebviewEditor(handle, this._proxy, viewType, title, viewColumn, options, options);
const webview = new ExtHostWebviewPanel(handle, this._proxy, viewType, title, viewColumn, options, options);
this._webviews.set(handle, webview);
return webview;
}
registerWebviewEditorSerializer(
registerWebviewPanelSerializer(
viewType: string,
serializer: vscode.WebviewEditorSerializer
serializer: vscode.WebviewPanelSerializer
): vscode.Disposable {
if (this._serializers.has(viewType)) {
throw new Error(`Serializer for '${viewType}' already registered`);
@ -274,9 +274,9 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
return TPromise.wrapError(new Error(`No serializer found for '${viewType}'`));
}
const revivedWebview = new ExtHostWebviewEditor(webviewHandle, this._proxy, viewType, title, typeConverters.toViewColumn(position), options as vscode.WebviewEditorOptions, options as vscode.WebviewOptions);
const revivedWebview = new ExtHostWebviewPanel(webviewHandle, this._proxy, viewType, title, typeConverters.toViewColumn(position), options as vscode.WebviewPanelOptions, options as vscode.WebviewOptions);
this._webviews.set(webviewHandle, revivedWebview);
return serializer.deserializeWebviewEditor(revivedWebview, state);
return serializer.deserializeWebviewPanel(revivedWebview, state);
}
$serializeWebview(
@ -292,10 +292,10 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
return TPromise.as(undefined);
}
return serialzer.serializeWebviewEditor(webview);
return serialzer.serializeWebviewPanel(webview);
}
private getWebview(handle: WebviewHandle): ExtHostWebviewEditor | undefined {
private getWebview(handle: WebviewHandle): ExtHostWebviewPanel | undefined {
return this._webviews.get(handle);
}
}

View file

@ -67,7 +67,7 @@ export interface WebviewEvents {
onDidClickLink?(link: URI, options: vscode.WebviewOptions): void;
}
export interface WebviewInputOptions extends vscode.WebviewOptions, vscode.WebviewEditorOptions {
export interface WebviewInputOptions extends vscode.WebviewOptions, vscode.WebviewPanelOptions {
tryRestoreScrollPosition?: boolean;
}

View file

@ -21,12 +21,12 @@ suite('ExtHostWebview', function () {
const shape = createNoopMainThreadWebviews();
const extHostWebviews = new ExtHostWebviews(SingleProxyRPCProtocol(shape));
let lastInvokedDeserializer: vscode.WebviewEditorSerializer | undefined = undefined;
let lastInvokedDeserializer: vscode.WebviewPanelSerializer | undefined = undefined;
class NoopSerializer implements vscode.WebviewEditorSerializer {
async serializeWebviewEditor(webview: vscode.WebviewEditor): Promise<any> { /* noop */ }
class NoopSerializer implements vscode.WebviewPanelSerializer {
async serializeWebviewPanel(webview: vscode.WebviewPanel): Promise<any> { /* noop */ }
async deserializeWebviewEditor(webview: vscode.WebviewEditor, state: any): Promise<void> {
async deserializeWebviewPanel(webview: vscode.WebviewPanel, state: any): Promise<void> {
lastInvokedDeserializer = this;
}
}
@ -34,18 +34,18 @@ suite('ExtHostWebview', function () {
const serializerA = new NoopSerializer();
const serializerB = new NoopSerializer();
const serializerARegistration = extHostWebviews.registerWebviewEditorSerializer(viewType, serializerA);
const serializerARegistration = extHostWebviews.registerWebviewPanelSerializer(viewType, serializerA);
await extHostWebviews.$deserializeWebview('x', viewType, 'title', {}, EditorPosition.ONE, {});
assert.strictEqual(lastInvokedDeserializer, serializerA);
assert.throws(
() => extHostWebviews.registerWebviewEditorSerializer(viewType, serializerB),
() => extHostWebviews.registerWebviewPanelSerializer(viewType, serializerB),
'Should throw when registering two serializers for the same view');
serializerARegistration.dispose();
extHostWebviews.registerWebviewEditorSerializer(viewType, serializerB);
extHostWebviews.registerWebviewPanelSerializer(viewType, serializerB);
await extHostWebviews.$deserializeWebview('x', viewType, 'title', {}, EditorPosition.ONE, {});
assert.strictEqual(lastInvokedDeserializer, serializerB);