32 行
1.1 KiB
C#
32 行
1.1 KiB
C#
namespace UndoTree;
|
|
|
|
internal static class UndoTreeTargetNames
|
|
{
|
|
public static UndoTreeTargetName Of(object target, UndoTreeOwners? owners)
|
|
{
|
|
if (UndoRedoCommandView.TryGetLabel(target, out var label))
|
|
return new UndoTreeTargetName(null, label);
|
|
|
|
var fallback = UndoTreeNames.OfType(target.GetType());
|
|
var names = new List<string>();
|
|
for (var current = target; owners?.LinkOf(current) is { } link; current = link.Owner)
|
|
{
|
|
if (!link.IsElement)
|
|
names.Add(UndoRedoCommandView.MemberLabel(link.Owner, link.Property.Name));
|
|
|
|
if (UndoRedoCommandView.TryGetLabel(link.Owner, out var ownerLabel))
|
|
{
|
|
names.Reverse();
|
|
return new UndoTreeTargetName(ownerLabel, names.Count == 0 ? fallback : string.Join(" / ", names));
|
|
}
|
|
}
|
|
|
|
return new UndoTreeTargetName(null, fallback);
|
|
}
|
|
}
|
|
|
|
internal readonly record struct UndoTreeTargetName(string? Owner, string Own)
|
|
{
|
|
public string Full => Owner is null ? Own : UndoTreeText.Join(Owner, Own);
|
|
}
|