|
| 1 | +// ***************************************************************************** |
| 2 | +// Copyright (C) 2025 EclipseSource 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 | +} |
0 commit comments