Skip to content

Commit 9e34269

Browse files
Null renderer with no interactable
1 parent 1ff9e09 commit 9e34269

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// *****************************************************************************
2+
// Copyright (C) 2025 Eclipse GmbH and others.
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License v. 2.0 which is available at
6+
// http://www.eclipse.org/legal/epl-2.0.
7+
//
8+
// This Source Code may also be made available under the following Secondary
9+
// Licenses when the conditions for such availability set forth in the Eclipse
10+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
11+
// with the GNU Classpath Exception which is available at
12+
// https://www.gnu.org/software/classpath/license.html.
13+
//
14+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15+
// *****************************************************************************
16+
17+
import { injectable, interfaces } from '@theia/core/shared/inversify';
18+
import { PreferenceLeafNodeRenderer, PreferenceNodeRenderer } from './preference-node-renderer';
19+
import { Preference } from '../../util/preference-types';
20+
import { PreferenceLeafNodeRendererContribution } from './preference-node-renderer-creator';
21+
22+
@injectable()
23+
/** For rendering preference items for which the only interesting feature is the description */
24+
export class PreferenceNullInputRenderer extends PreferenceLeafNodeRenderer<null, HTMLElement> {
25+
protected override createInteractable(container: HTMLElement): void {
26+
const span = document.createElement('span');
27+
this.interactable = span;
28+
container.appendChild(span);
29+
}
30+
31+
protected override getFallbackValue(): null {
32+
// eslint-disable-next-line no-null/no-null
33+
return null;
34+
}
35+
36+
protected override doHandleValueChange(): void { }
37+
}
38+
39+
@injectable()
40+
export class PreferenceNullRendererContribution extends PreferenceLeafNodeRendererContribution {
41+
static ID = 'preference-null-renderer';
42+
id = PreferenceNullRendererContribution.ID;
43+
44+
canHandleLeafNode(node: Preference.LeafNode): number {
45+
const isOnlyNull = node.preference.data.type === 'null' || Array.isArray(node.preference.data.type) && node.preference.data.type.every(candidate => candidate === 'null');
46+
return isOnlyNull ? 5 : 0;
47+
}
48+
49+
createLeafNodeRenderer(container: interfaces.Container): PreferenceNodeRenderer {
50+
return container.get(PreferenceNullInputRenderer);
51+
}
52+
}

packages/preferences/src/browser/views/preference-widget-bindings.ts

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { PreferencesScopeTabBar } from './preference-scope-tabbar-widget';
3636
import { PreferencesSearchbarWidget } from './preference-searchbar-widget';
3737
import { PreferencesTreeWidget } from './preference-tree-widget';
3838
import { PreferencesWidget } from './preference-widget';
39+
import { PreferenceNullInputRenderer, PreferenceNullRendererContribution } from './components/preference-null-input';
3940

4041
export function bindPreferencesWidgets(bind: interfaces.Bind): void {
4142
bind(PreferenceTreeLabelProvider).toSelf().inSingletonScope();
@@ -58,6 +59,8 @@ export function bindPreferencesWidgets(bind: interfaces.Bind): void {
5859

5960
bind(PreferenceStringInputRenderer).toSelf();
6061
bind(PreferenceNodeRendererContribution).to(PreferenceStringInputRendererContribution).inSingletonScope();
62+
bind(PreferenceNullInputRenderer).toSelf();
63+
bind(PreferenceNodeRendererContribution).to(PreferenceNullRendererContribution).inSingletonScope();
6164

6265
bind(PreferenceBooleanInputRenderer).toSelf();
6366
bind(PreferenceNodeRendererContribution).to(PreferenceBooleanInputRendererContribution).inSingletonScope();

0 commit comments

Comments
 (0)