I am trying to create a custom entry in the tree pane of the Preferences widget. I dug through the code and found a way to make it work.
Though it works, I would like to run it by the community to make sure what I am doing is valid and get some feedback.
custom-preference-frontend-module.ts
import { ContainerModule } from "inversify";
import { PreferenceTreeGenerator as TheiaPreferenceTreeGenerator } from "@theia/preferences/lib/browser/util/preference-tree-generator";
import { createPreferencesWidgetContainer } from "@theia/preferences/lib/browser/views/preference-widget-bindings";
import { PreferencesWidget } from "@theia/preferences/lib/browser/views/preference-widget";
import { WidgetFactory } from "@theia/core/lib/browser";
import { PreferenceTreeGenerator } from "./preferences-tree-generator";
export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(PreferenceTreeGenerator).toSelf().inSingletonScope();
rebind(TheiaPreferenceTreeGenerator).toService(PreferenceTreeGenerator);
bind(WidgetFactory)
.toDynamicValue(({ container }) => ({
id: PreferencesWidget.ID,
createWidget: (): PreferencesWidget =>
createPreferencesWidgetContainer(container).get(PreferencesWidget),
}))
.inSingletonScope();
});
preference-tree-generator.ts
import { postConstruct, injectable } from "inversify";
import { PreferenceTreeGenerator as TheiaPreferenceTreeGenerator } from "@theia/preferences/lib/browser/util/preference-tree-generator";
@injectable()
export class PreferenceTreeGenerator extends TheiaPreferenceTreeGenerator {
@postConstruct()
protected override async init(): Promise<void> {
this.topLevelCategories.set("custom", "Custom");
await super.init();
}
}
This shows up as expected
Similarly, I plan on adding entries to this.sectionAssignments to show custom child entries under custom.