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.

Reset one built-in donut to its defaults from Settings → Toolbar

KnifeLemona683905aac56
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.json
index df3dd260..24be5ac5 100644
--- a/src/Filee.App/Assets/i18n/en.json
+++ b/src/Filee.App/Assets/i18n/en.json
@@ -300,6 +300,8 @@
"toolbar.add_profile": "New profile",
"toolbar.profile_new": "New profile",
"toolbar.delete_profile": "Delete profile",
+ "toolbar.reset_profile": "Reset to default",
+ "toolbar.reset_profile_confirm": "Reset “{0}” to its default presets and extensions? Your other profiles and presets stay as they are.",
"toolbar.name": "Name",
"toolbar.extensions": "Used for these extensions",
"toolbar.extensions_hint": "Add an extension, e.g. jpg",
diff --git a/src/Filee.App/Assets/i18n/es.json b/src/Filee.App/Assets/i18n/es.json
index a4a7658f..b37f77e9 100644
--- a/src/Filee.App/Assets/i18n/es.json
+++ b/src/Filee.App/Assets/i18n/es.json
@@ -287,6 +287,8 @@
"toolbar.add_profile": "Nuevo perfil",
"toolbar.profile_new": "Nuevo perfil",
"toolbar.delete_profile": "Eliminar perfil",
+ "toolbar.reset_profile": "Restablecer perfil",
+ "toolbar.reset_profile_confirm": "¿Restablecer «{0}» con sus ajustes preestablecidos y extensiones predeterminados? Los demás perfiles y ajustes preestablecidos no cambian.",
"toolbar.name": "Nombre",
"toolbar.extensions": "Usar para estas extensiones",
"toolbar.extensions_hint": "Añade una extensión, p. ej. jpg",
diff --git a/src/Filee.App/Assets/i18n/hi.json b/src/Filee.App/Assets/i18n/hi.json
index cdef7ca9..674e227d 100644
--- a/src/Filee.App/Assets/i18n/hi.json
+++ b/src/Filee.App/Assets/i18n/hi.json
@@ -287,6 +287,8 @@
"toolbar.add_profile": "नई प्रोफ़ाइल",
"toolbar.profile_new": "नई प्रोफ़ाइल",
"toolbar.delete_profile": "प्रोफ़ाइल हटाएँ",
+ "toolbar.reset_profile": "डिफ़ॉल्ट पर रीसेट करें",
+ "toolbar.reset_profile_confirm": "“{0}” के प्रीसेट और एक्सटेंशन डिफ़ॉल्ट पर रीसेट करें? बाकी प्रोफ़ाइल और प्रीसेट जैसे हैं वैसे ही रहेंगे।",
"toolbar.name": "नाम",
"toolbar.extensions": "इन एक्सटेंशन के लिए इस्तेमाल",
"toolbar.extensions_hint": "एक्सटेंशन जोड़ें, जैसे jpg",
diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.json
index e70dfab9..ca3c55d4 100644
--- a/src/Filee.App/Assets/i18n/ko.json
+++ b/src/Filee.App/Assets/i18n/ko.json
@@ -300,6 +300,8 @@
"toolbar.add_profile": "새 프로필",
"toolbar.profile_new": "새 프로필",
"toolbar.delete_profile": "프로필 삭제",
+ "toolbar.reset_profile": "기본값으로 초기화",
+ "toolbar.reset_profile_confirm": "“{0}”의 프리셋과 확장자를 기본값으로 되돌릴까요? 다른 프로필과 프리셋은 그대로예요.",
"toolbar.name": "이름",
"toolbar.extensions": "적용할 확장자",
"toolbar.extensions_hint": "확장자 추가 (예: jpg)",
diff --git a/src/Filee.App/Assets/i18n/pl.json b/src/Filee.App/Assets/i18n/pl.json
index 969fc55b..580bb8bf 100644
--- a/src/Filee.App/Assets/i18n/pl.json
+++ b/src/Filee.App/Assets/i18n/pl.json
@@ -300,6 +300,8 @@
"toolbar.add_profile": "Nowy profil",
"toolbar.profile_new": "Nowy profil",
"toolbar.delete_profile": "Usuń profil",
+ "toolbar.reset_profile": "Przywróć domyślny",
+ "toolbar.reset_profile_confirm": "Przywrócić domyślne ustawienia i rozszerzenia profilu „{0}”? Pozostałe profile i ustawienia się nie zmienią.",
"toolbar.name": "Nazwa",
"toolbar.extensions": "Używany dla tych rozszerzeń",
"toolbar.extensions_hint": "Dodaj rozszerzenie, np. jpg",
diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.json
index 19c10eb3..a0b1fa35 100644
--- a/src/Filee.App/Assets/i18n/zh-CN.json
+++ b/src/Filee.App/Assets/i18n/zh-CN.json
@@ -300,6 +300,8 @@
"toolbar.add_profile": "新建配置",
"toolbar.profile_new": "新配置",
"toolbar.delete_profile": "删除配置",
+ "toolbar.reset_profile": "恢复默认",
+ "toolbar.reset_profile_confirm": "要将“{0}”的预设和扩展名恢复为默认吗?其他配置和预设保持不变。",
"toolbar.name": "名称",
"toolbar.extensions": "适用的扩展名",
"toolbar.extensions_hint": "添加扩展名,例如 jpg",
diff --git a/src/Filee.App/ViewModels/Pages/ToolbarPageViewModel.cs b/src/Filee.App/ViewModels/Pages/ToolbarPageViewModel.cs
index 48220249..86d38769 100644
--- a/src/Filee.App/ViewModels/Pages/ToolbarPageViewModel.cs
+++ b/src/Filee.App/ViewModels/Pages/ToolbarPageViewModel.cs
@@ -94,6 +94,9 @@ public sealed partial class ToolbarPageViewModel : ObservableObject
[ObservableProperty] private bool _canDelete;
+ /// <summary>The selected profile is a built-in donut, which "Reset to default" can put back (a new one can't).</summary>
+ [ObservableProperty] private bool _canReset;
+
/// <summary>Extension chips of a normal profile (null for a mixed one).</summary>
[ObservableProperty] private ExtensionTagsViewModel? _extensionTags;
@@ -176,6 +179,7 @@ public sealed partial class ToolbarPageViewModel : ObservableObject
_loading = false;
CanChangeMixed = profile is not null && !(profile.IsFallback && mixedCount <= 1);
CanDelete = CanChangeMixed;
+ CanReset = profile is not null && _store.CanResetProfile(profile);
ExtensionTags = profile is { IsFallback: false } ? new ExtensionTagsViewModel(profile, _store.Profiles, _loc, _store.SaveLibrary) : null;
MixedExtensions = profile is { IsFallback: true } ? new MixedExtensionsViewModel(profile, _store.Profiles, _loc, _store.SaveLibrary) : null;
}
@@ -310,6 +314,48 @@ public sealed partial class ToolbarPageViewModel : ObservableObject
SelectedProfile = Profiles.FirstOrDefault();
}
+ [RelayCommand]
+ private async Task ResetProfile()
+ {
+ if (SelectedProfile is not { } item || !CanReset || _windows.Main is null)
+ return;
+ if (!await _windows.ConfirmAsync(_windows.Main, _loc.Format("toolbar.reset_profile_confirm", item.Name), destructive: true))
+ return;
+ Reset(item);
+ }
+
+ /// <summary>Puts a built-in profile back to its defaults (see <see cref="UserDataStore.ResetProfile"/>).</summary>
+ internal void Reset(ProfileItemViewModel item)
+ {
+ if (!_store.ResetProfile(item.Profile))
+ return;
+ // A profile that changed kind moved to the border between the normal and the mixed ones.
+ var from = Profiles.IndexOf(item);
+ var to = _store.Profiles.IndexOf(item.Profile);
+ if (from != to)
+ {
+ _repositioning = true;
+ try
+ {
+ Profiles.Move(from, to);
+ SelectedProfile = item;
+ }
+ finally
+ {
+ _repositioning = false;
+ }
+ }
+ _loading = true;
+ ProfileName = _loc.DisplayName(item.Profile);
+ _loading = false;
+ Message = null;
+ // Every profile: the extension hints of the others change with this one's extensions.
+ foreach (var other in Profiles)
+ other.Refresh(_loc);
+ RebuildProfileEditor();
+ Rebuild();
+ }
+
private void Commit()
{
_store.SaveLibrary();
diff --git a/src/Filee.App/Views/Pages/ToolbarPage.axaml b/src/Filee.App/Views/Pages/ToolbarPage.axaml
index 88c238c0..62e7ddb4 100644
--- a/src/Filee.App/Views/Pages/ToolbarPage.axaml
+++ b/src/Filee.App/Views/Pages/ToolbarPage.axaml
@@ -243,8 +243,13 @@
</ContentControl.ContentTemplate>
</ContentControl>
- <Button HorizontalAlignment="Right" Content="{DynamicResource toolbar.delete_profile}" Command="{Binding DeleteProfileCommand}"
- IsVisible="{Binding CanDelete}" />
+ <!-- Only a built-in profile has a default to go back to; the last mixed one can't be deleted. -->
+ <StackPanel x:Name="ProfileActions" Orientation="Horizontal" HorizontalAlignment="Right" Spacing="8">
+ <Button Content="{DynamicResource toolbar.reset_profile}" Command="{Binding ResetProfileCommand}"
+ IsVisible="{Binding CanReset}" />
+ <Button Content="{DynamicResource toolbar.delete_profile}" Command="{Binding DeleteProfileCommand}"
+ IsVisible="{Binding CanDelete}" />
+ </StackPanel>
</StackPanel>
</Border>
diff --git a/src/Filee.Core/Settings/UserDataStore.cs b/src/Filee.Core/Settings/UserDataStore.cs
index 72d44f90..fddcda61 100644
--- a/src/Filee.Core/Settings/UserDataStore.cs
+++ b/src/Filee.Core/Settings/UserDataStore.cs
@@ -136,6 +136,66 @@ public sealed class UserDataStore
SaveLibrary();
}
+ /// <summary>
+ /// Whether <see cref="ResetProfile"/> can put <paramref name="profile"/> back: only a built-in donut has a default
+ /// state, and not when the reset would leave no profile for mixed selections (a built-in normal donut the user made
+ /// the only mixed one).
+ /// </summary>
+ public bool CanResetProfile(ToolbarProfile profile) =>
+ Profiles.Contains(profile)
+ && BuiltInData.CreateProfiles().FirstOrDefault(p => p.Id == profile.Id) is { } builtIn
+ && (builtIn.IsFallback || !profile.IsFallback || Profiles.Count(p => p.IsFallback) > 1);
+
+ /// <summary>
+ /// Puts one built-in donut back as a new library has it (name, slices and their order, extensions, normal or mixed)
+ /// and leaves the other donuts alone. So no file type opens two donuts, an extension another normal donut takes
+ /// now stays there. Presets are shared by every donut: the ones this donut drops stay in the library, edited ones
+ /// keep their settings, and a built-in preset of its default slices that the user deleted comes back. A donut that
+ /// changes kind moves to the border between the normal profiles and the mixed ones, the built-in mixed donut back
+ /// to the head of the mixed ones (the catch-all).
+ /// </summary>
+ /// <returns>False when the profile can't be reset (<see cref="CanResetProfile"/>).</returns>
+ public bool ResetProfile(ToolbarProfile profile)
+ {
+ if (!CanResetProfile(profile))
+ return false;
+ var builtIn = BuiltInData.CreateProfiles().Single(p => p.Id == profile.Id);
+ RestoreBuiltInPresets(builtIn.PresetIds);
+
+ // Extensions checked on a mixed-selection profile only limit that profile; they don't claim files.
+ var claimed = Profiles.Where(p => p != profile && !p.IsFallback)
+ .SelectMany(p => p.Extensions)
+ .ToHashSet(StringComparer.OrdinalIgnoreCase);
+ profile.Name = "";
+ profile.NameKey = builtIn.NameKey;
+ profile.Extensions = builtIn.IsFallback ? builtIn.Extensions : builtIn.Extensions.Where(e => !claimed.Contains(e)).ToList();
+ profile.PresetIds = builtIn.PresetIds;
+ if (profile.IsFallback != builtIn.IsFallback)
+ {
+ profile.IsFallback = builtIn.IsFallback;
+ Profiles.Remove(profile);
+ var index = Profiles.FindIndex(p => p.IsFallback);
+ Profiles.Insert(index < 0 ? Profiles.Count : index, profile);
+ }
+ SaveLibrary();
+ return true;
+ }
+
+ /// <summary>Adds back the built-in presets among <paramref name="ids"/> that the library no longer has, each after
+ /// the built-in preset before it (as a new library orders them).</summary>
+ private void RestoreBuiltInPresets(IEnumerable<string> ids)
+ {
+ var defaults = BuiltInData.CreatePresets();
+ foreach (var id in ids.Where(id => FindPreset(id) is null))
+ {
+ var at = defaults.FindIndex(p => p.Id == id);
+ if (at < 0)
+ continue;
+ var after = defaults.Take(at).Select(p => Presets.FindIndex(existing => existing.Id == p.Id)).LastOrDefault(i => i >= 0, -1);
+ Presets.Insert(after + 1, defaults[at]);
+ }
+ }
+
public Preset? FindPreset(string id) => Presets.FirstOrDefault(p => p.Id == id);
/// <summary>The preset <paramref name="id"/> when it converts (a group doesn't), for every place that runs one.</summary>
diff --git a/tests/Filee.App.Tests/RenderTests.cs b/tests/Filee.App.Tests/RenderTests.cs
index e398335e..f31a4871 100644
--- a/tests/Filee.App.Tests/RenderTests.cs
+++ b/tests/Filee.App.Tests/RenderTests.cs
@@ -305,6 +305,58 @@ public class RenderTests
}
}
+ [AvaloniaTheory]
+ [InlineData("en")]
+ [InlineData("es")]
+ [InlineData("ko")]
+ [InlineData("hi")]
+ public void Reset_to_default_sits_beside_delete_for_a_built_in_profile_only(string language)
+ {
+ TestServices.EnsureInitialized(language);
+ var store = AppHost.Get<UserDataStore>();
+ var profiles = store.Profiles.Select(p => p.Clone()).ToList();
+ try
+ {
+ var vm = new MainWindowViewModel(AppHost.Services, AppHost.Get<Filee.Core.Localization.ILocalizer>(), AppHost.Get<UpdateService>());
+ vm.Navigate("toolbar");
+ var page = (ToolbarPageViewModel)vm.CurrentPage!;
+ var window = new MainWindow { DataContext = vm, Width = 1080, Height = 820 };
+ window.Show();
+ page.SelectedProfile = page.Profiles.Single(p => p.Profile.Id == "images");
+ Pump();
+
+ var actions = window.GetVisualDescendants().OfType<StackPanel>().Single(s => s.Name == "ProfileActions");
+ var reset = (Button)actions.Children[0];
+ var delete = (Button)actions.Children[1];
+ Assert.Same(page.ResetProfileCommand, reset.Command);
+ Assert.Same(page.DeleteProfileCommand, delete.Command);
+ Assert.True(reset.IsVisible && delete.IsVisible);
+ // On one row, reset first, both inside the profile card.
+ var card = window.GetVisualDescendants().OfType<Border>().Single(b => b.Name == "ProfileCard");
+ var resetBox = Avalonia.VisualExtensions.TranslatePoint(reset, default, card)!.Value;
+ var deleteBox = Avalonia.VisualExtensions.TranslatePoint(delete, default, card)!.Value;
+ Assert.Equal(resetBox.Y, deleteBox.Y);
+ Assert.True(resetBox.X + reset.Bounds.Width < deleteBox.X);
+ Assert.True(resetBox.X >= 0 && deleteBox.X + delete.Bounds.Width <= card.Bounds.Width);
+ actions.BringIntoView();
+ Pump();
+ Save(window, $"toolbar-reset-profile-{language}.png");
+
+ // A profile the user made has no default: only delete.
+ page.AddProfileCommand.Execute(null);
+ Pump();
+ Assert.False(reset.IsVisible);
+ Assert.True(delete.IsVisible);
+ window.Close();
+ }
+ finally
+ {
+ store.Profiles.Clear();
+ store.Profiles.AddRange(profiles);
+ store.SaveLibrary();
+ }
+ }
+
[AvaloniaFact]
public void Dragging_a_preset_opens_a_gap_with_a_preview_slice()
{
diff --git a/tests/Filee.App.Tests/ToolbarEditorTests.cs b/tests/Filee.App.Tests/ToolbarEditorTests.cs
index 92c30703..dd458674 100644
--- a/tests/Filee.App.Tests/ToolbarEditorTests.cs
+++ b/tests/Filee.App.Tests/ToolbarEditorTests.cs
@@ -268,6 +268,56 @@ public class ToolbarPageTests
}
}
+ [AvaloniaFact]
+ public void Reset_puts_a_built_in_profile_back_and_the_list_follows()
+ {
+ TestServices.EnsureInitialized("en");
+ var store = AppHost.Get<UserDataStore>();
+ var presets = store.Presets.ToList();
+ var profiles = store.Profiles.Select(p => p.Clone()).ToList();
+ try
+ {
+ var vm = new ToolbarPageViewModel(store, AppHost.Get<Filee.Core.Localization.ILocalizer>(), AppHost.Get<WindowService>());
+ var item = vm.Profiles.Single(p => p.Profile.Id == "images");
+ vm.SelectedProfile = item;
+ Assert.True(vm.CanReset);
+ vm.ProfileName = "Pictures";
+ vm.RemoveAt(0);
+ vm.IsMixed = true; // moves behind "Mixed files"
+ Assert.Same(item.Profile, store.Profiles[^1]);
+
+ vm.Reset(item);
+
+ var builtIn = Filee.Core.Presets.BuiltInData.CreateProfiles().Single(p => p.Id == "images");
+ Assert.Same(item, vm.SelectedProfile);
+ Assert.Equal("Images", item.Name);
+ Assert.Equal("Images", vm.ProfileName);
+ Assert.Equal("Images", vm.CenterTitle);
+ Assert.False(vm.IsMixed);
+ Assert.NotNull(vm.ExtensionTags);
+ Assert.Equal(builtIn.PresetIds, vm.DonutItems.Select(d => d.Id));
+ Assert.Equal($"{builtIn.PresetIds.Count}", item.Count);
+ Assert.Equal(store.Profiles.Select(p => p.Id), vm.Profiles.Select(p => p.Profile.Id));
+ Assert.Equal(store.Profiles.FindIndex(p => p.IsFallback) - 1, store.Profiles.IndexOf(item.Profile));
+
+ // A new profile has nothing to go back to.
+ vm.AddProfileCommand.Execute(null);
+ Assert.False(vm.CanReset);
+ Assert.True(vm.CanDelete);
+ var mine = vm.SelectedProfile!;
+ vm.Reset(mine);
+ Assert.Equal("New profile", mine.Name);
+ }
+ finally
+ {
+ store.Presets.Clear();
+ store.Presets.AddRange(presets);
+ store.Profiles.Clear();
+ store.Profiles.AddRange(profiles);
+ store.SaveLibrary();
+ }
+ }
+
[AvaloniaFact]
public void The_last_mixed_profile_stays_mixed()
{
diff --git a/tests/Filee.Core.Tests/ProfileResetTests.cs b/tests/Filee.Core.Tests/ProfileResetTests.cs
new file mode 100644
index 00000000..248c7ac5
--- /dev/null
+++ b/tests/Filee.Core.Tests/ProfileResetTests.cs
@@ -0,0 +1,178 @@
+// "Reset to default" of one donut (Settings → Toolbar): the built-in state of that profile only.
+
+using Filee.Core.Presets;
+using Filee.Core.Profiles;
+using Filee.Core.Settings;
+
+namespace Filee.Core.Tests;
+
+public class ProfileResetTests
+{
+ 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);
+
+ [Fact]
+ public void A_built_in_donut_gets_its_name_slices_and_extensions_back_and_the_others_stay()
+ {
+ using var dir = new TempDir();
+ var store = NewStore(dir);
+ var images = Profile(store, "images");
+ images.Name = "My pictures";
+ images.PresetIds = ["to-webp", "to-png"];
+ images.Extensions.Remove("png");
+ images.Extensions.Add("xyz");
+ var pdf = Profile(store, "pdf");
+ pdf.Name = "Papers";
+ pdf.PresetIds.RemoveAt(0);
+ pdf.Extensions.Add("abc");
+ store.SaveLibrary();
+ var before = store.Profiles.Where(p => p.Id != "images").Select(p => p.Clone()).ToList();
+ var order = store.Profiles.Select(p => p.Id).ToList();
+
+ Assert.True(store.CanResetProfile(images));
+ Assert.True(store.ResetProfile(images));
+
+ var builtIn = BuiltIn("images");
+ Assert.Equal("", images.Name);
+ Assert.Equal(builtIn.NameKey, images.NameKey);
+ Assert.Equal(builtIn.PresetIds, images.PresetIds);
+ Assert.Equal(builtIn.Extensions, images.Extensions);
+ Assert.False(images.IsFallback);
+ // Every other donut as it was, the list in the same order.
+ Assert.Equal(order, store.Profiles.Select(p => p.Id));
+ foreach (var other in before)
+ {
+ var now = Profile(store, other.Id);
+ Assert.Equal(other.Name, now.Name);
+ Assert.Equal(other.PresetIds, now.PresetIds);
+ Assert.Equal(other.Extensions, now.Extensions);
+ Assert.Equal(other.IsFallback, now.IsFallback);
+ }
+
+ // Saved.
+ var reloaded = NewStore(dir);
+ Assert.Equal(builtIn.PresetIds, Profile(reloaded, "images").PresetIds);
+ Assert.Equal("", Profile(reloaded, "images").Name);
+ Assert.Equal("Papers", Profile(reloaded, "pdf").Name);
+ }
+
+ [Fact]
+ public void An_extension_another_donut_took_stays_there()
+ {
+ using var dir = new TempDir();
+ var store = NewStore(dir);
+ var images = Profile(store, "images");
+ images.Extensions.Remove("png");
+ var mine = new ToolbarProfile { Id = "mine", Name = "Screenshots", Extensions = ["PNG"], PresetIds = ["to-jpg"] };
+ store.Profiles.Insert(0, mine);
+ // Checked on a mixed profile, an extension only limits that profile: the reset still takes it.
+ Profile(store, "mixed").Extensions.Add("jpg");
+ store.SaveLibrary();
+
+ Assert.True(store.ResetProfile(images));
+
+ Assert.DoesNotContain("png", images.Extensions, StringComparer.OrdinalIgnoreCase);
+ Assert.Contains("jpg", images.Extensions);
+ Assert.Equal(BuiltIn("images").Extensions.Where(e => e != "png"), images.Extensions);
+ Assert.Equal(["PNG"], mine.Extensions);
+ Assert.Equal(["jpg"], Profile(store, "mixed").Extensions);
+ // No file type opens two normal donuts.
+ var normal = store.Profiles.Where(p => !p.IsFallback).SelectMany(p => p.Extensions).ToList();
+ Assert.Equal(normal.Count, normal.Distinct(StringComparer.OrdinalIgnoreCase).Count());
+ }
+
+ [Fact]
+ public void Presets_stay_in_the_library_and_a_deleted_built_in_one_comes_back()
+ {
+ using var dir = new TempDir();
+ var store = NewStore(dir);
+ store.Presets.Add(new Preset { Id = "mine", Name = "Mine", TargetFormat = "webp" });
+ store.FindPreset("to-png")!.Image.Quality = 42;
+ var images = Profile(store, "images");
+ images.PresetIds = ["mine", "to-png"];
+ // Deleted from the library, and so from every donut.
+ var tiff = store.Presets.FindIndex(p => p.Id == "to-tiff");
+ var after = store.Presets[tiff - 1].Id;
+ store.Presets.RemoveAt(tiff);
+ store.SaveLibrary();
+ Assert.DoesNotContain("to-tiff", images.PresetIds);
+
+ Assert.True(store.ResetProfile(images));
+
+ Assert.Equal(BuiltIn("images").PresetIds, images.PresetIds);
+ Assert.NotNull(store.FindPreset("mine")); // off this donut, still in the library
+ Assert.Equal(42, store.FindPreset("to-png")!.Image.Quality); // an edited preset keeps its settings
+ Assert.Equal(store.Presets.FindIndex(p => p.Id == after) + 1, store.Presets.FindIndex(p => p.Id == "to-tiff"));
+ Assert.Equal(store.Presets.Count, store.Presets.Select(p => p.Id).Distinct().Count());
+ Assert.Contains("to-tiff", NewStore(dir).Profiles.Single(p => p.Id == "images").PresetIds);
+ }
+
+ [Fact]
+ public void A_profile_the_user_made_has_no_default_to_go_back_to()
+ {
+ using var dir = new TempDir();
+ var store = NewStore(dir);
+ var mine = new ToolbarProfile { Name = "Mine", Extensions = ["png"], PresetIds = ["to-jpg"] };
+ store.Profiles.Insert(0, mine);
+ store.SaveLibrary();
+
+ Assert.False(store.CanResetProfile(mine));
+ Assert.False(store.ResetProfile(mine));
+ Assert.Equal("Mine", mine.Name);
+ Assert.Equal(["png"], mine.Extensions);
+ Assert.Equal(["to-jpg"], mine.PresetIds);
+ // Nor one that isn't in the library (any more).
+ Assert.False(store.CanResetProfile(BuiltIn("images")));
+ }
+
+ [Fact]
+ public void A_donut_that_changed_kind_goes_back_to_its_place()
+ {
+ using var dir = new TempDir();
+ var store = NewStore(dir);
+ var images = Profile(store, "images");
+ var mixed = Profile(store, "mixed");
+ // "Images" made mixed (it moves behind "Mixed files"), "Mixed files" made normal.
+ images.IsFallback = true;
+ store.Profiles.Remove(images);
+ store.Profiles.Add(images);
+ mixed.IsFallback = false;
+ mixed.Extensions = ["png"];
+ store.SaveLibrary();
+
+ Assert.True(store.ResetProfile(mixed));
+ Assert.True(mixed.IsFallback);
+ Assert.Empty(mixed.Extensions);
+ Assert.Same(mixed, ProfileSelector.CatchAll(store.Profiles)); // the head of the mixed ones again
+
+ Assert.True(store.ResetProfile(images));
+ Assert.False(images.IsFallback);
+ // Normal profiles first: right before the mixed ones.
+ Assert.Equal(store.Profiles.FindIndex(p => p.IsFallback) - 1, store.Profiles.IndexOf(images));
+ Assert.All(store.Profiles.SkipWhile(p => !p.IsFallback), p => Assert.True(p.IsFallback));
+ }
+
+ [Fact]
+ public void The_only_mixed_profile_is_not_reset_into_a_normal_one()
+ {
+ using var dir = new TempDir();
+ var store = NewStore(dir);
+ var images = Profile(store, "images");
+ images.IsFallback = true;
+ store.Profiles.Remove(Profile(store, "mixed"));
+ store.SaveLibrary();
+ Assert.Single(store.Profiles, p => p.IsFallback);
+
+ Assert.False(store.CanResetProfile(images));
+ Assert.False(store.ResetProfile(images));
+ Assert.True(images.IsFallback);
+ }
+}