diff --git a/src/Chronos.App/Sections/SequenceView.xaml b/src/Chronos.App/Sections/SequenceView.xaml index 10212366..5a6eb10f 100644 --- a/src/Chronos.App/Sections/SequenceView.xaml +++ b/src/Chronos.App/Sections/SequenceView.xaml @@ -127,6 +127,10 @@ + + diff --git a/src/Chronos.App/Sections/SequenceViewModel.cs b/src/Chronos.App/Sections/SequenceViewModel.cs index dbc17373..568222dd 100644 --- a/src/Chronos.App/Sections/SequenceViewModel.cs +++ b/src/Chronos.App/Sections/SequenceViewModel.cs @@ -608,12 +608,20 @@ public sealed class SequenceViewModel : SectionViewModel ImageDecoder decoder, Sequence row) { var request = TakeRequest(row.Id); - var entry = request switch + WorkspaceEntry? entry; + if (request is { ProjectId: { } id }) entry = await workspace.FindAsync(id); + else if (request is { Main: true }) entry = (await workspace.ProjectsOfAsync(row.Id)).FirstOrDefault(p => p.IsMain); + else { - { ProjectId: { } id } => await workspace.FindAsync(id), - { Main: true } => (await workspace.ProjectsOfAsync(row.Id)).FirstOrDefault(p => p.IsMain), - _ => await workspace.LastUsedAsync(row.Id), - }; + var (cancelled, chosen) = await PolicyEntryAsync(services, workspace, row.Id, row.DisplayTitle, _ => true); + if (cancelled) + { + _afterOpen = null; + Shell.KeepSequence(OpenSequenceId); + return null; + } + entry = chosen; + } // This Chronos cannot read its working state (damaged, or a newer Chronos's): nothing is checked out over it. if (entry is { IsReadable: false } unreadable) throw WorkspaceHost.Unreadable(unreadable); // No project of the sequence here opens, and its Main here is such a copy (never among its projects): said at once, @@ -634,10 +642,12 @@ public sealed class SequenceViewModel : SectionViewModel if (entry is { HasMedia: true }) { workspace.Remember(row.Id, entry.ProjectId); + workspace.RecordOpened(entry.ProjectId); return (new WorkspaceSequenceSource(workspace.Sync, entry.ProjectId, db, decoder, services.Engine), row.DisplayTitle); } var projectId = entry?.ProjectId ?? request?.ProjectId; string? newName = null; + var media = DefaultMedia(services); if (entry is null && projectId is { } wanted && (await workspace.HomeProjectsAsync(row.Id)).All(p => p.Id != wanted)) { // A project file of a project this home does not have (another PC's workspace): its sequence's Main takes it. @@ -653,12 +663,12 @@ public sealed class SequenceViewModel : SectionViewModel Shell.KeepSequence(OpenSequenceId); return null; } - (projectId, newName) = (choice.ProjectId, choice.NewName); + (projectId, newName, media) = (choice.ProjectId, choice.NewName, choice.Media); } WorkspaceCheckout checkout; try { - checkout = await workspace.CheckoutAsync(row.Id, projectId, newName); + checkout = await workspace.CheckoutAsync(row.Id, projectId, newName, media); } catch (WorkspaceException ex) when (ex.FolderRefused) { @@ -710,12 +720,20 @@ public sealed class SequenceViewModel : SectionViewModel private async Task OpenServerWorkspaceAsync(AppServices services, WorkspaceHost workspace, ChronosDatabase db, ImageDecoder decoder, Guid remoteId) { var request = _requested is { } asked && asked.SequenceId == remoteId ? asked : null; - var entry = request switch + WorkspaceEntry? entry; + if (request is { ProjectId: { } id }) entry = await workspace.FindAsync(id) is { IsServerHome: true } found && found.SequenceId == remoteId ? found : null; + else if (request is { Main: true }) entry = (await workspace.ProjectsOfAsync(remoteId)).FirstOrDefault(p => p is { IsMain: true, IsServerHome: true }); + else { - { ProjectId: { } id } => await workspace.FindAsync(id) is { IsServerHome: true } found && found.SequenceId == remoteId ? found : null, - { Main: true } => (await workspace.ProjectsOfAsync(remoteId)).FirstOrDefault(p => p is { IsMain: true, IsServerHome: true }), - _ => await workspace.LastUsedAsync(remoteId) is { IsServerHome: true } last ? last : null, - }; + var (cancelled, chosen) = await PolicyEntryAsync(services, workspace, remoteId, null, p => p.IsServerHome); + if (cancelled) + { + _afterOpen = null; + Shell.KeepSequence(OpenSequenceId); + return new ServerOpen(null); + } + entry = chosen; + } var sync = services.Sync; if (entry is { IsReadable: false } unreadable) { @@ -726,6 +744,7 @@ public sealed class SequenceViewModel : SectionViewModel { TakeRequest(remoteId); workspace.Remember(remoteId, entry.ProjectId); + workspace.RecordOpened(entry.ProjectId); // Its analyses and renders travel on a connection of the signed-in session, when that is the project's server: // made again whenever the sign-in changes, so a project opened signed out renders once signed in. var server = entry.Home.Server; @@ -755,6 +774,7 @@ public sealed class SequenceViewModel : SectionViewModel } var projectId = entry?.ProjectId ?? request?.ProjectId; string? newName = null; + var media = DefaultMedia(services); if (entry is null && projectId is { } wanted && (await workspace.HomeProjectsAsync(home)).All(p => p.Id != wanted)) { // A project the server does not have (deleted there, or another server's): the sequence's Main opens instead. @@ -770,12 +790,12 @@ public sealed class SequenceViewModel : SectionViewModel Shell.KeepSequence(OpenSequenceId); return new ServerOpen(null); } - (projectId, newName) = (choice.ProjectId, choice.NewName); + (projectId, newName, media) = (choice.ProjectId, choice.NewName, choice.Media); } WorkspaceCheckout checkout; try { - checkout = await workspace.CheckoutAsync(home, projectId, newName); + checkout = await workspace.CheckoutAsync(home, projectId, newName, media); } catch (WorkspaceException ex) when (ex.FolderRefused) { @@ -811,25 +831,23 @@ public sealed class SequenceViewModel : SectionViewModel /// /// "Open in workspace" for a sequence of (this PC's archive, or a server): its projects, the - /// media, and for this PC's archive what their copy writes and the room the workspace's drive has; null when closed - /// without a choice. , the copy of Main here this Chronos cannot read, is listed + /// media (Settings › Workspace › Media chosen first), what their copy writes and the room the workspace's drive has; null + /// when closed without a choice. , the copy of Main here this Chronos cannot read, is listed /// disabled, why in its tooltip. /// private async Task AskProjectAsync(WorkspaceHost workspace, BundleHome home, string title, WorkspaceEntry? unreadableMain) { var projects = await workspace.HomeProjectsAsync(home); WorkspaceCopyFacts? copy = null; - if (home.IsArchive) + try { - try - { - copy = await workspace.CopyFactsAsync(home.SequenceId); - } - catch (Exception ex) when (ex is System.IO.IOException or System.IO.InvalidDataException or InvalidOperationException or DatabaseException or UnauthorizedAccessException) - { - // Only shown: the copy measures again before it writes. - Log.Info("workspace", $"The copy of sequence {home.SequenceId} could not be measured: {ex.Message}"); - } + copy = await workspace.CopyFactsAsync(home); + } + catch (Exception ex) when (ex is System.IO.IOException or System.IO.InvalidDataException or InvalidOperationException or DatabaseException + or UnauthorizedAccessException or ChronosApiException or System.Net.Http.HttpRequestException) + { + // Only shown: the copy measures again before it writes. + Log.Info("workspace", $"The copy of sequence {home.SequenceId} could not be measured: {ex.Message}"); } var unreadable = unreadableMain is { } main ? new Dictionary @@ -837,7 +855,8 @@ public sealed class SequenceViewModel : SectionViewModel [main.ProjectId] = Loc.L(main.Newer ? "Tooltips.Editor.Workspace.State.NewerCopy" : "Tooltips.Editor.Workspace.State.DamagedCopy"), } : null; - var dialog = new OpenInWorkspaceDialogViewModel(title, projects, d => CloseDialog(d), copy: copy, unreadable: unreadable, server: !home.IsArchive); + var dialog = new OpenInWorkspaceDialogViewModel(title, projects, d => CloseDialog(d), copy: copy, unreadable: unreadable, server: !home.IsArchive, + defaultMedia: DefaultMedia(Shell.Services)); // The picker or the open sequence shows behind the dialog meanwhile, not the progress bar. IsLoading = false; OpenDialog(dialog); @@ -851,6 +870,37 @@ public sealed class SequenceViewModel : SectionViewModel } } + /// The media a checkout copies unless "Open in workspace" chose: Settings › Workspace › Media. + private static string DefaultMedia(AppServices services) => + services.Settings.WorkspaceDefaultMedia == BundleMedia.Originals ? BundleMedia.Originals : BundleMedia.Proxies; + + /// + /// The project of the sequence Edit opens when none was asked for (phase 5c, Settings › Workspace › Open project): the + /// one opened last, Main, or the one chosen in "Open which project?" when the workspace holds several (Cancelled: closed + /// without a choice). Only projects takes count; none here: null. + /// + private async Task<(bool Cancelled, WorkspaceEntry? Entry)> PolicyEntryAsync(AppServices services, WorkspaceHost workspace, Guid sequenceId, string? title, + Func fits) + { + var last = await workspace.LastUsedAsync(sequenceId) is { } used && fits(used) ? used : null; + var policy = services.Settings.WorkspaceOpenProject; + if (policy == WorkspaceOpenPolicy.LastUsed) return (false, last); + var here = (await workspace.ProjectsOfAsync(sequenceId)).Where(p => fits(p) && p.IsReadable).ToList(); + if (policy == WorkspaceOpenPolicy.Main) return (false, here.FirstOrDefault(p => p.IsMain) ?? last); + if (here.Count < 2) return (false, last ?? here.FirstOrDefault()); + var dialog = new OpenProjectDialogViewModel(title ?? here[0].SequenceTitle, here, last?.ProjectId, d => CloseDialog(d)); + IsLoading = false; + OpenDialog(dialog); + try + { + return await dialog.Choice is { } chosen ? (false, chosen) : (true, null); + } + finally + { + IsLoading = true; + } + } + /// The project the next open of takes, taken once; null when none was asked for. private ProjectRequest? TakeRequest(Guid sequenceId) { diff --git a/src/Chronos.App/Workspace/ProjectMenuViewModel.cs b/src/Chronos.App/Workspace/ProjectMenuViewModel.cs index 3a38bec6..318a7498 100644 --- a/src/Chronos.App/Workspace/ProjectMenuViewModel.cs +++ b/src/Chronos.App/Workspace/ProjectMenuViewModel.cs @@ -81,6 +81,8 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel private bool _isSyncing; private bool _homeFramesChanged; private Guid _copyJob; + private bool _copyingOriginals; + private bool _changingMedia; private bool _disposed; /// Counts the editor's changes, so only the last one's state read applies. @@ -110,6 +112,8 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel RenameCommand = new AsyncRelayCommand(OpenRenameAsync); DeleteCommand = new AsyncRelayCommand(DeleteAsync, () => !IsMain); RemoveCopyCommand = new AsyncRelayCommand(OpenRemoveCopyAsync); + CopyOriginalsCommand = new AsyncRelayCommand(CopyOriginalsAsync, () => !HoldsOriginals && !IsMediaBusy); + ProxiesOnlyCommand = new AsyncRelayCommand(ProxiesOnlyAsync, () => HoldsOriginals && !IsMediaBusy); source.JobChanged += OnJobChanged; session.ProjectChanged += OnProjectChanged; host.HomeChanged += OnHomeChanged; @@ -193,6 +197,27 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel public ICommand UpdateMediaCommand => _updateMedia; + /// The workspace holds the project's originals besides its proxies (phase 5c): renders run on this PC. + public bool HoldsOriginals => _source.Workspace?.Media.Kind == BundleMedia.Originals; + + /// + /// The media cannot change now: changes not saved as a version, a sync or a copy of the media running (the jobs of the + /// sequence are asked when the command runs). + /// + public bool IsMediaBusy => _changingMedia || _isSyncing || _copyJob != Guid.Empty || _status is { Modified: true, ReadOnly: false }; + + /// Copy originals… (phase 5c): the project's originals into the workspace, to render on this PC. + public ICommand CopyOriginalsCommand { get; } + + /// Proxies only… (phase 5c): the originals copied here deleted once the home is checked to hold each one. + public ICommand ProxiesOnlyCommand { get; } + + public string CopyOriginalsToolTip => IsMediaBusy ? Loc.L("Tooltips.Editor.Project.MediaBusy") + : WorkspaceText.ForHome("Tooltips.Editor.Project.CopyOriginals", IsServerHome); + + public string ProxiesOnlyToolTip => IsMediaBusy ? Loc.L("Tooltips.Editor.Project.MediaBusy") + : WorkspaceText.ForHome("Tooltips.Editor.Project.ProxiesOnly", IsServerHome); + /// Reads where the project stands (against its home) and whether the home's frames moved. public async Task RefreshAsync() { @@ -644,6 +669,130 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel } } + /// + /// Copy originals…: refused while the media cannot change (, or a job of the sequence waits or + /// runs); otherwise the copy is queued, the banner says it runs, and the editor reads the media again once it is done. + /// + private async Task CopyOriginalsAsync() + { + try + { + await StoreEditAsync(); + if (await MediaRefusalAsync() is { } refusal) + { + _ui.Notify(Loc.L("Editor.Workspace.CopyFailed"), refusal, isError: true); + return; + } + var job = await _host.QueueOriginalsCopyAsync(ProjectId); + _copyJob = job.Id; + _copyingOriginals = true; + RaiseState(); + _ui.Notify(Loc.L("Editor.Workspace.CopyingOriginals"), _session.Content.Sequence.DisplayTitle, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs")); + } + catch (Exception ex) when (ex is not OutOfMemoryException) + { + Log.Warning("workspace", $"The originals of project {ProjectId} could not be queued for copy", ex); + _ui.Notify(Loc.L("Editor.Workspace.CopyFailed"), WorkspaceText.Failure(ex, IsServerHome), isError: true); + } + } + + /// + /// Proxies only…: the plan (each original hashed and weighed against the home, read now), confirmed by the user, then + /// applied; the home out of reach, or anything changed since the plan, removes nothing. + /// + private async Task ProxiesOnlyAsync() + { + try + { + await StoreEditAsync(); + if (await MediaRefusalAsync() is { } refusal) + { + _ui.Notify(Loc.L("Editor.Workspace.OriginalsNotRemoved"), refusal, isError: true); + return; + } + SetChangingMedia(true); + var plan = await _host.PlanProxiesOnlyAsync(ProjectId); + if (_disposed) return; + var detail = new List + { + Loc.L("Editor.ProxiesOnly.Originals", Formatting.Count(plan.Originals)), + Loc.L("Editor.ProxiesOnly.Size", Formatting.Bytes(plan.Bytes)), + }; + if (plan.ToTrash > 0) detail.Add(Loc.L("Editor.ProxiesOnly.ToTrash", Formatting.Count(plan.ToTrash))); + if (!_ui.Confirm(new ConfirmRequest + { + Heading = Loc.L("Editor.ProxiesOnly.Title", Name), + Message = WorkspaceText.ForHome("Editor.ProxiesOnly.Message", IsServerHome), + Detail = string.Join(Environment.NewLine, detail), + IsDetailMonospaced = false, + DetailToolTip = plan.ToTrash > 0 ? WorkspaceText.ForHome("Tooltips.Editor.ProxiesOnly.ToTrash", IsServerHome) : null, + SafeText = Loc.L("Editor.Project.Keep"), + SafeToolTip = Loc.L("Tooltips.Editor.ProxiesOnly.Keep"), + ActionText = Loc.L("Editor.ProxiesOnly.Action"), + ActionToolTip = Loc.L("Tooltips.Editor.ProxiesOnly.Action"), + IsDestructive = true, + })) + return; + var trashed = await _host.ProxiesOnlyAsync(ProjectId, plan); + if (_disposed) return; + await _session.ReloadAsync(); + _ui.Notify(Loc.L("Editor.Workspace.OriginalsRemoved"), + trashed > 0 ? Loc.L("Editor.ProxiesOnly.ToTrash", Formatting.Count(trashed)) : _session.Content.Sequence.DisplayTitle); + } + catch (Exception ex) when (ex is not OutOfMemoryException) + { + Log.Warning("workspace", $"The originals of project {ProjectId} were not removed", ex); + _ui.Notify(Loc.L("Editor.Workspace.OriginalsNotRemoved"), WorkspaceText.Failure(ex, IsServerHome), isError: true); + } + finally + { + SetChangingMedia(false); + await RefreshAsync(); + } + } + + /// + /// Why the media cannot change now (Errors.Workspace.MediaBusy): changes not saved as a version, a copy or sync + /// running, or an analysis, render or workspace job of the sequence waiting or running; null when they can. + /// + private async Task MediaRefusalAsync() + { + var local = await _host.StatusAsync(ProjectId, askHome: false); + if (_disposed) return null; + Apply(WithLocal(_status, local)); + if (IsMediaBusy) return Loc.L("Errors.Workspace.MediaBusy"); + var jobs = await _source.ListJobsAsync(CancellationToken.None); + var sequenceId = SequenceId; + return jobs.Any(j => j.State is JobState.Queued or JobState.Running or JobState.Paused && j.TargetIds.Contains(sequenceId) + && j.Kind is JobKind.DeepAnalyse or JobKind.LightAnalyse or JobKind.Render or JobKind.WorkspaceCopy or JobKind.WorkspaceRender + or JobKind.WorkspaceSend) + ? Loc.L("Errors.Workspace.MediaBusy") + : null; + } + + /// The copy of the originals ended: said, with the frames that have none (they stay proxies, and a local render waits for them). + private void NotifyOriginalsCopied() + { + int missing; + try + { + missing = _source.Project.ReadMedia()?.Frames.Count(f => f.Original is null) ?? 0; + } + catch (Exception ex) when (ex is System.IO.IOException or System.IO.InvalidDataException or UnauthorizedAccessException) + { + Log.Warning("workspace", $"The media of project {ProjectId} could not be read after the copy of its originals", ex); + missing = 0; + } + if (missing == 0) _ui.Notify(Loc.L("Editor.Workspace.OriginalsCopied"), _session.Content.Sequence.DisplayTitle); + else _ui.Notify(Loc.L("Editor.Workspace.OriginalsCopied"), Loc.L("Editor.Workspace.OriginalsMissing", Formatting.Count(missing))); + } + + private void SetChangingMedia(bool changing) + { + _changingMedia = changing; + RaiseState(); + } + /// The editor's last edit stored in the working state before an operation reads it. /// It could not be stored (it is retried in the background; nothing was lost). private async Task StoreEditAsync() @@ -787,10 +936,13 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel { if (_disposed || job.Id != _copyJob) return; _copyJob = Guid.Empty; + var originals = _copyingOriginals; + _copyingOriginals = false; if (job.State == JobState.Failed) _ui.Notify(Loc.L("Editor.Workspace.CopyFailed"), job.Error ?? _session.Content.Sequence.DisplayTitle, isError: true); try { if (job.State == JobState.Done) await _session.ReloadAsync(); + if (job.State == JobState.Done && originals) NotifyOriginalsCopied(); } catch (Exception ex) when (ex is not OutOfMemoryException) { @@ -836,6 +988,10 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel OnPropertyChanged(nameof(RemoveCopyToolTip)); OnPropertyChanged(nameof(MediaChangedToolTip)); OnPropertyChanged(nameof(UpdateMediaToolTip)); + OnPropertyChanged(nameof(HoldsOriginals)); + OnPropertyChanged(nameof(IsMediaBusy)); + OnPropertyChanged(nameof(CopyOriginalsToolTip)); + OnPropertyChanged(nameof(ProxiesOnlyToolTip)); _updateMedia.RaiseCanExecuteChanged(); CommandManager.InvalidateRequerySuggested(); } diff --git a/src/Chronos.App/Workspace/WorkspaceDialogs.cs b/src/Chronos.App/Workspace/WorkspaceDialogs.cs index 3fb826a8..60467b4f 100644 --- a/src/Chronos.App/Workspace/WorkspaceDialogs.cs +++ b/src/Chronos.App/Workspace/WorkspaceDialogs.cs @@ -47,8 +47,9 @@ public static class ProjectNames /// /// "Open in workspace" (owner review 2, R8), asked when a sequence has no project in the workspace yet, and by the project /// menu's Open project: which project of its home (Main, made from the sequence's settings as they are, or another) or a -/// new one with its name, and the media to copy (proxies; the originals come in phase 5c). Open queues the copy; the -/// sequence opens once it is done. +/// new one with its name, and the media to copy: the proxies, or (phase 5c) the originals besides, to render on this PC, +/// offered while the workspace's drive has room for them (Settings › Workspace › Media chooses the default). Open queues +/// the copy; the sequence opens once it is done. /// public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel { @@ -56,6 +57,7 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel private readonly bool _server; private ProjectOption? _selected; private bool _isNew; + private bool _isOriginals; /// The names a new project cannot take (default: those of ). /// What the copy of the media writes and the free space of the workspace's drive; null when not measured (shown as nothing). @@ -63,8 +65,10 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel /// The projects whose copy here this Chronos cannot read (damaged, or a newer Chronos's), with why: listed, never chosen. /// /// The sequence's home is a server (phase 5b): the texts name the server. + /// The media chosen first (); the proxies when the originals have no room. public OpenInWorkspaceDialogViewModel(string sequenceTitle, IReadOnlyList projects, Action close, - IReadOnlyList? taken = null, WorkspaceCopyFacts? copy = null, IReadOnlyDictionary? unreadable = null, bool server = false) + IReadOnlyList? taken = null, WorkspaceCopyFacts? copy = null, IReadOnlyDictionary? unreadable = null, bool server = false, + string defaultMedia = BundleMedia.Proxies) : base(close) { _server = server; @@ -76,7 +80,11 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel new DialogFact(Loc.L("Editor.OpenWorkspace.Size"), Formatting.Bytes(copy.Bytes), Reason: Loc.L("Tooltips.Editor.OpenWorkspace.Size")), new DialogFact(Loc.L("Editor.OpenWorkspace.Free"), copy.Free is { } free ? Formatting.Bytes(free) : Loc.L("Server.Sync.None"), Reason: Loc.L(copy.TooLittleSpace ? "Errors.Workspace.NoRoom" : "Tooltips.Editor.OpenWorkspace.Free")), + .. copy.OriginalsBytes is { } originals + ? [new DialogFact(Loc.L("Editor.OpenWorkspace.Originals"), Formatting.Bytes(originals), Reason: Loc.L("Tooltips.Editor.OpenWorkspace.OriginalsSize"))] + : Array.Empty(), ]; + _isOriginals = defaultMedia == BundleMedia.Originals && CanCopyOriginals; Projects = [.. projects.OrderByDescending(p => p.IsMain).Select(p => new ProjectOption(p, unreadable?.GetValueOrDefault(p.Id)))]; _selected = Projects.FirstOrDefault(p => p.IsAvailable); _isNew = !HasProjects; @@ -97,8 +105,8 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel /// "Copy size" and "Free space", under the media. public IReadOnlyList CopyFacts { get; } - /// The drive lacks room for the copy: the free space says so (the copy would stop saying how much is missing). - public bool IsShortOfSpace => Copy?.TooLittleSpace == true; + /// The drive lacks room for the copy of the media chosen: the free space says so (the copy would stop saying how much is missing). + public bool IsShortOfSpace => Copy?.TooLittleSpaceFor(Media) == true; public string Heading => Loc.L("Editor.OpenWorkspace.Title"); @@ -147,11 +155,37 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel public string ProxiesToolTip => WorkspaceText.ForHome("Tooltips.Editor.OpenWorkspace.Proxies", _server); - /// The proxies, the only media this phase copies. - public bool IsProxies => true; + /// The proxies alone: light to edit, renders run where the originals are. + public bool IsProxies + { + get => !_isOriginals; + set + { + if (value) IsOriginals = false; + } + } - /// The originals: offered from phase 5c, to render on this PC. - public bool CanCopyOriginals => false; + /// The proxies and the originals (phase 5c): renders run on this PC. + public bool IsOriginals + { + get => _isOriginals; + set + { + if (!Set(ref _isOriginals, value && CanCopyOriginals)) return; + OnPropertyChanged(nameof(IsProxies)); + OnPropertyChanged(nameof(IsShortOfSpace)); + } + } + + /// The media copies. + public string Media => _isOriginals ? BundleMedia.Originals : BundleMedia.Proxies; + + /// The originals can be chosen: the drive has room for them besides the proxies (or was not measured: the copy measures again). + public bool CanCopyOriginals => Copy?.TooLittleSpaceFor(BundleMedia.Originals) != true; + + public string OriginalsToolTip => CanCopyOriginals + ? WorkspaceText.ForHome("Tooltips.Editor.OpenWorkspace.OriginalsReady", _server) + : Loc.L("Tooltips.Editor.OpenWorkspace.NoRoomOriginals"); public ICommand OpenCommand { get; } @@ -169,7 +203,7 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel private void Open() { if (!CanOpen) return; - _choice.TrySetResult(_isNew ? new OpenChoice(null, NewName.Text.Trim(), BundleMedia.Proxies) : new OpenChoice(_selected!.Project.Id, null, BundleMedia.Proxies)); + _choice.TrySetResult(_isNew ? new OpenChoice(null, NewName.Text.Trim(), Media) : new OpenChoice(_selected!.Project.Id, null, Media)); Close(); } @@ -181,6 +215,69 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel } } +/// A project of the workspace offered by "Open which project?" (Main in the UI language). +public sealed record WorkspaceProjectChoice(WorkspaceEntry Entry) +{ + public string Label => WorkspaceText.ProjectName(Entry.Name, Entry.IsMain); + + public override string ToString() => Label; +} + +/// +/// "Open which project?" (phase 5c, Settings › Workspace › Open project: Ask): Edit asks which of the sequence's projects in +/// the workspace opens, the one opened last chosen first. +/// +public sealed class OpenProjectDialogViewModel : ArchiveDialogViewModel +{ + private readonly TaskCompletionSource _choice = new(TaskCreationOptions.RunContinuationsAsynchronously); + private WorkspaceProjectChoice? _selected; + + /// The sequence's readable projects in the workspace. + /// The project opened last, chosen first; null: Main. + public OpenProjectDialogViewModel(string sequenceTitle, IReadOnlyList projects, Guid? last, Action close) + : base(close) + { + ArgumentNullException.ThrowIfNull(projects); + Message = Loc.L("Editor.OpenProject.Message", sequenceTitle); + Projects = [.. projects.OrderByDescending(p => p.IsMain).ThenBy(p => p.Name, StringComparer.CurrentCultureIgnoreCase).Select(p => new WorkspaceProjectChoice(p))]; + _selected = Projects.FirstOrDefault(p => p.Entry.ProjectId == last) ?? Projects.FirstOrDefault(); + OpenCommand = new RelayCommand(Open, () => _selected is not null); + } + + /// Completes with the project chosen, or null when the dialog was closed without one. + public Task Choice => _choice.Task; + + public string Heading => Loc.L("Editor.OpenProject.Title"); + + public string Message { get; } + + public IReadOnlyList Projects { get; } + + public WorkspaceProjectChoice? SelectedProject + { + get => _selected; + set + { + if (Set(ref _selected, value)) CommandManager.InvalidateRequerySuggested(); + } + } + + public ICommand OpenCommand { get; } + + public override void Dispose() + { + _choice.TrySetResult(null); + base.Dispose(); + } + + private void Open() + { + if (_selected is null) return; + _choice.TrySetResult(_selected.Entry); + Close(); + } +} + /// Names a project: "New project" (made from the open project's last version at the home) or "Rename". public sealed class ProjectNameDialogViewModel : ArchiveDialogViewModel { diff --git a/src/Chronos.App/Workspace/WorkspaceDialogs.xaml b/src/Chronos.App/Workspace/WorkspaceDialogs.xaml index cb9391be..d7af2a3b 100644 --- a/src/Chronos.App/Workspace/WorkspaceDialogs.xaml +++ b/src/Chronos.App/Workspace/WorkspaceDialogs.xaml @@ -54,10 +54,10 @@ IsEnabled="{Binding IsNew}" ToolTip="{Binding NewName.ToolTip}" MaxLength="60" AutomationProperties.Name="{l:Loc Editor.OpenWorkspace.New}" /> - - + @@ -88,6 +88,30 @@ + + + + + + + + + + + + + + + +