From 7be0fa60a8bdaf3b56c6ed66c96946f4ca77fbb6 Mon Sep 17 00:00:00 2001 From: "Christian W. Damus" Date: Mon, 15 Jul 2024 08:18:29 -0400 Subject: [PATCH] Make Notebook preferences registration substitutable Implement the commonly employed pattern for preference contribution registration to enable substitution of the Notebook preference schema. Fixes #13913 Signed-off-by: Christian W. Damus --- .../src/browser/contributions/notebook-preferences.ts | 11 ++++++++++- .../notebook/src/browser/notebook-frontend-module.ts | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/notebook/src/browser/contributions/notebook-preferences.ts b/packages/notebook/src/browser/contributions/notebook-preferences.ts index bb947fb756dc3..4187d6d914d80 100644 --- a/packages/notebook/src/browser/contributions/notebook-preferences.ts +++ b/packages/notebook/src/browser/contributions/notebook-preferences.ts @@ -19,7 +19,8 @@ *--------------------------------------------------------------------------------------------*/ import { nls } from '@theia/core'; -import { PreferenceSchema } from '@theia/core/lib/browser'; +import { interfaces } from '@theia/core/shared/inversify'; +import { PreferenceContribution, PreferenceSchema } from '@theia/core/lib/browser'; export namespace NotebookPreferences { export const NOTEBOOK_LINE_NUMBERS = 'notebook.lineNumbers'; @@ -81,3 +82,11 @@ export const notebookPreferenceSchema: PreferenceSchema = { } }; + +export const NotebookPreferenceContribution = Symbol('NotebookPreferenceContribution'); + +export function bindNotebookPreferences(bind: interfaces.Bind): void { + // We don't need a NotebookPreferenceConfiguration class, so there's no preference proxy to bind + bind(NotebookPreferenceContribution).toConstantValue({ schema: notebookPreferenceSchema }); + bind(PreferenceContribution).toService(NotebookPreferenceContribution); +} diff --git a/packages/notebook/src/browser/notebook-frontend-module.ts b/packages/notebook/src/browser/notebook-frontend-module.ts index 681780f512655..fda9e983c0d8b 100644 --- a/packages/notebook/src/browser/notebook-frontend-module.ts +++ b/packages/notebook/src/browser/notebook-frontend-module.ts @@ -16,7 +16,7 @@ import '../../src/browser/style/index.css'; import { ContainerModule } from '@theia/core/shared/inversify'; -import { FrontendApplicationContribution, KeybindingContribution, LabelProviderContribution, OpenHandler, PreferenceContribution, WidgetFactory } from '@theia/core/lib/browser'; +import { FrontendApplicationContribution, KeybindingContribution, LabelProviderContribution, OpenHandler, WidgetFactory } from '@theia/core/lib/browser'; import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution'; import { NotebookOpenHandler } from './notebook-open-handler'; import { CommandContribution, MenuContribution, ResourceResolver, } from '@theia/core'; @@ -44,7 +44,7 @@ import { NotebookOutlineContribution } from './contributions/notebook-outline-co import { NotebookLabelProviderContribution } from './contributions/notebook-label-provider-contribution'; import { NotebookOutputActionContribution } from './contributions/notebook-output-action-contribution'; import { NotebookClipboardService } from './service/notebook-clipboard-service'; -import { notebookPreferenceSchema } from './contributions/notebook-preferences'; +import { bindNotebookPreferences } from './contributions/notebook-preferences'; import { NotebookOptionsService } from './service/notebook-options'; export default new ContainerModule((bind, unbind, isBound, rebind) => { @@ -106,6 +106,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => { bind(NotebookLabelProviderContribution).toSelf().inSingletonScope(); bind(LabelProviderContribution).toService(NotebookLabelProviderContribution); - bind(PreferenceContribution).toConstantValue({ schema: notebookPreferenceSchema }); + bindNotebookPreferences(bind); bind(NotebookOptionsService).toSelf().inSingletonScope(); });