From 941f8e04ebb63784049831b4901c709a0bd24e89 Mon Sep 17 00:00:00 2001 From: SeoJCalive <180237232+SeoJCalive@users.noreply.github.com> Date: Tue, 3 Nov 2026 19:47:51 +0900 Subject: [PATCH] feat(toolbar): the group editor's add list follows the field switches A preset whose target belongs only to turned-off fields isn't offered when adding to a group, the same check as the toolbar editor's palette. Presets already in the group stay. Part of #806 --- .../ViewModels/GroupEditorViewModel.cs | 9 +++++-- tests/Filee.App.Tests/GroupEditorTests.cs | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Filee.App/ViewModels/GroupEditorViewModel.cs b/src/Filee.App/ViewModels/GroupEditorViewModel.cs index aceaa3fc..09d3e70f 100644 --- a/src/Filee.App/ViewModels/GroupEditorViewModel.cs +++ b/src/Filee.App/ViewModels/GroupEditorViewModel.cs @@ -5,6 +5,7 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Filee.App.Services; +using Filee.Core.Formats; using Filee.Core.Localization; using Filee.Core.Presets; using Filee.Core.Settings; @@ -48,7 +49,10 @@ public GroupEditorViewModel(Preset group, UserDataStore store, ILocalizer loc, b /// The presets the group fans out, in order. public ObservableCollection Members { get; } = []; - /// Actions that can still be added (not groups, not already in it). + /// + /// Actions that can still be added (not groups, not already in it), without the ones whose target belongs only to + /// turned-off fields, like the toolbar editor's palette. Members already in the group stay. + /// public ObservableCollection> Available { get; } = []; [ObservableProperty] @@ -139,8 +143,9 @@ public void Delete() private void Refresh() { var taken = Members.Select(m => m.PresetId).ToHashSet(); + var off = _store.Settings.TurnedOffFieldSet(); Available.Clear(); - foreach (var preset in _store.Presets.Where(p => !p.IsGroup && !taken.Contains(p.Id))) + foreach (var preset in _store.Presets.Where(p => !p.IsGroup && !taken.Contains(p.Id) && FormatFields.IsShown(p.TargetFormat, off))) Available.Add(new Choice(preset.Id, _loc.DisplayName(preset), CaptionOf(preset))); OnPropertyChanged(nameof(IsFull)); OnPropertyChanged(nameof(IsEmpty)); diff --git a/tests/Filee.App.Tests/GroupEditorTests.cs b/tests/Filee.App.Tests/GroupEditorTests.cs index ad62b382..e325fd3f 100644 --- a/tests/Filee.App.Tests/GroupEditorTests.cs +++ b/tests/Filee.App.Tests/GroupEditorTests.cs @@ -30,6 +30,33 @@ private static void Add(GroupEditorViewModel vm, string presetId) vm.AddCommand.Execute(null); } + [AvaloniaFact] + public void Presets_of_turned_off_fields_are_not_offered_but_members_stay() + { + TestServices.EnsureInitialized("en"); + var settings = AppHost.Get().Settings; + var off = settings.TurnedOffFields; + settings.TurnedOffFields = ["font"]; + try + { + var vm = Edit(new Preset { Name = "Fonts", Kind = PresetKind.Group, SubPresetIds = ["to-ttf"] }); + Assert.Equal("to-ttf", Assert.Single(vm.Members).PresetId); // saved members aren't dropped (rule 7) + Assert.DoesNotContain(vm.Available, c => c.Value == "to-otf"); + Assert.Contains(vm.Available, c => c.Value == "to-eot"); // also in Old formats, which is on + Assert.Contains(vm.Available, c => c.Value == "to-png"); + + vm.RemoveCommand.Execute(vm.Members[0]); + Assert.DoesNotContain(vm.Available, c => c.Value == "to-ttf"); + + settings.TurnedOffFields = []; + Assert.Contains(Edit(new Preset { Name = "Fonts", Kind = PresetKind.Group }).Available, c => c.Value == "to-otf"); + } + finally + { + settings.TurnedOffFields = off; + } + } + [AvaloniaFact] public void Presets_are_added_in_order_moved_and_removed_then_saved_into_the_group() {