Merge branch 'p5c-p5' into review2-p5c
This commit is contained in:
commit
6daf5fa056
4 files changed
+866
-36
No files matched your search
@@ -520,32 +520,80 @@
|
||||
</HeaderedContentControl>
|
||||
</StackPanel>
|
||||
|
||||
<!-- ================= Workspace (owner review 2, R8) ================= -->
|
||||
<!-- ================= Workspace (owner review 2, R8; phase 5c) ================= -->
|
||||
<StackPanel Style="{StaticResource Page}" Visibility="{Binding Page, Converter={x:Static shell:EqualsToVisibilityConverter.Instance}, ConverterParameter=Workspace}">
|
||||
<!-- The folder is shown, opened and changed here (another folder after its plan; nothing is moved: moving it with its projects comes with phase 5c). -->
|
||||
<!-- The folder is shown, opened, changed (another folder after its plan; nothing is moved) and moved with its projects (after its plan,
|
||||
by the workspace-move job); what it takes of its drive under it. -->
|
||||
<HeaderedContentControl Style="{StaticResource Setting.Row}" Header="{l:Loc Settings.Workspace.Folder}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" MinWidth="160" MaxWidth="360" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Style="{StaticResource TextBox.Path}" IsReadOnly="True" Text="{Binding WorkspaceRows.Folder, Mode=OneWay}" ToolTip="{l:Loc Tooltips.Settings.WorkspaceFolder}"
|
||||
AutomationProperties.Name="{l:Loc Settings.Workspace.Folder}" />
|
||||
<Button Grid.Column="1" Content="{l:Loc Common.Open}" Command="{Binding WorkspaceRows.OpenCommand}" ToolTip="{l:Loc Tooltips.Settings.OpenWorkspace}"
|
||||
Margin="10,0,0,0" />
|
||||
<Button Grid.Column="2" Content="{l:Loc Settings.Workspace.Change}" Command="{Binding WorkspaceRows.ChangeCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Settings.ChangeWorkspace}" Margin="8,0,0,0"
|
||||
Visibility="{Binding WorkspaceRows.CanChange, Converter={StaticResource BoolToVisibility}}" />
|
||||
</Grid>
|
||||
<StackPanel>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" MinWidth="160" MaxWidth="360" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Style="{StaticResource TextBox.Path}" IsReadOnly="True" Text="{Binding WorkspaceRows.Folder, Mode=OneWay}" ToolTip="{l:Loc Tooltips.Settings.Workspace.Folder}"
|
||||
AutomationProperties.Name="{l:Loc Settings.Workspace.Folder}" />
|
||||
<Button Grid.Column="1" Content="{l:Loc Common.Open}" Command="{Binding WorkspaceRows.OpenCommand}" ToolTip="{l:Loc Tooltips.Settings.OpenWorkspace}"
|
||||
Margin="10,0,0,0" />
|
||||
<Button Grid.Column="2" Content="{l:Loc Settings.Workspace.Change}" Command="{Binding WorkspaceRows.ChangeCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Settings.ChangeWorkspace}" Margin="8,0,0,0"
|
||||
Visibility="{Binding WorkspaceRows.CanChange, Converter={StaticResource BoolToVisibility}}" />
|
||||
<Button Grid.Column="3" Content="{l:Loc Settings.Workspace.Move}" Command="{Binding WorkspaceRows.MoveCommand}"
|
||||
ToolTip="{Binding WorkspaceRows.MoveToolTip}" ToolTipService.ShowOnDisabled="True" Margin="8,0,0,0"
|
||||
Visibility="{Binding WorkspaceRows.CanMove, Converter={StaticResource BoolToVisibility}}" />
|
||||
</Grid>
|
||||
<TextBlock Style="{StaticResource Text.Hint}" Text="{Binding WorkspaceRows.UsageText}" ToolTip="{l:Loc Tooltips.Settings.Workspace.Used}" Margin="0,6,0,0"
|
||||
Visibility="{Binding WorkspaceRows.HasUsageText, Converter={StaticResource BoolToVisibility}}" />
|
||||
</StackPanel>
|
||||
</HeaderedContentControl>
|
||||
<HeaderedContentControl Style="{StaticResource Setting.Row}" Header="{l:Loc Settings.Workspace.SizeLimit}">
|
||||
<ComboBox Width="170" HorizontalAlignment="Left" ItemsSource="{Binding WorkspaceRows.SizeLimitChoices}" SelectedItem="{Binding WorkspaceRows.SelectedSizeLimit}"
|
||||
DisplayMemberPath="Label" ToolTip="{Binding WorkspaceRows.SizeLimitToolTip}" AutomationProperties.Name="{l:Loc Settings.Workspace.SizeLimit}" />
|
||||
</HeaderedContentControl>
|
||||
<HeaderedContentControl Style="{StaticResource Setting.Row}" Header="{l:Loc Settings.Workspace.DefaultMedia}">
|
||||
<WrapPanel Margin="0,4,0,0">
|
||||
<RadioButton GroupName="WorkspaceMedia" Content="{l:Loc Settings.Workspace.Proxies}" IsChecked="{Binding WorkspaceRows.IsDefaultProxies}"
|
||||
ToolTip="{l:Loc Tooltips.Settings.Workspace.Proxies}" Margin="0,0,20,0" />
|
||||
<RadioButton GroupName="WorkspaceMedia" Content="{l:Loc Settings.Workspace.Originals}" IsChecked="{Binding WorkspaceRows.IsDefaultOriginals}"
|
||||
ToolTip="{l:Loc Tooltips.Settings.Workspace.Originals}" />
|
||||
</WrapPanel>
|
||||
</HeaderedContentControl>
|
||||
<HeaderedContentControl Style="{StaticResource Setting.Row}" Header="{l:Loc Settings.Workspace.Sync}">
|
||||
<CheckBox Content="{l:Loc Settings.Workspace.AfterSave}" IsChecked="{Binding WorkspaceRows.AutoSync}" ToolTip="{l:Loc Tooltips.Settings.WorkspaceSync}" Margin="0,4,0,0" />
|
||||
</HeaderedContentControl>
|
||||
<HeaderedContentControl Style="{StaticResource Setting.Row}" Header="{l:Loc Settings.Workspace.VersionOnRender}">
|
||||
<CheckBox Content="{l:Loc Settings.Workspace.SaveBeforeRender}" IsChecked="{Binding WorkspaceRows.VersionOnRender}"
|
||||
ToolTip="{l:Loc Tooltips.Settings.Workspace.VersionOnRender}" Margin="0,4,0,0" />
|
||||
</HeaderedContentControl>
|
||||
<HeaderedContentControl Style="{StaticResource Setting.Row}" Header="{l:Loc Settings.Workspace.Kept}">
|
||||
<ComboBox Width="170" HorizontalAlignment="Left" ItemsSource="{Binding WorkspaceRows.KeptChoices}" SelectedItem="{Binding WorkspaceRows.SelectedKept}"
|
||||
DisplayMemberPath="Label" ToolTip="{l:Loc Tooltips.Settings.KeptVersions}" AutomationProperties.Name="{l:Loc Settings.Workspace.Kept}" />
|
||||
</HeaderedContentControl>
|
||||
<HeaderedContentControl Style="{StaticResource Setting.Row}" Header="{l:Loc Settings.Workspace.CleanAfter}">
|
||||
<ComboBox Width="170" HorizontalAlignment="Left" ItemsSource="{Binding WorkspaceRows.CleanAfterChoices}" SelectedItem="{Binding WorkspaceRows.SelectedCleanAfter}"
|
||||
DisplayMemberPath="Label" ToolTip="{Binding WorkspaceRows.CleanAfterToolTip}" AutomationProperties.Name="{l:Loc Settings.Workspace.CleanAfter}" />
|
||||
</HeaderedContentControl>
|
||||
<HeaderedContentControl Style="{StaticResource Setting.Row}" Header="{l:Loc Settings.Workspace.OpenProject}">
|
||||
<WrapPanel Margin="0,4,0,0">
|
||||
<RadioButton GroupName="WorkspaceOpen" Content="{l:Loc Settings.Workspace.LastUsed}" IsChecked="{Binding WorkspaceRows.IsOpenLastUsed}"
|
||||
ToolTip="{l:Loc Tooltips.Settings.Workspace.LastUsed}" Margin="0,0,20,0" />
|
||||
<RadioButton GroupName="WorkspaceOpen" Content="{l:Loc Settings.Workspace.Main}" IsChecked="{Binding WorkspaceRows.IsOpenMain}"
|
||||
ToolTip="{l:Loc Tooltips.Settings.Workspace.Main}" Margin="0,0,20,0" />
|
||||
<RadioButton GroupName="WorkspaceOpen" Content="{l:Loc Settings.Workspace.Ask}" IsChecked="{Binding WorkspaceRows.IsOpenAsk}"
|
||||
ToolTip="{l:Loc Tooltips.Settings.Workspace.Ask}" />
|
||||
</WrapPanel>
|
||||
</HeaderedContentControl>
|
||||
<!-- What removed copies and the clean-up set aside; only Empty… erases it, after its plan and the typed number of its entries. -->
|
||||
<HeaderedContentControl Style="{StaticResource Setting.Row}" Header="{l:Loc Settings.Workspace.Trash}">
|
||||
<WrapPanel>
|
||||
<TextBlock Style="{StaticResource Text.Hint}" Text="{Binding WorkspaceRows.TrashText}" ToolTip="{l:Loc Tooltips.Settings.Workspace.Trash}" Margin="0,0,12,0"
|
||||
VerticalAlignment="Center" />
|
||||
<Button Style="{StaticResource Button.Compact}" Content="{l:Loc Settings.Workspace.EmptyTrash}" Command="{Binding WorkspaceRows.EmptyTrashCommand}"
|
||||
ToolTip="{Binding WorkspaceRows.EmptyTrashToolTip}" ToolTipService.ShowOnDisabled="True" />
|
||||
</WrapPanel>
|
||||
</HeaderedContentControl>
|
||||
</StackPanel>
|
||||
|
||||
<!-- ================= Server ================= -->
|
||||
|
||||
@@ -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 ----------------
|
||||
|
||||
/// <summary>Settings › Workspace (owner review 2, R8): the folder, Sync automatically and Kept versions.</summary>
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public WorkspaceSettingsRows WorkspaceRows { get; }
|
||||
|
||||
/// <summary>Shows the workspace folder in Explorer (made, with its manifest, when the workspace was never used).</summary>
|
||||
@@ -747,6 +755,14 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
{
|
||||
await WorkspaceFolderChange.ChooseAsync(Shell);
|
||||
WorkspaceRows.Refresh();
|
||||
await WorkspaceRows.MeasureAsync();
|
||||
}
|
||||
|
||||
/// <summary>The workspace folder moved with its projects, after its plan: the move job takes them, and Edit waits for it.</summary>
|
||||
private async Task MoveWorkspaceFolderAsync()
|
||||
{
|
||||
await WorkspaceFolderChange.MoveAsync(Shell);
|
||||
WorkspaceRows.Refresh();
|
||||
}
|
||||
|
||||
// ---------------- Server ----------------
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 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 <see cref="WorkspaceHost"/> (<see cref="For"/>); tests give their own.
|
||||
/// </summary>
|
||||
public sealed class WorkspaceSettingsRows(AppSettings settings, Action save, Func<string> folder, Action open, Func<Task>? change = null) : ObservableObject
|
||||
public sealed class WorkspaceSettingsServices
|
||||
{
|
||||
/// <summary>What the workspace takes of its drive (<see cref="WorkspaceHost.UsageAsync"/>).</summary>
|
||||
public required Func<CancellationToken, Task<WorkspaceUsage>> Usage { get; init; }
|
||||
|
||||
/// <summary>The plan of emptying the workspace's trash (<see cref="WorkspaceHost.PlanTrashAsync"/>).</summary>
|
||||
public required Func<CancellationToken, Task<WorkspaceTrashPlan>> PlanTrash { get; init; }
|
||||
|
||||
/// <summary>Erases the entries of a confirmed plan (<see cref="WorkspaceHost.EmptyTrashAsync"/>).</summary>
|
||||
public required Func<WorkspaceTrashPlan, CancellationToken, Task<WorkspaceTrashResult>> EmptyTrash { get; init; }
|
||||
|
||||
/// <summary>Asks a confirmation; true when the user chose the action.</summary>
|
||||
public required Func<ConfirmRequest, bool> Confirm { get; init; }
|
||||
|
||||
/// <summary>Shows a toast: its title, its message, and whether it tells of something that did not happen.</summary>
|
||||
public required Action<string, string?, bool> Notify { get; init; }
|
||||
|
||||
/// <summary>Picks a folder, shows the move's plan and queues it (<see cref="WorkspaceFolderChange.MoveAsync(Shell.ShellViewModel)"/>); null where the folder cannot move.</summary>
|
||||
public Func<Task>? Move { get; init; }
|
||||
|
||||
/// <summary>A move of the workspace folder is queued or running (<see cref="WorkspaceHost.IsMoving"/>).</summary>
|
||||
public Func<bool> IsMoving { get; init; } = () => false;
|
||||
|
||||
/// <summary>The workspace's own operations, with the shell's <paramref name="dialogs"/> and toasts (<paramref name="notify"/>).</summary>
|
||||
public static WorkspaceSettingsServices For(WorkspaceHost host, IAppDialogs dialogs, Action<string, string?, bool> notify, Func<Task>? 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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public sealed class WorkspaceSettingsRows(AppSettings settings, Action save, Func<string> folder, Action open, Func<Task>? 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 ----------------
|
||||
|
||||
/// <summary>The workspace folder in use.</summary>
|
||||
public string Folder => folder();
|
||||
@@ -22,11 +91,73 @@ public sealed class WorkspaceSettingsRows(AppSettings settings, Action save, Fun
|
||||
/// <summary>Shows the folder in Explorer.</summary>
|
||||
public RelayCommand OpenCommand { get; } = new(open);
|
||||
|
||||
/// <summary>Uses another folder, after its plan (WorkspaceFolderChange); none where the folder cannot change.</summary>
|
||||
public AsyncRelayCommand ChangeCommand { get; } = new(change ?? (() => Task.CompletedTask), () => change is not null);
|
||||
/// <summary>Uses another folder, after its plan (WorkspaceFolderChange); none where the folder cannot change, nor while it moves.</summary>
|
||||
public AsyncRelayCommand ChangeCommand { get; } = new(change ?? (() => Task.CompletedTask), () => change is not null && !(services?.IsMoving() ?? false));
|
||||
|
||||
public bool CanChange => change is not null;
|
||||
|
||||
/// <summary>Moves the folder with its projects, after its plan (WorkspaceFolderChange.MoveAsync); none where it cannot move, nor while it moves.</summary>
|
||||
public AsyncRelayCommand MoveCommand { get; } = new(services?.Move ?? (() => Task.CompletedTask), () => services?.Move is not null && !services.IsMoving());
|
||||
|
||||
public bool CanMove => services?.Move is not null;
|
||||
|
||||
/// <summary>The move button's tooltip: what it does, or that a move is under way.</summary>
|
||||
public string MoveToolTip => IsMoving ? Loc.L("Errors.Workspace.Moving") : Loc.L("Tooltips.Settings.Workspace.Move");
|
||||
|
||||
/// <summary>"12.4 GB used" (the whole folder, its trash included); "Measuring…" meanwhile; null before the first measure or when it failed.</summary>
|
||||
public string? UsageText =>
|
||||
_isMeasuring ? Loc.L("Settings.Workspace.Measuring")
|
||||
: _usage is { } usage ? Loc.L("Settings.Workspace.Used", Formatting.Bytes(usage.TotalBytes))
|
||||
: null;
|
||||
|
||||
/// <summary>The usage line shows.</summary>
|
||||
public bool HasUsageText => UsageText is not null;
|
||||
|
||||
public bool IsMeasuring => _isMeasuring;
|
||||
|
||||
// ---------------- Size limit ----------------
|
||||
|
||||
/// <summary>The presets in GB, a value set elsewhere among them, then No limit (0).</summary>
|
||||
public IReadOnlyList<SettingsOption<int>> SizeLimitChoices =>
|
||||
[
|
||||
.. With(SizeLimitPresets, SizeLimit).Where(n => n > 0).Select(n => new SettingsOption<int>(n, Loc.L("Common.Size.GB", Formatting.Count(n)))),
|
||||
new(0, Loc.L("Settings.Workspace.NoLimit")),
|
||||
];
|
||||
|
||||
public SettingsOption<int> 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));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>What the limit chosen does: removes the oldest media past it, or nothing at all.</summary>
|
||||
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<SettingsOption<int>> KeptChoices =>
|
||||
[.. (KeptPresets.Contains(Kept) ? KeptPresets : KeptPresets.Append(Kept)).Order().Select(n => new SettingsOption<int>(n, Loc.Plural("Settings.Workspace.Versions", n)))];
|
||||
[.. With(KeptPresets, Kept).Select(n => new SettingsOption<int>(n, Loc.Plural("Settings.Workspace.Versions", n)))];
|
||||
|
||||
public SettingsOption<int> 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));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The defaults of every row (Reset section); the caller saves. The folder stays (Change chooses it, after its plan).</summary>
|
||||
// ---------------- Clean after ----------------
|
||||
|
||||
/// <summary>The presets in days, a value set elsewhere among them, then Never (0).</summary>
|
||||
public IReadOnlyList<SettingsOption<int>> CleanAfterChoices =>
|
||||
[
|
||||
.. With(CleanAfterPresets, CleanAfter).Where(n => n > 0).Select(n => new SettingsOption<int>(n, Loc.Plural("Settings.Workspace.Days", n))),
|
||||
new(0, Loc.L("Settings.Workspace.Never")),
|
||||
];
|
||||
|
||||
public SettingsOption<int> 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));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>What the age chosen does: removes the media of projects not opened so long, or never.</summary>
|
||||
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 ----------------
|
||||
|
||||
/// <summary>"3 items, 1.2 GB", "Nothing in trash", "Measuring…" meanwhile; null before the first measure or when it failed.</summary>
|
||||
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));
|
||||
|
||||
/// <summary>The trash holds something, as measured last: Empty… is enabled.</summary>
|
||||
public bool HasTrash => _usage is { TrashItems: > 0 };
|
||||
|
||||
/// <summary>Lists the trash, asks for the typed number of its entries, then erases them (<see cref="EmptyTrashAsync"/>).</summary>
|
||||
public AsyncRelayCommand EmptyTrashCommand => _emptyTrash ??= new AsyncRelayCommand((_, token) => EmptyTrashAsync(token), _ => services is not null && HasTrash && !_isMeasuring);
|
||||
|
||||
private AsyncRelayCommand? _emptyTrash;
|
||||
|
||||
/// <summary>Empty…'s tooltip: what it does, or that there is nothing to erase.</summary>
|
||||
public string EmptyTrashToolTip => Loc.L(HasTrash ? "Tooltips.Settings.Workspace.EmptyTrash" : "Tooltips.Settings.Workspace.EmptyTrash.Disabled");
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Empty…: the trash's plan (nothing erased), its confirmation with the number of entries typed
|
||||
/// (<see cref="TrashRequest"/>), 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.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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<string>
|
||||
{
|
||||
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 ----------------
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>Labels in the current language, values as the settings have them now.</summary>
|
||||
internal void Refresh() => OnAllPropertiesChanged();
|
||||
|
||||
private bool IsMoving => services?.IsMoving() ?? false;
|
||||
|
||||
/// <summary>The value the workspace applies: at least one version.</summary>
|
||||
private int Kept => Math.Max(1, settings.WorkspaceKeptVersions);
|
||||
|
||||
/// <summary>The limit the clean-up applies: none below 1 GB.</summary>
|
||||
private int SizeLimit => Math.Max(0, settings.WorkspaceSizeLimitGb);
|
||||
|
||||
/// <summary>The age the clean-up applies: never below 1 day.</summary>
|
||||
private int CleanAfter => Math.Max(0, settings.WorkspaceCleanAfterDays);
|
||||
|
||||
/// <summary>Open in workspace copies the originals; any other value stored reads as the proxies, as the open dialog takes it.</summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stores a choice that differs from the stored value (<paramref name="current"/>, 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.
|
||||
/// </summary>
|
||||
private bool Store(SettingsOption<int>? choice, int current, Action<int> 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<int> With(int[] presets, int current) => (presets.Contains(current) ? presets : presets.Append(current)).Order();
|
||||
}
|
||||
Reference in new issue
Block a user