| 45 | } |
| 46 | |
| 47 | export class EditorWindow implements IEditorWindow { |
| 48 | id: string = uniqueId('window'); |
| 49 | icon: React.ReactElement | undefined; |
| 50 | |
| 51 | private emitter: IEventBus = createModuleEventBus('Project'); |
| 52 | |
| 53 | title: string | undefined; |
| 54 | |
| 55 | url: string | undefined; |
| 56 | |
| 57 | @obx.ref _editorView: Context; |
| 58 | |
| 59 | @obx editorViews: Map<string, Context> = new Map<string, Context>(); |
| 60 | |
| 61 | @obx initReady = false; |
| 62 | |
| 63 | sleep: boolean | undefined; |
| 64 | |
| 65 | get editorView() { |
| 66 | if (!this._editorView) { |
| 67 | return this.editorViews.values().next().value; |
| 68 | } |
| 69 | return this._editorView; |
| 70 | } |
| 71 | |
| 72 | constructor(readonly resource: IResource, readonly workspace: IWorkspace, private config: IWindowCOnfig) { |
| 73 | makeObservable(this); |
| 74 | this.title = config.title; |
| 75 | this.icon = resource.icon; |
| 76 | this.sleep = config.sleep; |
| 77 | if (config.sleep) { |
| 78 | this.updateState(WINDOW_STATE.sleep); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | updateState(state: WINDOW_STATE): void { |
| 83 | switch (state) { |
| 84 | case WINDOW_STATE.active: |
| 85 | this._editorView?.setActivate(true); |
| 86 | break; |
| 87 | case WINDOW_STATE.inactive: |
| 88 | this._editorView?.setActivate(false); |
| 89 | break; |
| 90 | case WINDOW_STATE.destroyed: |
| 91 | break; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | async importSchema(schema: any) { |
| 96 | const newSchema = await this.resource.import(schema); |
| 97 | |
| 98 | if (!newSchema) { |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | Object.keys(newSchema).forEach(key => { |
| 103 | const view = this.editorViews.get(key); |
| 104 | view?.project.importSchema(newSchema[key]); |
nothing calls this directly
no test coverage detected
searching dependent graphs…