115 行
3.4 KiB
C#
115 行
3.4 KiB
C#
using System.Windows;
|
|
using YukkuriMovieMaker.Commons;
|
|
|
|
namespace UndoTree;
|
|
|
|
internal class UndoTreeNodeViewModel : Bindable
|
|
{
|
|
internal UndoTreeNodeViewModel(int id, object? handle, UndoTreeNodeViewModel? parent, string label, IReadOnlyList<UndoTreeCommandInfo> commands, DateTime time, long visit)
|
|
{
|
|
Id = id;
|
|
Handle = handle;
|
|
Parent = parent;
|
|
Label = label;
|
|
Commands = commands;
|
|
Time = time;
|
|
Visit = visit;
|
|
Keys = commands.Select(command => command.Key).OfType<UndoTreeChangeKey>().Distinct().ToArray();
|
|
}
|
|
|
|
public int Id { get; }
|
|
|
|
public object? Handle { get; internal set; }
|
|
|
|
public UndoTreeNodeViewModel? Parent { get; internal set; }
|
|
|
|
public List<UndoTreeNodeViewModel> Children { get; } = [];
|
|
|
|
public UndoTreeNodeViewModel? LastVisited { get; internal set; }
|
|
|
|
public IReadOnlyList<UndoTreeCommandInfo> Commands { get; }
|
|
|
|
public IReadOnlyList<UndoTreeChangeKey> Keys { get; }
|
|
|
|
public string Label { get; }
|
|
|
|
public DateTime Time { get; }
|
|
|
|
public long Visit { get; internal set; }
|
|
|
|
public bool IsRoot => Parent is null;
|
|
|
|
public bool IsArchived { get; init; }
|
|
|
|
public int Depth
|
|
{
|
|
get
|
|
{
|
|
var depth = 0;
|
|
for (var node = Parent; node is not null; node = node.Parent)
|
|
depth++;
|
|
|
|
return depth;
|
|
}
|
|
}
|
|
|
|
public UndoTreeNodeViewModel? Primary
|
|
=> LastVisited is { } visited && Children.Contains(visited) ? visited : Children.Count > 0 ? Children[^1] : null;
|
|
|
|
public IEnumerable<UndoTreeNodeViewModel> SideBranches
|
|
{
|
|
get
|
|
{
|
|
var primary = Primary;
|
|
return Children.Where(child => !ReferenceEquals(child, primary));
|
|
}
|
|
}
|
|
|
|
public string Text => IsRoot ? Texts.InitialState : Label;
|
|
|
|
public string DisplayText => IsRunHidden ? string.Format(Texts.FoldedRun, Text, FoldedCount + 1) : Text;
|
|
|
|
public int FoldedCount { get; set => Set(ref field, value, nameof(FoldedCount), nameof(DisplayText)); }
|
|
|
|
public bool IsRunHidden { get; set => Set(ref field, value, nameof(IsRunHidden), nameof(DisplayText)); }
|
|
|
|
public string TimeText => Time == DateTime.MinValue ? string.Empty : Time.ToString("T");
|
|
|
|
public int Level { get; set => Set(ref field, value, nameof(Level), nameof(Margin)); }
|
|
|
|
public Thickness Margin => new(Level * 16, 0, 0, 0);
|
|
|
|
public bool IsExpanded
|
|
{
|
|
get;
|
|
set
|
|
{
|
|
if (!Set(ref field, value))
|
|
return;
|
|
|
|
if (value)
|
|
ExpandRequested?.Invoke(this, EventArgs.Empty);
|
|
else
|
|
CollapseRequested?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
|
|
public bool HasSideBranches { get; set => Set(ref field, value); }
|
|
|
|
public bool CanExpand { get; set => Set(ref field, value); }
|
|
|
|
public bool IsSelected { get; set => Set(ref field, value); }
|
|
|
|
public bool IsCurrent { get; set => Set(ref field, value, nameof(IsCurrent), nameof(Opacity)); }
|
|
|
|
public bool IsOnPath { get; set => Set(ref field, value, nameof(IsOnPath), nameof(Opacity)); }
|
|
|
|
public bool IsRedoable { get; set => Set(ref field, value, nameof(IsRedoable), nameof(Opacity)); }
|
|
|
|
public double Opacity => IsCurrent || IsOnPath ? 1 : IsRedoable ? 0.75 : 0.55;
|
|
|
|
public event EventHandler? ExpandRequested;
|
|
|
|
public event EventHandler? CollapseRequested;
|
|
}
|