mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-06 09:35:41 -05:00
Fix modelview webview to work in query tab (#6119)
* WIP * Rebuild webview when switching tabs * Remove unneeded code * Make ready promise private * Undo edit in sendMessage * Add null check prior to using ready promise * Remove extra whitespace * Rename parameter and fix strict null check errors
This commit is contained in:
@@ -41,6 +41,7 @@ export default class WebViewComponent extends ComponentBase implements IComponen
|
||||
private _webview: WebviewElement;
|
||||
private _renderedHtml: string;
|
||||
private _extensionLocationUri: URI;
|
||||
private _ready: Promise<void>;
|
||||
|
||||
protected contextKey: IContextKey<boolean>;
|
||||
protected findInputFocusContextKey: IContextKey<boolean>;
|
||||
@@ -74,15 +75,28 @@ export default class WebViewComponent extends ComponentBase implements IComponen
|
||||
|
||||
this._webview.mountTo(this._el.nativeElement);
|
||||
|
||||
this._register(this._webview.onDidClickLink(link => this.onDidClickLink(link)));
|
||||
this._ready = new Promise(resolve => {
|
||||
let webview = (<any>this._webview)._webview;
|
||||
const subscription = this._register(addDisposableListener(webview, 'ipc-message', (event) => {
|
||||
if (event.channel === 'webview-ready') {
|
||||
subscription.dispose();
|
||||
resolve();
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
this._register(this._webview.onMessage(e => {
|
||||
this.fireEvent({
|
||||
eventType: ComponentEventType.onMessage,
|
||||
args: e
|
||||
});
|
||||
}));
|
||||
this.setHtml();
|
||||
this._ready.then(() => {
|
||||
this._register(this._webview.onDidClickLink(link => this.onDidClickLink(link)));
|
||||
|
||||
this._register(this._webview.onMessage(e => {
|
||||
this.fireEvent({
|
||||
eventType: ComponentEventType.onMessage,
|
||||
args: e
|
||||
});
|
||||
}));
|
||||
|
||||
this.setHtml();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
@@ -125,9 +139,13 @@ export default class WebViewComponent extends ComponentBase implements IComponen
|
||||
/// IComponent implementation
|
||||
|
||||
public layout(): void {
|
||||
let element = <HTMLElement>this._el.nativeElement;
|
||||
element.style.position = this.position;
|
||||
this._webview.layout();
|
||||
if (this._ready) {
|
||||
this._ready.then(() => {
|
||||
let element = <HTMLElement>this._el.nativeElement;
|
||||
element.style.position = this.position;
|
||||
this._webview.layout();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public setLayout(layout: any): void {
|
||||
@@ -136,18 +154,21 @@ export default class WebViewComponent extends ComponentBase implements IComponen
|
||||
}
|
||||
|
||||
public setProperties(properties: { [key: string]: any; }): void {
|
||||
super.setProperties(properties);
|
||||
if (this.options) {
|
||||
this._webview.options = this.getExtendedOptions();
|
||||
if (this._ready) {
|
||||
this._ready.then(() => {
|
||||
super.setProperties(properties);
|
||||
if (this.options) {
|
||||
this._webview.options = this.getExtendedOptions();
|
||||
}
|
||||
if (this.html !== this._renderedHtml) {
|
||||
this.setHtml();
|
||||
}
|
||||
if (this.extensionLocation) {
|
||||
this._extensionLocationUri = URI.revive(this.extensionLocation);
|
||||
}
|
||||
this.sendMessage();
|
||||
});
|
||||
}
|
||||
if (this.html !== this._renderedHtml) {
|
||||
this.setHtml();
|
||||
}
|
||||
if (this.extensionLocation) {
|
||||
this._extensionLocationUri = URI.revive(this.extensionLocation);
|
||||
}
|
||||
this.sendMessage();
|
||||
|
||||
}
|
||||
|
||||
// CSS-bound properties
|
||||
|
||||
@@ -249,7 +249,7 @@ export class QueryResultsView extends Disposable {
|
||||
tab.view._componentId = parts[2];
|
||||
this.dynamicModelViewTabs.push(tab);
|
||||
if (!this._panelView.contains(tab)) {
|
||||
this._panelView.pushTab(tab);
|
||||
this._panelView.pushTab(tab, undefined, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -393,7 +393,7 @@ export class QueryResultsView extends Disposable {
|
||||
|
||||
this.input.state.visibleTabs.add('querymodelview;' + title + ';' + componentId);
|
||||
if (!this._panelView.contains(tab)) {
|
||||
this._panelView.pushTab(tab);
|
||||
this._panelView.pushTab(tab, undefined, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user