Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1031 Restored the Settings UI. Deferred model loading. #1046

Merged
merged 1 commit into from
Jun 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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