Skip to content

Commit

Permalink
Restored the Settings UI. Deferred model loading.
Browse files Browse the repository at this point in the history
Closes #1031

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
  • Loading branch information
Akos Kitta authored and kittaakos committed Jun 13, 2022
1 parent 7c2843f commit a804766
Showing 1 changed file with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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<void> {
// 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;
}
Expand Down

0 comments on commit a804766

Please sign in to comment.