24 行
1.0 KiB
C#
24 行
1.0 KiB
C#
namespace UndoTree;
|
|
|
|
internal static class UndoTreeArchive
|
|
{
|
|
public static IReadOnlyList<UndoTreeNodeViewModel> Restore(UndoTreeRecord record)
|
|
{
|
|
var restored = new Dictionary<int, UndoTreeNodeViewModel>();
|
|
var nodes = new List<UndoTreeNodeViewModel>();
|
|
foreach (var item in record.Nodes.OrderBy(node => node.Id))
|
|
{
|
|
restored.TryGetValue(item.Parent, out var parent);
|
|
var commands = item.Commands
|
|
.Select(command => new UndoTreeCommandInfo(Enum.TryParse<CommandKind>(command.Kind, out var kind) ? kind : CommandKind.Other, null, command.Target, command.Member, command.Detail, null))
|
|
.ToArray();
|
|
var node = new UndoTreeNodeViewModel(item.Id, null, parent, item.Label, commands, item.Time, 0) { IsArchived = true, IsOnPath = true, Tag = item.Tag ?? string.Empty, IsSaved = item.Saved };
|
|
parent?.Children.Add(node);
|
|
restored[item.Id] = node;
|
|
nodes.Add(node);
|
|
}
|
|
|
|
return nodes;
|
|
}
|
|
}
|