add create webview event and fix fire event in model view (#2405)

This commit is contained in:
Abbie Petchtes
2018-09-05 14:07:52 -07:00
committed by GitHub
parent b7f4f6af3a
commit 534bbe9b9a
17 changed files with 39 additions and 20 deletions

View File

@@ -67,8 +67,8 @@ export default class ButtonComponent extends ComponentWithIconBase implements IC
let reader = new FileReader(); let reader = new FileReader();
reader.onload = (e) => { reader.onload = (e) => {
let text = (<FileReader>e.target).result; let text = (<FileReader>e.target).result;
self.fileContent = text; self.fileContent = text.toString();
self._onEventEmitter.fire({ self.fireEvent({
eventType: ComponentEventType.onDidClick, eventType: ComponentEventType.onDidClick,
args: self.fileContent args: self.fileContent
}); });
@@ -76,7 +76,7 @@ export default class ButtonComponent extends ComponentWithIconBase implements IC
reader.readAsText(file); reader.readAsText(file);
}; };
} else { } else {
this._onEventEmitter.fire({ this.fireEvent({
eventType: ComponentEventType.onDidClick, eventType: ComponentEventType.onDidClick,
args: e args: e
}); });

View File

@@ -53,7 +53,7 @@ export default class CardComponent extends ComponentWithIconBase implements ICom
if (this.selectable) { if (this.selectable) {
this.selected = !this.selected; this.selected = !this.selected;
this._changeRef.detectChanges(); this._changeRef.detectChanges();
this._onEventEmitter.fire({ this.fireEvent({
eventType: ComponentEventType.onDidClick, eventType: ComponentEventType.onDidClick,
args: this.selected args: this.selected
}); });
@@ -158,7 +158,7 @@ export default class CardComponent extends ComponentWithIconBase implements ICom
} }
private onDidActionClick(action: ActionDescriptor): void { private onDidActionClick(action: ActionDescriptor): void {
this._onEventEmitter.fire({ this.fireEvent({
eventType: ComponentEventType.onDidClick, eventType: ComponentEventType.onDidClick,
args: action args: action
}); });

View File

@@ -49,7 +49,7 @@ export default class CheckBoxComponent extends ComponentBase implements ICompone
this._register(this._input); this._register(this._input);
this._register(this._input.onChange(e => { this._register(this._input.onChange(e => {
this.checked = this._input.checked; this.checked = this._input.checked;
this._onEventEmitter.fire({ this.fireEvent({
eventType: ComponentEventType.onDidChange, eventType: ComponentEventType.onDidChange,
args: e args: e
}); });

View File

@@ -195,7 +195,7 @@ export abstract class ComponentBase extends Disposable implements IComponent, On
return this._onEventEmitter.event(handler); return this._onEventEmitter.event(handler);
} }
private fireEvent(event: IComponentEventArgs) { protected fireEvent(event: IComponentEventArgs) {
this._onEventEmitter.fire(event); this._onEventEmitter.fire(event);
if (this._eventQueue) { if (this._eventQueue) {
this._eventQueue.push(event); this._eventQueue.push(event);

View File

@@ -139,7 +139,7 @@ export default class DeclarativeTableComponent extends ComponentBase implements
column: cell, column: cell,
value: newValue value: newValue
}; };
this._onEventEmitter.fire({ this.fireEvent({
eventType: ComponentEventType.onDidChange, eventType: ComponentEventType.onDidChange,
args: newCellData args: newCellData
}); });

View File

@@ -68,7 +68,7 @@ export default class DropDownComponent extends ComponentBase implements ICompone
this._register(this._editableDropdown.onValueChange(e => { this._register(this._editableDropdown.onValueChange(e => {
if (this.editable) { if (this.editable) {
this.setSelectedValue(this._editableDropdown.value); this.setSelectedValue(this._editableDropdown.value);
this._onEventEmitter.fire({ this.fireEvent({
eventType: ComponentEventType.onDidChange, eventType: ComponentEventType.onDidChange,
args: e args: e
}); });
@@ -83,7 +83,7 @@ export default class DropDownComponent extends ComponentBase implements ICompone
this._register(this._selectBox.onDidSelect(e => { this._register(this._selectBox.onDidSelect(e => {
if (!this.editable) { if (!this.editable) {
this.setSelectedValue(this._selectBox.value); this.setSelectedValue(this._selectBox.value);
this._onEventEmitter.fire({ this.fireEvent({
eventType: ComponentEventType.onDidChange, eventType: ComponentEventType.onDidChange,
args: e args: e
}); });

View File

@@ -65,7 +65,13 @@ export default class EditorComponent extends ComponentBase implements IComponent
let uri = this.createUri(); let uri = this.createUri();
this._editorInput = instantiationService.createInstance(UntitledEditorInput, uri, false, 'sql', '', ''); this._editorInput = instantiationService.createInstance(UntitledEditorInput, uri, false, 'sql', '', '');
this._editor.setInput(this._editorInput, undefined); this._editor.setInput(this._editorInput, undefined);
this._editorInput.resolve().then(model => this._editorModel = model.textEditorModel); this._editorInput.resolve().then(model => {
this._editorModel = model.textEditorModel;
this.fireEvent({
eventType: ComponentEventType.onComponentCreated,
args: this._uri
});
});
this._register(this._editor); this._register(this._editor);
this._register(this._editorInput); this._register(this._editorInput);
@@ -73,7 +79,7 @@ export default class EditorComponent extends ComponentBase implements IComponent
this.content = this._editorModel.getValue(); this.content = this._editorModel.getValue();
// Notify via an event so that extensions can detect and propagate changes // Notify via an event so that extensions can detect and propagate changes
this._onEventEmitter.fire({ this.fireEvent({
eventType: ComponentEventType.onDidChange, eventType: ComponentEventType.onDidChange,
args: e args: e
}); });

View File

@@ -60,7 +60,7 @@ export default class FileBrowserTreeComponent extends ComponentBase implements I
} }
private onClicked(selectedNode: FileNode) { private onClicked(selectedNode: FileNode) {
this._onEventEmitter.fire({ this.fireEvent({
eventType: ComponentEventType.onDidChange, eventType: ComponentEventType.onDidChange,
args: { fullPath: selectedNode.fullPath, isFile: selectedNode.isFile } args: { fullPath: selectedNode.fullPath, isFile: selectedNode.isFile }
}); });

View File

@@ -121,7 +121,7 @@ export default class InputBoxComponent extends ComponentBase implements ICompone
if (input.hideErrors) { if (input.hideErrors) {
input.hideErrors = false; input.hideErrors = false;
} }
this._onEventEmitter.fire({ this.fireEvent({
eventType: ComponentEventType.onDidChange, eventType: ComponentEventType.onDidChange,
args: e args: e
}); });

View File

@@ -69,7 +69,8 @@ export enum ComponentEventType {
onDidClick, onDidClick,
validityChanged, validityChanged,
onMessage, onMessage,
onSelectedRowChanged onSelectedRowChanged,
onComponentCreated
} }
export interface IModelStore { export interface IModelStore {

View File

@@ -56,7 +56,7 @@ export default class ListBoxComponent extends ComponentBase implements IComponen
this._register(attachListBoxStyler(this._input, this.themeService)); this._register(attachListBoxStyler(this._input, this.themeService));
this._register(this._input.onDidSelect(e => { this._register(this._input.onDidSelect(e => {
this.selectedRow = e.index; this.selectedRow = e.index;
this._onEventEmitter.fire({ this.fireEvent({
eventType: ComponentEventType.onSelectedRowChanged, eventType: ComponentEventType.onSelectedRowChanged,
args: e args: e
}); });

View File

@@ -51,7 +51,7 @@ export default class RadioButtonComponent extends ComponentBase implements IComp
this._register(this._input); this._register(this._input);
this._register(this._input.onClicked(e => { this._register(this._input.onClicked(e => {
this.checked = this._input.checked; this.checked = this._input.checked;
this._onEventEmitter.fire({ this.fireEvent({
eventType: ComponentEventType.onDidClick, eventType: ComponentEventType.onDidClick,
args: e args: e
}); });

View File

@@ -109,7 +109,7 @@ export default class TableComponent extends ComponentBase implements IComponent,
this._register(attachTableStyler(this._table, this.themeService)); this._register(attachTableStyler(this._table, this.themeService));
this._register(this._table.onSelectedRowsChanged((e, data) => { this._register(this._table.onSelectedRowsChanged((e, data) => {
this.selectedRows = data.rows; this.selectedRows = data.rows;
this._onEventEmitter.fire({ this.fireEvent({
eventType: ComponentEventType.onSelectedRowChanged, eventType: ComponentEventType.onSelectedRowChanged,
args: e args: e
}); });

View File

@@ -82,7 +82,7 @@ export default class WebViewComponent extends ComponentBase implements IComponen
this._register(this._webview.onDidClickLink(link => this.onDidClickLink(link))); this._register(this._webview.onDidClickLink(link => this.onDidClickLink(link)));
this._register(this._webview.onMessage(e => { this._register(this._webview.onMessage(e => {
this._onEventEmitter.fire({ this.fireEvent({
eventType: ComponentEventType.onMessage, eventType: ComponentEventType.onMessage,
args: e args: e
}); });

View File

@@ -641,6 +641,11 @@ declare module 'sqlops' {
*/ */
readonly onContentChanged: vscode.Event<any>; readonly onContentChanged: vscode.Event<any>;
/**
* An event called when the editor is created
*/
readonly onEditorCreated: vscode.Event<any>;
} }
export interface ButtonComponent extends Component, ButtonProperties { export interface ButtonComponent extends Component, ButtonProperties {

View File

@@ -173,7 +173,8 @@ export enum ComponentEventType {
onDidClick, onDidClick,
validityChanged, validityChanged,
onMessage, onMessage,
onSelectedRowChanged onSelectedRowChanged,
onComponentCreated
} }
export interface IComponentEventArgs { export interface IComponentEventArgs {

View File

@@ -850,6 +850,7 @@ class EditorWrapper extends ComponentWrapper implements sqlops.EditorComponent {
super(proxy, handle, ModelComponentTypes.Editor, id); super(proxy, handle, ModelComponentTypes.Editor, id);
this.properties = {}; this.properties = {};
this._emitterMap.set(ComponentEventType.onDidChange, new Emitter<any>()); this._emitterMap.set(ComponentEventType.onDidChange, new Emitter<any>());
this._emitterMap.set(ComponentEventType.onComponentCreated, new Emitter<any>());
} }
public get content(): string { public get content(): string {
@@ -874,6 +875,11 @@ class EditorWrapper extends ComponentWrapper implements sqlops.EditorComponent {
let emitter = this._emitterMap.get(ComponentEventType.onDidChange); let emitter = this._emitterMap.get(ComponentEventType.onDidChange);
return emitter && emitter.event; return emitter && emitter.event;
} }
public get onEditorCreated(): vscode.Event<any> {
let emitter = this._emitterMap.get(ComponentEventType.onComponentCreated);
return emitter && emitter.event;
}
} }
class RadioButtonWrapper extends ComponentWrapper implements sqlops.RadioButtonComponent { class RadioButtonWrapper extends ComponentWrapper implements sqlops.RadioButtonComponent {