Phase 5c (owner review 2, R8) is built by six packages in parallel. This commit settles everything they share, so each one touches its own files: - job kinds WorkspaceRender (21), WorkspaceSend (22) and WorkspaceMove (23) with their wire names, default priorities, notices and parameter records; their handlers are registered as skeletons that throw until their package lands - WorkspaceJobOptions and a new CreateHandlers overload; the earlier ones stay and default the options - originals in the media index (an index of phase 5b reads as proxies only), their file names, and the exports/renders.json ledger of local renders, written atomically - the optional project and version of an uploaded render - the workspace settings (size limit, default media, version on render, clean-up age, project to open) and when each project was opened, which Reset and Import keep and Export leaves out - WorkspaceHost split into partial files, with stubs for usage, trash and the folder move, removal hooks for unsent renders and last originals, and a guard that holds work while the workspace moves - every new string of the phase in English and Italian, with tooltips Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
112 lines
5.8 KiB
C#
112 lines
5.8 KiB
C#
using System.IO;
|
||
using Chronos.App.Editor;
|
||
using Chronos.App.Infrastructure;
|
||
using Chronos.App.Shell;
|
||
using Chronos.Core.Diagnostics;
|
||
using Chronos.Core.Localization;
|
||
|
||
namespace Chronos.App.Workspace;
|
||
|
||
/// <summary>
|
||
/// Choosing another workspace folder (owner review 2, R8): Settings › Workspace › Change, and the refusal of a folder
|
||
/// inside a library, where Edit cannot be used until one is chosen. The folder is picked, its plan shown and confirmed
|
||
/// (the projects the folder in use keeps, those the new one holds), a workspace project open in the editor closes (its
|
||
/// last edit stored first), and only then does the setting change. Nothing is moved or deleted: the projects of the
|
||
/// folder left stay there, listed again once it is chosen back. Moving a workspace with its projects comes in phase 5c.
|
||
/// </summary>
|
||
public static class WorkspaceFolderChange
|
||
{
|
||
/// <summary>The shell's flow: its folder picker and confirmation, its editor, its toasts.</summary>
|
||
public static async Task<bool> ChooseAsync(ShellViewModel shell)
|
||
{
|
||
ArgumentNullException.ThrowIfNull(shell);
|
||
var changed = await ChooseAsync(shell.Services.Workspace, shell.Services.Dialogs, async () =>
|
||
{
|
||
if (shell.Sequence.Editor?.Session.Source is not WorkspaceSequenceSource) return true;
|
||
if (!await shell.Sequence.ConfirmCloseAsync()) return false;
|
||
await shell.Sequence.CloseAsync();
|
||
shell.KeepSequence(null);
|
||
return true;
|
||
}, message => shell.Notify(Loc.L("Settings.Workspace.NotChanged"), message, isError: true));
|
||
if (changed) shell.Notify(Loc.L("Settings.Workspace.Changed"), shell.Services.Workspace.Root);
|
||
return changed;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Picks a folder through <paramref name="dialogs"/>, confirms its plan, lets <paramref name="closeProject"/> close a
|
||
/// workspace project open in the editor (false keeps everything as it is), then makes it the workspace's folder.
|
||
/// <paramref name="failed"/> hears why a folder was refused. True when the folder changed.
|
||
/// </summary>
|
||
public static async Task<bool> ChooseAsync(WorkspaceHost host, IAppDialogs dialogs, Func<Task<bool>> closeProject, Action<string> failed)
|
||
{
|
||
ArgumentNullException.ThrowIfNull(host);
|
||
ArgumentNullException.ThrowIfNull(dialogs);
|
||
ArgumentNullException.ThrowIfNull(closeProject);
|
||
ArgumentNullException.ThrowIfNull(failed);
|
||
if (dialogs.PickFolder(Loc.L("Settings.Workspace.ChooseTitle"), Directory.Exists(host.Root) ? host.Root : null) is not { } folder) return false;
|
||
try
|
||
{
|
||
var plan = await host.PlanFolderAsync(folder);
|
||
if (plan.IsSame) return false;
|
||
if (plan.InsideLibrary)
|
||
{
|
||
failed(Loc.L("Errors.Workspace.InsideLibraryFolder", plan.Folder));
|
||
return false;
|
||
}
|
||
if (!dialogs.Confirm(Request(plan))) return false;
|
||
if (!await closeProject()) return false;
|
||
await host.UseFolderAsync(plan.Folder);
|
||
return true;
|
||
}
|
||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or ArgumentException or WorkspaceException)
|
||
{
|
||
Log.Warning("workspace", $"The workspace folder was not changed to {folder}", ex);
|
||
failed(ex is WorkspaceException ? ex.Message : Loc.L("Errors.Workspace.FolderUnusable", folder));
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Settings › Workspace › Move… (phase 5c): the shell's flow over <see cref="MoveAsync(WorkspaceHost, IAppDialogs, Func{Task{bool}}, Action{string})"/>,
|
||
/// with its folder picker, confirmation, editor and toasts. True when the move was queued.
|
||
/// </summary>
|
||
public static Task<bool> MoveAsync(ShellViewModel shell)
|
||
{
|
||
ArgumentNullException.ThrowIfNull(shell);
|
||
throw new NotImplementedException("Moving the workspace folder comes with phase 5c (P6).");
|
||
}
|
||
|
||
/// <summary>
|
||
/// Picks the folder the workspace moves to through <paramref name="dialogs"/>, shows its plan
|
||
/// (<see cref="WorkspaceHost.PlanMoveAsync"/>) and asks for the user's word, lets <paramref name="closeProject"/> close a
|
||
/// workspace project open in the editor (false keeps everything as it is), then queues the move
|
||
/// (<see cref="WorkspaceHost.QueueMoveAsync"/>). <paramref name="failed"/> hears why it was refused. True when it was queued.
|
||
/// </summary>
|
||
public static Task<bool> MoveAsync(WorkspaceHost host, IAppDialogs dialogs, Func<Task<bool>> closeProject, Action<string> failed)
|
||
{
|
||
ArgumentNullException.ThrowIfNull(host);
|
||
ArgumentNullException.ThrowIfNull(dialogs);
|
||
ArgumentNullException.ThrowIfNull(closeProject);
|
||
ArgumentNullException.ThrowIfNull(failed);
|
||
throw new NotImplementedException("Moving the workspace folder comes with phase 5c (P6).");
|
||
}
|
||
|
||
/// <summary>The plan as a confirmation: where Edit's projects come from now, and what stays where it is.</summary>
|
||
public static ConfirmRequest Request(WorkspaceFolderPlan plan)
|
||
{
|
||
ArgumentNullException.ThrowIfNull(plan);
|
||
return new ConfirmRequest
|
||
{
|
||
Heading = Loc.L("Settings.Workspace.ChangeTitle"),
|
||
Message = Loc.L("Settings.Workspace.ChangeMessage", plan.Folder, plan.Current),
|
||
Detail = string.Join(Environment.NewLine, Loc.L("Settings.Workspace.ProjectsLeft", Formatting.Count(plan.ProjectsLeft)),
|
||
Loc.L("Settings.Workspace.ProjectsFound", Formatting.Count(plan.ProjectsFound))),
|
||
IsDetailMonospaced = false,
|
||
SafeText = Loc.L("Archive.Dialog.Cancel"),
|
||
SafeToolTip = Loc.L("Tooltips.Settings.KeepWorkspace"),
|
||
ActionText = Loc.L("Settings.Workspace.Use"),
|
||
ActionToolTip = Loc.L("Tooltips.Settings.UseWorkspace"),
|
||
};
|
||
}
|
||
}
|