55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Avalonia.PropertyGrid.Models;
|
|
|
|
/// <summary>
|
|
/// Represents a category group of properties
|
|
/// </summary>
|
|
public class PropertyCategory
|
|
{
|
|
/// <summary>
|
|
/// Gets or sets the category name.
|
|
/// </summary>
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the list of properties in this category.
|
|
/// </summary>
|
|
public List<PropertyItem> Properties { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// Gets or sets whether the category is expanded in the UI.
|
|
/// </summary>
|
|
public bool IsExpanded { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the display order of the category.
|
|
/// </summary>
|
|
public int Order { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Helper for grouping properties by category
|
|
/// </summary>
|
|
public static class PropertyCategoryHelper
|
|
{
|
|
/// <summary>
|
|
/// Groups a list of properties by their category.
|
|
/// </summary>
|
|
public static List<PropertyCategory> GroupByCategory(List<PropertyItem> properties)
|
|
{
|
|
return properties.GroupBy(p => p.Category)
|
|
.Select(g => new PropertyCategory
|
|
{
|
|
Name = g.Key,
|
|
Properties = g.ToList(),
|
|
IsExpanded = true,
|
|
Order = g.Min(p => p.Order)
|
|
})
|
|
.OrderBy(c => c.Order)
|
|
.ThenBy(c => c.Name)
|
|
.ToList();
|
|
}
|
|
}
|