mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-16 01:25:36 -05:00
Dialog with custom UI API (#561)
* initial checkin for dialog with custom UI API
This commit is contained in:
122
src/sql/workbench/api/node/extHostModalDialog.ts
Normal file
122
src/sql/workbench/api/node/extHostModalDialog.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import { ExtHostThreadService } from 'vs/workbench/services/thread/node/extHostT
|
||||
import * as sqlExtHostTypes from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
|
||||
import { ExtHostConfiguration } from 'vs/workbench/api/node/extHostConfiguration';
|
||||
import { ExtHostModalDialogs } from 'sql/workbench/api/node/extHostModalDialog';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { IExtensionApiFactory } from 'vs/workbench/api/node/extHost.api.impl';
|
||||
|
||||
@@ -52,6 +53,7 @@ export function createApiFactory(
|
||||
const extHostDataProvider = threadService.set(SqlExtHostContext.ExtHostDataProtocol, new ExtHostDataProtocol(threadService));
|
||||
const extHostSerializationProvider = threadService.set(SqlExtHostContext.ExtHostSerializationProvider, new ExtHostSerializationProvider(threadService));
|
||||
const extHostResourceProvider = threadService.set(SqlExtHostContext.ExtHostResourceProvider, new ExtHostResourceProvider(threadService));
|
||||
const extHostModalDialogs = threadService.set(SqlExtHostContext.ExtHostModalDialogs, new ExtHostModalDialogs(threadService));
|
||||
|
||||
return {
|
||||
vsCodeFactory: vsCodeFactory,
|
||||
@@ -236,6 +238,12 @@ export function createApiFactory(
|
||||
}
|
||||
};
|
||||
|
||||
const window = {
|
||||
createDialog(name: string) {
|
||||
return extHostModalDialogs.createDialog(name);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
accounts,
|
||||
credentials,
|
||||
@@ -248,7 +256,8 @@ export function createApiFactory(
|
||||
MetadataType: sqlExtHostTypes.MetadataType,
|
||||
TaskStatus: sqlExtHostTypes.TaskStatus,
|
||||
TaskExecutionMode: sqlExtHostTypes.TaskExecutionMode,
|
||||
ScriptOperation: sqlExtHostTypes.ScriptOperation
|
||||
ScriptOperation: sqlExtHostTypes.ScriptOperation,
|
||||
window
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -409,7 +409,8 @@ export const SqlMainContext = {
|
||||
MainThreadCredentialManagement: createMainId<MainThreadCredentialManagementShape>('MainThreadCredentialManagement'),
|
||||
MainThreadDataProtocol: createMainId<MainThreadDataProtocolShape>('MainThreadDataProtocol'),
|
||||
MainThreadSerializationProvider: createMainId<MainThreadSerializationProviderShape>('MainThreadSerializationProvider'),
|
||||
MainThreadResourceProvider: createMainId<MainThreadResourceProviderShape>('MainThreadResourceProvider')
|
||||
MainThreadResourceProvider: createMainId<MainThreadResourceProviderShape>('MainThreadResourceProvider'),
|
||||
MainThreadModalDialog: createMainId<MainThreadModalDialogShape>('MainThreadModalDialog'),
|
||||
};
|
||||
|
||||
export const SqlExtHostContext = {
|
||||
@@ -417,5 +418,19 @@ export const SqlExtHostContext = {
|
||||
ExtHostCredentialManagement: createExtId<ExtHostCredentialManagementShape>('ExtHostCredentialManagement'),
|
||||
ExtHostDataProtocol: createExtId<ExtHostDataProtocolShape>('ExtHostDataProtocol'),
|
||||
ExtHostSerializationProvider: createExtId<ExtHostSerializationProviderShape>('ExtHostSerializationProvider'),
|
||||
ExtHostResourceProvider: createExtId<ExtHostResourceProviderShape>('ExtHostResourceProvider')
|
||||
ExtHostResourceProvider: createExtId<ExtHostResourceProviderShape>('ExtHostResourceProvider'),
|
||||
ExtHostModalDialogs: createExtId<ExtHostModalDialogsShape>('ExtHostModalDialogs')
|
||||
};
|
||||
|
||||
export interface MainThreadModalDialogShape extends IDisposable {
|
||||
$createDialog(handle: number): void;
|
||||
$disposeDialog(handle: number): void;
|
||||
$show(handle: number): void;
|
||||
$setTitle(handle: number, value: string): void;
|
||||
$setHtml(handle: number, value: string): void;
|
||||
$sendMessage(handle: number, value: any): Thenable<boolean>;
|
||||
}
|
||||
export interface ExtHostModalDialogsShape {
|
||||
$onMessage(handle: number, message: any): void;
|
||||
$onClosed(handle: number): void;
|
||||
}
|
||||
Reference in New Issue
Block a user