From bd44b49416367b55b0d771a90371ba082dd06212 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Sat, 11 Jun 2022 15:26:01 +0200 Subject: [PATCH] Restored the Settings UI. Deferred model loading. Closes #1031 Signed-off-by: Akos Kitta --- .../preferences/preference-tree-generator.ts | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/arduino-ide-extension/src/browser/theia/preferences/preference-tree-generator.ts b/arduino-ide-extension/src/browser/theia/preferences/preference-tree-generator.ts index 0dcb7af66..6ff7df05b 100644 --- a/arduino-ide-extension/src/browser/theia/preferences/preference-tree-generator.ts +++ b/arduino-ide-extension/src/browser/theia/preferences/preference-tree-generator.ts @@ -1,16 +1,43 @@ +import { + FrontendApplicationState, + FrontendApplicationStateService, +} from '@theia/core/lib/browser/frontend-application-state'; import { CompositeTreeNode } from '@theia/core/lib/browser/tree/tree'; -import { injectable } from '@theia/core/shared/inversify'; +import { inject, injectable } from '@theia/core/shared/inversify'; import { PreferenceTreeGenerator as TheiaPreferenceTreeGenerator } from '@theia/preferences/lib/browser/util/preference-tree-generator'; @injectable() export class PreferenceTreeGenerator extends TheiaPreferenceTreeGenerator { + private shouldHandleChangedSchemaOnReady = false; + private state: FrontendApplicationState | undefined; + + @inject(FrontendApplicationStateService) + private readonly appStateService: FrontendApplicationStateService; + protected override async init(): Promise { - // The IDE2 does not use the default Theia preferences UI. - // There is no need to create and keep the the tree model synchronized when there is no UI for it. + this.appStateService.onStateChanged((state) => { + this.state = state; + // manually trigger a model (and UI) refresh if it was requested during the startup phase. + if (this.state === 'ready' && this.shouldHandleChangedSchemaOnReady) { + this.doHandleChangedSchema(); + } + }); + return super.init(); + } + + override doHandleChangedSchema(): void { + if (this.state === 'ready') { + super.doHandleChangedSchema(); + } + // don't do anything until the app is `ready`, then invoke `doHandleChangedSchema`. + this.shouldHandleChangedSchemaOnReady = true; } - // Just returns with the empty root. override generateTree(): CompositeTreeNode { + if (this.state === 'ready') { + return super.generateTree(); + } + // always create an empty root when the app is not ready. this._root = this.createRootNode(); return this._root; }