diff --git a/src/Chronos.App/Sections/SettingsView.xaml b/src/Chronos.App/Sections/SettingsView.xaml
index cef31194..1f4641f6 100644
--- a/src/Chronos.App/Sections/SettingsView.xaml
+++ b/src/Chronos.App/Sections/SettingsView.xaml
@@ -520,32 +520,80 @@
-
+
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Chronos.App/Sections/SettingsViewModel.cs b/src/Chronos.App/Sections/SettingsViewModel.cs
index 065a9dab..1035379d 100644
--- a/src/Chronos.App/Sections/SettingsViewModel.cs
+++ b/src/Chronos.App/Sections/SettingsViewModel.cs
@@ -87,7 +87,9 @@ public sealed class SettingsViewModel : SectionViewModel
"Settings.Rendering.Hardware", "Settings.Rendering.Encoders"]),
new(SettingsPage.Formats, ["Settings.Formats.Title", "Settings.Formats.Column.Tier", "Settings.Formats.Install"]),
new(SettingsPage.Storage, ["Settings.Storage.Folder", "Settings.Storage.Thumbnails", "Settings.Storage.Limit"]),
- new(SettingsPage.Workspace, ["Settings.Workspace.Folder", "Settings.Workspace.Sync", "Settings.Workspace.AfterSave", "Settings.Workspace.Kept"]),
+ new(SettingsPage.Workspace, ["Settings.Workspace.Folder", "Settings.Workspace.Move", "Settings.Workspace.SizeLimit", "Settings.Workspace.DefaultMedia",
+ "Settings.Workspace.Sync", "Settings.Workspace.AfterSave", "Settings.Workspace.VersionOnRender", "Settings.Workspace.SaveBeforeRender",
+ "Settings.Workspace.Kept", "Settings.Workspace.CleanAfter", "Settings.Workspace.OpenProject", "Settings.Workspace.Trash"]),
new(SettingsPage.Server, ["Settings.Server.Default", "Settings.Server.RenderNode", "Settings.Server.Certificates"]),
new(SettingsPage.Updates, ["Settings.General.CheckOnStart", "Settings.Updates.Latest", "About.Update.Check", "About.Releases"]),
new(SettingsPage.Advanced, ["Settings.Advanced.DataFolder", "Settings.Advanced.Logs", "Settings.Advanced.LogLevel", "Settings.Advanced.KeepLogs",
@@ -169,7 +171,9 @@ public sealed class SettingsViewModel : SectionViewModel
Logs = new LogSettingsRows(_s, Save);
// ---- Workspace ----
- WorkspaceRows = new WorkspaceSettingsRows(_s, Save, () => AppEnvironment.Shown(Shell.Services.Workspace.Root), OpenWorkspaceFolder, ChangeWorkspaceFolderAsync);
+ WorkspaceRows = new WorkspaceSettingsRows(_s, Save, () => AppEnvironment.Shown(Shell.Services.Workspace.Root), OpenWorkspaceFolder, ChangeWorkspaceFolderAsync,
+ WorkspaceSettingsServices.For(Shell.Services.Workspace, Shell.Services.Dialogs, (title, message, isError) => Shell.Notify(title, message, isError: isError),
+ MoveWorkspaceFolderAsync));
// ---- Storage ----
// A capture shows its folders under a sample data folder; what is typed is taken back to the folder it stands for.
@@ -259,6 +263,7 @@ public sealed class SettingsViewModel : SectionViewModel
if (value == SettingsPage.Rendering && Encoders.Count == 0 && !_isDetecting) _ = DetectEncodersAsync();
if (value == SettingsPage.Formats && Formats.Count == 0 && !_isDetectingFormats) _ = DetectFormatsAsync(refresh: false);
if (value == SettingsPage.Storage) _ = UpdateCacheUsageAsync();
+ if (value == SettingsPage.Workspace) _ = WorkspaceRows.MeasureAsync();
if (value == SettingsPage.Advanced) LoadBackups();
}
}
@@ -726,7 +731,10 @@ public sealed class SettingsViewModel : SectionViewModel
// ---------------- Workspace ----------------
- /// Settings › Workspace (owner review 2, R8): the folder, Sync automatically and Kept versions.
+ ///
+ /// Settings › Workspace (owner review 2, R8; phase 5c): the folder (Change, Move…, what it takes), Size limit, Default
+ /// media, Sync automatically, Version on render, Kept versions, Clean after, Open project and Trash.
+ ///
public WorkspaceSettingsRows WorkspaceRows { get; }
/// Shows the workspace folder in Explorer (made, with its manifest, when the workspace was never used).
@@ -747,6 +755,14 @@ public sealed class SettingsViewModel : SectionViewModel
{
await WorkspaceFolderChange.ChooseAsync(Shell);
WorkspaceRows.Refresh();
+ await WorkspaceRows.MeasureAsync();
+ }
+
+ /// The workspace folder moved with its projects, after its plan: the move job takes them, and Edit waits for it.
+ private async Task MoveWorkspaceFolderAsync()
+ {
+ await WorkspaceFolderChange.MoveAsync(Shell);
+ WorkspaceRows.Refresh();
}
// ---------------- Server ----------------
diff --git a/src/Chronos.App/Settings/WorkspaceSettingsRows.cs b/src/Chronos.App/Settings/WorkspaceSettingsRows.cs
index ae154743..52b83d4e 100644
--- a/src/Chronos.App/Settings/WorkspaceSettingsRows.cs
+++ b/src/Chronos.App/Settings/WorkspaceSettingsRows.cs
@@ -1,20 +1,89 @@
+using System.Globalization;
+using System.IO;
+using Chronos.App.Archiving;
using Chronos.App.Infrastructure;
+using Chronos.App.Shell;
+using Chronos.App.Workspace;
+using Chronos.Core.Diagnostics;
using Chronos.Core.Localization;
+using Chronos.Core.Project;
using Chronos.Ui.Mvvm;
namespace Chronos.App.Settings;
///
-/// Settings › Workspace (owner review 2, R8): the workspace folder (shown with Open, and Change, which uses another
-/// folder after a plan without moving anything; moving it with its projects comes with phase 5c), Sync automatically (a version saved is sent to its home at once, and the home's
-/// new versions taken; on by default) and Kept versions (the versions taken from the home a project keeps in the
-/// workspace besides its base and those not sent; 20 by default). Each choice is stored and saved at once. A value set
-/// elsewhere (an imported or hand-edited settings file) is listed with the presets; one below 1 is shown as 1, as the
-/// workspace applies it.
+/// What Settings › Workspace reaches beyond the settings file (phase 5c): what the workspace takes of its drive, the plan
+/// and emptying of its trash, the move of its folder with its projects, and the shell's confirmation and toasts. The app
+/// takes them from (); tests give their own.
///
-public sealed class WorkspaceSettingsRows(AppSettings settings, Action save, Func folder, Action open, Func? change = null) : ObservableObject
+public sealed class WorkspaceSettingsServices
+{
+ /// What the workspace takes of its drive ().
+ public required Func> Usage { get; init; }
+
+ /// The plan of emptying the workspace's trash ().
+ public required Func> PlanTrash { get; init; }
+
+ /// Erases the entries of a confirmed plan ().
+ public required Func> EmptyTrash { get; init; }
+
+ /// Asks a confirmation; true when the user chose the action.
+ public required Func Confirm { get; init; }
+
+ /// Shows a toast: its title, its message, and whether it tells of something that did not happen.
+ public required Action Notify { get; init; }
+
+ /// Picks a folder, shows the move's plan and queues it (); null where the folder cannot move.
+ public Func? Move { get; init; }
+
+ /// A move of the workspace folder is queued or running ().
+ public Func IsMoving { get; init; } = () => false;
+
+ /// The workspace's own operations, with the shell's and toasts ().
+ public static WorkspaceSettingsServices For(WorkspaceHost host, IAppDialogs dialogs, Action notify, Func? move)
+ {
+ ArgumentNullException.ThrowIfNull(host);
+ ArgumentNullException.ThrowIfNull(dialogs);
+ ArgumentNullException.ThrowIfNull(notify);
+ return new WorkspaceSettingsServices
+ {
+ Usage = host.UsageAsync,
+ PlanTrash = host.PlanTrashAsync,
+ EmptyTrash = host.EmptyTrashAsync,
+ Confirm = dialogs.Confirm,
+ Notify = notify,
+ Move = move,
+ IsMoving = () => host.IsMoving,
+ };
+ }
+}
+
+///
+/// Settings › Workspace (owner review 2, R8; completed in phase 5c), its rows in order: the folder (shown with Open; Change,
+/// which uses another folder after a plan without moving anything; Move…, which takes the projects along after its plan;
+/// and what the folder takes of its drive), Size limit (past it the clean-up removes the media of the projects used longest
+/// ago; 100 GB by default), Default media (what Open in workspace copies; proxies by default), Sync automatically (a version
+/// saved is sent to its home at once, and the home's new versions taken; on by default), Version on render (a render of
+/// changes not saved as a version saves one first; on by default), Kept versions (the versions taken from the home a project
+/// keeps in the workspace besides its base and those not sent; 20 by default), Clean after (the media of a project not opened
+/// for so long are removed; 30 days by default), Open project (which project Edit opens for a sequence with several; the last
+/// used by default) and Trash (what it holds, and Empty…, which erases it after its plan and the typed number of its entries).
+/// Each choice is stored and saved at once. A value set elsewhere (an imported or hand-edited settings file) is listed with
+/// the presets; a size limit or clean-up age below 1 is shown as none, as the clean-up applies it, and kept versions below 1
+/// as the 1 the workspace keeps.
+///
+public sealed class WorkspaceSettingsRows(AppSettings settings, Action save, Func folder, Action open, Func? change = null,
+ WorkspaceSettingsServices? services = null) : ObservableObject
{
public static readonly int[] KeptPresets = [5, 10, 20, 50, 100, 200];
+ public static readonly int[] SizeLimitPresets = [25, 50, 100, 200, 500, 1000];
+ public static readonly int[] CleanAfterPresets = [7, 14, 30, 60, 90];
+
+ private WorkspaceUsage? _usage;
+ private bool _isMeasuring;
+ private CancellationTokenSource? _measure;
+
+ // ---------------- Folder ----------------
/// The workspace folder in use.
public string Folder => folder();
@@ -22,11 +91,73 @@ public sealed class WorkspaceSettingsRows(AppSettings settings, Action save, Fun
/// Shows the folder in Explorer.
public RelayCommand OpenCommand { get; } = new(open);
- /// Uses another folder, after its plan (WorkspaceFolderChange); none where the folder cannot change.
- public AsyncRelayCommand ChangeCommand { get; } = new(change ?? (() => Task.CompletedTask), () => change is not null);
+ /// Uses another folder, after its plan (WorkspaceFolderChange); none where the folder cannot change, nor while it moves.
+ public AsyncRelayCommand ChangeCommand { get; } = new(change ?? (() => Task.CompletedTask), () => change is not null && !(services?.IsMoving() ?? false));
public bool CanChange => change is not null;
+ /// Moves the folder with its projects, after its plan (WorkspaceFolderChange.MoveAsync); none where it cannot move, nor while it moves.
+ public AsyncRelayCommand MoveCommand { get; } = new(services?.Move ?? (() => Task.CompletedTask), () => services?.Move is not null && !services.IsMoving());
+
+ public bool CanMove => services?.Move is not null;
+
+ /// The move button's tooltip: what it does, or that a move is under way.
+ public string MoveToolTip => IsMoving ? Loc.L("Errors.Workspace.Moving") : Loc.L("Tooltips.Settings.Workspace.Move");
+
+ /// "12.4 GB used" (the whole folder, its trash included); "Measuring…" meanwhile; null before the first measure or when it failed.
+ public string? UsageText =>
+ _isMeasuring ? Loc.L("Settings.Workspace.Measuring")
+ : _usage is { } usage ? Loc.L("Settings.Workspace.Used", Formatting.Bytes(usage.TotalBytes))
+ : null;
+
+ /// The usage line shows.
+ public bool HasUsageText => UsageText is not null;
+
+ public bool IsMeasuring => _isMeasuring;
+
+ // ---------------- Size limit ----------------
+
+ /// The presets in GB, a value set elsewhere among them, then No limit (0).
+ public IReadOnlyList> SizeLimitChoices =>
+ [
+ .. With(SizeLimitPresets, SizeLimit).Where(n => n > 0).Select(n => new SettingsOption(n, Loc.L("Common.Size.GB", Formatting.Count(n)))),
+ new(0, Loc.L("Settings.Workspace.NoLimit")),
+ ];
+
+ public SettingsOption SelectedSizeLimit
+ {
+ get => SizeLimitChoices.First(c => c.Value == SizeLimit);
+ set
+ {
+ if (Store(value, settings.WorkspaceSizeLimitGb, v => settings.WorkspaceSizeLimitGb = v)) Raise(nameof(SizeLimitChoices), nameof(SelectedSizeLimit), nameof(SizeLimitToolTip));
+ }
+ }
+
+ /// What the limit chosen does: removes the oldest media past it, or nothing at all.
+ public string SizeLimitToolTip => Loc.L(SizeLimit == 0 ? "Tooltips.Settings.Workspace.NoLimit" : "Tooltips.Settings.Workspace.SizeLimit");
+
+ // ---------------- Default media ----------------
+
+ public bool IsDefaultProxies
+ {
+ get => !IsOriginalsDefault;
+ set
+ {
+ if (value) SetDefaultMedia(BundleMedia.Proxies);
+ }
+ }
+
+ public bool IsDefaultOriginals
+ {
+ get => IsOriginalsDefault;
+ set
+ {
+ if (value) SetDefaultMedia(BundleMedia.Originals);
+ }
+ }
+
+ // ---------------- Sync automatically ----------------
+
public bool AutoSync
{
get => settings.WorkspaceAutoSync;
@@ -39,34 +170,276 @@ public sealed class WorkspaceSettingsRows(AppSettings settings, Action save, Fun
}
}
+ // ---------------- Version on render ----------------
+
+ public bool VersionOnRender
+ {
+ get => settings.WorkspaceVersionOnRender;
+ set
+ {
+ if (settings.WorkspaceVersionOnRender == value) return;
+ settings.WorkspaceVersionOnRender = value;
+ save();
+ OnPropertyChanged();
+ }
+ }
+
+ // ---------------- Kept versions ----------------
+
public IReadOnlyList> KeptChoices =>
- [.. (KeptPresets.Contains(Kept) ? KeptPresets : KeptPresets.Append(Kept)).Order().Select(n => new SettingsOption(n, Loc.Plural("Settings.Workspace.Versions", n)))];
+ [.. With(KeptPresets, Kept).Select(n => new SettingsOption(n, Loc.Plural("Settings.Workspace.Versions", n)))];
public SettingsOption SelectedKept
{
get => KeptChoices.First(c => c.Value == Kept);
set
{
- if (value is null || value.Value == settings.WorkspaceKeptVersions) return;
- settings.WorkspaceKeptVersions = value.Value;
- save();
- OnPropertyChanged(nameof(KeptChoices));
- OnPropertyChanged();
+ if (Store(value, settings.WorkspaceKeptVersions, v => settings.WorkspaceKeptVersions = v)) Raise(nameof(KeptChoices), nameof(SelectedKept));
}
}
- /// The defaults of every row (Reset section); the caller saves. The folder stays (Change chooses it, after its plan).
+ // ---------------- Clean after ----------------
+
+ /// The presets in days, a value set elsewhere among them, then Never (0).
+ public IReadOnlyList> CleanAfterChoices =>
+ [
+ .. With(CleanAfterPresets, CleanAfter).Where(n => n > 0).Select(n => new SettingsOption(n, Loc.Plural("Settings.Workspace.Days", n))),
+ new(0, Loc.L("Settings.Workspace.Never")),
+ ];
+
+ public SettingsOption SelectedCleanAfter
+ {
+ get => CleanAfterChoices.First(c => c.Value == CleanAfter);
+ set
+ {
+ if (Store(value, settings.WorkspaceCleanAfterDays, v => settings.WorkspaceCleanAfterDays = v)) Raise(nameof(CleanAfterChoices), nameof(SelectedCleanAfter), nameof(CleanAfterToolTip));
+ }
+ }
+
+ /// What the age chosen does: removes the media of projects not opened so long, or never.
+ public string CleanAfterToolTip => Loc.L(CleanAfter == 0 ? "Tooltips.Settings.Workspace.Never" : "Tooltips.Settings.Workspace.CleanAfter");
+
+ // ---------------- Open project ----------------
+
+ public bool IsOpenLastUsed
+ {
+ get => settings.WorkspaceOpenProject == WorkspaceOpenPolicy.LastUsed || !Enum.IsDefined(settings.WorkspaceOpenProject);
+ set
+ {
+ if (value) SetOpenProject(WorkspaceOpenPolicy.LastUsed);
+ }
+ }
+
+ public bool IsOpenMain
+ {
+ get => settings.WorkspaceOpenProject == WorkspaceOpenPolicy.Main;
+ set
+ {
+ if (value) SetOpenProject(WorkspaceOpenPolicy.Main);
+ }
+ }
+
+ public bool IsOpenAsk
+ {
+ get => settings.WorkspaceOpenProject == WorkspaceOpenPolicy.Ask;
+ set
+ {
+ if (value) SetOpenProject(WorkspaceOpenPolicy.Ask);
+ }
+ }
+
+ // ---------------- Trash ----------------
+
+ /// "3 items, 1.2 GB", "Nothing in trash", "Measuring…" meanwhile; null before the first measure or when it failed.
+ public string? TrashText =>
+ _isMeasuring ? Loc.L("Settings.Workspace.Measuring")
+ : _usage is not { } usage ? null
+ : usage.TrashItems == 0 ? Loc.L("Settings.Workspace.TrashIsEmpty")
+ : Loc.Plural("Settings.Workspace.TrashItems", usage.TrashItems, Formatting.Bytes(usage.TrashBytes));
+
+ /// The trash holds something, as measured last: Empty… is enabled.
+ public bool HasTrash => _usage is { TrashItems: > 0 };
+
+ /// Lists the trash, asks for the typed number of its entries, then erases them ().
+ public AsyncRelayCommand EmptyTrashCommand => _emptyTrash ??= new AsyncRelayCommand((_, token) => EmptyTrashAsync(token), _ => services is not null && HasTrash && !_isMeasuring);
+
+ private AsyncRelayCommand? _emptyTrash;
+
+ /// Empty…'s tooltip: what it does, or that there is nothing to erase.
+ public string EmptyTrashToolTip => Loc.L(HasTrash ? "Tooltips.Settings.Workspace.EmptyTrash" : "Tooltips.Settings.Workspace.EmptyTrash.Disabled");
+
+ ///
+ /// Measures what the workspace takes of its drive and what its trash holds (the page shown, after Empty…, Change and Move);
+ /// a measure started meanwhile replaces this one.
+ ///
+ public async Task MeasureAsync()
+ {
+ if (services is null) return;
+ _measure?.Cancel();
+ using var measure = new CancellationTokenSource();
+ _measure = measure;
+ SetMeasuring(true);
+ try
+ {
+ var usage = await services.Usage(measure.Token);
+ if (_measure == measure) _usage = usage;
+ }
+ catch (OperationCanceledException) when (measure.IsCancellationRequested)
+ {
+ // A newer measure took over.
+ }
+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
+ {
+ Log.Warning("workspace", "The workspace folder could not be measured", ex);
+ if (_measure == measure) _usage = null;
+ }
+ finally
+ {
+ if (_measure == measure)
+ {
+ _measure = null;
+ SetMeasuring(false);
+ }
+ }
+ }
+
+ ///
+ /// Empty…: the trash's plan (nothing erased), its confirmation with the number of entries typed
+ /// (), then the entries of exactly that plan erased, refused when the trash changed since. The
+ /// result is told in a toast, and the trash measured again.
+ ///
+ public async Task EmptyTrashAsync(CancellationToken cancellationToken = default)
+ {
+ if (services is null) return;
+ try
+ {
+ var plan = await services.PlanTrash(cancellationToken);
+ if (TrashRequest(plan) is not { } request || !services.Confirm(request)) return;
+ var result = await services.EmptyTrash(plan, cancellationToken);
+ Log.Info("workspace", $"Workspace trash emptied: {result.Items} entries, {result.Bytes} bytes");
+ services.Notify(Loc.L("Settings.Workspace.TrashEmptied"), Formatting.Bytes(result.Bytes), false);
+ }
+ catch (Exception ex) when (ex is WorkspaceException or IOException or UnauthorizedAccessException)
+ {
+ Log.Warning("workspace", "The workspace trash was not emptied", ex);
+ services.Notify(Loc.L("Settings.Workspace.TrashNotEmptied"), ex is WorkspaceException ? ex.Message : ErrorText.For(ex), true);
+ }
+ finally
+ {
+ await MeasureAsync();
+ }
+ }
+
+ ///
+ /// The confirmation of emptying the workspace's trash: how many entries and bytes, the newest entries named (the rest
+ /// counted), and their number typed before the action enables; null when the trash holds nothing.
+ ///
+ public static ConfirmRequest? TrashRequest(WorkspaceTrashPlan plan)
+ {
+ ArgumentNullException.ThrowIfNull(plan);
+ if (plan.IsEmpty) return null;
+ var count = plan.Items.Count.ToString(CultureInfo.InvariantCulture);
+ var lines = new List
+ {
+ Loc.L("Settings.Workspace.TrashPlan.Items", Formatting.Count(plan.Items.Count)),
+ Loc.L("Settings.Workspace.TrashPlan.Size", Formatting.Bytes(plan.Bytes)),
+ };
+ lines.AddRange(plan.Items.OrderByDescending(i => i.Trashed).Take(DeletePlans.ListedLines)
+ .Select(i => Loc.L("Settings.Workspace.TrashPlan.Item", i.Name, Formatting.Bytes(i.Bytes), Formatting.Date(i.Trashed))));
+ if (plan.Items.Count > DeletePlans.ListedLines) lines.Add(Loc.Plural("Archive.Delete.More", plan.Items.Count - DeletePlans.ListedLines));
+ return new ConfirmRequest
+ {
+ Heading = Loc.L("Settings.Workspace.TrashPlan.Title"),
+ Message = Loc.L("Settings.Workspace.TrashPlan.Message"),
+ Detail = string.Join(Environment.NewLine, lines),
+ IsDetailMonospaced = false,
+ DetailToolTip = Loc.L("Tooltips.Settings.Workspace.Trash"),
+ SafeText = Loc.L("Archive.Delete.Keep"),
+ SafeToolTip = Loc.L("Tooltips.Settings.Workspace.TrashPlan.Keep"),
+ ActionText = Loc.L("Settings.Workspace.TrashPlan.Action"),
+ ActionToolTip = Loc.L("Tooltips.Settings.Workspace.TrashPlan.Action"),
+ IsDestructive = true,
+ TypedConfirmation = count,
+ TypedPrompt = Loc.L("Settings.Workspace.TrashPlan.Type", count),
+ };
+ }
+
+ // ---------------- Reset ----------------
+
+ ///
+ /// The defaults of every row (Reset section); the caller saves. The folder stays (Change chooses it, after its plan;
+ /// Move takes it elsewhere), as do the trash and what the workspace remembers of the projects opened.
+ ///
public void Reset()
{
var defaults = new AppSettings();
+ settings.WorkspaceSizeLimitGb = defaults.WorkspaceSizeLimitGb;
+ settings.WorkspaceDefaultMedia = defaults.WorkspaceDefaultMedia;
settings.WorkspaceAutoSync = defaults.WorkspaceAutoSync;
+ settings.WorkspaceVersionOnRender = defaults.WorkspaceVersionOnRender;
settings.WorkspaceKeptVersions = defaults.WorkspaceKeptVersions;
+ settings.WorkspaceCleanAfterDays = defaults.WorkspaceCleanAfterDays;
+ settings.WorkspaceOpenProject = defaults.WorkspaceOpenProject;
Refresh();
}
/// Labels in the current language, values as the settings have them now.
internal void Refresh() => OnAllPropertiesChanged();
+ private bool IsMoving => services?.IsMoving() ?? false;
+
/// The value the workspace applies: at least one version.
private int Kept => Math.Max(1, settings.WorkspaceKeptVersions);
+
+ /// The limit the clean-up applies: none below 1 GB.
+ private int SizeLimit => Math.Max(0, settings.WorkspaceSizeLimitGb);
+
+ /// The age the clean-up applies: never below 1 day.
+ private int CleanAfter => Math.Max(0, settings.WorkspaceCleanAfterDays);
+
+ /// Open in workspace copies the originals; any other value stored reads as the proxies, as the open dialog takes it.
+ private bool IsOriginalsDefault => string.Equals(settings.WorkspaceDefaultMedia, BundleMedia.Originals, StringComparison.OrdinalIgnoreCase);
+
+ private void SetDefaultMedia(string media)
+ {
+ if (string.Equals(settings.WorkspaceDefaultMedia, media, StringComparison.Ordinal)) return;
+ settings.WorkspaceDefaultMedia = media;
+ save();
+ Raise(nameof(IsDefaultProxies), nameof(IsDefaultOriginals));
+ }
+
+ private void SetOpenProject(WorkspaceOpenPolicy policy)
+ {
+ if (settings.WorkspaceOpenProject == policy) return;
+ settings.WorkspaceOpenProject = policy;
+ save();
+ Raise(nameof(IsOpenLastUsed), nameof(IsOpenMain), nameof(IsOpenAsk));
+ }
+
+ private void SetMeasuring(bool measuring)
+ {
+ _isMeasuring = measuring;
+ Raise(nameof(IsMeasuring), nameof(UsageText), nameof(HasUsageText), nameof(TrashText), nameof(HasTrash), nameof(EmptyTrashToolTip));
+ _emptyTrash?.RaiseCanExecuteChanged();
+ }
+
+ ///
+ /// Stores a choice that differs from the stored value (, which may lie out of range: choosing
+ /// the value shown then saves it as applied) and saves; false when there was nothing to store. The caller raises the
+ /// choices before the selection, so a list that changes keeps the item chosen.
+ ///
+ private bool Store(SettingsOption? choice, int current, Action set)
+ {
+ if (choice is null || choice.Value == current) return false;
+ set(choice.Value);
+ save();
+ return true;
+ }
+
+ private void Raise(params string[] properties)
+ {
+ foreach (var property in properties) OnPropertyChanged(property);
+ }
+
+ private static IEnumerable With(int[] presets, int current) => (presets.Contains(current) ? presets : presets.Append(current)).Order();
}
diff --git a/tests/Chronos.App.Tests/Settings/SettingsLogicTests.cs b/tests/Chronos.App.Tests/Settings/SettingsLogicTests.cs
index 3d48219f..174567ff 100644
--- a/tests/Chronos.App.Tests/Settings/SettingsLogicTests.cs
+++ b/tests/Chronos.App.Tests/Settings/SettingsLogicTests.cs
@@ -1,17 +1,26 @@
using System.ComponentModel;
using System.Globalization;
using System.IO;
+using Chronos.App.Infrastructure;
using Chronos.App.Settings;
+using Chronos.App.Workspace;
using Chronos.Core.Localization;
using Chronos.Core.Naming;
using Chronos.Core.Video;
+using Chronos.Core.Windows.Shell;
using Chronos.Testing;
namespace Chronos.App.Tests.Settings;
public sealed class SettingsLogicTests
{
- public SettingsLogicTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
+ private readonly TestContext _context;
+
+ public SettingsLogicTests(TestContext context)
+ {
+ _context = context;
+ Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
+ }
[Test]
public void DefaultTemplatesPreviewThreeNames()
@@ -355,4 +364,388 @@ public sealed class SettingsLogicTests
.ToHashSet(StringComparer.Ordinal);
foreach (var key in keys) Assert.True(english.Contains(key), key);
}
+
+ // ---------------- Settings › Workspace (phase 5c) ----------------
+
+ [Test]
+ public void TheWorkspaceSizeLimitOffersItsPresetsThenNoLimit()
+ {
+ var (settings, rows, saves) = WorkspaceRows();
+ Assert.SequenceEqual([25, 50, 100, 200, 500, 1000, 0], rows.SizeLimitChoices.Select(c => c.Value));
+ Assert.Equal(("100 GB", "No limit"), (rows.SizeLimitChoices.Single(c => c.Value == 100).Label, rows.SizeLimitChoices[^1].Label));
+ Assert.Equal(100, rows.SelectedSizeLimit.Value);
+ Assert.Equal(Loc.L("Tooltips.Settings.Workspace.SizeLimit"), rows.SizeLimitToolTip);
+
+ rows.SelectedSizeLimit = rows.SizeLimitChoices.Single(c => c.Value == 500);
+ Assert.Equal((500, 1), (settings.WorkspaceSizeLimitGb, saves()));
+ rows.SelectedSizeLimit = rows.SizeLimitChoices.Single(c => c.Value == 500);
+ rows.SelectedSizeLimit = null!;
+ Assert.Equal(1, saves(), "nothing to store");
+ rows.SelectedSizeLimit = rows.SizeLimitChoices[^1];
+ Assert.Equal((0, 2), (settings.WorkspaceSizeLimitGb, saves()));
+ Assert.Equal(Loc.L("Tooltips.Settings.Workspace.NoLimit"), rows.SizeLimitToolTip);
+
+ // A value set by hand is listed in order with the presets; one below 1 is no limit, as the clean-up applies it.
+ settings.WorkspaceSizeLimitGb = 300;
+ Assert.SequenceEqual([25, 50, 100, 200, 300, 500, 1000, 0], rows.SizeLimitChoices.Select(c => c.Value));
+ Assert.Equal(300, rows.SelectedSizeLimit.Value);
+ settings.WorkspaceSizeLimitGb = -5;
+ Assert.Equal(0, rows.SelectedSizeLimit.Value);
+ Assert.Count(7, rows.SizeLimitChoices);
+ }
+
+ [Test]
+ public void TheDefaultMediaAreTheProxiesUnlessTheOriginalsAreChosen()
+ {
+ var (settings, rows, saves) = WorkspaceRows();
+ Assert.Equal((true, false), (rows.IsDefaultProxies, rows.IsDefaultOriginals));
+ rows.IsDefaultOriginals = true;
+ Assert.Equal((Chronos.Core.Project.BundleMedia.Originals, 1), (settings.WorkspaceDefaultMedia, saves()));
+ Assert.Equal((false, true), (rows.IsDefaultProxies, rows.IsDefaultOriginals));
+ // A radio button unchecked by its sibling stores nothing.
+ rows.IsDefaultProxies = false;
+ rows.IsDefaultOriginals = true;
+ Assert.Equal(1, saves());
+ rows.IsDefaultProxies = true;
+ Assert.Equal((Chronos.Core.Project.BundleMedia.Proxies, 2), (settings.WorkspaceDefaultMedia, saves()));
+
+ // What the open dialog takes from a hand-edited file: originals in any case, anything else the proxies.
+ settings.WorkspaceDefaultMedia = "ORIGINALS";
+ Assert.True(rows.IsDefaultOriginals);
+ settings.WorkspaceDefaultMedia = "everything";
+ Assert.Equal((true, false), (rows.IsDefaultProxies, rows.IsDefaultOriginals));
+ }
+
+ [Test]
+ public void VersionOnRenderIsOnUntilTurnedOff()
+ {
+ var (settings, rows, saves) = WorkspaceRows();
+ Assert.True(rows.VersionOnRender);
+ rows.VersionOnRender = false;
+ Assert.Equal((false, 1), (settings.WorkspaceVersionOnRender, saves()));
+ rows.VersionOnRender = false;
+ Assert.Equal(1, saves(), "nothing to store");
+ rows.VersionOnRender = true;
+ Assert.Equal((true, 2), (settings.WorkspaceVersionOnRender, saves()));
+ }
+
+ [Test]
+ public void CleanAfterOffersItsDaysThenNever()
+ {
+ var (settings, rows, saves) = WorkspaceRows();
+ Assert.SequenceEqual([7, 14, 30, 60, 90, 0], rows.CleanAfterChoices.Select(c => c.Value));
+ Assert.Equal(("30 days", "Never"), (rows.CleanAfterChoices.Single(c => c.Value == 30).Label, rows.CleanAfterChoices[^1].Label));
+ Assert.Equal(30, rows.SelectedCleanAfter.Value);
+ Assert.Equal(Loc.L("Tooltips.Settings.Workspace.CleanAfter"), rows.CleanAfterToolTip);
+
+ rows.SelectedCleanAfter = rows.CleanAfterChoices.Single(c => c.Value == 7);
+ Assert.Equal((7, 1), (settings.WorkspaceCleanAfterDays, saves()));
+ rows.SelectedCleanAfter = rows.CleanAfterChoices[^1];
+ Assert.Equal((0, 2), (settings.WorkspaceCleanAfterDays, saves()));
+ Assert.Equal(Loc.L("Tooltips.Settings.Workspace.Never"), rows.CleanAfterToolTip);
+
+ settings.WorkspaceCleanAfterDays = 1;
+ Assert.Equal("1 day", rows.SelectedCleanAfter.Label);
+ Assert.SequenceEqual([1, 7, 14, 30, 60, 90, 0], rows.CleanAfterChoices.Select(c => c.Value));
+ settings.WorkspaceCleanAfterDays = -1;
+ Assert.Equal(0, rows.SelectedCleanAfter.Value);
+ }
+
+ [Test]
+ public void OpenProjectIsTheLastUsedUnlessMainOrAskIsChosen()
+ {
+ var (settings, rows, saves) = WorkspaceRows();
+ Assert.Equal((true, false, false), (rows.IsOpenLastUsed, rows.IsOpenMain, rows.IsOpenAsk));
+ rows.IsOpenMain = true;
+ Assert.Equal((WorkspaceOpenPolicy.Main, 1), (settings.WorkspaceOpenProject, saves()));
+ rows.IsOpenLastUsed = false;
+ Assert.Equal(1, saves());
+ rows.IsOpenAsk = true;
+ Assert.Equal((WorkspaceOpenPolicy.Ask, 2), (settings.WorkspaceOpenProject, saves()));
+ Assert.Equal((false, false, true), (rows.IsOpenLastUsed, rows.IsOpenMain, rows.IsOpenAsk));
+ rows.IsOpenLastUsed = true;
+ Assert.Equal((WorkspaceOpenPolicy.LastUsed, 3), (settings.WorkspaceOpenProject, saves()));
+
+ // A value the enum does not know reads as the default.
+ settings.WorkspaceOpenProject = (WorkspaceOpenPolicy)99;
+ Assert.Equal((true, false, false), (rows.IsOpenLastUsed, rows.IsOpenMain, rows.IsOpenAsk));
+ }
+
+ [Test]
+ public void AWorkspaceListThatChangesIsRaisedBeforeItsSelection()
+ {
+ var (settings, rows, _) = WorkspaceRows();
+ settings.WorkspaceSizeLimitGb = 300;
+ var raised = new List();
+ rows.PropertyChanged += (_, e) => raised.Add(e.PropertyName);
+ rows.SelectedSizeLimit = rows.SizeLimitChoices.Single(c => c.Value == 50);
+ Assert.SequenceEqual([nameof(rows.SizeLimitChoices), nameof(rows.SelectedSizeLimit), nameof(rows.SizeLimitToolTip)], raised);
+ raised.Clear();
+ rows.SelectedCleanAfter = rows.CleanAfterChoices.Single(c => c.Value == 90);
+ Assert.SequenceEqual([nameof(rows.CleanAfterChoices), nameof(rows.SelectedCleanAfter), nameof(rows.CleanAfterToolTip)], raised);
+ raised.Clear();
+ rows.SelectedKept = rows.KeptChoices.Single(c => c.Value == 5);
+ Assert.SequenceEqual([nameof(rows.KeptChoices), nameof(rows.SelectedKept)], raised);
+ }
+
+ [Test]
+ public void ResetRestoresEveryWorkspaceRowButKeepsTheFolderAndWhatItRemembers()
+ {
+ var (settings, rows, _) = WorkspaceRows();
+ var project = Guid.NewGuid();
+ settings.WorkspaceFolder = @"E:\Fast\Chronos workspace";
+ settings.WorkspaceRecent[Guid.NewGuid()] = project;
+ settings.WorkspaceOpened[project] = DateTimeOffset.UnixEpoch;
+ settings.WorkspaceSizeLimitGb = 0;
+ settings.WorkspaceDefaultMedia = Chronos.Core.Project.BundleMedia.Originals;
+ settings.WorkspaceAutoSync = false;
+ settings.WorkspaceVersionOnRender = false;
+ settings.WorkspaceKeptVersions = 5;
+ settings.WorkspaceCleanAfterDays = 0;
+ settings.WorkspaceOpenProject = WorkspaceOpenPolicy.Ask;
+ var raised = new List();
+ rows.PropertyChanged += (_, e) => raised.Add(e.PropertyName);
+
+ rows.Reset();
+ var defaults = new AppSettings();
+ Assert.Equal((defaults.WorkspaceSizeLimitGb, defaults.WorkspaceDefaultMedia, defaults.WorkspaceAutoSync, defaults.WorkspaceVersionOnRender),
+ (settings.WorkspaceSizeLimitGb, settings.WorkspaceDefaultMedia, settings.WorkspaceAutoSync, settings.WorkspaceVersionOnRender));
+ Assert.Equal((defaults.WorkspaceKeptVersions, defaults.WorkspaceCleanAfterDays, defaults.WorkspaceOpenProject),
+ (settings.WorkspaceKeptVersions, settings.WorkspaceCleanAfterDays, settings.WorkspaceOpenProject));
+ Assert.Equal((100, BundleMediaProxies, true, true, 20, 30, WorkspaceOpenPolicy.LastUsed),
+ (rows.SelectedSizeLimit.Value, settings.WorkspaceDefaultMedia, rows.AutoSync, rows.VersionOnRender, rows.SelectedKept.Value, rows.SelectedCleanAfter.Value,
+ settings.WorkspaceOpenProject));
+ Assert.Equal(@"E:\Fast\Chronos workspace", settings.WorkspaceFolder);
+ Assert.Count(1, settings.WorkspaceRecent);
+ Assert.Equal(DateTimeOffset.UnixEpoch, settings.WorkspaceOpened[project]);
+ Assert.Contains(raised, p => string.IsNullOrEmpty(p));
+ }
+
+ [Test]
+ public void MoveTakesTheFolderAlongAndWaitsWhileAMoveRuns()
+ {
+ var moving = false;
+ var moves = 0;
+ var (_, rows, _) = WorkspaceRows(new FakeWorkspace(), move: () =>
+ {
+ moves++;
+ return Task.CompletedTask;
+ }, isMoving: () => moving);
+ Assert.True(rows.CanMove);
+ Assert.True(rows.MoveCommand.CanExecute(null));
+ Assert.Equal(Loc.L("Tooltips.Settings.Workspace.Move"), rows.MoveToolTip);
+ rows.MoveCommand.Execute(null);
+ Assert.Equal(1, moves);
+
+ moving = true;
+ Assert.False(rows.MoveCommand.CanExecute(null));
+ Assert.False(rows.ChangeCommand.CanExecute(null), "the folder changes only once the move ends");
+ Assert.Equal(Loc.L("Errors.Workspace.Moving"), rows.MoveToolTip);
+
+ // Without the workspace's services (or a move), no Move… button.
+ var (_, bare, _) = WorkspaceRows();
+ Assert.False(bare.CanMove);
+ Assert.False(bare.MoveCommand.CanExecute(null));
+ Assert.Null(bare.UsageText);
+ Assert.Null(bare.TrashText);
+ }
+
+ [Test]
+ public async Task TheWorkspaceIsMeasuredWithItsTrash()
+ {
+ var workspace = new FakeWorkspace();
+ var pending = new TaskCompletionSource();
+ workspace.Measure = _ => pending.Task;
+ var (_, rows, _) = WorkspaceRows(workspace);
+ var measuring = rows.MeasureAsync();
+ Assert.True(rows.IsMeasuring);
+ Assert.Equal(("Measuring…", "Measuring…"), (rows.UsageText, rows.TrashText));
+ Assert.False(rows.EmptyTrashCommand.CanExecute(null), "nothing to erase is known yet");
+
+ pending.SetResult(new WorkspaceUsage(MediaBytes: 9_000_000_000, TotalBytes: 12_400_000_000, TrashBytes: 1_200_000_000, TrashItems: 3));
+ await measuring;
+ Assert.False(rows.IsMeasuring);
+ Assert.Equal(("12.4 GB used", "3 items, 1.2 GB"), (rows.UsageText, rows.TrashText));
+ Assert.True(rows.HasUsageText);
+ Assert.True(rows.HasTrash);
+ Assert.True(rows.EmptyTrashCommand.CanExecute(null));
+ Assert.Equal(Loc.L("Tooltips.Settings.Workspace.EmptyTrash"), rows.EmptyTrashToolTip);
+
+ workspace.Measure = _ => Task.FromResult(new WorkspaceUsage(0, 4_000, 0, 0));
+ await rows.MeasureAsync();
+ Assert.Equal(("4 KB used", "Nothing in trash"), (rows.UsageText, rows.TrashText));
+ Assert.False(rows.HasTrash);
+ Assert.False(rows.EmptyTrashCommand.CanExecute(null));
+ Assert.Equal(Loc.L("Tooltips.Settings.Workspace.EmptyTrash.Disabled"), rows.EmptyTrashToolTip);
+ workspace.Measure = _ => Task.FromResult(new WorkspaceUsage(0, 1_000, 2_000, 1));
+ await rows.MeasureAsync();
+ Assert.Equal("1 item, 2 KB", rows.TrashText);
+ }
+
+ [Test]
+ public async Task ALaterMeasureReplacesOneStillRunningAndAFailureShowsNothing()
+ {
+ var workspace = new FakeWorkspace();
+ var first = new TaskCompletionSource();
+ CancellationToken firstToken = default;
+ workspace.Measure = token =>
+ {
+ firstToken = token;
+ return first.Task;
+ };
+ var (_, rows, _) = WorkspaceRows(workspace);
+ var older = rows.MeasureAsync();
+ workspace.Measure = _ => Task.FromResult(new WorkspaceUsage(0, 2_000_000, 0, 0));
+ await rows.MeasureAsync();
+ Assert.True(firstToken.IsCancellationRequested, "the older measure is told to stop");
+ first.SetResult(new WorkspaceUsage(0, 9_000_000_000, 0, 5));
+ await older;
+ Assert.Equal(("2 MB used", false, false), (rows.UsageText, rows.HasTrash, rows.IsMeasuring));
+
+ workspace.Measure = _ => Task.FromException(new IOException("the drive went away"));
+ await rows.MeasureAsync();
+ Assert.Null(rows.UsageText);
+ Assert.False(rows.HasUsageText);
+ Assert.Null(rows.TrashText);
+ Assert.False(rows.HasTrash);
+ }
+
+ [Test]
+ public async Task EmptyingTheWorkspaceTrashShowsItsPlanAndAsksForTheCountTyped()
+ {
+ var workspace = new FakeWorkspace { Confirmed = false };
+ var items = Enumerable.Range(1, 8).Select(i => new WorkspaceTrashItem($"{Guid.Empty:N}-{i}", i * 1_000_000, i, DateTimeOffset.UnixEpoch.AddDays(i))).ToList();
+ var plan = new WorkspaceTrashPlan(@"C:\workspace\.trash", items, items.Sum(i => i.Bytes), "fingerprint");
+ workspace.Plan = plan;
+ workspace.Measure = _ => Task.FromResult(new WorkspaceUsage(0, 50_000_000, plan.Bytes, items.Count));
+ var (_, rows, _) = WorkspaceRows(workspace);
+ await rows.MeasureAsync();
+
+ // Kept: the plan was shown, nothing erased.
+ await rows.EmptyTrashAsync();
+ var request = Assert.NotNull(workspace.Asked);
+ Assert.Equal(0, workspace.Emptied.Count);
+ Assert.Equal((Loc.L("Settings.Workspace.TrashPlan.Title"), "8", Loc.L("Settings.Workspace.TrashPlan.Type", "8")),
+ (request.Heading, request.TypedConfirmation, request.TypedPrompt));
+ Assert.True(request.IsDestructive);
+ Assert.Equal((Loc.L("Settings.Workspace.TrashPlan.Action"), Loc.L("Tooltips.Settings.Workspace.TrashPlan.Action"), Loc.L("Tooltips.Settings.Workspace.TrashPlan.Keep")),
+ (request.ActionText, request.ActionToolTip, request.SafeToolTip));
+ var lines = request.Detail!.Split(Environment.NewLine);
+ Assert.Equal(("Entries: 8", "Size: 36 MB"), (lines[0], lines[1]));
+ // The newest entries are named, the rest counted.
+ Assert.Equal(Loc.L("Settings.Workspace.TrashPlan.Item", items[7].Name, "8 MB", Formatting.Date(items[7].Trashed)), lines[2]);
+ Assert.Equal(2 + DeletePlansListed + 1, lines.Length);
+ Assert.Equal(Loc.Plural("Archive.Delete.More", 2), lines[^1]);
+
+ // Erased: exactly the plan shown, then told and measured again.
+ workspace.Confirmed = true;
+ workspace.Measure = _ => Task.FromResult(new WorkspaceUsage(0, 14_000_000, 0, 0));
+ await rows.EmptyTrashAsync();
+ Assert.Same(plan, Assert.Contains(workspace.Emptied, _ => true));
+ Assert.Equal((Loc.L("Settings.Workspace.TrashEmptied"), "36 MB", false), Assert.Contains(workspace.Notices, _ => true));
+ Assert.Equal("Nothing in trash", rows.TrashText);
+
+ // An empty trash asks nothing.
+ workspace.Asked = null;
+ workspace.Plan = new WorkspaceTrashPlan(@"C:\workspace\.trash", [], 0, string.Empty);
+ await rows.EmptyTrashAsync();
+ Assert.Null(workspace.Asked);
+ Assert.Null(SettingsTrashRequest(workspace.Plan));
+ }
+
+ [Test]
+ public async Task ATrashThatChangedSinceItsPlanIsNotEmptied()
+ {
+ var item = new WorkspaceTrashItem("copy", 1_000, 1, DateTimeOffset.UnixEpoch);
+ var workspace = new FakeWorkspace
+ {
+ Plan = new WorkspaceTrashPlan(@"C:\workspace\.trash", [item], 1_000, "before"),
+ Empty = _ => throw new WorkspaceException(Loc.L("Errors.Workspace.TrashChanged")),
+ };
+ workspace.Measure = _ => Task.FromResult(new WorkspaceUsage(0, 1_000, 1_000, 1));
+ var (_, rows, _) = WorkspaceRows(workspace);
+ await rows.EmptyTrashAsync();
+ Assert.Equal((Loc.L("Settings.Workspace.TrashNotEmptied"), Loc.L("Errors.Workspace.TrashChanged"), true), Assert.Contains(workspace.Notices, _ => true));
+ Assert.Equal("1 item, 1 KB", rows.TrashText);
+
+ workspace.Notices.Clear();
+ workspace.Empty = _ => throw new UnauthorizedAccessException("denied");
+ await rows.EmptyTrashAsync();
+ var (title, _, isError) = Assert.Contains(workspace.Notices, _ => true);
+ Assert.Equal((Loc.L("Settings.Workspace.TrashNotEmptied"), true), (title, isError));
+ }
+
+ [Test]
+ public async Task TheWorkspaceRowsReachTheWorkspaceHost()
+ {
+ var local = _context.CreateTempDirectory("local");
+ var environment = AppEnvironment.From(AppPaths.Resolve(_context.CreateTempDirectory("app"), local, []));
+ var settings = new AppSettings { WorkspaceFolder = _context.CreateTempDirectory("fast") };
+ var host = new WorkspaceHost(environment, settings, () => { }, () => null, () => null, () => null);
+ var notices = new List();
+ var services = WorkspaceSettingsServices.For(host, new NoDialogs(), (title, _, _) => notices.Add(title), () => Task.CompletedTask);
+ Assert.False(services.IsMoving());
+ var rows = new WorkspaceSettingsRows(settings, () => { }, () => host.Root, () => { }, () => Task.CompletedTask, services);
+ await rows.MeasureAsync();
+ Assert.Equal(("Nothing in trash", false), (rows.TrashText, rows.HasTrash));
+ await rows.EmptyTrashAsync();
+ Assert.Empty(notices);
+ Assert.True(rows.CanMove);
+ }
+
+ private const int DeletePlansListed = Chronos.App.Archiving.DeletePlans.ListedLines;
+ private const string BundleMediaProxies = Chronos.Core.Project.BundleMedia.Proxies;
+
+ private static ConfirmRequest? SettingsTrashRequest(WorkspaceTrashPlan plan) => WorkspaceSettingsRows.TrashRequest(plan);
+
+ private static (AppSettings Settings, WorkspaceSettingsRows Rows, Func Saves) WorkspaceRows(FakeWorkspace? workspace = null, Func? move = null,
+ Func? isMoving = null)
+ {
+ var settings = new AppSettings();
+ var saves = 0;
+ WorkspaceSettingsServices? services = workspace is null ? null : new WorkspaceSettingsServices
+ {
+ Usage = token => workspace.Measure(token),
+ PlanTrash = _ => Task.FromResult(workspace.Plan),
+ EmptyTrash = (plan, _) =>
+ {
+ var result = workspace.Empty(plan);
+ workspace.Emptied.Add(plan);
+ return Task.FromResult(result);
+ },
+ Confirm = request =>
+ {
+ workspace.Asked = request;
+ return workspace.Confirmed;
+ },
+ Notify = (title, message, isError) => workspace.Notices.Add((title, message, isError)),
+ Move = move,
+ IsMoving = isMoving ?? (() => false),
+ };
+ var rows = new WorkspaceSettingsRows(settings, () => saves++, () => @"C:\Users\me\AppData\Local\Chronos\workspace", () => { }, () => Task.CompletedTask, services);
+ return (settings, rows, () => saves);
+ }
+
+ /// The workspace as Settings › Workspace reaches it: its usage, its trash's plan and emptying, the questions and toasts.
+ private sealed class FakeWorkspace
+ {
+ public Func> Measure { get; set; } = _ => Task.FromResult(WorkspaceUsage.None);
+ public WorkspaceTrashPlan Plan { get; set; } = new(@"C:\workspace\.trash", [], 0, string.Empty);
+ public Func Empty { get; set; } = plan => new WorkspaceTrashResult(plan.Items.Count, plan.Bytes);
+ public bool Confirmed { get; set; } = true;
+ public ConfirmRequest? Asked { get; set; }
+ public List Emptied { get; } = [];
+ public List<(string Title, string? Message, bool IsError)> Notices { get; } = [];
+ }
+
+ private sealed class NoDialogs : IAppDialogs
+ {
+ public string? PickFolder(string title, string? initialFolder = null) => null;
+
+ public string? PickJsonFile(string title) => null;
+
+ public bool Confirm(ConfirmRequest request) => throw new InvalidOperationException("nothing to confirm");
+
+ public bool SignIn(string server, string? username, Func> signIn) => false;
+ }
}