mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-21 17:22:55 -05:00
Fix view model editor and webview component (#1483)
* destroy viewmodel when editor is closed and add example * support retainContextWhenHidden option for webview component * fix breaking change from master * dispose html element during dispose * add more comments
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import 'vs/css!./modelViewEditor';
|
||||
|
||||
import { Builder, $ } from 'vs/base/browser/builder';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
@@ -15,19 +13,16 @@ import * as DOM from 'vs/base/browser/dom';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
import { ModelViewInput } from 'sql/parts/modelComponents/modelEditor/modelViewInput';
|
||||
import { bootstrapAngular } from 'sql/services/bootstrap/bootstrapService';
|
||||
import { Dialog } from 'sql/platform/dialog/dialogTypes';
|
||||
import { DialogPane } from 'sql/platform/dialog/dialogPane';
|
||||
|
||||
export class ModelViewEditor extends BaseEditor {
|
||||
|
||||
public static ID: string = 'workbench.editor.modelViewEditor';
|
||||
private _modelViewMap = new Map<string, HTMLElement>();
|
||||
|
||||
private _editorFrame: HTMLElement;
|
||||
|
||||
constructor(
|
||||
@ITelemetryService telemetryService: ITelemetryService,
|
||||
@IThemeService themeService: IThemeService,
|
||||
@IInstantiationService private _instantiationService: IInstantiationService
|
||||
@IThemeService themeService: IThemeService
|
||||
) {
|
||||
super(ModelViewEditor.ID, telemetryService, themeService);
|
||||
}
|
||||
@@ -36,6 +31,7 @@ export class ModelViewEditor extends BaseEditor {
|
||||
* Called to create the editor in the parent builder.
|
||||
*/
|
||||
public createEditor(parent: Builder): void {
|
||||
this._editorFrame = parent.getHTMLElement();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,23 +40,43 @@ export class ModelViewEditor extends BaseEditor {
|
||||
public focus(): void {
|
||||
}
|
||||
|
||||
public setInput(input: ModelViewInput, options?: EditorOptions): TPromise<void, any> {
|
||||
async setInput(input: ModelViewInput, options?: EditorOptions): TPromise<void, any> {
|
||||
if (this.input && this.input.matches(input)) {
|
||||
return TPromise.as(undefined);
|
||||
}
|
||||
|
||||
const parentElement = this.getContainer().getHTMLElement();
|
||||
$(parentElement).clearChildren();
|
||||
|
||||
if (!this._modelViewMap.get(input.modelViewId)) {
|
||||
let modelViewContainer = DOM.$('div.model-view-container');
|
||||
let dialogPane = new DialogPane(input.title, input.modelViewId, () => undefined, this._instantiationService);
|
||||
dialogPane.createBody(modelViewContainer);
|
||||
this._modelViewMap.set(input.modelViewId, modelViewContainer);
|
||||
if (this.input instanceof ModelViewInput) {
|
||||
if (this.input.container) {
|
||||
if (this.input.options && this.input.options.retainContextWhenHidden) {
|
||||
this.input.container.style.visibility = 'hidden';
|
||||
} else {
|
||||
parentElement.removeChild(this.input.container);
|
||||
}
|
||||
}
|
||||
}
|
||||
let element = this._modelViewMap.get(input.modelViewId);
|
||||
DOM.append(parentElement, element);
|
||||
|
||||
return super.setInput(input, options);
|
||||
if (!parentElement.contains(input.container)) {
|
||||
parentElement.appendChild(input.container);
|
||||
}
|
||||
input.container.style.visibility = 'visible';
|
||||
|
||||
await super.setInput(input, options);
|
||||
this.doUpdateContainer();
|
||||
}
|
||||
|
||||
private doUpdateContainer() {
|
||||
const modelViewContainer = this.input && (this.input as ModelViewInput).container;
|
||||
if (modelViewContainer) {
|
||||
const frameRect = this._editorFrame.getBoundingClientRect();
|
||||
const containerRect = modelViewContainer.parentElement.getBoundingClientRect();
|
||||
|
||||
modelViewContainer.style.position = 'absolute';
|
||||
modelViewContainer.style.top = `${frameRect.top}px`;
|
||||
modelViewContainer.style.left = `${frameRect.left - containerRect.left}px`;
|
||||
modelViewContainer.style.width = `${frameRect.width}px`;
|
||||
modelViewContainer.style.height = `${frameRect.height}px`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,7 +84,12 @@ export class ModelViewEditor extends BaseEditor {
|
||||
* To be called when the container of this editor changes size.
|
||||
*/
|
||||
public layout(dimension: Dimension): void {
|
||||
|
||||
if (this.input instanceof ModelViewInput) {
|
||||
if (this.input.container && this.input.dialogPane) {
|
||||
this.doUpdateContainer();
|
||||
// todo: layout this.input.dialogPane (Github issue: #1484)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user