Dialog with custom UI API (#561)

* initial checkin for dialog with custom UI API
This commit is contained in:
Leila Lali
2018-01-29 14:31:12 -08:00
committed by GitHub
parent 495c2e62e6
commit 1b2e264c7d
12 changed files with 499 additions and 4 deletions

View File

@@ -0,0 +1,122 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { SqlMainContext, MainThreadModalDialogShape, ExtHostModalDialogsShape } from 'sql/workbench/api/node/sqlextHost.protocol';
import { IMainContext } from 'vs/workbench/api/node/extHost.protocol';
import * as vscode from 'vscode';
import * as data from 'data';
import { Emitter } from 'vs/base/common/event';
class ExtHostDialog implements data.ModalDialog {
private _title: string;
private _html: string;
private _okTitle: string;
private _closeTitle: string;
public onMessageEmitter = new Emitter<any>();
public onClosedEmitter = new Emitter<any>();
constructor(
private readonly _proxy: MainThreadModalDialogShape,
private readonly _handle: number,
) { }
get title(): string {
return this._title;
}
set title(value: string) {
if (this._title !== value) {
this._title = value;
this._proxy.$setTitle(this._handle, value);
}
}
get html(): string {
return this._html;
}
set html(value: string) {
if (this._html !== value) {
this._html = value;
this._proxy.$setHtml(this._handle, value);
}
}
public set okTitle(value: string) {
this._okTitle = value;
}
public get okTitle(): string {
return this._okTitle;
}
public set closeTitle(value: string) {
this._closeTitle = value;
}
public get closeTitle(): string {
return this._closeTitle;
}
public open(): void {
this._proxy.$show(this._handle);
}
public close(): void {
this._proxy.$disposeDialog(this._handle);
}
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;
}
}
export class ExtHostModalDialogs implements ExtHostModalDialogsShape {
private static _handlePool = 0;
private readonly _proxy: MainThreadModalDialogShape;
private readonly _webviews = new Map<number, ExtHostDialog>();
constructor(
mainContext: IMainContext
) {
this._proxy = mainContext.get(SqlMainContext.MainThreadModalDialog);
}
createDialog(
title: string
): data.ModalDialog {
console.log(title);
const handle = ExtHostModalDialogs._handlePool++;
this._proxy.$createDialog(handle);
const webview = new ExtHostDialog(this._proxy, handle);
this._webviews.set(handle, webview);
webview.title = title;
//webview.options = options;
//this._proxy.$show(handle);
return webview;
}
$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();
}
}