Files
LanMountainDesktop/airapp/LanMountainDesktop.AirAppSdk/AirAppSettingsSectionRegistration.cs

59 lines
1.9 KiB
C#
Raw Normal View History

2026-04-13 01:23:11 +08:00
using System;
2026-03-13 00:33:00 +08:00
using System.Collections.Generic;
2026-08-11 23:03:55 +08:00
namespace LanMountainDesktop.AirAppSdk;
2026-03-13 00:33:00 +08:00
2026-08-11 23:03:55 +08:00
public sealed class AirAppSettingsSectionRegistration
2026-03-13 00:33:00 +08:00
{
2026-08-11 23:03:55 +08:00
public AirAppSettingsSectionRegistration(
2026-03-13 00:33:00 +08:00
string id,
string titleLocalizationKey,
2026-08-11 23:03:55 +08:00
IReadOnlyList<AirAppSettingOptionDefinition> options,
2026-03-13 00:33:00 +08:00
string? descriptionLocalizationKey = null,
string iconKey = "PuzzlePiece",
2026-04-13 01:23:11 +08:00
int sortOrder = 0,
Type? customViewType = null)
2026-03-13 00:33:00 +08:00
{
ArgumentException.ThrowIfNullOrWhiteSpace(id);
ArgumentException.ThrowIfNullOrWhiteSpace(titleLocalizationKey);
ArgumentException.ThrowIfNullOrWhiteSpace(iconKey);
Id = id.Trim();
TitleLocalizationKey = titleLocalizationKey.Trim();
DescriptionLocalizationKey = string.IsNullOrWhiteSpace(descriptionLocalizationKey)
? null
: descriptionLocalizationKey.Trim();
IconKey = iconKey.Trim();
SortOrder = sortOrder;
Options = options ?? [];
2026-04-13 01:23:11 +08:00
2026-08-11 23:03:55 +08:00
if (customViewType is not null && !typeof(AirAppSettingsPageBase).IsAssignableFrom(customViewType))
2026-04-13 01:23:11 +08:00
{
throw new ArgumentException(
2026-08-11 23:03:55 +08:00
$"Custom view type must be a subclass of {nameof(AirAppSettingsPageBase)}.",
2026-04-13 01:23:11 +08:00
nameof(customViewType));
}
CustomViewType = customViewType;
2026-03-13 00:33:00 +08:00
}
public string Id { get; }
public string TitleLocalizationKey { get; }
public string? DescriptionLocalizationKey { get; }
public string IconKey { get; }
public int SortOrder { get; }
2026-08-11 23:03:55 +08:00
public IReadOnlyList<AirAppSettingOptionDefinition> Options { get; }
2026-04-13 01:23:11 +08:00
/// <summary>
2026-08-11 23:03:55 +08:00
/// When set, the host application will instantiate this <see cref="AirAppSettingsPageBase"/> subclass
2026-04-13 01:23:11 +08:00
/// instead of generating a page from <see cref="Options"/>.
/// This allows plugins to provide fully custom AXAML views with any Fluent Avalonia controls.
/// </summary>
public Type? CustomViewType { get; }
2026-03-13 00:33:00 +08:00
}