任意の2つの操作を比べられるようにする

このコミットが含まれているのは:
routersys committed 2026-11-01 08:28:23 +09:00
1 親 0ba394be93
コミット f02ac798d1
6ファイル変更
+187 -7

検索条件に一致するファイルはありません

+128
ファイルの表示
@@ -0,0 +1,128 @@
using YukkuriMovieMaker.Plugin;
using YukkuriMovieMaker.Project;
using YukkuriMovieMaker.UndoRedo;
namespace UndoTree.Tests;
[Collection("Settings")]
public sealed class UndoTreeCompareTests
{
static UndoTreeHistory Track(UndoRedoManager manager, IUndoRedoable root)
=> new(manager, new AsyncAwaitStatus(), [root], 100, UndoRedoManagerReader.Create(manager));
static string[] Lines(IEnumerable<UndoTreeCommandInfo> infos)
=> infos.Select(info => info.Detail.Length > 0 ? $"{info.Text}: {info.Detail}" : info.Text).Order().ToArray();
static (UndoTreeViewModel Model, UndoRedoManager Manager, Document Document) Open()
{
var (manager, document) = Histories.NewDocument("p1");
var model = new UndoTreeViewModel();
model.SetTimelineToolInfo(new TimelineToolInfo(null!, new Scenes(true), manager, new AsyncAwaitStatus()));
return (model, manager, document);
}
[Fact]
public void TwoChosenNodesAreComparedInEitherDirectionWhereverTheCurrentPositionIs()
{
var (manager, document) = Histories.NewDocument("p1");
using var history = Track(manager, document);
Histories.Edit(manager, () => document.X = 1);
var a = history.Cursor;
Histories.Edit(manager, () => document.Y = 5);
var b = history.Cursor;
Assert.Equal(["Document / X: 0 → 1", "Document / Y: 0 → 5"], Lines(history.Diff(history.Root, b)));
Assert.Equal(["Document / Y: 0 → 5"], Lines(history.Diff(a, b)));
Assert.Equal(["Document / Y: 5 → 0"], Lines(history.Diff(b, a)));
Assert.Empty(history.Diff(a, a));
Assert.Equal(Lines(history.Diff(b, a)), Lines(history.DiffFromCurrent(a)));
}
[Fact]
public async Task TwoNodesOnDifferentBranchesAreComparedThroughTheirCommonAncestor()
{
var (manager, document) = Histories.NewDocument("p1");
using var history = Track(manager, document);
Histories.Edit(manager, () => document.X = 1);
var a = history.Cursor;
Histories.Edit(manager, () => document.X = 2);
var b = history.Cursor;
await history.JumpAsync(a);
Histories.Edit(manager, () => document.X = 3);
var c = history.Cursor;
Assert.Equal(["Document / X: 2 → 3"], Lines(history.Diff(b, c)));
Assert.Equal(["Document / X: 3 → 2"], Lines(history.Diff(c, b)));
}
[Fact]
public void ABaseTurnsTheDetailsIntoADifferenceFromThatNodeAndMarksItsRow()
{
var (model, manager, document) = Open();
Histories.Edit(manager, () => document.X = 1);
Histories.Edit(manager, () => document.Y = 5);
var a = model.Items[1];
var b = model.Items[2];
model.SetCompareBaseCommand.Execute(a);
b.IsSelected = true;
Assert.True(model.IsDiffMode);
Assert.Same(a, model.CompareBase);
Assert.Equal($"[{Texts.BaseMark}] Document / X", a.DisplayText);
Assert.Equal(Texts.DiffHeaderFrom, model.Details[0].Text);
Assert.Equal(["Document", "Y: 0 → 5"], model.Details.Skip(1).Select(row => row.Display));
a.IsSelected = true;
Assert.Equal([Texts.DiffHeaderFrom, Texts.DiffEmptyFrom], model.Details.Select(row => row.Text));
}
[Fact]
public void ClearingTheBaseGoesBackToComparingWithTheCurrentPosition()
{
var (model, manager, document) = Open();
Histories.Edit(manager, () => document.X = 1);
Histories.Edit(manager, () => document.Y = 5);
var a = model.Items[1];
model.SetCompareBaseCommand.Execute(a);
model.Items[2].IsSelected = true;
Assert.True(model.ClearCompareBaseCommand.CanExecute(null));
model.ClearCompareBaseCommand.Execute(null);
Assert.Null(model.CompareBase);
Assert.False(a.IsCompareBase);
Assert.Equal(Texts.DiffHeader, model.Details[0].Text);
Assert.False(model.ClearCompareBaseCommand.CanExecute(null));
}
[Fact]
public async Task ABaseOnABranchThatIsDroppedIsForgotten()
{
var (model, manager, document) = Open();
Histories.Edit(manager, () => document.X = 1);
var a = model.Items[^1];
Histories.Edit(manager, () => document.Parts[0].Value = 5);
var b = model.Items[^1];
await manager.UndoAsync();
Histories.Edit(manager, () => document.Y = 7);
a.IsExpanded = true;
model.SetCompareBaseCommand.Execute(b);
model.DropBranchesCommand.Execute(null);
Assert.Null(model.CompareBase);
}
[Fact]
public void APreviousNodeCannotBeABase()
{
var (model, manager, document) = Open();
Histories.Edit(manager, () => document.X = 1);
model.SetRecord(new UndoTreeRecord(DateTime.Now, [new UndoTreeRecordNode(0, -1, string.Empty, DateTime.MinValue, []), new UndoTreeRecordNode(1, 0, "old", DateTime.Now, [])]));
model.IsShowingRecord = true;
Assert.False(model.SetCompareBaseCommand.CanExecute(model.Items[1]));
}
}
+6
ファイルの表示
@@ -68,6 +68,12 @@ TagNode,,タグを付ける,Add a tag,添加标签,新增標籤,태그 달기,A
ClearTag,,タグを外す,Remove the tag,移除标签,移除標籤,태그 제거,Quitar la etiqueta,إزالة الوسم,Hapus tag
SavedMark,,保存,Saved,已保存,已儲存,저장됨,Guardado,محفوظ,Tersimpan
LinkTimeline,,選んだ操作のアイテムをタイムラインで選択,Select the items of the chosen operation in the timeline,在时间轴中选择所选操作的项目,在時間軸中選取所選操作的項目,선택한 작업의 항목을 타임라인에서 선택,Seleccionar en la línea de tiempo los elementos de la operación elegida,تحديد عناصر العملية المختارة في الجدول الزمني,Pilih item dari operasi yang dipilih di lini masa
SetCompareBase,,比較の基準にする,Use as the base of a comparison,设为比较的基准,設為比較的基準,비교의 기준으로 삼기,Usar como base de comparación,استخدام كأساس للمقارنة,Jadikan dasar perbandingan
SetCompareBaseTip,,このあとに選ぶ操作との差を、詳細に表示します。,Shows the difference from the operations you choose next in the details.,在详细信息中显示与之后所选操作的差异。,在詳細資訊中顯示與之後所選操作的差異。,이후에 선택하는 작업과의 차이를 세부 정보에 표시합니다.,Muestra en los detalles la diferencia con las operaciones que elija a continuación.,يعرض في التفاصيل الفرق عن العمليات التي تختارها لاحقًا.,Menampilkan selisih dengan operasi yang Anda pilih berikutnya pada detail.
ClearCompareBase,,比較の基準を解除,Clear the base of the comparison,取消比较的基准,取消比較的基準,비교 기준 해제,Quitar la base de comparación,إلغاء أساس المقارنة,Hapus dasar perbandingan
DiffHeaderFrom,,基準の操作からの変更点,Changes from the base operation,与基准操作的差异,與基準操作的差異,기준 작업에서의 변경점,Cambios respecto a la operación base,التغييرات عن العملية الأساسية,Perubahan dari operasi dasar
DiffEmptyFrom,,基準との差はありません,There is no difference from the base,与基准没有差异,與基準沒有差異,기준과 차이가 없습니다,No hay diferencias con la base,لا يوجد فرق عن الأساس,Tidak ada selisih dari dasar
BaseMark,,基準,Base,基准,基準,기준,Base,أساس,Dasar
ConflictDeadTarget,,{0} / {1}: 対象が存在しないためスキップしました,{0} / {1}: skipped because the target no longer exists,{0} / {1}:对象已不存在,已跳过,{0} / {1}:物件已不存在,已略過,{0} / {1}: 대상이 없어 건너뛰었습니다,{0} / {1}: omitido porque el objetivo ya no existe,{0} / {1}: تم التخطي لأن الهدف لم يعد موجودًا,{0} / {1}: dilewati karena target sudah tidak ada
ConflictSameSkipped,,{0} / {1}: 現在の位置で既に変更されているためスキップしました,{0} / {1}: skipped because it was already changed here,{0} / {1}:已在当前位置更改,已跳过,{0} / {1}:已在目前位置變更,已略過,{0} / {1}: 현재 위치에서 이미 변경되어 건너뛰었습니다,{0} / {1}: omitido porque ya se modificó aquí,{0} / {1}: تم التخطي لأنه تغيّر هنا بالفعل,{0} / {1}: dilewati karena sudah diubah di sini
ConflictSameApplied,,{0} / {1}: 現在の位置で既に変更されていたため、操作の値で上書きしました,"{0} / {1}: already changed here, overwritten with the value of the operation",{0} / {1}:已在当前位置更改,已用该操作的值覆盖,{0} / {1}:已在目前位置變更,已用該操作的值覆蓋,{0} / {1}: 현재 위치에서 이미 변경되어 작업의 값으로 덮어썼습니다,"{0} / {1}: ya se modificó aquí, sobrescrito con el valor de la operación",{0} / {1}: تغيّر هنا بالفعل وتمت الكتابة فوقه بقيمة العملية,"{0} / {1}: sudah diubah di sini, ditimpa dengan nilai operasi"
1 Key Parameter ja-jp en-us zh-cn zh-tw ko-kr es-es ar-sa id-id
68 ClearTag タグを外す Remove the tag 移除标签 移除標籤 태그 제거 Quitar la etiqueta إزالة الوسم Hapus tag
69 SavedMark 保存 Saved 已保存 已儲存 저장됨 Guardado محفوظ Tersimpan
70 LinkTimeline 選んだ操作のアイテムをタイムラインで選択 Select the items of the chosen operation in the timeline 在时间轴中选择所选操作的项目 在時間軸中選取所選操作的項目 선택한 작업의 항목을 타임라인에서 선택 Seleccionar en la línea de tiempo los elementos de la operación elegida تحديد عناصر العملية المختارة في الجدول الزمني Pilih item dari operasi yang dipilih di lini masa
71 SetCompareBase 比較の基準にする Use as the base of a comparison 设为比较的基准 設為比較的基準 비교의 기준으로 삼기 Usar como base de comparación استخدام كأساس للمقارنة Jadikan dasar perbandingan
72 SetCompareBaseTip このあとに選ぶ操作との差を、詳細に表示します。 Shows the difference from the operations you choose next in the details. 在详细信息中显示与之后所选操作的差异。 在詳細資訊中顯示與之後所選操作的差異。 이후에 선택하는 작업과의 차이를 세부 정보에 표시합니다. Muestra en los detalles la diferencia con las operaciones que elija a continuación. يعرض في التفاصيل الفرق عن العمليات التي تختارها لاحقًا. Menampilkan selisih dengan operasi yang Anda pilih berikutnya pada detail.
73 ClearCompareBase 比較の基準を解除 Clear the base of the comparison 取消比较的基准 取消比較的基準 비교 기준 해제 Quitar la base de comparación إلغاء أساس المقارنة Hapus dasar perbandingan
74 DiffHeaderFrom 基準の操作からの変更点 Changes from the base operation 与基准操作的差异 與基準操作的差異 기준 작업에서의 변경점 Cambios respecto a la operación base التغييرات عن العملية الأساسية Perubahan dari operasi dasar
75 DiffEmptyFrom 基準との差はありません There is no difference from the base 与基准没有差异 與基準沒有差異 기준과 차이가 없습니다 No hay diferencias con la base لا يوجد فرق عن الأساس Tidak ada selisih dari dasar
76 BaseMark 基準 Base 基准 基準 기준 Base أساس Dasar
77 ConflictDeadTarget {0} / {1}: 対象が存在しないためスキップしました {0} / {1}: skipped because the target no longer exists {0} / {1}:对象已不存在,已跳过 {0} / {1}:物件已不存在,已略過 {0} / {1}: 대상이 없어 건너뛰었습니다 {0} / {1}: omitido porque el objetivo ya no existe {0} / {1}: تم التخطي لأن الهدف لم يعد موجودًا {0} / {1}: dilewati karena target sudah tidak ada
78 ConflictSameSkipped {0} / {1}: 現在の位置で既に変更されているためスキップしました {0} / {1}: skipped because it was already changed here {0} / {1}:已在当前位置更改,已跳过 {0} / {1}:已在目前位置變更,已略過 {0} / {1}: 현재 위치에서 이미 변경되어 건너뛰었습니다 {0} / {1}: omitido porque ya se modificó aquí {0} / {1}: تم التخطي لأنه تغيّر هنا بالفعل {0} / {1}: dilewati karena sudah diubah di sini
79 ConflictSameApplied {0} / {1}: 現在の位置で既に変更されていたため、操作の値で上書きしました {0} / {1}: already changed here, overwritten with the value of the operation {0} / {1}:已在当前位置更改,已用该操作的值覆盖 {0} / {1}:已在目前位置變更,已用該操作的值覆蓋 {0} / {1}: 현재 위치에서 이미 변경되어 작업의 값으로 덮어썼습니다 {0} / {1}: ya se modificó aquí, sobrescrito con el valor de la operación {0} / {1}: تغيّر هنا بالفعل وتمت الكتابة فوقه بقيمة العملية {0} / {1}: sudah diubah di sini, ditimpa dengan nilai operasi
+5 -3
ファイルの表示
@@ -349,13 +349,15 @@ internal class UndoTreeHistory : IDisposable
return new UndoTreeRecord(DateTime.Now, nodes.ToArray());
}
public IReadOnlyList<UndoTreeCommandInfo> DiffFromCurrent(UndoTreeNodeViewModel node)
public IReadOnlyList<UndoTreeCommandInfo> DiffFromCurrent(UndoTreeNodeViewModel node) => Diff(Cursor, node);
public IReadOnlyList<UndoTreeCommandInfo> Diff(UndoTreeNodeViewModel from, UndoTreeNodeViewModel to)
{
if (source is null)
return [];
var ancestor = CommonAncestor(Cursor, node);
return UndoTreeDiff.Between(source, PathFromRoot(Cursor).Skip(ancestor.Depth + 1).ToArray(), PathFromRoot(node).Skip(ancestor.Depth + 1).ToArray());
var ancestor = CommonAncestor(from, to);
return UndoTreeDiff.Between(source, PathFromRoot(from).Skip(ancestor.Depth + 1).ToArray(), PathFromRoot(to).Skip(ancestor.Depth + 1).ToArray());
}
public UndoTreeNodeViewModel CommonAncestor(UndoTreeNodeViewModel first, UndoTreeNodeViewModel second)
+3 -1
ファイルの表示
@@ -72,13 +72,15 @@ internal class UndoTreeNodeViewModel : Bindable
get
{
var text = IsRunHidden ? string.Format(Texts.FoldedRun, Text, FoldedCount + 1) : Text;
var marks = (IsSaved ? $"[{Texts.SavedMark}]" : string.Empty) + (Tag.Length > 0 ? $"[{Tag}]" : string.Empty);
var marks = (IsCompareBase ? $"[{Texts.BaseMark}]" : string.Empty) + (IsSaved ? $"[{Texts.SavedMark}]" : string.Empty) + (Tag.Length > 0 ? $"[{Tag}]" : string.Empty);
return marks.Length > 0 ? $"{marks} {text}" : text;
}
}
public string Tag { get; set => Set(ref field, value ?? string.Empty, nameof(Tag), nameof(DisplayText)); } = string.Empty;
public bool IsCompareBase { get; set => Set(ref field, value, nameof(IsCompareBase), nameof(DisplayText)); }
public bool IsSaved { get; set => Set(ref field, value, nameof(IsSaved), nameof(DisplayText)); }
public bool IsRenaming { get; set => Set(ref field, value); }
+3
ファイルの表示
@@ -26,6 +26,9 @@
<Separator/>
<MenuItem Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ListBox}, Path=DataContext.RenameCommand}" CommandParameter="{Binding}" Header="{x:Static local:Texts.TagNode}" InputGestureText="F2"/>
<MenuItem Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ListBox}, Path=DataContext.ClearTagCommand}" CommandParameter="{Binding}" Header="{x:Static local:Texts.ClearTag}"/>
<Separator/>
<MenuItem Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ListBox}, Path=DataContext.SetCompareBaseCommand}" CommandParameter="{Binding}" Header="{x:Static local:Texts.SetCompareBase}" ToolTip="{x:Static local:Texts.SetCompareBaseTip}"/>
<MenuItem Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ListBox}, Path=DataContext.ClearCompareBaseCommand}" Header="{x:Static local:Texts.ClearCompareBase}"/>
</ContextMenu>
<Style x:Key="ToolBarButtonStyle" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Padding" Value="3"/>
+42 -3
ファイルの表示
@@ -54,6 +54,10 @@ internal class UndoTreeViewModel : Bindable, IToolViewModel, ITimelineToolViewMo
public bool IsDetailsVisible { get; set => Set(ref field, value); } = true;
public UndoTreeNodeViewModel? CompareBase { get; private set => Set(ref field, value, nameof(CompareBase), nameof(HasCompareBase)); }
public bool HasCompareBase => CompareBase is not null;
public bool HasRecord { get; private set => Set(ref field, value); }
public bool IsShowingRecord
@@ -103,6 +107,10 @@ internal class UndoTreeViewModel : Bindable, IToolViewModel, ITimelineToolViewMo
public ActionCommand RevertCommand { get; }
public ActionCommand SetCompareBaseCommand { get; }
public ActionCommand ClearCompareBaseCommand { get; }
public ActionCommand RenameCommand { get; }
public ActionCommand CommitRenameCommand { get; }
@@ -130,6 +138,8 @@ internal class UndoTreeViewModel : Bindable, IToolViewModel, ITimelineToolViewMo
RevertCommand,
RenameCommand,
ClearTagCommand,
SetCompareBaseCommand,
ClearCompareBaseCommand,
ExpandAllCommand,
CollapseAllCommand,
GoToCurrentCommand,
@@ -177,6 +187,16 @@ internal class UndoTreeViewModel : Bindable, IToolViewModel, ITimelineToolViewMo
if (NodeOf(parameter) is { } node)
_ = RunAsync(() => ApplyAsync([node], inverse: true));
});
SetCompareBaseCommand = new ActionCommand(
parameter => CanTag(NodeOf(parameter)) && history is { IsSupported: true },
parameter =>
{
if (NodeOf(parameter) is { } node)
SetCompareBase(node);
});
ClearCompareBaseCommand = new ActionCommand(
_ => CompareBase is not null,
_ => SetCompareBase(null));
RenameCommand = new ActionCommand(
parameter => CanTag(NodeOf(parameter)),
parameter =>
@@ -320,6 +340,22 @@ internal class UndoTreeViewModel : Bindable, IToolViewModel, ITimelineToolViewMo
bool CanApply(UndoTreeNodeViewModel? node)
=> !isRunning && history is { CanReplay: true } && node is { IsRoot: false, IsCurrent: false, IsOnPath: false, IsArchived: false };
void SetCompareBase(UndoTreeNodeViewModel? node)
{
if (CompareBase is not null)
CompareBase.IsCompareBase = false;
CompareBase = node;
if (node is not null)
{
node.IsCompareBase = true;
IsDiffMode = true;
}
UpdateDetails();
RaiseCommandExecutable();
}
bool CanTag(UndoTreeNodeViewModel? node)
=> history is not null && node is { IsArchived: false };
@@ -460,6 +496,9 @@ internal class UndoTreeViewModel : Bindable, IToolViewModel, ITimelineToolViewMo
SyncSettings();
Filter.Owners = Filter.Selection.Count > 0 ? new UndoTreeOwners(history.Roots) : null;
UpdateRecordAvailability();
if (CompareBase is { } start && !history.Nodes.Contains(start))
SetCompareBase(null);
RebuildRows();
StatusText = IsShowingRecord && record is not null
? string.Format(Texts.StatusPrevious, recordNodes.Count - 1, record.SavedAt.ToString("g"))
@@ -713,11 +752,11 @@ internal class UndoTreeViewModel : Bindable, IToolViewModel, ITimelineToolViewMo
if (diff)
{
commands = history.DiffFromCurrent(node);
Details.Add(new UndoTreeDetailItemViewModel(Texts.DiffHeader, string.Empty, 0, true));
commands = CompareBase is { } start ? history.Diff(start, node) : history.DiffFromCurrent(node);
Details.Add(new UndoTreeDetailItemViewModel(CompareBase is null ? Texts.DiffHeader : Texts.DiffHeaderFrom, string.Empty, 0, true));
if (commands.Count == 0)
{
Details.Add(new UndoTreeDetailItemViewModel(Texts.DiffEmpty, string.Empty, 1, false));
Details.Add(new UndoTreeDetailItemViewModel(CompareBase is null ? Texts.DiffEmpty : Texts.DiffEmptyFrom, string.Empty, 1, false));
return;
}
}