Files
azuredatastudio/src/sql/workbench/api/node/extHostDashboardWebview.ts
Karl Burtram dafb780987 Merge VS Code 1.21 source code (#1067)
* Initial VS Code 1.21 file copy with patches

* A few more merges

* Post npm install

* Fix batch of build breaks

* Fix more build breaks

* Fix more build errors

* Fix more build breaks

* Runtime fixes 1

* Get connection dialog working with some todos

* Fix a few packaging issues

* Copy several node_modules to package build to fix loader issues

* Fix breaks from master

* A few more fixes

* Make tests pass

* First pass of license header updates

* Second pass of license header updates

* Fix restore dialog issues

* Remove add additional themes menu items

* fix select box issues where the list doesn't show up

* formatting

* Fix editor dispose issue

* Copy over node modules to correct location on all platforms
2018-04-04 15:27:51 -07:00

95 lines
3.0 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { SqlMainContext, ExtHostDashboardWebviewsShape, MainThreadDashboardWebviewShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
import { IMainContext } from 'vs/workbench/api/node/extHost.protocol';
import { Emitter } from 'vs/base/common/event';
import { deepClone } from 'vs/base/common/objects';
import * as vscode from 'vscode';
import * as sqlops from 'sqlops';
class ExtHostDashboardWebview implements sqlops.DashboardWebview {
private _html: string;
public onMessageEmitter = new Emitter<any>();
public onClosedEmitter = new Emitter<any>();
constructor(
private readonly _proxy: MainThreadDashboardWebviewShape,
private readonly _handle: number,
private readonly _connection: sqlops.connection.Connection,
private readonly _serverInfo: sqlops.ServerInfo
) { }
public postMessage(message: any): Thenable<any> {
return this._proxy.$sendMessage(this._handle, message);
}
public get onMessage(): vscode.Event<any> {
return this.onMessageEmitter.event;
}
public get onClosed(): vscode.Event<any> {
return this.onClosedEmitter.event;
}
public get connection(): sqlops.connection.Connection {
return deepClone(this._connection);
}
public get serverInfo(): sqlops.ServerInfo {
return deepClone(this._serverInfo);
}
get html(): string {
return this._html;
}
set html(value: string) {
if (this._html !== value) {
this._html = value;
this._proxy.$setHtml(this._handle, value);
}
}
}
export class ExtHostDashboardWebviews implements ExtHostDashboardWebviewsShape {
private readonly _proxy: MainThreadDashboardWebviewShape;
private readonly _webviews = new Map<number, ExtHostDashboardWebview>();
private readonly _handlers = new Map<string, (webview: sqlops.DashboardWebview) => void>();
constructor(
mainContext: IMainContext
) {
this._proxy = mainContext.getProxy(SqlMainContext.MainThreadDashboardWebview);
}
$onMessage(handle: number, message: any): void {
const webview = this._webviews.get(handle);
webview.onMessageEmitter.fire(message);
}
$onClosed(handle: number): void {
const webview = this._webviews.get(handle);
webview.onClosedEmitter.fire();
this._webviews.delete(handle);
}
$registerProvider(widgetId: string, handler: (webview: sqlops.DashboardWebview) => void): void {
this._handlers.set(widgetId, handler);
this._proxy.$registerProvider(widgetId);
}
$registerWidget(handle: number, id: string, connection: sqlops.connection.Connection, serverInfo: sqlops.ServerInfo): void {
let webview = new ExtHostDashboardWebview(this._proxy, handle, connection, serverInfo);
this._webviews.set(handle, webview);
this._handlers.get(id)(webview);
}
}