Skip to content

armgit / Filee

Public Imported from GitHub
0

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.

Merge origin/main: the back faces become settings schema 30

KnifeLemon4a9545309876
diff --cc README.ko.md
index 735794de,6f579b0b..6fffb6d6
--- a/README.ko.md
+++ b/README.ko.md
@@@ -64,7 -64,6 +64,7 @@@
- **커서 옆 도넛**: 키를 누른 채 파일을 끌어 형식 위에 놓으면 끝. 파일에 맞는 형식만 나와요.
- **파일 종류마다 툴바**를 드래그로 배치하고, 품질·크기·DPI·PDF 페이지와 압축·동영상·오디오·저장 위치·파일 이름을
프리셋으로 정해요.
- - **도넛 뒷면**: 도넛이 열려 있을 때 <kbd>Tab</kbd>을 누르면 뒤집혀서 덜 쓰는 형식과 도구가 나와요.
++- **도넛 뒷면**: 도넛이 열려 있을 때 <kbd>Tab</kbd>을 누르거나 마우스 휠을 돌리면 뒤집혀서 덜 쓰는 형식과 도구가 나와요.
- **여러 파일을 한 번에** 병렬로 변환해요. 여러 단계가 필요한 변환(HWP → HWPX → DOCX)도 알아서 찾아요.
- **자동 변환 폴더**에 들어온 파일을 바로 변환해요.
- **다른 방법**: 우클릭 메뉴, 키보드 단축키, 드롭 영역, [`filee` 명령](#명령줄)
diff --cc README.md
index 0e4c1d2d,3c60c743..5ac0dd2b
--- a/README.md
+++ b/README.md
@@@ -64,7 -64,6 +64,7 @@@ Filee shows new releases in its menu an
- **A donut at the cursor**: hold a key, drag files and drop them on a format. Only formats that fit the files appear.
- **One toolbar per file type**, arranged by drag and drop, with presets for quality, size, DPI, PDF pages and compression,
video and audio, output folder and file names.
- - **Two sides to every donut**: press <kbd>Tab</kbd> while it is open to flip it over to less common formats and tools.
++- **Two sides to every donut**: press <kbd>Tab</kbd> or turn the mouse wheel while it is open to flip it over to less common formats and tools.
- **Many files at once**, in parallel. Routes with several steps (HWP → HWPX → DOCX) are found automatically.
- **Watch folders** convert every file that lands in them.
- **Other ways in**: the right-click menu, a keyboard shortcut, the drop zone and the [`filee` command](#command-line).
diff --cc README.zh-CN.md
index 21cc073a,84ca9489..c6c03038
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@@ -63,7 -63,6 +63,7 @@@
- **光标旁的圆环**,按住按键拖动文件,放到格式上即可。只显示适合这些文件的格式。
- **每种文件类型一个工具栏**,拖放排列。质量、尺寸、DPI、PDF 页面和压缩、视频音频、保存位置和文件名都能用预设设置。
- - **圆环有背面**,圆环打开时按 <kbd>Tab</kbd> 翻过来,背面是不常用的格式和工具。
++- **圆环有背面**,圆环打开时按 <kbd>Tab</kbd> 或转动鼠标滚轮翻过来,背面是不常用的格式和工具。
- **一次转换多个文件**,并行处理。需要多步的转换(HWP → HWPX → DOCX)会自动找到路线。
- **监视文件夹**,放入的文件自动转换。
- **其他方式** 右键菜单、键盘快捷键、拖放区域和 [`filee` 命令](#命令行)。
diff --cc docs/ARCHITECTURE.md
index d34bb0c3,69aee0c4..f22bf9b6
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@@ -56,18 -56,6 +56,22 @@@
editor on the *Donut toolbar* settings page (drag to reorder, ✎ / right-click to edit).
Animations are small springs advanced per frame; `Motion.Enabled == false` (*Reduce animations*) snaps them.
+Every `ToolbarProfile` has two faces: `PresetIds` (the front) and `BackPresetIds` (the back; the built-in donuts get
- the less common formats and tools of their file type, see `BuiltInData.CreateProfiles`). Tab, or Shift+Tab, flips
- the open donut (`DonutMenu.Flip.cs`): the ring turns about its vertical axis in 200 ms, an open group's ring folding
- first, and halfway, edge-on, `FaceSwapping` has `RadialViewModel` show the other face, so slices, hit tests and
- drops always belong to the face that is drawn. *Reduce animations* swaps the faces at once. `RadialViewModel` builds
- both faces with the same `PresetAvailability` check; a face with no slice for the files (or none at all) isn't
- flipped to, and only then does the hub leave out its "Tab ↻ back" hint. In click mode the focused window gets Tab
- (`DonutMenu.HandleKey`). During a drag the donut's window has no keyboard focus, so `RadialController` turns on
- `TriggerService.WatchFlipKey` while the drag donut shows files and flips on `FlipKeyPressed`: the global hook only
- listens (nothing is swallowed, Explorer and Finder ignore Tab during a drag) and reports one flip per key press.
++the less common formats and tools of their file type, see `BuiltInData.CreateProfiles`). The flip key
++(`DonutSettings.FlipKey`, Tab unless recorded otherwise in Settings → Shortcuts; `EffectiveFlipKey` refuses keys the
++donut or a keyboard shortcut uses) and the mouse wheel (`FlipWithWheel`, one flip per turn of the wheel: notches less
++than `DonutMenu.WheelQuietMs` apart are one turn) flip the open donut (`DonutMenu.Flip.cs`): the ring turns about its
++vertical axis in 200 ms, an open group's ring folding first, and halfway, edge-on, `FaceSwapping` has
++`RadialViewModel` show the other face, so slices, hit tests and drops always belong to the face that is drawn.
++*Reduce animations* swaps the faces at once. `RadialViewModel` builds both faces with the same `PresetAvailability`
++check (the back right after the front is on screen); a face with no slice for the files (or none at all) isn't
++flipped to, and only then does the hub leave out its "Tab ↻ back" hint (a mouse in place of the key when only the
++wheel flips). In click mode the focused window gets the key (`DonutMenu.HandleKey`) and the donut the wheel. During a
++drag the donut's window has no keyboard focus, so `RadialController` turns on `TriggerService.WatchFlipKey` while
++the drag donut shows files and flips on `FlipKeyPressed` / `FlipWheelTurned`: the global hook only listens (it
++can't hold an event back; Explorer and Finder ignore Tab during a drag) and reports one flip per key press.
+The editor's Front / Back switch (`ToolbarPageViewModel.EditingBack`) edits either list with the same drag and drop.
+
## Settings and data
`UserDataStore` owns `settings.json`, `presets.json`, `profiles.json` and `history.json`
diff --cc src/Filee.Core/Presets/BuiltInData.cs
index 3278250d,d6174613..8e58a795
--- a/src/Filee.Core/Presets/BuiltInData.cs
+++ b/src/Filee.Core/Presets/BuiltInData.cs
@@@ -330,11 -340,7 +340,11 @@@ public static class BuiltInDat
new() { Id = "to-vcf", Name = "vCard", TargetFormat = "vcf" },
];
- /// <summary>Creates the default toolbar profiles.</summary>
+ /// <summary>
- /// Creates the default toolbar profiles. Each has a back face (Tab flips the open donut to it, settings schema 29)
++ /// Creates the default toolbar profiles. Each has a back face (Tab or the mouse wheel flips the open donut to it, settings schema 30)
+ /// with presets for its files that aren't on its front: less common formats and tools (rotate, merge, compress
+ /// into one ZIP, ...). The fronts are as they were before back faces.
+ /// </summary>
public static List<ToolbarProfile> CreateProfiles() =>
[
new()
@@@ -342,7 -348,6 +352,7 @@@
Id = "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 = ["tool-crop", "rotate", "flip", "remove-background", "grayscale", "jpg-70", "to-avif", "to-gif", "merge-pdf", "zip-all"],
++ BackPresetIds = ["tool-crop", "rotate", "flip", "remove-background", "grayscale", "extract-motion", "to-avif", "to-gif", "merge-pdf", "zip-all"],
},
new()
{
diff --cc src/Filee.Core/Profiles/ToolbarProfile.cs
index cfafc204,95406ab1..f11f9e0a
--- a/src/Filee.Core/Profiles/ToolbarProfile.cs
+++ b/src/Filee.Core/Profiles/ToolbarProfile.cs
@@@ -36,14 -36,6 +36,14 @@@ public sealed class ToolbarProfil
/// <summary>Preset ids in donut order, clockwise starting at 12 o'clock.</summary>
public List<string> PresetIds { get; set; } = [];
+ /// <summary>
+ /// Preset ids of the back face, which Tab flips the open donut to: less common conversions and tools, in the same
+ /// order and up to the same <see cref="MaxSlices"/> as <see cref="PresetIds"/>. Empty: the donut doesn't flip.
- /// Null only as read from a file without back faces (a Filee from before settings schema 29, or one that saved
++ /// Null only as read from a file without back faces (a Filee from before settings schema 30, or one that saved
+ /// the library since): loading gives a built-in donut its default back face then, and any other none.
+ /// </summary>
+ public List<string>? BackPresetIds { get; set; }
+
/// <summary>Returns true if the extension (with or without dot) belongs to this profile.</summary>
public bool Matches(string extension) =>
Extensions.Contains(extension.TrimStart('.'), StringComparer.OrdinalIgnoreCase);
diff --cc src/Filee.Core/Settings/AppSettings.cs
index a350061d,863795d3..ae9f64ea
--- a/src/Filee.Core/Settings/AppSettings.cs
+++ b/src/Filee.Core/Settings/AppSettings.cs
@@@ -109,7 -65,7 +109,7 @@@ public sealed class DonutSetting
public sealed class AppSettings
{
/// <summary>Current schema version. Increase when the format changes and add a migration.</summary>
-- public const int CurrentSchemaVersion = 29;
++ public const int CurrentSchemaVersion = 30;
public int SchemaVersion { get; set; } = CurrentSchemaVersion;
diff --cc src/Filee.Core/Settings/UserDataStore.cs
index 9d93ddff,cdb64750..8bfee9b7
--- a/src/Filee.Core/Settings/UserDataStore.cs
+++ b/src/Filee.Core/Settings/UserDataStore.cs
@@@ -685,31 -678,29 +685,54 @@@ internal static class SettingsMigration
// 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 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))
+ // v29: "Extract live video" (the video of a Live / Motion Photo as MP4), after "Extract frames" as in a new
+ // library, on no donut: the images donut is full. Present already but saved since by a Filee before 29:
+ // that one dropped the option and left a plain MP4 preset, so it is put back. The images donut learns
+ // ".livp" (iPhone Live Photos downloaded from iCloud) unless a donut of the user already takes it.
+ if (from < 29)
+ {
+ foreach (var motion in BuiltInData.MotionPhotoPresets())
+ {
+ if (presets.FirstOrDefault(p => p.Id == motion.Id) is { } existing)
+ {
+ if (!existing.Media.ExtractMotionPhoto && existing.TargetFormat == motion.TargetFormat)
+ {
+ existing.Media.ExtractMotionPhoto = true;
+ changed = true;
+ }
+ continue;
+ }
+ var at = presets.FindIndex(p => p.Id == "extract-frames-jpg");
+ presets.Insert(at < 0 ? presets.Count : at + 1, motion);
+ changed = true;
+ }
+ changed |= LearnExtensions(profiles, out _, ["livp"]);
+ }
++ // v30: every donut gets a back face, which Tab (or the mouse wheel) 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. Also at a later schema when a donut has no back face at all, not even an empty one: a Filee
++ // before 30 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 < 30 || 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.cs
index ebe23515,00000000..7b64d507
mode 100644,000000..100644
--- a/tests/Filee.App.Tests/DonutFlipTests.cs
+++ b/tests/Filee.App.Tests/DonutFlipTests.cs
@@@ -1,700 -1,0 +1,704 @@@
+// 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", string? flipKey = null,
+ bool? wheel = null)
+ {
+ TestServices.EnsureInitialized(language);
+ var images = Images;
+ var (front, before) = (images.PresetIds.ToList(), images.BackPresetIds?.ToList());
+ var donut = Store.Settings.Donut;
+ var (keyBefore, wheelBefore) = (donut.FlipKey, donut.FlipWithWheel);
+ try
+ {
+ if (back is not null)
+ images.BackPresetIds = back;
+ donut.FlipKey = flipKey ?? DonutSettings.DefaultFlipKey;
+ donut.FlipWithWheel = wheel ?? true;
+ Motion.Configure(!animations, () => false);
+ test();
+ }
+ finally
+ {
+ Motion.Configure(false, () => false);
+ images.PresetIds = front;
+ images.BackPresetIds = before;
+ (donut.FlipKey, donut.FlipWithWheel) = (keyBefore, wheelBefore);
+ }
+ }
+
+ /// <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.Format("donut.flip_to_back", "Tab"), 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.Format("donut.flip_to_front", "Tab"), 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(5, n));
+ donut.SetExternalHit(donut.HitTest(at), at);
+ 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);
++ // What that slice does with these files, or why it can't (an engine to download).
++ var there = vm.Items[expected];
++ Assert.Equal(there.IsEnabled ? AppHost.Get<ILocalizer>().Format("donut.drop_to", there.Label) : there.DisabledReason, 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>Another flip key from Settings → Shortcuts: it flips, Tab no longer does, and the hub names it.</summary>
+ [AvaloniaFact]
+ public void A_flip_key_from_the_settings_flips_in_click_mode_and_tab_no_longer_does() =>
+ With(animations: false, back: null, flipKey: "F2", test: () =>
+ {
+ var loc = AppHost.Get<ILocalizer>();
+ var (vm, window, donut) = OpenClickMode();
+ Assert.Equal("F2", donut.FlipKey);
+ Assert.Equal(loc.Format("donut.flip_to_back", "F2"), vm.FlipHint);
+ Assert.False(vm.FlipHintWheel);
+
+ Assert.False(donut.HandleKey(Key.Tab)); // the window's again
+ Assert.False(vm.IsBackFace);
+ Assert.True(donut.HandleKey(Key.F2, KeyModifiers.Shift));
+ Assert.True(vm.IsBackFace);
+ Assert.Equal(loc.Format("donut.flip_to_front", "F2"), vm.FlipHint);
+ window.Close();
+ });
+
+ /// <summary>No key, the wheel on: the hub shows a mouse; neither: no hint and the donut doesn't flip by input.</summary>
+ [AvaloniaFact]
+ public void The_hub_shows_a_mouse_when_only_the_wheel_flips_and_nothing_when_nothing_does() =>
+ With(animations: false, back: null, flipKey: "", wheel: true, test: () =>
+ {
+ var (vm, window, donut) = OpenClickMode();
+ Assert.Null(donut.FlipKey);
+ Assert.True(vm.FlipHintWheel);
+ Assert.Equal(AppHost.Get<ILocalizer>().Format("donut.flip_to_back", "").Trim(), vm.FlipHint);
+ Assert.False(donut.HandleKey(Key.Tab));
+ RenderTests.Pump();
+ RenderTests.Save(window, "donut-front-hint-wheel-en.png");
+ window.Close();
+
+ Store.Settings.Donut.FlipWithWheel = false;
+ (vm, window, donut) = OpenClickMode();
+ Assert.True(vm.CanFlip);
+ Assert.Null(vm.FlipHint);
+ Assert.False(vm.FlipHintWheel);
+ Assert.False(donut.FlipWithWheel);
+ window.MouseWheel(new Point(window.Bounds.Width / 2, window.Bounds.Height / 2), new Vector(0, -1));
+ Dispatcher.UIThread.RunJobs();
+ Assert.False(vm.IsBackFace);
+ window.Close();
+ });
+
+ /// <summary>
+ /// One flip per turn of the wheel: the notches of one turn (and a touchpad's many small steps) come close together,
+ /// and a fast scroll mustn't flip back and forth. A pause starts a new turn.
+ /// </summary>
+ [AvaloniaFact]
+ public void The_wheel_flips_once_per_turn() => With(animations: false, back: null, test: () =>
+ {
+ var (vm, window, donut) = OpenClickMode();
+ Assert.True(donut.FlipWithWheel);
+ Assert.True(donut.FlipFromWheel(10_000));
+ Assert.True(vm.IsBackFace);
+ Assert.False(donut.FlipFromWheel(10_040)); // the same turn
+ Assert.False(donut.FlipFromWheel(10_200));
+ Assert.False(donut.FlipFromWheel(10_450)); // still: 250 ms after the last notch
+ Assert.True(vm.IsBackFace);
+ Assert.True(donut.FlipFromWheel(10_450 + DonutMenu.WheelQuietMs)); // a new turn after a pause
+ Assert.False(vm.IsBackFace);
+
+ // Click mode: the wheel over the donut, as the window gets it.
+ var over = new Point(window.Bounds.Width / 2, window.Bounds.Height / 2);
+ Thread.Sleep((int)DonutMenu.WheelQuietMs + 50); // a new turn by the clock the window's wheel uses
+ window.MouseWheel(over, new Vector(0, -1));
+ window.MouseWheel(over, new Vector(0, -1));
+ window.MouseWheel(over, new Vector(0, 1));
+ Dispatcher.UIThread.RunJobs();
+ Assert.True(vm.IsBackFace);
+ window.Close();
+ });
+
+ /// <summary>Drag mode: the wheel and another flip key come from the global hook while the drag donut shows files.</summary>
+ [AvaloniaFact]
+ public void In_drag_mode_the_wheel_and_the_set_key_from_the_global_hook_flip_the_donut() =>
+ With(animations: false, back: null, flipKey: "F2", test: () =>
+ {
+ var provider = new TriggerServiceLifecycleTests.DelayedProvider();
+ provider.AllowExit.Set();
+ using var triggers = TriggerServiceLifecycleTests.Create(provider, () => { });
+ triggers.Apply(Store.Settings);
+ 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!;
+ RenderTests.Pump(); // laid out: the drag enters where the donut is
+ var data = new DataTransfer();
+ data.Add(DataTransferItem.CreateFile(window.StorageProvider.TryGetFileFromPathAsync(file).GetAwaiter().GetResult()!));
+ window.DragDrop(new Point(window.Bounds.Width / 2 + 60, window.Bounds.Height / 2), RawDragEventType.DragEnter, data,
+ DragDropEffects.Copy, RawInputModifiers.Control);
+ Dispatcher.UIThread.RunJobs();
+ Assert.True(triggers.WatchFlipKey);
+
+ // Tab isn't the flip key now; F2 is.
+ provider.PostKey(EventType.KeyPressed, KeyCode.VcTab, EventMask.LeftCtrl);
+ Assert.False(TriggerServiceLifecycleTests.Settle(() => vm.IsBackFace));
+ provider.PostKey(EventType.KeyPressed, KeyCode.VcF2, EventMask.LeftCtrl);
+ Assert.True(TriggerServiceLifecycleTests.Settle(() => vm.IsBackFace));
+ provider.PostKey(EventType.KeyReleased, KeyCode.VcF2, EventMask.LeftCtrl);
+
+ // A fast turn of the wheel, many notches: one flip. Sideways scrolling doesn't flip.
+ Thread.Sleep((int)DonutMenu.WheelQuietMs + 50);
+ for (var i = 0; i < 6; i++)
+ provider.PostWheel(-120);
+ Assert.False(TriggerServiceLifecycleTests.Settle(() => vm.IsBackFace));
+ Thread.Sleep((int)DonutMenu.WheelQuietMs + 50);
+ provider.PostWheel(120, MouseWheelScrollDirection.Horizontal);
+ Assert.False(TriggerServiceLifecycleTests.Settle(() => vm.IsBackFace));
+ Thread.Sleep((int)DonutMenu.WheelQuietMs + 50);
+ provider.PostWheel(120);
+ Assert.True(TriggerServiceLifecycleTests.Settle(() => vm.IsBackFace));
+
+ // The wheel switched off in the settings: it is left alone.
+ Store.Settings.Donut.FlipWithWheel = false;
+ triggers.Apply(Store.Settings);
+ Thread.Sleep((int)DonutMenu.WheelQuietMs + 50);
+ provider.PostWheel(-120);
+ Assert.True(TriggerServiceLifecycleTests.Settle(() => vm.IsBackFace));
+
+ radial.Close(animate: false);
+ window.Close();
+ }
+ finally
+ {
+ folder.Delete(recursive: true);
+ }
+ });
+
+ /// <summary>
+ /// Settings → Shortcuts records the flip key: modifiers alone wait for a key; Esc, Enter, Space, the arrows and the
+ /// key of a keyboard shortcut are refused with the reason; another key is saved. "Use Tab", "Clear" and the wheel
+ /// switch are saved too.
+ /// </summary>
+ [AvaloniaTheory]
+ [InlineData("en", false)]
+ [InlineData("ko", false)]
+ [InlineData("ja", true)]
+ public void The_flip_key_is_recorded_and_checked_in_the_shortcut_settings(string language, bool dark) =>
+ With(animations: false, back: null, language: language, test: () =>
+ {
+ var loc = AppHost.Get<ILocalizer>();
+ var theme = AppHost.Get<ThemeService>();
+ var triggersBefore = Store.Settings.Triggers.Select(t => t.Clone()).ToList();
+ Avalonia.Controls.Window? window = null;
+ try
+ {
+ Store.Settings.Triggers.Add(new TriggerGesture { Kind = TriggerKind.KeyChord, Modifiers = Filee.Core.Settings.ModifierKeys.Ctrl, Key = "K" });
+ if (dark)
+ theme.Apply(new ThemeSettings { Mode = ThemeMode.Dark }, language);
+ var page = new TriggersPageViewModel(Store, loc);
+ var flip = page.Flip;
+ Assert.Equal("Tab", flip.KeyText);
+ Assert.True(flip.FlipWithWheel);
+
+ flip.IsRecording = true;
+ Assert.Equal(loc["triggers.recording_key"], flip.KeyText);
+ Assert.False(flip.Record(Key.LeftCtrl)); // waits for a real key
+ Assert.True(flip.IsRecording);
+ foreach (var refused in new[] { Key.Escape, Key.Enter, Key.Space, Key.Left, Key.K })
+ {
+ flip.IsRecording = true;
+ Assert.True(flip.Record(refused));
+ Assert.False(flip.IsRecording);
+ Assert.NotNull(flip.Error);
+ Assert.Equal("Tab", Store.Settings.Donut.FlipKey);
+ }
+ Assert.Equal(loc.Format("triggers.flip_key_taken", "K"), flip.Error);
+
+ window = new Avalonia.Controls.Window
+ {
- Content = new Filee.App.Views.Pages.TriggersPage { DataContext = page }, Width = 820, Height = 1500,
++ Content = new Filee.App.Views.Pages.TriggersPage { DataContext = page },
++ Width = 820,
++ Height = 1500,
+ };
+ window.Show();
+ RenderTests.Pump();
+ Assert.Single(window.GetVisualDescendants().OfType<Avalonia.Controls.Border>(), b => b.Name == "FlipCard");
+ RenderTests.Save(window, $"triggers-flip-refused-{language}{(dark ? "-dark" : "")}.png");
+
+ // Recorded on the button itself, as the user does it.
+ var recorder = window.GetVisualDescendants().OfType<Avalonia.Controls.Primitives.ToggleButton>().Single(b => b.Name == "FlipRecorder");
+ flip.IsRecording = true;
+ recorder.Focus();
+ window.KeyPress(Key.F2, RawInputModifiers.Control, PhysicalKey.F2, null);
+ Dispatcher.UIThread.RunJobs();
+ Assert.False(flip.IsRecording);
+ Assert.Null(flip.Error);
+ Assert.Equal("F2", Store.Settings.Donut.FlipKey);
+ Assert.Equal("F2", flip.KeyText);
+ Assert.Equal("F2", new UserDataStoreProbe(TestServices.DataDirectory).FlipKey); // saved
+ RenderTests.Pump();
+ RenderTests.Save(window, $"triggers-flip-{language}{(dark ? "-dark" : "")}.png");
+
+ var wheel = window.GetVisualDescendants().OfType<Avalonia.Controls.ToggleSwitch>().Single(t => t.Name == "FlipWheel");
+ wheel.IsChecked = false;
+ Assert.False(Store.Settings.Donut.FlipWithWheel);
+ flip.ClearKeyCommand.Execute(null);
+ Assert.Equal("", Store.Settings.Donut.FlipKey);
+ Assert.Equal("—", flip.KeyText);
+ flip.ResetKeyCommand.Execute(null);
+ Assert.Equal("Tab", Store.Settings.Donut.FlipKey);
+ }
+ finally
+ {
+ window?.Close();
+ if (dark)
+ theme.Apply(new ThemeSettings(), language);
+ Store.Settings.Triggers.Clear();
+ Store.Settings.Triggers.AddRange(triggersBefore);
+ Store.Settings.Donut.FlipWithWheel = true;
+ Store.SaveSettings();
+ }
+ });
+
+ /// <summary>The settings as saved on disk, read by a second store.</summary>
+ private sealed class UserDataStoreProbe(string directory)
+ {
+ public string FlipKey { get; } = Load(directory).Settings.Donut.FlipKey;
+
+ private static UserDataStore Load(string directory)
+ {
+ var store = new UserDataStore(directory);
+ store.Load();
+ return store;
+ }
+ }
+
+ /// <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)]
+ [InlineData("ja", 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);
+ // Applying a theme follows the system's animation setting again, and build servers report it off.
+ Motion.Configure(false, () => false);
+ 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)]
+ [InlineData("ja", 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.App.Tests/RenderTests.cs
index c31acd54,40051d06..cf491d1f
--- a/tests/Filee.App.Tests/RenderTests.cs
+++ b/tests/Filee.App.Tests/RenderTests.cs
@@@ -1754,7 -1754,36 +1754,36 @@@ public class RenderTest
notice.Close();
}
+ [AvaloniaTheory]
+ [InlineData("en")]
+ [InlineData("ko")]
+ [InlineData("zh-CN")]
+ public void Extract_live_photo_video_option_renders_and_saves_for_mp4_and_mov_only(string language)
+ {
+ TestServices.EnsureInitialized(language);
+ var preset = Filee.Core.Presets.BuiltInData.MotionPhotoPresets().Single();
+ var vm = new PresetEditorViewModel(preset, AppHost.Get<ILocalizer>());
+ Assert.True(vm.ShowExtractMotionPhoto);
+ Assert.True(vm.ExtractMotionPhoto);
+ var window = new PresetEditorWindow { DataContext = vm, Height = 980 };
+ window.Show();
+ Pump();
+ Save(window, $"preset-extract-motion-{language}.png");
+ window.Close();
+
+ vm.Target = vm.Targets.Single(t => t.Value == "mov");
+ Assert.True(vm.ShowExtractMotionPhoto);
+ Assert.True(vm.Apply());
+ Assert.True(preset.Media.ExtractMotionPhoto);
+ // A box ticked for MP4 and left behind by another target saves nothing.
+ var restored = new PresetEditorViewModel(preset, AppHost.Get<ILocalizer>());
+ restored.Target = restored.Targets.Single(t => t.Value == "webm");
+ Assert.False(restored.ShowExtractMotionPhoto);
+ Assert.True(restored.Apply());
+ Assert.False(preset.Media.ExtractMotionPhoto);
+ }
+
- private static void Pump()
+ internal static void Pump()
{
// Let layout, bindings and a few animation frames run.
for (var i = 0; i < 40; i++)
diff --cc tests/Filee.Core.Tests/BackFaceTests.cs
index 41dc146e,00000000..113fd83b
mode 100644,000000..100644
--- a/tests/Filee.Core.Tests/BackFaceTests.cs
+++ b/tests/Filee.Core.Tests/BackFaceTests.cs
@@@ -1,295 -1,0 +1,295 @@@
- // The back face of a donut (Tab flips the open donut to it): the built-in ones, settings schema 29 that gives existing
++// The back face of a donut (Tab flips the open donut to it): the built-in ones, settings schema 30 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.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()
++ public void Version_29_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.
++ // As written with schema 29: 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-gif");
+ var fronts = profiles.ToDictionary(p => p.Id, p => p.PresetIds.ToList());
+
- Assert.True(SettingsMigrations.ApplyToLibrary(24, presets, profiles));
++ Assert.True(SettingsMigrations.ApplyToLibrary(29, presets, profiles));
+
+ foreach (var profile in profiles.Where(p => p != mine))
+ {
+ 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(29, 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);
++ DropBackFaces(dir, schema: 29);
+
+ 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
++ [InlineData(29)] // the older Filee also saved its settings, with its own schema
++ [InlineData(null)] // it only saved the library: the settings still say 30
+ 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 The_flip_key_and_the_wheel_are_saved_and_older_settings_get_tab_and_the_wheel()
+ {
+ using var dir = new TempDir();
+ var path = Path.Combine(dir.Path, "settings.json");
+ File.WriteAllText(path, """{ "schemaVersion": 24, "donut": { "outerRadius": 180 } }""");
+ var store = NewStore(dir);
+ Assert.Equal("Tab", store.Settings.Donut.FlipKey);
+ Assert.True(store.Settings.Donut.FlipWithWheel);
+ Assert.Equal(180, store.Settings.Donut.OuterRadius);
+
+ store.Settings.Donut.FlipKey = "F2";
+ store.Settings.Donut.FlipWithWheel = false;
+ store.SaveSettings();
+ var reloaded = NewStore(dir);
+ Assert.Equal("F2", reloaded.Settings.Donut.FlipKey);
+ Assert.False(reloaded.Settings.Donut.FlipWithWheel);
+
+ // Cleared: no key, saved as such (not back to Tab).
+ reloaded.Settings.Donut.FlipKey = "";
+ reloaded.SaveSettings();
+ Assert.Null(NewStore(dir).Settings.Donut.EffectiveFlipKey([]));
+ }
+
+ [Theory]
+ [InlineData("Tab", true)]
+ [InlineData("F2", true)]
+ [InlineData("Q", true)]
+ [InlineData("Escape", false)] // closes the donut
+ [InlineData("Enter", false)] // converts / opens a group
+ [InlineData("Space", false)]
+ [InlineData("Left", false)] // moves between slices
+ [InlineData("Backspace", false)] // folds a group's ring
+ [InlineData("K", false)] // the key of a keyboard shortcut below
+ [InlineData("", false)]
+ public void Keys_the_donut_or_a_shortcut_uses_do_not_flip(string key, bool allowed)
+ {
+ TriggerGesture[] gestures =
+ [
+ new() { Kind = TriggerKind.Drag, Modifiers = ModifierKeys.Ctrl },
+ new() { Kind = TriggerKind.KeyChord, Modifiers = ModifierKeys.Ctrl | ModifierKeys.Shift, Key = "K" },
+ ];
+ Assert.Equal(allowed, DonutSettings.IsFlipKeyAllowed(key, gestures));
+ }
+
+ [Fact]
+ public void A_flip_key_that_is_not_allowed_falls_back_to_tab()
+ {
+ TriggerGesture[] chordOnF2 = [new() { Kind = TriggerKind.KeyChord, Key = "F2" }];
+ Assert.Equal("Tab", new DonutSettings { FlipKey = "Escape" }.EffectiveFlipKey([]));
+ Assert.Equal("Tab", new DonutSettings { FlipKey = "F2" }.EffectiveFlipKey(chordOnF2)); // a shortcut took it since
+ Assert.Equal("F2", new DonutSettings { FlipKey = "F2" }.EffectiveFlipKey([]));
+ Assert.Null(new DonutSettings { FlipKey = "Escape" }.EffectiveFlipKey([new() { Kind = TriggerKind.KeyChord, Key = "Tab" }]));
+ }
+
+ [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);
+ }
+}