fix(workspace): settle conflicts in one answer and give refused folders a way on
Phase 5a fix round 2 of owner review 2 (desktop):
- Take library's no longer commits the working state first, so a take that
leaves only the library's values sends no empty version; the working state
it replaces is kept aside in versions/.replaced, outside the chain.
- Conflicts list this side's value as the working state holds it, so one
answer settles them instead of asking again for the newer value.
- A conflict of format (library saved by a newer Chronos) offers only Save
both and Later, says why in its tooltip and shows no raw format numbers.
- Conflict lines count the photos a setting differs on ("Excluded frames
(3)") instead of dropping the duplicates.
- A read-only library is named as such, not as offline; checkouts from it
stay editable and their versions wait in the workspace.
- A workspace folder refused inside a library offers Choose folder, and
Settings > Workspace gets Change...: a plan (projects left, projects found)
is confirmed before the folder changes; nothing is moved.
- Open in workspace shows the copy's size and the drive's free space, and
warns when the copy would not fit with its 0.5 GB reserve.
- A cancelled first copy removes the half media it wrote.
- A copy whose project.chronos cannot be read is listed as damaged instead of
hidden, and goes only through Remove local copy > Discard, after a plan.
- Pruning keeps a version whose archive file is damaged (test added).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8256b72913
commit
64fc5521c0
30 files changed
+1017
-98
No files matched your search
@@ -0,0 +1,86 @@
|
||||
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>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"),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user