提交 ea680fae 编写于 作者: M Matt Bierner

Update to use more consistent WebviewPanel naming

上级 a322ceb0
......@@ -11,7 +11,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { Position } from 'vs/platform/editor/common/editor';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { ExtHostContext, ExtHostWebviewsShape, IExtHostContext, MainContext, MainThreadWebviewsShape, WebviewHandle } from 'vs/workbench/api/node/extHost.protocol';
import { ExtHostContext, ExtHostWebviewsShape, IExtHostContext, MainContext, MainThreadWebviewsShape, WebviewPanelHandle } from 'vs/workbench/api/node/extHost.protocol';
import { WebviewEditor } from 'vs/workbench/parts/webview/electron-browser/webviewEditor';
import { WebviewEditorInput } from 'vs/workbench/parts/webview/electron-browser/webviewEditorInput';
import { IWebviewEditorService, WebviewInputOptions, WebviewReviver } from 'vs/workbench/parts/webview/electron-browser/webviewEditorService';
......@@ -34,10 +34,10 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
private _toDispose: IDisposable[] = [];
private readonly _proxy: ExtHostWebviewsShape;
private readonly _webviews = new Map<WebviewHandle, WebviewEditorInput>();
private readonly _webviews = new Map<WebviewPanelHandle, WebviewEditorInput>();
private readonly _revivers = new Set<string>();
private _activeWebview: WebviewHandle | undefined = undefined;
private _activeWebview: WebviewPanelHandle | undefined = undefined;
constructor(
context: IExtHostContext,
......@@ -63,8 +63,8 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
this._toDispose = dispose(this._toDispose);
}
$createWebview(
handle: WebviewHandle,
$createWebviewPanel(
handle: WebviewPanelHandle,
viewType: string,
title: string,
column: Position,
......@@ -80,27 +80,27 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
this._webviews.set(handle, webview);
}
$disposeWebview(handle: WebviewHandle): void {
$disposeWebview(handle: WebviewPanelHandle): void {
const webview = this.getWebview(handle);
webview.dispose();
}
$setTitle(handle: WebviewHandle, value: string): void {
$setTitle(handle: WebviewPanelHandle, value: string): void {
const webview = this.getWebview(handle);
webview.setName(value);
}
$setHtml(handle: WebviewHandle, value: string): void {
$setHtml(handle: WebviewPanelHandle, value: string): void {
const webview = this.getWebview(handle);
webview.html = value;
}
$reveal(handle: WebviewHandle, column: Position): void {
$reveal(handle: WebviewPanelHandle, column: Position): void {
const webview = this.getWebview(handle);
this._webviewService.revealWebview(webview, column);
}
async $sendMessage(handle: WebviewHandle, message: any): TPromise<boolean> {
async $sendMessage(handle: WebviewPanelHandle, message: any): TPromise<boolean> {
const webview = this.getWebview(handle);
const editors = this._editorService.getVisibleEditors()
.filter(e => e instanceof WebviewEditor)
......@@ -129,7 +129,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
this._webviews.set(handle, webview);
webview._events = this.createWebviewEventDelegate(handle);
return this._proxy.$deserializeWebview(handle, webview.state.viewType, webview.getTitle(), webview.state.state, webview.position, webview.options)
return this._proxy.$deserializeWebviewPanel(handle, webview.state.viewType, webview.getTitle(), webview.state.state, webview.position, webview.options)
.then(undefined, () => {
webview.html = MainThreadWebviews.getDeserializationFailedContents(viewType);
});
......@@ -141,7 +141,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
}
private _onWillShutdown(): TPromise<boolean> {
const toRevive: WebviewHandle[] = [];
const toRevive: WebviewPanelHandle[] = [];
this._webviews.forEach((view, key) => {
if (this.canRevive(view)) {
toRevive.push(key);
......@@ -150,7 +150,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
const reviveResponses = toRevive.map(handle =>
TPromise.any([
this._proxy.$serializeWebview(handle).then(
this._proxy.$serializeWebviewPanel(handle).then(
state => ({ handle, state }),
() => ({ handle, state: null })),
TPromise.timeout(MainThreadWebviews.serializeTimeout).then(() => ({ handle, state: null }))
......@@ -171,19 +171,19 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
});
}
private createWebviewEventDelegate(handle: WebviewHandle) {
private createWebviewEventDelegate(handle: WebviewPanelHandle) {
return {
onDidClickLink: uri => this.onDidClickLink(handle, uri),
onMessage: message => this._proxy.$onMessage(handle, message),
onDispose: () => {
this._proxy.$onDidDisposeWebview(handle).then(() => {
this._proxy.onDidDisposeWebviewPanel(handle).then(() => {
this._webviews.delete(handle);
});
}
};
}
private getWebview(handle: WebviewHandle): WebviewEditorInput {
private getWebview(handle: WebviewPanelHandle): WebviewEditorInput {
const webview = this._webviews.get(handle);
if (!webview) {
throw new Error('Unknown webview handle:' + handle);
......@@ -193,7 +193,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
private onEditorsChanged() {
const activeEditor = this._editorService.getActiveEditor();
let newActiveWebview: { input: WebviewEditorInput, handle: WebviewHandle } | undefined = undefined;
let newActiveWebview: { input: WebviewEditorInput, handle: WebviewPanelHandle } | undefined = undefined;
if (activeEditor && activeEditor.input instanceof WebviewEditorInput) {
for (const handle of map.keys(this._webviews)) {
const input = this._webviews.get(handle);
......@@ -213,20 +213,20 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
if (typeof this._activeWebview !== 'undefined') {
const oldActiveWebview = this._webviews.get(this._activeWebview);
if (oldActiveWebview) {
this._proxy.$onDidChangeWebviewViewState(this._activeWebview, false, oldActiveWebview.position);
this._proxy.$onDidChangeWebviewPanelViewState(this._activeWebview, false, oldActiveWebview.position);
}
}
// Then for newly active
if (newActiveWebview) {
this._proxy.$onDidChangeWebviewViewState(newActiveWebview.handle, true, activeEditor.position);
this._proxy.$onDidChangeWebviewPanelViewState(newActiveWebview.handle, true, activeEditor.position);
this._activeWebview = newActiveWebview.handle;
} else {
this._activeWebview = undefined;
}
}
private onDidClickLink(handle: WebviewHandle, link: URI): void {
private onDidClickLink(handle: WebviewPanelHandle, link: URI): void {
if (!link) {
return;
}
......
......@@ -347,26 +347,26 @@ export interface MainThreadTelemetryShape extends IDisposable {
$publicLog(eventName: string, data?: any): void;
}
export type WebviewHandle = string;
export type WebviewPanelHandle = string;
export interface MainThreadWebviewsShape extends IDisposable {
$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;
$setHtml(handle: WebviewHandle, value: string): void;
$sendMessage(handle: WebviewHandle, value: any): Thenable<boolean>;
$createWebviewPanel(handle: WebviewPanelHandle, viewType: string, title: string, column: EditorPosition, options: vscode.WebviewPanelOptions & vscode.WebviewOptions, extensionFolderPath: string): void;
$disposeWebview(handle: WebviewPanelHandle): void;
$reveal(handle: WebviewPanelHandle, column: EditorPosition): void;
$setTitle(handle: WebviewPanelHandle, value: string): void;
$setHtml(handle: WebviewPanelHandle, value: string): void;
$sendMessage(handle: WebviewPanelHandle, value: any): Thenable<boolean>;
$registerSerializer(viewType: string): void;
$unregisterSerializer(viewType: string): void;
}
export interface ExtHostWebviewsShape {
$onMessage(handle: WebviewHandle, message: any): void;
$onDidChangeWebviewViewState(handle: WebviewHandle, active: boolean, position: EditorPosition): void;
$onDidDisposeWebview(handle: WebviewHandle): Thenable<void>;
$deserializeWebview(newWebviewHandle: WebviewHandle, viewType: string, title: string, state: any, position: EditorPosition, options: vscode.WebviewOptions): Thenable<void>;
$serializeWebview(webviewHandle: WebviewHandle): Thenable<any>;
$onMessage(handle: WebviewPanelHandle, message: any): void;
$onDidChangeWebviewPanelViewState(handle: WebviewPanelHandle, active: boolean, position: EditorPosition): void;
onDidDisposeWebviewPanel(handle: WebviewPanelHandle): Thenable<void>;
$deserializeWebviewPanel(newWebviewHandle: WebviewPanelHandle, viewType: string, title: string, state: any, position: EditorPosition, options: vscode.WebviewOptions): Thenable<void>;
$serializeWebviewPanel(webviewHandle: WebviewPanelHandle): Thenable<any>;
}
export interface MainThreadWorkspaceShape extends IDisposable {
......
......@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { MainContext, MainThreadWebviewsShape, IMainContext, ExtHostWebviewsShape, WebviewHandle } from './extHost.protocol';
import { MainContext, MainThreadWebviewsShape, IMainContext, ExtHostWebviewsShape, WebviewPanelHandle } from './extHost.protocol';
import * as vscode from 'vscode';
import { Event, Emitter } from 'vs/base/common/event';
import * as typeConverters from 'vs/workbench/api/node/extHostTypeConverters';
......@@ -12,7 +12,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { Disposable } from './extHostTypes';
export class ExtHostWebview implements vscode.Webview {
private readonly _handle: WebviewHandle;
private readonly _handle: WebviewPanelHandle;
private readonly _proxy: MainThreadWebviewsShape;
private _title: string;
private _html: string;
......@@ -26,7 +26,7 @@ export class ExtHostWebview implements vscode.Webview {
public readonly onDidChangeViewState: Event<vscode.WebviewPanelOnDidChangeViewStateEvent> = this.onDidChangeViewStateEmitter.event;
constructor(
handle: WebviewHandle,
handle: WebviewPanelHandle,
proxy: MainThreadWebviewsShape,
title: string,
options: vscode.WebviewOptions
......@@ -91,7 +91,7 @@ export class ExtHostWebview implements vscode.Webview {
export class ExtHostWebviewPanel implements vscode.WebviewPanel {
private readonly _handle: WebviewHandle;
private readonly _handle: WebviewPanelHandle;
private readonly _viewType: string;
private readonly _options: vscode.WebviewPanelOptions;
private readonly _proxy: MainThreadWebviewsShape;
......@@ -108,7 +108,7 @@ export class ExtHostWebviewPanel implements vscode.WebviewPanel {
private _webview: ExtHostWebview;
constructor(
handle: WebviewHandle,
handle: WebviewPanelHandle,
proxy: MainThreadWebviewsShape,
viewType: string,
title: string,
......@@ -194,7 +194,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
private readonly _proxy: MainThreadWebviewsShape;
private readonly _webviewPanels = new Map<WebviewHandle, ExtHostWebviewPanel>();
private readonly _webviewPanels = new Map<WebviewPanelHandle, ExtHostWebviewPanel>();
private readonly _serializers = new Map<string, vscode.WebviewPanelSerializer>();
constructor(
......@@ -211,7 +211,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
extensionFolderPath: string
): vscode.WebviewPanel {
const handle = ExtHostWebviews.webviewHandlePool++ + '';
this._proxy.$createWebview(handle, viewType, title, typeConverters.fromViewColumn(viewColumn), options, extensionFolderPath);
this._proxy.$createWebviewPanel(handle, viewType, title, typeConverters.fromViewColumn(viewColumn), options, extensionFolderPath);
const panel = new ExtHostWebviewPanel(handle, this._proxy, viewType, title, viewColumn, options, options);
this._webviewPanels.set(handle, panel);
......@@ -235,14 +235,14 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
});
}
$onMessage(handle: WebviewHandle, message: any): void {
$onMessage(handle: WebviewPanelHandle, message: any): void {
const panel = this.getWebviewPanel(handle);
if (panel) {
panel.webview.onMessageEmitter.fire(message);
}
}
$onDidChangeWebviewViewState(handle: WebviewHandle, visible: boolean, position: Position): void {
$onDidChangeWebviewPanelViewState(handle: WebviewPanelHandle, visible: boolean, position: Position): void {
const panel = this.getWebviewPanel(handle);
if (panel) {
const viewColumn = typeConverters.toViewColumn(position);
......@@ -254,7 +254,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
}
}
$onDidDisposeWebview(handle: WebviewHandle): Thenable<void> {
onDidDisposeWebviewPanel(handle: WebviewPanelHandle): Thenable<void> {
const panel = this.getWebviewPanel(handle);
if (panel) {
panel.dispose();
......@@ -263,8 +263,8 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
return TPromise.as(void 0);
}
$deserializeWebview(
webviewHandle: WebviewHandle,
$deserializeWebviewPanel(
webviewHandle: WebviewPanelHandle,
viewType: string,
title: string,
state: any,
......@@ -281,8 +281,8 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
return serializer.deserializeWebviewPanel(revivedPanel, state);
}
$serializeWebview(
webviewHandle: WebviewHandle
$serializeWebviewPanel(
webviewHandle: WebviewPanelHandle
): Thenable<any> {
const panel = this.getWebviewPanel(webviewHandle);
if (!panel) {
......@@ -297,7 +297,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
return serialzer.serializeWebviewPanel(panel);
}
private getWebviewPanel(handle: WebviewHandle): ExtHostWebviewPanel | undefined {
private getWebviewPanel(handle: WebviewPanelHandle): ExtHostWebviewPanel | undefined {
return this._webviewPanels.get(handle);
}
}
\ No newline at end of file
......@@ -36,7 +36,7 @@ suite('ExtHostWebview', function () {
const serializerARegistration = extHostWebviews.registerWebviewPanelSerializer(viewType, serializerA);
await extHostWebviews.$deserializeWebview('x', viewType, 'title', {}, EditorPosition.ONE, {});
await extHostWebviews.$deserializeWebviewPanel('x', viewType, 'title', {}, EditorPosition.ONE, {});
assert.strictEqual(lastInvokedDeserializer, serializerA);
assert.throws(
......@@ -47,7 +47,7 @@ suite('ExtHostWebview', function () {
extHostWebviews.registerWebviewPanelSerializer(viewType, serializerB);
await extHostWebviews.$deserializeWebview('x', viewType, 'title', {}, EditorPosition.ONE, {});
await extHostWebviews.$deserializeWebviewPanel('x', viewType, 'title', {}, EditorPosition.ONE, {});
assert.strictEqual(lastInvokedDeserializer, serializerB);
});
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册