From 41cd8a976a1f35df381cc7759f47401b9cb6d000 Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 1 Nov 2026 09:19:57 +0900 Subject: [PATCH] =?UTF-8?q?=E5=9E=8B=E3=81=A8=E9=A0=85=E7=9B=AE=E3=81=AE?= =?UTF-8?q?=E5=90=8D=E5=89=8D=E3=81=AE=E7=BF=BB=E8=A8=B3=E3=82=92YMM4?= =?UTF-8?q?=E3=81=AE=E5=90=8D=E5=89=8D=E7=A9=BA=E9=96=93=E3=81=AE=E3=82=82?= =?UTF-8?q?=E3=81=AE=E3=81=AB=E9=99=90=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- UndoTree.Tests/Documents.cs | 11 -------- UndoTree.Tests/ForeignTypes.cs | 14 ++++++++++ UndoTree.Tests/UndoRedoCommandViewTests.cs | 13 +++++----- UndoTree.Tests/UndoTreeNamesTests.cs | 30 ++++++++++++++++++---- UndoTree/UndoRedoCommandView.cs | 8 +++--- UndoTree/UndoTreeNames.cs | 7 +++-- 7 files changed, 57 insertions(+), 28 deletions(-) create mode 100644 UndoTree.Tests/ForeignTypes.cs diff --git a/README.md b/README.md index b1d559b..d48902e 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ YMM4の取り消しとやり直しの履歴は1本の列で、取り消したあ 現在の位置は太字と青い丸、現在の位置までの経路は黒い丸、ほかは白抜きの丸で示します。やり直せるノードは少し薄く、ほかのブランチはさらに薄く表示します。右端には、ツールがノードを作った時刻を表示します。 -ノードの名前は、変更の対象の名前と項目名を「/」でつなぎます。対象の名前はアイテムやエフェクトの名前で、ないときは型の名前です。項目名はYMM4の画面に出る名前で、取れないときはプロパティの名前です。1つのノードに複数の変更があるときは、先頭の変更のあとに「(ほかN件)」を付けます。リストの追加と削除は、追加だけなら「項目をn件追加」、削除だけなら「項目をm件削除」、両方なら「項目をn件追加、m件削除」と書きます。 +ノードの名前は、変更の対象の名前と項目名を「/」でつなぎます。対象の名前はアイテムやエフェクトの名前で、ないときは型の名前です。項目名はYMM4の画面に出る名前で、取れないときはプロパティの名前です。型の名前と項目名は、名前空間がYukkuriMovieMakerのものだけを、画面の言語に訳します。ほかのプラグインの型と項目は、名前のまま表示します。1つのノードに複数の変更があるときは、先頭の変更のあとに「(ほかN件)」を付けます。リストの追加と削除は、追加だけなら「項目をn件追加」、削除だけなら「項目をm件削除」、両方なら「項目をn件追加、m件削除」と書きます。 履歴が変わるたびに、現在の位置のノードを選びます。この動作はメニューの「現在の位置に追従する」で切り替えられます。「現在の位置を表示」ボタンは、現在の位置を隠している折りたたまれたブランチを開いて、そのノードを選びます。「すべてのブランチを展開」と「すべてのブランチを折りたたむ」ボタンは、ブランチを一度に開閉します。 diff --git a/UndoTree.Tests/Documents.cs b/UndoTree.Tests/Documents.cs index 7c423bc..67b971d 100644 --- a/UndoTree.Tests/Documents.cs +++ b/UndoTree.Tests/Documents.cs @@ -100,17 +100,6 @@ public sealed class Labelled : UndoRedoable } } -public sealed class CharacterSettings : UndoRedoable -{ - int letterSpacing; - - public int LetterSpacing - { - get => letterSpacing; - set => Set(ref letterSpacing, value); - } -} - public enum Shade { [Display(Name = "Visible shade")] diff --git a/UndoTree.Tests/ForeignTypes.cs b/UndoTree.Tests/ForeignTypes.cs new file mode 100644 index 0000000..3ee74c5 --- /dev/null +++ b/UndoTree.Tests/ForeignTypes.cs @@ -0,0 +1,14 @@ +namespace Foreign +{ + public sealed class Animation + { + public double Length { get; set; } + } +} + +namespace YukkuriMovieMakerExtras +{ + public sealed class Animation + { + } +} diff --git a/UndoTree.Tests/UndoRedoCommandViewTests.cs b/UndoTree.Tests/UndoRedoCommandViewTests.cs index 887efd8..613db71 100644 --- a/UndoTree.Tests/UndoRedoCommandViewTests.cs +++ b/UndoTree.Tests/UndoRedoCommandViewTests.cs @@ -1,5 +1,6 @@ using YukkuriMovieMaker.Commons; using YukkuriMovieMaker.Controls; +using YukkuriMovieMaker.Project; using YukkuriMovieMaker.UndoRedo; namespace UndoTree.Tests; @@ -168,14 +169,14 @@ public sealed class UndoRedoCommandViewTests public void ATargetAndAMemberWithoutLabelsAreNamedInTheLanguageOfTheTexts() { var (manager, _) = Histories.NewDocument(); - var settings = new CharacterSettings(); - manager.Subscribe(settings); - Histories.Edit(manager, () => settings.LetterSpacing = 1); + var video = new VideoInfo(); + manager.Subscribe(video); + Histories.Edit(manager, () => video.Width = 1280); var info = UndoRedoCommandView.Read(Only(manager)).Describe(); - Assert.Equal("Character settings", info.TargetLabel); - Assert.Equal("Letter spacing", info.Member); + Assert.Equal("Video information", info.TargetLabel); + Assert.Equal("Width", info.Member); } [Fact] @@ -265,7 +266,7 @@ public sealed class UndoRedoCommandViewTests public void AnObjectWithoutItsOwnTextIsShownByItsLabelOrItsTypeName() { Assert.Equal("blur", UndoRedoCommandView.TextOf(new Part("blur"))); - Assert.Equal("Character settings", UndoRedoCommandView.TextOf(new CharacterSettings())); + Assert.Equal("Video information", UndoRedoCommandView.TextOf(new VideoInfo())); Assert.Equal("42", UndoRedoCommandView.TextOf(42)); } diff --git a/UndoTree.Tests/UndoTreeNamesTests.cs b/UndoTree.Tests/UndoTreeNamesTests.cs index a8c64fa..8f45750 100644 --- a/UndoTree.Tests/UndoTreeNamesTests.cs +++ b/UndoTree.Tests/UndoTreeNamesTests.cs @@ -30,14 +30,14 @@ public sealed class UndoTreeNamesTests var cultureInfo = CultureInfo.GetCultureInfo(culture); Assert.Equal(type, UndoTreeNames.OfType(typeof(Animation), cultureInfo)); - Assert.Equal(member, UndoTreeNames.OfMember(nameof(Animation.Length), cultureInfo)); + Assert.Equal(member, UndoTreeNames.OfMember(typeof(Animation), nameof(Animation.Length), cultureInfo)); } [Fact] public void TheLanguageOfTheTextsIsUsedByDefault() { - Assert.Equal("Effects above", UndoTreeNames.OfMember("AboveEffects")); - Assert.Equal("上のエフェクト", UndoTreeNames.OfMember("AboveEffects", CultureInfo.GetCultureInfo("ja-JP"))); + Assert.Equal("Effects above", UndoTreeNames.OfMember(typeof(Animation), "AboveEffects")); + Assert.Equal("上のエフェクト", UndoTreeNames.OfMember(typeof(Animation), "AboveEffects", CultureInfo.GetCultureInfo("ja-JP"))); } [Fact] @@ -45,7 +45,27 @@ public sealed class UndoTreeNamesTests { Assert.Equal(nameof(Document), UndoTreeNames.OfType(typeof(Document))); Assert.Equal("List`1", UndoTreeNames.OfType(typeof(List))); - Assert.Equal("Unlisted", UndoTreeNames.OfMember("Unlisted")); + Assert.Equal("Unlisted", UndoTreeNames.OfMember(typeof(Animation), "Unlisted")); + } + + [Fact] + public void ATypeOutsideTheHostNamespaceIsNotTranslatedEvenWithTheSameName() + { + var japanese = CultureInfo.GetCultureInfo("ja-JP"); + + Assert.Equal("アニメーション", UndoTreeNames.OfType(typeof(Animation), japanese)); + Assert.Equal("Animation", UndoTreeNames.OfType(typeof(Foreign.Animation), japanese)); + Assert.Equal("長さ", UndoTreeNames.OfMember(typeof(Animation), "Length", japanese)); + Assert.Equal("Length", UndoTreeNames.OfMember(typeof(Foreign.Animation), "Length", japanese)); + Assert.Equal("Length", UndoTreeNames.OfMember(null, "Length", japanese)); + } + + [Fact] + public void ANamespaceThatOnlyStartsWithTheHostNameIsNotTheHost() + { + var japanese = CultureInfo.GetCultureInfo("ja-JP"); + + Assert.Equal("Animation", UndoTreeNames.OfType(typeof(YukkuriMovieMakerExtras.Animation), japanese)); } [Theory] @@ -54,7 +74,7 @@ public sealed class UndoTreeNamesTests { var cultureInfo = CultureInfo.GetCultureInfo(culture); - Assert.All(["X", "Y", "Z", "BPM", "FPS", "Hz"], member => Assert.Equal(member, UndoTreeNames.OfMember(member, cultureInfo))); + Assert.All(["X", "Y", "Z", "BPM", "FPS", "Hz"], member => Assert.Equal(member, UndoTreeNames.OfMember(typeof(Animation), member, cultureInfo))); } [Fact] diff --git a/UndoTree/UndoRedoCommandView.cs b/UndoTree/UndoRedoCommandView.cs index 26a76d9..88a66bf 100644 --- a/UndoTree/UndoRedoCommandView.cs +++ b/UndoTree/UndoRedoCommandView.cs @@ -144,10 +144,12 @@ internal sealed class UndoRedoCommandView static string MemberLabel(object? target, string member) { + Type? owner = null; try { - var name = target?.GetType().GetProperty(member, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)? - .GetCustomAttribute()?.GetName(); + var property = target?.GetType().GetProperty(member, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + owner = property?.DeclaringType; + var name = property?.GetCustomAttribute()?.GetName(); if (!string.IsNullOrEmpty(name)) return name; } @@ -155,7 +157,7 @@ internal sealed class UndoRedoCommandView { } - return UndoTreeNames.OfMember(member); + return UndoTreeNames.OfMember(owner, member); } internal static string ListChangeOf(int added, int removed) => (added, removed) switch diff --git a/UndoTree/UndoTreeNames.cs b/UndoTree/UndoTreeNames.cs index 787b605..3e63331 100644 --- a/UndoTree/UndoTreeNames.cs +++ b/UndoTree/UndoTreeNames.cs @@ -13,12 +13,13 @@ internal static class UndoTreeNames { const string TypePrefix = "Type_"; const string MemberPrefix = "Member_"; + const string HostNamespace = "YukkuriMovieMaker"; static readonly ConcurrentDictionary Plugins = new(); - public static string OfType(Type type, CultureInfo? culture = null) => Find(TypePrefix + type.Name, culture) ?? type.Name; + public static string OfType(Type type, CultureInfo? culture = null) => (IsHost(type) ? Find(TypePrefix + type.Name, culture) : null) ?? type.Name; - public static string OfMember(string member, CultureInfo? culture = null) => Find(MemberPrefix + member, culture) ?? member; + public static string OfMember(Type? owner, string member, CultureInfo? culture = null) => (owner is not null && IsHost(owner) ? Find(MemberPrefix + member, culture) : null) ?? member; public static string OfPlugin(Type type) => Plugins.GetOrAdd(type, CreatePlugin)?.Name is { Length: > 0 } name ? name : OfType(type); @@ -32,6 +33,8 @@ internal static class UndoTreeNames return string.Join(", ", value.ToString().Split(", ").Select(field => DisplayName(type, field))); } + static bool IsHost(Type type) => type.Namespace is { } name && (name == HostNamespace || name.StartsWith(HostNamespace + ".", StringComparison.Ordinal)); + static string? Find(string key, CultureInfo? culture) => Texts.ResourceManager.GetString(key, culture ?? Texts.Culture) is { Length: > 0 } text ? text : null;