Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
Merge remote-tracking branch 'origin/main' into feature/donut-flip
KnifeLemonfde9c5e998ca
diff --cc src/Filee.Core/Presets/BuiltInData.csindex 719c1c4a,45aaec14..9b4d0d37--- a/src/Filee.Core/Presets/BuiltInData.cs+++ b/src/Filee.Core/Presets/BuiltInData.cs@@@ -323,7 -324,6 +328,7 @@@ public static class BuiltInDatId = "images", NameKey = "profile.images",Extensions = ExtensionsOf(FormatCategory.Image),PresetIds = ["to-png", "to-jpg", "to-webp", "to-pdf", "trace-svg", "trace-line-art", "to-tiff", "to-bmp", "to-ico", "half-size"],- BackPresetIds = ["rotate", "flip", "remove-background", "grayscale", "jpg-70", "to-avif", "to-jxl", "to-gif", "merge-pdf", "zip-all"],++ BackPresetIds = ["tool-crop", "rotate", "flip", "remove-background", "grayscale", "jpg-70", "to-avif", "to-gif", "merge-pdf", "zip-all"],},new(){@@@ -438,8 -425,8 +443,10 @@@{Id = "archives", NameKey = "profile.archives",Extensions = ExtensionsOf(FormatCategory.Archive),- PresetIds = ["extract", "to-zip", "to-7z", "to-tgz", "to-tar"],- BackPresetIds = ["zip-all"],+ // "One ZIP" since settings schema 28.+ PresetIds = ["extract", "zip-all", "to-zip", "to-7z", "to-tgz", "to-tar"],++ // Nothing else converts archives: no back face, Tab does nothing.++ BackPresetIds = [],},new(){diff --cc src/Filee.Core/Settings/UserDataStore.csindex cb457816,c8bd5fb7..bc1d5dc4--- a/src/Filee.Core/Settings/UserDataStore.cs+++ b/src/Filee.Core/Settings/UserDataStore.cs@@@ -638,31 -632,33 +639,58 @@@ internal static class SettingsMigration// of the user already takes them.if (from < 24)changed |= LearnExtensions(profiles, out _, ["potm"]);+ // v26: interactive "Crop" tool, after "Remove background" as in a new library, on no donut: users add it in+ // Settings → Toolbar. Present already but saved since by a Filee before 26: that one read the unknown+ // kind as a Group, dropped the target format and left an empty group. Kind and target format are put back,+ // the user's own changes (name, file name pattern) stay.+ if (from < 26)+ {+ if (BuiltInData.CreatePresets().FirstOrDefault(p => p.Id == "tool-crop") is { } crop)+ {+ if (presets.FirstOrDefault(p => p.Id == "tool-crop") is not { } existing)+ {+ var at = presets.FindIndex(p => p.Id == "remove-background");+ presets.Insert(at < 0 ? presets.Count : at + 1, crop);+ changed = true;+ }+ else if (existing.Kind != PresetKind.Tool)+ {+ existing.Kind = PresetKind.Tool;+ existing.TargetFormat = crop.TargetFormat;+ existing.SubPresetIds = [];+ changed = true;+ }+ }+ }+ // v28: "One ZIP" on the archives donut after "Extract", to pack several archives into one. A donut+ // the user filled up, or a library without the preset, stays as it is.+ if (from < 28)+ changed |= Offer(presets, profiles, "archives", "zip-all", "extract");+ // v29: every donut gets a back face, which Tab flips the open donut to. A built-in donut gets its default one+ // (with the presets the library still has), a donut the user made none; no front changes. (Schema 29 may- // be renumbered: 25 to 28 are taken by changes still open.) Also at a later schema when a donut has no++ // be renumbered if another change takes it first.) Also at a later schema when a donut has no+ // back face at all, not even an empty one: a Filee before 29 saved the library since and dropped what it+ // didn't know, so the built-in back faces come back. One the user emptied is saved empty and stays so.+ if (from < 29 || profiles.Any(p => p.BackPresetIds is null))+ changed |= AddBackFaces(presets, profiles);+ return changed;+ }++ /// <summary>+ /// Gives each built-in donut without a back face (<see cref="ToolbarProfile.BackPresetIds"/> null) its default one,+ /// with only the presets in <paramref name="presets"/>. Donuts the user made are left for+ /// <see cref="UserDataStore"/> to give an empty one. Returns true when one was added.+ /// </summary>+ internal static bool AddBackFaces(List<Preset> presets, IEnumerable<ToolbarProfile> profiles)+ {+ var defaults = BuiltInData.CreateProfiles().ToDictionary(p => p.Id);+ var ids = presets.Select(p => p.Id).ToHashSet();+ var changed = false;+ foreach (var profile in profiles.Where(p => p.BackPresetIds is null && defaults.ContainsKey(p.Id)))+ {+ profile.BackPresetIds = (defaults[profile.Id].BackPresetIds ?? []).Where(ids.Contains).ToList();+ changed = true;+ }return changed;}diff --cc tests/Filee.App.Tests/DonutFlipTests.csindex f774141f,00000000..c828d4c6mode 100644,000000..100644--- a/tests/Filee.App.Tests/DonutFlipTests.cs+++ b/tests/Filee.App.Tests/DonutFlipTests.cs@@@ -1,455 -1,0 +1,455 @@@+// Tab flips the open donut to the back face of its profile: in click mode as a key of the focused window, in drag+// mode through the global hook. Arrows still move between slices, an empty or unusable back face doesn't flip, the+// back face greys out what can't convert the files like the front, and "Reduce animations" swaps the faces at once.++using Avalonia;+using Avalonia.Headless;+using Avalonia.Headless.XUnit;+using Avalonia.Input;+using Avalonia.Input.Raw;+using Avalonia.Platform.Storage;+using Avalonia.Threading;+using Avalonia.VisualTree;+using Filee.App.Controls;+using Filee.App.Services;+using Filee.App.ViewModels;+using Filee.App.ViewModels.Pages;+using Filee.App.Views;+using Filee.Core.Localization;+using Filee.Core.Platform;+using Filee.Core.Presets;+using Filee.Core.Profiles;+using Filee.Core.Settings;+using Microsoft.Extensions.Logging.Abstractions;+using SharpHook.Data;++namespace Filee.App.Tests;++[Collection("Motion")]+public class DonutFlipTests+{+ private static readonly string[] Photos = [@"C:\photos\a.jpg", @"C:\photos\b.jpg"];++ private static UserDataStore Store => AppHost.Get<UserDataStore>();++ private static ToolbarProfile Images => Store.Profiles.Single(p => p.Id == "images");++ /// <summary>The image donut's back face, as the library has it now.</summary>+ private static List<string> ImageBack => Images.BackPresetIds!.Where(id => Store.FindPreset(id) is not null).ToList();++ /// <summary>+ /// Runs <paramref name="test"/> with animations on or off and the image donut's back face as given (null: the+ /// built-in one); everything is put back afterwards.+ /// </summary>+ private static void With(bool animations, List<string>? back, Action test, string language = "en")+ {+ TestServices.EnsureInitialized(language);+ var images = Images;+ var (front, before) = (images.PresetIds.ToList(), images.BackPresetIds?.ToList());+ try+ {+ if (back is not null)+ images.BackPresetIds = back;+ Motion.Configure(!animations, () => false);+ test();+ }+ finally+ {+ Motion.Configure(false, () => false);+ images.PresetIds = front;+ images.BackPresetIds = before;+ }+ }++ /// <summary>The donut for <paramref name="files"/>, opened like the selection shortcut opens it.</summary>+ private static (RadialViewModel Vm, RadialWindow Window, DonutMenu Donut) OpenClickMode(params string[] files)+ {+ var vm = AppHost.Get<RadialViewModel>();+ vm.Load(files.Length > 0 ? files : Photos, clickMode: true);+ vm.FitToThisDonut();+ var window = new RadialWindow { DataContext = vm };+ HintLikeTheController(vm, window.DonutControl);+ window.Show();+ Dispatcher.UIThread.RunJobs();+ return (vm, window, window.DonutControl);+ }++ /// <summary>The hub says what the slice under the pointer or the keyboard does, as RadialController has it.</summary>+ private static void HintLikeTheController(RadialViewModel vm, DonutMenu donut) =>+ donut.ActiveIndexChanged += (_, index) => vm.ShowHint(index, donut.ActiveSubIndex, donut.IsCenterHot);++ [AvaloniaFact]+ public void Tab_flips_to_the_back_and_shift_tab_back_to_the_front_in_click_mode() => With(animations: true, back: null, () =>+ {+ var loc = AppHost.Get<ILocalizer>();+ var (vm, window, donut) = OpenClickMode();+ var front = vm.Items.Select(i => i.Id).ToList();+ Assert.True(vm.CanFlip);+ Assert.Equal(loc["donut.flip_to_back"], vm.FlipHint);+ Assert.Equal(vm.FlipHint, donut.CenterHint);++ Assert.True(donut.HandleKey(Key.Tab));+ Assert.True(donut.IsFlipping);+ donut.Advance(DonutMenu.FlipDuration * 0.3);+ Assert.InRange(donut.FlipScale, 0.01, 0.99); // turning, still the front+ Assert.False(vm.IsBackFace);+ Assert.Equal(front, vm.Items.Select(i => i.Id));++ donut.Advance(DonutMenu.FlipDuration * 0.3); // past edge-on: the back+ Assert.True(vm.IsBackFace);+ Assert.Equal(ImageBack, vm.Items.Select(i => i.Id));+ Assert.Equal(loc["donut.flip_to_front"], donut.CenterHint);+ Assert.Equal(loc["donut.close_hint"], vm.CenterSubtitle);+ donut.Advance(DonutMenu.FlipDuration);+ Assert.False(donut.IsFlipping);+ Assert.Equal(1, donut.FlipScale);++ Assert.True(donut.HandleKey(Key.Tab, KeyModifiers.Shift));+ donut.Advance(DonutMenu.FlipDuration);+ Assert.False(vm.IsBackFace);+ Assert.Equal(front, vm.Items.Select(i => i.Id));+ window.Close();+ });++ [AvaloniaFact]+ public void The_window_hands_tab_to_the_donut() => With(animations: false, back: null, () =>+ {+ var (vm, window, _) = OpenClickMode();+ window.KeyPress(Key.Tab, RawInputModifiers.None, PhysicalKey.Tab, null);+ Dispatcher.UIThread.RunJobs();+ Assert.True(vm.IsBackFace);+ Assert.True(window.IsVisible);+ window.Close();+ });++ [AvaloniaFact]+ public void Tab_pressed_again_during_a_flip_flips_once_more_after_it() => With(animations: true, back: null, () =>+ {+ var (vm, window, donut) = OpenClickMode();+ donut.HandleKey(Key.Tab);+ donut.Advance(0.02);+ donut.HandleKey(Key.Tab); // before the first turn ended+ for (var i = 0; i < 40; i++)+ donut.Advance(1 / 60.0);+ Assert.False(donut.IsFlipping);+ Assert.False(vm.IsBackFace); // turned over twice+ window.Close();+ });++ [AvaloniaFact]+ public void Arrows_still_move_between_slices_and_start_over_on_the_other_face() => With(animations: false, back: null, () =>+ {+ var (vm, window, donut) = OpenClickMode();+ Assert.True(donut.HandleKey(Key.Right));+ Assert.True(donut.HandleKey(Key.Right));+ Assert.Equal(1, donut.ActiveIndex);+ Assert.Contains(vm.Items[1].Label, vm.CenterSubtitle);++ Assert.True(donut.HandleKey(Key.Tab));+ Assert.True(vm.IsBackFace);+ Assert.Equal(-1, donut.ActiveIndex); // the selection starts over on the back+ Assert.Equal(AppHost.Get<ILocalizer>()["donut.close_hint"], vm.CenterSubtitle);++ Assert.True(donut.HandleKey(Key.Left)); // wraps to the last slice of the back+ Assert.Equal(vm.Items.Count - 1, donut.ActiveIndex);+ Assert.Equal(ImageBack[^1], vm.Items[donut.ActiveIndex].Id);+ Assert.Equal(ImageBack[^1], vm.PresetAt(donut.ActiveIndex, -1)!.Id); // what Enter converts with+ window.Close();+ });++ [AvaloniaFact]+ public void With_animations_off_the_faces_swap_at_once() => With(animations: false, back: null, () =>+ {+ var (vm, window, donut) = OpenClickMode();+ Assert.True(donut.Flip());+ Assert.False(donut.IsFlipping);+ Assert.Equal(1, donut.FlipScale);+ Assert.True(vm.IsBackFace);+ Assert.False(donut.Advance(0)); // nothing left to animate+ window.Close();+ });++ [AvaloniaFact]+ public void A_donut_without_a_back_face_does_not_flip() => With(animations: true, back: [], () =>+ {+ var (vm, window, donut) = OpenClickMode();+ Assert.False(vm.CanFlip);+ Assert.Null(vm.FlipHint);+ Assert.False(donut.CanFlip);++ Assert.True(donut.HandleKey(Key.Tab)); // still Tab's: it doesn't move the focus off the donut+ Assert.False(donut.IsFlipping);+ Assert.False(donut.Flip());+ Assert.False(vm.IsBackFace);+ Assert.False(vm.ToggleFace());+ window.Close();+ });++ [AvaloniaFact]+ public void The_back_face_greys_out_what_cannot_convert_the_files_and_one_with_nothing_left_does_not_flip()+ {+ var group = new Preset+ {+ Id = "flip-test-sounds",+ Name = "Sounds",+ Kind = PresetKind.Group,+ TargetFormat = Preset.GroupTarget,+ SubPresetIds = ["to-wav", "to-flac"],+ };+ With(animations: false, back: ["to-wav", "flip-test-sounds"], () =>+ {+ Store.Presets.Add(group);+ try+ {+ // Pictures can't become sounds: nothing on the back is for them, so there is nothing to flip to.+ var (vm, window, donut) = OpenClickMode();+ Assert.False(vm.CanFlip);+ Assert.Null(vm.FlipHint);+ Assert.False(donut.Flip());+ window.Close();++ // One slice for them is enough; the others are greyed out with the reason, as on the front.+ Images.BackPresetIds = ["to-wav", "flip-test-sounds", "to-gif"];+ (vm, window, donut) = OpenClickMode();+ Assert.True(vm.CanFlip);+ Assert.True(donut.Flip());+ Assert.Equal(["to-wav", "flip-test-sounds", "to-gif"], vm.Items.Select(i => i.Id));+ Assert.False(vm.Items[0].IsEnabled);+ Assert.NotNull(vm.Items[0].DisabledReason);+ Assert.True(vm.Items[1].IsGroup);+ Assert.False(vm.Items[1].IsEnabled); // every slice of its ring is greyed out+ Assert.All(vm.Items[1].Children!, child => Assert.False(child.IsEnabled));+ Assert.True(vm.Items[2].IsEnabled);+ Assert.Null(vm.PresetAt(0, -1));+ Assert.Equal("to-gif", vm.PresetAt(2, -1)!.Id);+ window.Close();+ }+ finally+ {+ Store.Presets.Remove(group);+ }+ });+ }++ [AvaloniaFact]+ public void An_open_group_ring_folds_before_the_donut_turns() => With(animations: true, back: null, () =>+ {+ Images.PresetIds = [.. Images.PresetIds, "rotate"];+ var (vm, window, donut) = OpenClickMode();+ Assert.True(vm.ReserveSubRing);+ var group = vm.Items.Count - 1;+ donut.SetExternalHit(new DonutHit(DonutHitKind.Segment, group));+ donut.ExpandPendingGroup();+ Assert.Equal(DonutHitKind.SubSegment, donut.HitTest(donut.SubSliceCenter(group, 1)).Kind);++ donut.HandleKey(Key.Tab);+ Assert.NotEqual(DonutHitKind.SubSegment, donut.HitTest(donut.SubSliceCenter(group, 1)).Kind);+ Assert.False(vm.IsBackFace); // the ring folds first, the faces swap halfway through the turn+ donut.Advance(DonutMenu.FlipDuration);+ Assert.True(vm.IsBackFace);+ window.Close();+ });++ [AvaloniaFact]+ public void A_drag_resting_on_a_slice_lights_up_the_slice_there_on_the_other_face() => With(animations: false, back: null, () =>+ {+ var vm = AppHost.Get<RadialViewModel>();+ vm.ResetForDrag();+ var window = new RadialWindow { DataContext = vm };+ HintLikeTheController(vm, window.DonutControl);+ window.Show();+ vm.Load(Photos, clickMode: false);+ Dispatcher.UIThread.RunJobs();+ var donut = window.DonutControl;+ var n = vm.Items.Count;+ var center = new Point(donut.Bounds.Width / 2, donut.Bounds.Height / 2);- var at = DonutGeometry.PointAt(center, vm.OuterRadius * (1 + vm.HoleRatio) / 2, DonutGeometry.MidAngle(2, n));++ var at = DonutGeometry.PointAt(center, vm.OuterRadius * (1 + vm.HoleRatio) / 2, DonutGeometry.MidAngle(5, n));+ donut.SetExternalHit(donut.HitTest(at), at);- Assert.Equal(2, donut.ActiveIndex);++ Assert.Equal(5, donut.ActiveIndex);++ Assert.True(donut.Flip());++ var back = vm.Items.Count;+ var expected = DonutGeometry.HitTest(center, at, vm.OuterRadius * vm.HoleRatio, vm.OuterRadius, back, 7).Index;+ Assert.Equal(expected, donut.ActiveIndex);+ Assert.Equal(AppHost.Get<ILocalizer>().Format("donut.drop_to", vm.Items[expected].Label), vm.CenterSubtitle);+ window.Close();+ });++ /// <summary>+ /// Drag mode: the donut's window has no keyboard focus during the OS drag, so Tab comes from the global hook (here a+ /// stand-in for libuiohook): it flips the donut while files are on it, and is left alone once the donut is gone.+ /// </summary>+ [AvaloniaFact]+ public void In_drag_mode_tab_from_the_global_hook_flips_the_donut() => With(animations: false, back: null, () =>+ {+ var provider = new TriggerServiceLifecycleTests.DelayedProvider();+ provider.AllowExit.Set();+ using var triggers = TriggerServiceLifecycleTests.Create(provider, () => { });+ triggers.Start();+ Assert.True(SpinWait.SpinUntil(() => provider.Runs == 1, 2000));+ var vm = AppHost.Get<RadialViewModel>();+ var radial = new RadialController(vm, AppHost.Get<ConversionService>(), AppHost.Get<WindowService>(), Store,+ AppHost.Get<IPlatformServices>(), triggers, NullLogger<RadialController>.Instance);+ var folder = Directory.CreateTempSubdirectory("filee-flip-");+ try+ {+ var file = Path.Combine(folder.FullName, "photo.jpg");+ File.WriteAllBytes(file, [0xFF, 0xD8, 0xFF]);++ radial.ShowForDrag(400, 400);+ var window = radial.Window!;+ provider.PostKey(EventType.KeyPressed, KeyCode.VcTab); // before files: nothing to flip, not even watched+ provider.PostKey(EventType.KeyReleased, KeyCode.VcTab);+ Assert.False(TriggerServiceLifecycleTests.Settle(() => triggers.WatchFlipKey));++ var data = new DataTransfer();+ var item = window.StorageProvider.TryGetFileFromPathAsync(file).GetAwaiter().GetResult();+ Assert.NotNull(item);+ data.Add(DataTransferItem.CreateFile(item));+ var at = new Point(window.Bounds.Width / 2 + 60, window.Bounds.Height / 2);+ window.DragDrop(at, RawDragEventType.DragEnter, data, DragDropEffects.Copy, RawInputModifiers.Control);+ Dispatcher.UIThread.RunJobs();+ Assert.Equal(new[] { file }, vm.Files);+ Assert.False(vm.IsBackFace);+ Assert.True(triggers.WatchFlipKey);++ provider.PostKey(EventType.KeyPressed, KeyCode.VcTab, EventMask.LeftCtrl);+ Assert.True(TriggerServiceLifecycleTests.Settle(() => vm.IsBackFace));+ Assert.Equal(ImageBack, vm.Items.Select(i => i.Id));+ provider.PostKey(EventType.KeyReleased, KeyCode.VcTab, EventMask.LeftCtrl);+ provider.PostKey(EventType.KeyPressed, KeyCode.VcTab, EventMask.LeftCtrl);+ Assert.False(TriggerServiceLifecycleTests.Settle(() => vm.IsBackFace));++ // The drag moved on: Tab is the user's again.+ radial.Close(animate: false);+ Assert.False(triggers.WatchFlipKey);+ provider.PostKey(EventType.KeyReleased, KeyCode.VcTab);+ provider.PostKey(EventType.KeyPressed, KeyCode.VcTab);+ Assert.False(TriggerServiceLifecycleTests.Settle(() => vm.IsBackFace));+ window.Close();+ }+ finally+ {+ folder.Delete(recursive: true);+ }+ });++ /// <summary>The image donut's back face, light and dark, and the ring halfway through its turn.</summary>+ [AvaloniaTheory]+ [InlineData("en", false)]+ [InlineData("ko", false)]+ [InlineData("ko", true)]+ [InlineData("zh-CN", false)]+ public void The_back_face_renders(string language, bool dark) => With(animations: true, back: null, () =>+ {+ var theme = AppHost.Get<ThemeService>();+ try+ {+ if (dark)+ theme.Apply(new ThemeSettings { Mode = ThemeMode.Dark, CornerRadius = 16 }, language);+ var (vm, window, donut) = OpenClickMode(@"C:\photos\a.jpg", @"C:\photos\b.jpg", @"C:\photos\c.jpg");+ var suffix = $"{language}{(dark ? "-dark" : "")}";+ donut.FinishAnimations();+ RenderTests.Pump();+ RenderTests.Save(window, $"donut-front-hint-{suffix}.png");++ // Drawn right here, not by the render loop: that would play the rest of the turn first.+ donut.HandleKey(Key.Tab);+ donut.Advance(DonutMenu.FlipDuration * 0.3);+ Assert.InRange(donut.FlipScale, 0.2, 0.8);+ var size = new PixelSize((int)window.Bounds.Width, (int)window.Bounds.Height);+ using (var turning = new Avalonia.Media.Imaging.RenderTargetBitmap(size))+ {+ turning.Render(window);+ turning.Save(Path.Combine(TestServices.ScreenshotDirectory, $"donut-flip-midway-{suffix}.png"));+ }++ donut.FinishAnimations();+ Assert.True(vm.IsBackFace);+ donut.SetExternalHighlight(2);+ RenderTests.Pump();+ Assert.Equal(1, donut.FlipScale);+ RenderTests.Save(window, $"donut-back-{suffix}.png");+ window.Close();+ }+ finally+ {+ if (dark)+ theme.Apply(new ThemeSettings(), language);+ }+ }, language);++ /// <summary>+ /// The editor's Front / Back switch: the donut shows and edits the back face, the front stays as it was, and+ /// "Reset to default" puts the built-in back face back.+ /// </summary>+ [AvaloniaTheory]+ [InlineData("en", false)]+ [InlineData("ko", false)]+ [InlineData("ko", true)]+ [InlineData("zh-CN", false)]+ public void The_editor_switches_between_the_front_and_the_back(string language, bool dark) => With(animations: false, back: null, () =>+ {+ var theme = AppHost.Get<ThemeService>();+ var snapshot = Store.Profiles.Select(p => p.Clone()).ToList();+ Avalonia.Controls.Window? window = null;+ try+ {+ if (dark)+ theme.Apply(new ThemeSettings { Mode = ThemeMode.Dark }, language);+ var main = new MainWindowViewModel(AppHost.Services, AppHost.Get<ILocalizer>(), AppHost.Get<UpdateService>());+ main.Navigate("toolbar");+ window = new MainWindow { DataContext = main, Width = 1080, Height = 1000 };+ window.Show();+ var page = (ToolbarPageViewModel)main.CurrentPage!;+ page.SelectedProfile = page.Profiles.Single(p => p.Profile.Id == "images");+ RenderTests.Pump();+ var front = Images.PresetIds.ToList();+ var switcher = window.GetVisualDescendants().OfType<Avalonia.Controls.Border>().Single(b => b.Name == "FaceSwitch");+ var faces = switcher.GetVisualDescendants().OfType<Avalonia.Controls.RadioButton>().ToList();+ Assert.Equal(2, faces.Count);+ Assert.True(faces[0].IsChecked);+ Assert.Equal(front, page.DonutItems.Select(i => i.Id));++ // The switch shows the back face, and every edit goes there.+ faces[1].IsChecked = true;+ RenderTests.Pump();+ Assert.True(page.EditingBack);+ Assert.False(faces[0].IsChecked);+ Assert.Equal(ImageBack, page.DonutItems.Select(i => i.Id));+ Assert.Equal(ImageBack.Count, page.BackCount);+ Assert.DoesNotContain(page.Palette, chip => ImageBack.Contains(chip.PresetId));+ Assert.Contains(page.Palette, chip => chip.PresetId == "to-png"); // on the front, still free for the back+ Assert.Contains(AppHost.Get<ILocalizer>()["toolbar.face_back"], page.CenterSubtitle);+ RenderTests.Save(window, $"toolbar-back-face-{language}{(dark ? "-dark" : "")}.png");++ var back = ImageBack;+ Assert.True(page.Insert("to-psd", 0));+ page.Move(0, 2);+ page.RemoveAt(page.SliceCount - 1);+ List<string> edited = [.. back[..2], "to-psd", .. back[2..^1]];+ Assert.Equal(edited, Images.BackPresetIds);+ Assert.Equal(front, Images.PresetIds); // the front as it was+ Assert.Equal(edited, page.DonutItems.Select(i => i.Id));++ page.Reset(page.SelectedProfile!);+ Assert.Equal(BuiltInData.CreateProfiles().Single(p => p.Id == "images").BackPresetIds, Images.BackPresetIds);+ Assert.Equal(Images.BackPresetIds, page.DonutItems.Select(i => i.Id)); // still on the back++ faces[0].IsChecked = true;+ RenderTests.Pump();+ Assert.False(page.EditingBack);+ Assert.Equal(front, page.DonutItems.Select(i => i.Id));+ }+ finally+ {+ window?.Close();+ if (dark)+ theme.Apply(new ThemeSettings(), language);+ Store.Profiles.Clear();+ Store.Profiles.AddRange(snapshot);+ Store.SaveLibrary();+ }+ }, language);+}diff --cc tests/Filee.Core.Tests/BackFaceTests.csindex b6201476,00000000..56c948bdmode 100644,000000..100644--- a/tests/Filee.Core.Tests/BackFaceTests.cs+++ b/tests/Filee.Core.Tests/BackFaceTests.cs@@@ -1,239 -1,0 +1,240 @@@+// The back face of a donut (Tab flips the open donut to it): the built-in ones, settings schema 29 that gives existing+// libraries theirs, a round trip through a Filee from before back faces, "Reset to default" and import.++using System.Text.Json.Nodes;+using Filee.Core.Presets;+using Filee.Core.Profiles;+using Filee.Core.Settings;++namespace Filee.Core.Tests;++public class BackFaceTests+{+ private static ToolbarProfile BuiltIn(string id) => BuiltInData.CreateProfiles().Single(p => p.Id == id);++ private static UserDataStore NewStore(TempDir dir)+ {+ var store = new UserDataStore(dir.Path);+ store.Load();+ return store;+ }++ private static ToolbarProfile Profile(UserDataStore store, string id) => store.Profiles.Single(p => p.Id == id);++ /// <summary>A library as a Filee from before back faces wrote it: no "backPresetIds" anywhere.</summary>+ private static void DropBackFaces(TempDir dir, int? schema)+ {+ var path = Path.Combine(dir.Path, "profiles.json");+ var profiles = JsonNode.Parse(File.ReadAllText(path))!.AsArray();+ foreach (var profile in profiles)+ profile!.AsObject().Remove("backPresetIds");+ File.WriteAllText(path, profiles.ToJsonString());+ if (schema is null)+ return;+ var settingsPath = Path.Combine(dir.Path, "settings.json");+ var settings = JsonNode.Parse(File.ReadAllText(settingsPath))!.AsObject();+ settings["schemaVersion"] = schema;+ File.WriteAllText(settingsPath, settings.ToJsonString());+ }++ [Fact]+ public void Every_built_in_donut_has_a_back_face_of_other_built_in_presets()+ {+ var presets = BuiltInData.CreatePresets().ToDictionary(p => p.Id);+ foreach (var profile in BuiltInData.CreateProfiles())+ {+ var back = profile.BackPresetIds;+ Assert.NotNull(back);- Assert.NotEmpty(back);+ Assert.True(back.Count <= ToolbarProfile.MaxSlices, profile.Id);+ Assert.Equal(back.Count, back.Distinct().Count());+ Assert.All(back, id => Assert.True(presets.ContainsKey(id), $"{profile.Id}: {id}"));+ // Nothing moved off the front, nothing shown twice.+ Assert.Empty(back.Intersect(profile.PresetIds));+ }++ // Only archives have nothing more to offer ("One ZIP" is on their front since settings schema 28).++ Assert.Equal(["archives"], BuiltInData.CreateProfiles().Where(p => p.BackPresetIds!.Count == 0).Select(p => p.Id));+ }++ [Fact]+ public void The_fronts_stay_as_they_were_before_back_faces()+ {+ Assert.Equal(["to-png", "to-jpg", "to-webp", "to-pdf", "trace-svg", "trace-line-art", "to-tiff", "to-bmp", "to-ico", "half-size"],+ BuiltIn("images").PresetIds);+ Assert.Equal(BuiltInData.PdfDonut, BuiltIn("pdf").PresetIds);+ Assert.Equal(["to-pdf", "to-hwpx", "to-hwp", "to-docx", "to-odt", "to-txt", "to-html", "to-epub", "to-png", "merge-pdf"],+ BuiltIn("office").PresetIds);+ Assert.Equal(["to-pdf", "merge-pdf", "zip-all", "to-png", "to-txt"], BuiltIn("mixed").PresetIds);+ Assert.Equal(["to-mp4", "mp4-720", "mp4-hevc", "to-webm", "to-mov", "to-gif", "to-mp3", "extract-subtitles", "to-mkv", "to-avi"],+ BuiltIn("video").PresetIds);+ }++ [Fact]+ public void A_new_library_saves_and_loads_the_back_faces()+ {+ using var dir = new TempDir();+ var store = NewStore(dir);+ var images = Profile(store, "images");+ Assert.Equal(BuiltIn("images").BackPresetIds, images.BackPresetIds);+ images.BackPresetIds = ["to-gif", "zip-all"];+ store.SaveLibrary();++ Assert.Contains("\"backPresetIds\"", File.ReadAllText(Path.Combine(dir.Path, "profiles.json")));+ var reloaded = NewStore(dir);+ Assert.Equal(["to-gif", "zip-all"], Profile(reloaded, "images").BackPresetIds);+ Assert.Equal(BuiltIn("pdf").BackPresetIds, Profile(reloaded, "pdf").BackPresetIds);+ }++ [Fact]+ public void Version_24_libraries_get_the_built_in_back_faces_and_keep_their_fronts()+ {+ // As written with schema 24: no back faces, the user's own front on the images donut and a donut of their own.+ var presets = BuiltInData.CreatePresets();+ var profiles = BuiltInData.CreateProfiles();+ foreach (var p in profiles)+ p.BackPresetIds = null;+ var images = profiles.Single(p => p.Id == "images");+ images.PresetIds = ["to-webp", "to-png"];+ var mine = new ToolbarProfile { Id = "mine", Name = "Mine", Extensions = ["xyz"], PresetIds = ["to-pdf"] };+ profiles.Insert(0, mine);+ // A preset of the default back face the user deleted stays deleted.- presets.RemoveAll(p => p.Id == "to-jxl");++ presets.RemoveAll(p => p.Id == "to-gif");+ var fronts = profiles.ToDictionary(p => p.Id, p => p.PresetIds.ToList());++ Assert.True(SettingsMigrations.ApplyToLibrary(24, presets, profiles));++ foreach (var profile in profiles.Where(p => p != mine))+ {- var expected = BuiltIn(profile.Id).BackPresetIds!.Where(id => id != "to-jxl");++ var expected = BuiltIn(profile.Id).BackPresetIds!.Where(id => id != "to-gif");+ Assert.Equal(expected, profile.BackPresetIds);+ }+ Assert.Null(mine.BackPresetIds); // the store gives it an empty one (below)+ Assert.All(profiles, p => Assert.Equal(fronts[p.Id], p.PresetIds));+ Assert.False(SettingsMigrations.ApplyToLibrary(24, presets, profiles)); // once only+ Assert.False(SettingsMigrations.ApplyToLibrary(AppSettings.CurrentSchemaVersion, presets, profiles));+ }++ [Fact]+ public void An_existing_user_gets_the_back_faces_and_their_own_donuts_none()+ {+ using var dir = new TempDir();+ var store = NewStore(dir);+ Profile(store, "images").PresetIds = ["to-webp", "to-png"];+ store.Profiles.Insert(0, new ToolbarProfile { Id = "mine", Name = "Mine", Extensions = ["xyz"], PresetIds = ["to-pdf"] });+ store.SaveLibrary();+ store.SaveSettings();+ DropBackFaces(dir, schema: 24);++ var upgraded = NewStore(dir);++ Assert.Equal(AppSettings.CurrentSchemaVersion, upgraded.Settings.SchemaVersion);+ Assert.Equal(["to-webp", "to-png"], Profile(upgraded, "images").PresetIds);+ Assert.Equal(BuiltIn("images").BackPresetIds, Profile(upgraded, "images").BackPresetIds);+ Assert.Equal(BuiltIn("mixed").BackPresetIds, Profile(upgraded, "mixed").BackPresetIds);+ Assert.Equal([], Profile(upgraded, "mine").BackPresetIds);+ // Written at once, so it runs once.+ Assert.Contains("\"backPresetIds\"", File.ReadAllText(Path.Combine(dir.Path, "profiles.json")));+ var again = NewStore(dir);+ Assert.Equal(BuiltIn("images").BackPresetIds, Profile(again, "images").BackPresetIds);+ Assert.Equal([], Profile(again, "mine").BackPresetIds);+ }++ [Theory]+ [InlineData(24)] // the older Filee also saved its settings, with its own schema+ [InlineData(null)] // it only saved the library: the settings still say 29+ public void Back_from_an_older_Filee_the_built_in_back_faces_return_and_an_emptied_one_stays_empty(int? schema)+ {+ using var dir = new TempDir();+ var store = NewStore(dir);+ Profile(store, "images").BackPresetIds = ["to-gif"];+ Profile(store, "pdf").BackPresetIds = [];+ store.SaveLibrary();+ store.SaveSettings();++ // Opened with this Filee again, the user's back faces are as they left them, the emptied one too.+ var same = NewStore(dir);+ Assert.Equal(["to-gif"], Profile(same, "images").BackPresetIds);+ Assert.Equal([], Profile(same, "pdf").BackPresetIds);++ // An older Filee saved the library in between: it dropped the back faces it didn't know.+ DropBackFaces(dir, schema);+ var back = NewStore(dir);++ Assert.Equal(BuiltIn("images").BackPresetIds, Profile(back, "images").BackPresetIds);+ Assert.Equal(BuiltIn("pdf").BackPresetIds, Profile(back, "pdf").BackPresetIds);+ Assert.Equal(BuiltIn("images").PresetIds, Profile(back, "images").PresetIds);+ Assert.Equal(AppSettings.CurrentSchemaVersion, back.Settings.SchemaVersion);+ Assert.False(File.Exists(Path.Combine(dir.Path, "profiles.json.broken")));+ }++ [Fact]+ public void Dangling_and_extra_back_slices_are_dropped()+ {+ using var dir = new TempDir();+ var store = NewStore(dir);+ var images = Profile(store, "images");+ images.BackPresetIds = ["does-not-exist", "to-gif", "to-gif", .. store.Presets.Select(p => p.Id).Take(20)];+ store.SaveLibrary();++ Assert.DoesNotContain("does-not-exist", images.BackPresetIds);+ Assert.Equal(ToolbarProfile.MaxSlices, images.BackPresetIds.Count);+ Assert.Single(images.BackPresetIds, "to-gif");+ }++ [Fact]+ public void Reset_to_default_restores_the_back_face_too()+ {+ using var dir = new TempDir();+ var store = NewStore(dir);+ var images = Profile(store, "images");+ images.BackPresetIds = ["to-pdf"];+ // A preset of the default back face and one the "Rotate" group fans out, both deleted.+ store.Presets.RemoveAll(p => p.Id is "to-avif" or "rotate-180");+ store.SaveLibrary();+ Assert.DoesNotContain("rotate-180", store.FindPreset("rotate")!.SubPresetIds);++ Assert.True(store.ResetProfile(images));++ Assert.Equal(BuiltIn("images").BackPresetIds, images.BackPresetIds);+ Assert.Equal(BuiltIn("images").PresetIds, images.PresetIds);+ Assert.NotNull(store.FindPreset("to-avif"));+ Assert.NotNull(store.FindPreset("rotate-180"));+ Assert.Equal(store.Presets.Count, store.Presets.Select(p => p.Id).Distinct().Count());+ Assert.Equal(BuiltIn("images").BackPresetIds, Profile(NewStore(dir), "images").BackPresetIds);+ }++ [Fact]+ public void Reset_to_default_leaves_the_other_back_faces_alone()+ {+ using var dir = new TempDir();+ var store = NewStore(dir);+ Profile(store, "pdf").BackPresetIds = ["to-gif"];+ Profile(store, "images").BackPresetIds = [];+ store.SaveLibrary();++ Assert.True(store.ResetProfile(Profile(store, "images")));++ Assert.Equal(["to-gif"], Profile(store, "pdf").BackPresetIds);+ }++ [Fact]+ public void A_bundle_from_before_back_faces_imports_built_in_donuts_with_theirs()+ {+ using var dir = new TempDir();+ var store = NewStore(dir);+ var bundle = Path.Combine(dir.Path, "bundle.json");+ store.Export(bundle);+ var json = JsonNode.Parse(File.ReadAllText(bundle))!.AsObject();+ foreach (var profile in json["profiles"]!.AsArray())+ profile!.AsObject().Remove("backPresetIds");+ json["profiles"]!.AsArray().Add(new JsonObject { ["id"] = "theirs", ["name"] = "Theirs", ["presetIds"] = new JsonArray("to-png") });+ File.WriteAllText(bundle, json.ToJsonString());++ using var other = new TempDir();+ var target = NewStore(other);+ Profile(target, "images").BackPresetIds = ["to-gif"];+ target.Import(bundle);++ Assert.Equal(BuiltIn("images").BackPresetIds, Profile(target, "images").BackPresetIds);+ Assert.Equal([], Profile(target, "theirs").BackPresetIds);+ }+}