名前のない対象を持ち主と保持する項目の名前で呼ぶ
このコミットが含まれているのは:
7ファイル変更
+193
-14
検索条件に一致するファイルはありません
@@ -81,7 +81,7 @@ YMM4の取り消しとやり直しの履歴は1本の列で、取り消したあ
|
||||
|
||||
現在の位置は太字と青い丸、現在の位置までの経路は黒い丸、ほかは白抜きの丸で示します。やり直せるノードは少し薄く、ほかのブランチはさらに薄く表示します。右端には、ツールがノードを作った時刻を表示します。
|
||||
|
||||
ノードの名前は、変更の対象の名前と項目名を「/」でつなぎます。対象の名前はアイテムやエフェクトの名前で、ないときは型の名前です。項目名はYMM4の画面に出る名前で、取れないときはプロパティの名前です。YMM4が持つ型と項目の名前は、このプラグインが画面の言語に訳します。ほかのプラグインのアイテムやエフェクトが、自分の名前や項目の表示名を持っているときは、そのプラグインが用意した言語の名前のままです。図形、波形、模様、場面切り替え、音声、立ち絵のパラメータが名前を持たないときは、同じDLLにあるプラグインの名前に、パラメータの種類を示す語を付けた名前になります。たとえばプラグインの名前が「ローソク足」なら、「ローソク足の図形パラメータ」です。同じDLLに同じ種類のプラグインが複数あるときは、型の名前の先頭が4文字以上一致し、一致が最も長いプラグインを選びます。同じ長さで並んだときは選びません。選べないときや、これらのいずれにも当たらないときに出るのは、型やプロパティの名前そのものです。1つのノードに複数の変更があるときは、先頭の変更のあとに「(ほかN件)」を付けます。リストの追加と削除は、追加だけなら「項目をn件追加」、削除だけなら「項目をm件削除」、両方なら「項目をn件追加、m件削除」と書きます。
|
||||
ノードの名前は、変更の対象の名前と項目名を「/」でつなぎます。対象の名前はアイテムやエフェクトの名前です。名前を持たない対象は、名前を持つ持ち主の名前に、持ち主がその対象を保持している項目の名前を続けます。たとえばアイテムのXのアニメーションの値を変えると、「アイテムの名前 / X / 値」になります。持ち主が見つからないときの名前は、型の名前です。項目名はYMM4の画面に出る名前で、取れないときはプロパティの名前です。YMM4が持つ型と項目の名前は、このプラグインが画面の言語に訳します。ほかのプラグインのアイテムやエフェクトが、自分の名前や項目の表示名を持っているときは、そのプラグインが用意した言語の名前のままです。図形、波形、模様、場面切り替え、音声、立ち絵のパラメータが名前を持たないときは、同じDLLにあるプラグインの名前に、パラメータの種類を示す語を付けた名前になります。たとえばプラグインの名前が「ローソク足」なら、「ローソク足の図形パラメータ」です。同じDLLに同じ種類のプラグインが複数あるときは、型の名前の先頭が4文字以上一致し、一致が最も長いプラグインを選びます。同じ長さで並んだときは選びません。選べないときや、これらのいずれにも当たらないときに出るのは、型やプロパティの名前そのものです。1つのノードに複数の変更があるときは、先頭の変更のあとに「(ほかN件)」を付けます。リストの追加と削除は、追加だけなら「項目をn件追加」、削除だけなら「項目をm件削除」、両方なら「項目をn件追加、m件削除」と書きます。
|
||||
|
||||
履歴が変わるたびに、現在の位置のノードを選びます。この動作はメニューの「現在の位置に追従する」で切り替えられます。「現在の位置を表示」ボタンは、現在の位置を隠している折りたたまれたブランチを開いて、そのノードを選びます。「すべてのブランチを展開」と「すべてのブランチを折りたたむ」ボタンは、ブランチを一度に開閉します。
|
||||
|
||||
|
||||
@@ -69,6 +69,32 @@ public sealed class Sheet : UndoRedoable
|
||||
public string Snapshot() => $"X={X} Parts=[{string.Join(",", Parts.Select(part => part.Label))}]";
|
||||
}
|
||||
|
||||
public sealed class Slot : UndoRedoable
|
||||
{
|
||||
int level;
|
||||
|
||||
public int Level
|
||||
{
|
||||
get => level;
|
||||
set => Set(ref level, value);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Panel : UndoRedoable
|
||||
{
|
||||
public Panel()
|
||||
{
|
||||
SubscribeChildUndoRedoable(Gain);
|
||||
SubscribeObservableCollectionChangedAndChild(Slots);
|
||||
}
|
||||
|
||||
public string Label => "panel";
|
||||
|
||||
public Slot Gain { get; } = new();
|
||||
|
||||
public ObservableCollection<Slot> Slots { get; } = [];
|
||||
}
|
||||
|
||||
public sealed class Rig : UndoRedoable
|
||||
{
|
||||
public Part Knob { get; } = new("knob");
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
using YukkuriMovieMaker.Project;
|
||||
using YukkuriMovieMaker.UndoRedo;
|
||||
|
||||
namespace UndoTree.Tests;
|
||||
|
||||
public sealed class UndoTreeTargetNamesTests
|
||||
{
|
||||
static UndoTreeHistory Track(UndoRedoManager manager, IUndoRedoable root)
|
||||
=> new(manager, new AsyncAwaitStatus(), [root], 100, UndoRedoManagerReader.Create(manager));
|
||||
|
||||
[Fact]
|
||||
public void AnObjectWithItsOwnLabelKeepsIt()
|
||||
{
|
||||
var panel = new Panel();
|
||||
|
||||
var name = UndoTreeTargetNames.Of(panel, new UndoTreeOwners([panel]));
|
||||
|
||||
Assert.Null(name.Owner);
|
||||
Assert.Equal("panel", name.Own);
|
||||
Assert.Equal("panel", name.Full);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnObjectWithoutALabelIsNamedByTheLabeledOwnerAndThePropertyThatHoldsIt()
|
||||
{
|
||||
var panel = new Panel();
|
||||
|
||||
var name = UndoTreeTargetNames.Of(panel.Gain, new UndoTreeOwners([panel]));
|
||||
|
||||
Assert.Equal("panel", name.Owner);
|
||||
Assert.Equal("Gain", name.Own);
|
||||
Assert.Equal("panel / Gain", name.Full);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnElementOfAListIsNamedByTheOwnerAndItsTypeBecauseThePositionIsNoName()
|
||||
{
|
||||
var panel = new Panel();
|
||||
var slot = new Slot();
|
||||
panel.Slots.Add(slot);
|
||||
|
||||
var name = UndoTreeTargetNames.Of(slot, new UndoTreeOwners([panel]));
|
||||
|
||||
Assert.Equal("panel / Slot", name.Full);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AListItselfIsNamedByTheOwnerAndTheProperty()
|
||||
{
|
||||
var panel = new Panel();
|
||||
|
||||
var name = UndoTreeTargetNames.Of(panel.Slots, new UndoTreeOwners([panel]));
|
||||
|
||||
Assert.Equal("panel / Slots", name.Full);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnObjectOutsideTheOwnersOrWithoutOwnersKeepsItsTypeName()
|
||||
{
|
||||
var panel = new Panel();
|
||||
var outsider = new Slot();
|
||||
|
||||
Assert.Equal(new UndoTreeTargetName(null, "Slot"), UndoTreeTargetNames.Of(outsider, new UndoTreeOwners([panel])));
|
||||
Assert.Equal(new UndoTreeTargetName(null, "Slot"), UndoTreeTargetNames.Of(panel.Gain, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ANodeIsNamedWithTheOwnerAndThePropertyOfWhatChanged()
|
||||
{
|
||||
var panel = new Panel();
|
||||
var manager = new UndoRedoManager();
|
||||
manager.Subscribe(panel);
|
||||
using var history = Track(manager, panel);
|
||||
|
||||
Histories.Edit(manager, () => panel.Gain.Level = 5);
|
||||
var value = history.Cursor;
|
||||
Histories.Edit(manager, () => panel.Slots.Add(new Slot()));
|
||||
var list = history.Cursor;
|
||||
|
||||
Assert.Equal("panel / Gain / Level", value.Label);
|
||||
Assert.Equal("panel / Gain", value.Commands[0].TargetLabel);
|
||||
Assert.Equal("panel / Slots / " + string.Format(Texts.ListAdded, 1), list.Label);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ObjectsOfTheOwnersAreLinkedWithTheirPropertyAndWhetherTheyAreElements()
|
||||
{
|
||||
var panel = new Panel();
|
||||
var slot = new Slot();
|
||||
panel.Slots.Add(slot);
|
||||
|
||||
var owners = new UndoTreeOwners([panel]);
|
||||
|
||||
Assert.Equal("Gain", owners.LinkOf(panel.Gain)!.Value.Property.Name);
|
||||
Assert.False(owners.LinkOf(panel.Gain)!.Value.IsElement);
|
||||
Assert.Equal("Slots", owners.LinkOf(slot)!.Value.Property.Name);
|
||||
Assert.True(owners.LinkOf(slot)!.Value.IsElement);
|
||||
Assert.Same(panel, owners.LinkOf(panel.Slots)!.Value.Owner);
|
||||
Assert.Null(owners.LinkOf(panel));
|
||||
}
|
||||
}
|
||||
@@ -244,7 +244,7 @@ internal class UndoTreeHistory : IDisposable
|
||||
foreach (var command in commands.Where(command => !command.IsAction))
|
||||
{
|
||||
var view = UndoRedoCommandView.Read(command);
|
||||
var info = view.Describe();
|
||||
var info = InContext(view.Describe());
|
||||
var verdict = Judge(view, touched, inverse);
|
||||
if (verdict is Verdict.DeadTarget)
|
||||
conflicts.Add(new UndoTreeConflict(ConflictKind.DeadTarget, info.TargetLabel, info.Member, false));
|
||||
@@ -428,6 +428,20 @@ internal class UndoTreeHistory : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
UndoTreeCommandInfo InContext(UndoTreeCommandInfo info)
|
||||
{
|
||||
if (info.Target is not { } target)
|
||||
return info;
|
||||
|
||||
var name = UndoTreeTargetNames.Of(target, Owners);
|
||||
return info.Kind switch
|
||||
{
|
||||
CommandKind.Property or CommandKind.Indexer => info with { TargetLabel = name.Full },
|
||||
CommandKind.ListItems when name.Owner is not null => info with { TargetLabel = name.Full },
|
||||
_ => info,
|
||||
};
|
||||
}
|
||||
|
||||
static string LabelOf(IReadOnlyList<UndoTreeCommandInfo> commands)
|
||||
{
|
||||
if (commands.Count == 0)
|
||||
@@ -581,7 +595,7 @@ internal class UndoTreeHistory : IDisposable
|
||||
string label;
|
||||
try
|
||||
{
|
||||
commands = source!.CommandsOf(handle).Select(command => UndoRedoCommandView.Read(command).Describe()).ToArray();
|
||||
commands = source!.CommandsOf(handle).Select(command => InContext(UndoRedoCommandView.Read(command).Describe())).ToArray();
|
||||
label = LabelOf(commands);
|
||||
}
|
||||
catch (Exception exception) when (exception is not OperationCanceledException)
|
||||
@@ -775,7 +789,7 @@ internal class UndoTreeHistory : IDisposable
|
||||
}
|
||||
|
||||
var view = UndoRedoCommandView.Read(command);
|
||||
var info = view.Describe();
|
||||
var info = InContext(view.Describe());
|
||||
var verdict = Judge(view, touched, inverse);
|
||||
var apply = policy == ConflictPolicy.Apply;
|
||||
switch (verdict)
|
||||
|
||||
@@ -6,13 +6,15 @@ using YukkuriMovieMaker.UndoRedo;
|
||||
|
||||
namespace UndoTree;
|
||||
|
||||
internal readonly record struct UndoTreeOwnerLink(object Owner, PropertyInfo Property, bool IsElement);
|
||||
|
||||
internal class UndoTreeOwners
|
||||
{
|
||||
const int MaxDepth = 32;
|
||||
|
||||
static readonly ConcurrentDictionary<Type, PropertyInfo[]> Properties = new();
|
||||
|
||||
readonly Dictionary<object, object> parents = new(ReferenceEqualityComparer.Instance);
|
||||
readonly Dictionary<object, UndoTreeOwnerLink> parents = new(ReferenceEqualityComparer.Instance);
|
||||
|
||||
public UndoTreeOwners(IEnumerable<object> roots)
|
||||
{
|
||||
@@ -32,11 +34,13 @@ internal class UndoTreeOwners
|
||||
}
|
||||
}
|
||||
|
||||
public UndoTreeOwnerLink? LinkOf(object target) => parents.TryGetValue(target, out var link) ? link : null;
|
||||
|
||||
public IReadOnlyList<object> OwnersOf(object target)
|
||||
{
|
||||
var owners = new List<object>();
|
||||
for (var current = target; parents.TryGetValue(current, out var parent); current = parent)
|
||||
owners.Add(parent);
|
||||
for (var current = target; parents.TryGetValue(current, out var link); current = link.Owner)
|
||||
owners.Add(link.Owner);
|
||||
|
||||
owners.Reverse();
|
||||
return owners;
|
||||
@@ -58,24 +62,27 @@ internal class UndoTreeOwners
|
||||
|
||||
if (value is IUndoRedoable child)
|
||||
{
|
||||
Link(child, owner, childDepth, rootSet, pending);
|
||||
Link(child, new UndoTreeOwnerLink(owner, property, false), childDepth, rootSet, pending);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value is not IEnumerable items || value is string)
|
||||
continue;
|
||||
|
||||
if (value is INotifyCollectionChanged)
|
||||
parents.TryAdd(value, new UndoTreeOwnerLink(owner, property, false));
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item is IUndoRedoable member)
|
||||
Link(member, owner, childDepth, rootSet, pending);
|
||||
Link(member, new UndoTreeOwnerLink(owner, property, true), childDepth, rootSet, pending);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Link(object child, object owner, int childDepth, HashSet<object> rootSet, Queue<(object Owner, int Depth)> pending)
|
||||
void Link(object child, UndoTreeOwnerLink link, int childDepth, HashSet<object> rootSet, Queue<(object Owner, int Depth)> pending)
|
||||
{
|
||||
if (rootSet.Contains(child) || !parents.TryAdd(child, owner))
|
||||
if (rootSet.Contains(child) || !parents.TryAdd(child, link))
|
||||
return;
|
||||
|
||||
pending.Enqueue((child, childDepth));
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
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);
|
||||
}
|
||||
@@ -830,7 +830,7 @@ internal class UndoTreeViewModel : Bindable, IToolViewModel, ITimelineToolViewMo
|
||||
}
|
||||
|
||||
var owners = history.Owners;
|
||||
var group = new DetailGroup(null, string.Empty);
|
||||
var group = new DetailGroup(null, string.Empty, owner => UndoTreeTargetNames.Of(owner, owners).Own);
|
||||
foreach (var command in commands)
|
||||
{
|
||||
var current = group;
|
||||
@@ -860,7 +860,7 @@ internal class UndoTreeViewModel : Bindable, IToolViewModel, ITimelineToolViewMo
|
||||
|
||||
internal sealed record TimelineLink(Func<object, bool> Contains, Action<IReadOnlyList<object>> Select);
|
||||
|
||||
sealed class DetailGroup(object? key, string text)
|
||||
sealed class DetailGroup(object? key, string text, Func<object, string> nameOf)
|
||||
{
|
||||
public object? Key { get; } = key;
|
||||
|
||||
@@ -876,7 +876,7 @@ internal class UndoTreeViewModel : Bindable, IToolViewModel, ITimelineToolViewMo
|
||||
if (existing is not null)
|
||||
return existing;
|
||||
|
||||
var created = new DetailGroup(owner, UndoRedoCommandView.LabelOf(owner));
|
||||
var created = new DetailGroup(owner, nameOf(owner), nameOf);
|
||||
Children.Add(created);
|
||||
return created;
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする