feat: owner review 2 phase 5a: workspace and projects with a local home (#14)
CI / Build and test (push) Successful in 9m43s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 27s
CI / PostgreSQL 16 integration (push) Failing after 8m41s
CI / PostgreSQL 17 integration (push) Successful in 12m37s
CI / Docker image (push) Successful in 56s
Release / Build, test and publish (push) Successful in 14m59s
Release / Server image (push) Successful in 1m51s

Edit opens a sequence as a project of a workspace folder outside the library. Projects have linear version histories kept as sidecars in .chronos/projects/, Main mirrors the sequence's settings, and sync merges setting by setting. Migration 0009, JobKind.WorkspaceCopy = 20, Settings › Workspace, and 241 new strings in 38 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #14.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-11-04 09:22:08 +01:00
1 parent efa87f68ce
commit 9b24cf74fc
370 files changed
+29237 -287

No files matched your search

+103 -46
View File
@@ -5,12 +5,14 @@
xmlns:v="clr-namespace:Chronos.Ui.Visuals;assembly=Chronos.Ui"
xmlns:l="clr-namespace:Chronos.Ui.Localization;assembly=Chronos.Ui"
xmlns:lib="clr-namespace:Chronos.App.Library"
xmlns:ws="clr-namespace:Chronos.App.Workspace"
IsVisibleChanged="OnVisibleChanged">
<!--
The sequence picker of Edit (owner review 1, R7), over the section's view model: one searchable list of this PC's and
the server's sequences, newest first; Enter or a double-click opens one, Esc clears the search and then goes back to
the open sequence. Each row reads as its title to screen readers; the date, frames and states columns are as wide as
their widest row, so the states are never cut.
The sequence picker of Edit (owner review 1, R7), over the section's view model: the workspace's projects (owner review
2, R8), then one searchable list of this PC's and the server's sequences, newest first; Enter or a double-click opens
one, Esc clears the search and then goes back to the open sequence. Each row reads as its title (a project: its name,
sequence and state) to screen readers; the date, frames and states columns are as wide as their widest row, so the
states are never cut.
-->
<UserControl.Resources>
<DataTemplate x:Key="Template.Status" DataType="{x:Type v:CardStatus}">
@@ -24,6 +26,11 @@
<Setter Property="AutomationProperties.Name" Value="{Binding Title}" />
<EventSetter Event="MouseDoubleClick" Handler="OnRowDoubleClick" />
</Style>
<!-- A project of the workspace reads as its name, its sequence and where it stands. -->
<Style x:Key="ListBoxItem.ProjectRow" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem.Row}">
<Setter Property="AutomationProperties.Name" Value="{Binding Description}" />
<EventSetter Event="MouseDoubleClick" Handler="OnProjectDoubleClick" />
</Style>
</UserControl.Resources>
<Border Style="{StaticResource Border.Panel}" MaxWidth="880" Margin="16,24,16,16">
@@ -57,49 +64,99 @@
<ProgressBar Grid.Row="2" Margin="16,0" Height="6" IsIndeterminate="True" Visibility="{Binding Picker.IsLoading, Converter={StaticResource BoolToVisibility}}"
AutomationProperties.Name="{l:Loc Editor.Picker.Loading}" />
<ListBox x:Name="List" Grid.Row="3" Margin="0,4,0,8" ItemsSource="{Binding Picker.Items}" SelectedItem="{Binding Picker.Selected}" SelectionMode="Single"
ItemContainerStyle="{StaticResource ListBoxItem.PickerRow}" TextSearch.TextPath="Title" VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.VirtualizationMode="Recycling" VirtualizingPanel.ScrollUnit="Pixel" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.ScrollChanged="OnScrollChanged" AutomationProperties.Name="{l:Loc Editor.Picker.List}" ToolTip="{l:Loc Tooltips.Editor.Picker.Row}"
KeyboardNavigation.TabNavigation="Continue" Grid.IsSharedSizeScope="True" SelectionChanged="OnSelectionChanged">
<ListBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding Picker.OpenCommand}" />
</ListBox.InputBindings>
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type lib:SequenceItem}">
<Grid Height="40">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="2*" MinWidth="140" />
<ColumnDefinition Width="Auto" MinWidth="84" SharedSizeGroup="PickerDate" />
<ColumnDefinition Width="*" MinWidth="80" />
<ColumnDefinition Width="Auto" MinWidth="56" SharedSizeGroup="PickerFrames" />
<ColumnDefinition Width="Auto" SharedSizeGroup="PickerStates" />
</Grid.ColumnDefinitions>
<!-- Pictures stay left to right in a right-to-left window. -->
<Border Width="64" Height="36" CornerRadius="4" Background="{DynamicResource Brush.Card}" ClipToBounds="True" FlowDirection="LeftToRight"
lib:ThumbnailLoading.Width="64">
<Image Source="{Binding Thumbnail}" Stretch="UniformToFill" />
</Border>
<!-- Cells that may be shortened show their text in their tooltip (an empty camera has none). -->
<TextBlock Grid.Column="1" Style="{StaticResource Text.Cell}" Text="{Binding Title}" Margin="12,0,0,0" FontWeight="SemiBold" ToolTip="{Binding Title}" />
<TextBlock Grid.Column="2" Style="{StaticResource Text.Cell}" Text="{Binding DateText}" Margin="12,0,0,0" Foreground="{DynamicResource Brush.TextMuted}" />
<TextBlock Grid.Column="3" Style="{StaticResource Text.Cell}" Text="{Binding Camera}" Margin="12,0,0,0" Foreground="{DynamicResource Brush.TextMuted}"
ToolTip="{Binding Camera, Converter={x:Static ui:EmptyToNullConverter.Instance}}" />
<TextBlock Grid.Column="4" Style="{StaticResource Text.CellNumber}" Text="{Binding FramesText}" Margin="12,0,0,0" />
<ItemsControl Grid.Column="5" Margin="12,0,0,0" ItemsSource="{Binding Statuses}" ItemTemplate="{StaticResource Template.Status}"
ItemsPanel="{StaticResource Panel.Row}" VerticalAlignment="Center" Focusable="False" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<!-- Owner review 2, R8: two groups, the workspace's projects (each with where it stands) above the library's sequences. -->
<Grid Grid.Row="3">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="{l:Loc Editor.Picker.Workspace}" Style="{StaticResource Text.Label}" Margin="16,8,16,2"
Visibility="{Binding Picker.HasWorkspaceItems, Converter={StaticResource BoolToVisibility}}" />
<ListBox x:Name="Projects" Grid.Row="1" Margin="0,2,0,4" MaxHeight="184" ItemsSource="{Binding Picker.WorkspaceItems}" SelectedItem="{Binding Picker.SelectedProject}"
SelectionMode="Single" ItemContainerStyle="{StaticResource ListBoxItem.ProjectRow}" TextSearch.TextPath="Name" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
AutomationProperties.Name="{l:Loc Editor.Picker.Workspace}" ToolTip="{l:Loc Tooltips.Editor.Picker.Project}" KeyboardNavigation.TabNavigation="Continue"
Grid.IsSharedSizeScope="True" Visibility="{Binding Picker.HasWorkspaceItems, Converter={StaticResource BoolToVisibility}}">
<ListBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding Picker.OpenProjectCommand}" />
<KeyBinding Key="Delete" Command="{Binding Picker.RemoveCopyCommand}" />
</ListBox.InputBindings>
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type ws:WorkspaceProjectItem}">
<!-- Remove local copy also for a project that cannot open (its copy failed, or the library no longer has it). -->
<Grid Height="40" Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ListBox}}">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="{l:Loc Editor.Project.RemoveCopy}" Command="{Binding PlacementTarget.Tag.Picker.RemoveCopyCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
CommandParameter="{Binding}" ToolTip="{l:Loc Tooltips.Editor.Project.RemoveCopy}" />
</ContextMenu>
</Grid.ContextMenu>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" MinWidth="120" />
<ColumnDefinition Width="2*" MinWidth="120" />
<ColumnDefinition Width="Auto" SharedSizeGroup="ProjectState" />
</Grid.ColumnDefinitions>
<!-- Pictures stay left to right in a right-to-left window. -->
<Border Width="64" Height="36" CornerRadius="4" Background="{DynamicResource Brush.Card}" ClipToBounds="True" FlowDirection="LeftToRight"
lib:ThumbnailLoading.Width="64" DataContext="{Binding Sequence}">
<Image Source="{Binding Thumbnail}" Stretch="UniformToFill" />
</Border>
<TextBlock Grid.Column="1" Style="{StaticResource Text.Cell}" Text="{Binding Name}" Margin="12,0,0,0" FontWeight="SemiBold" ToolTip="{Binding Name}" />
<TextBlock Grid.Column="2" Style="{StaticResource Text.Cell}" Text="{Binding SequenceTitle}" Margin="12,0,0,0" Foreground="{DynamicResource Brush.TextMuted}"
ToolTip="{Binding SequenceTitle}" />
<ui:StatusGlyph Grid.Column="3" Kind="{Binding StateKind}" Text="{Binding StateText}" ToolTip="{Binding StateToolTip}" Margin="12,0,8,0" VerticalAlignment="Center" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock Grid.Row="2" Text="{l:Loc Editor.Picker.Library}" Style="{StaticResource Text.Label}" Margin="16,8,16,2"
Visibility="{Binding Picker.HasWorkspaceItems, Converter={StaticResource BoolToVisibility}}" />
<ListBox x:Name="List" Grid.Row="3" Margin="0,4,0,8" ItemsSource="{Binding Picker.Items}" SelectedItem="{Binding Picker.Selected}" SelectionMode="Single"
ItemContainerStyle="{StaticResource ListBoxItem.PickerRow}" TextSearch.TextPath="Title" VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.VirtualizationMode="Recycling" VirtualizingPanel.ScrollUnit="Pixel" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.ScrollChanged="OnScrollChanged" AutomationProperties.Name="{l:Loc Editor.Picker.List}" ToolTip="{l:Loc Tooltips.Editor.Picker.Row}"
KeyboardNavigation.TabNavigation="Continue" Grid.IsSharedSizeScope="True" SelectionChanged="OnSelectionChanged">
<ListBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding Picker.OpenCommand}" />
</ListBox.InputBindings>
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type lib:SequenceItem}">
<Grid Height="40">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="2*" MinWidth="140" />
<ColumnDefinition Width="Auto" MinWidth="84" SharedSizeGroup="PickerDate" />
<ColumnDefinition Width="*" MinWidth="80" />
<ColumnDefinition Width="Auto" MinWidth="56" SharedSizeGroup="PickerFrames" />
<ColumnDefinition Width="Auto" SharedSizeGroup="PickerStates" />
</Grid.ColumnDefinitions>
<!-- Pictures stay left to right in a right-to-left window. -->
<Border Width="64" Height="36" CornerRadius="4" Background="{DynamicResource Brush.Card}" ClipToBounds="True" FlowDirection="LeftToRight"
lib:ThumbnailLoading.Width="64">
<Image Source="{Binding Thumbnail}" Stretch="UniformToFill" />
</Border>
<!-- Cells that may be shortened show their text in their tooltip (an empty camera has none). -->
<TextBlock Grid.Column="1" Style="{StaticResource Text.Cell}" Text="{Binding Title}" Margin="12,0,0,0" FontWeight="SemiBold" ToolTip="{Binding Title}" />
<TextBlock Grid.Column="2" Style="{StaticResource Text.Cell}" Text="{Binding DateText}" Margin="12,0,0,0" Foreground="{DynamicResource Brush.TextMuted}" />
<TextBlock Grid.Column="3" Style="{StaticResource Text.Cell}" Text="{Binding Camera}" Margin="12,0,0,0" Foreground="{DynamicResource Brush.TextMuted}"
ToolTip="{Binding Camera, Converter={x:Static ui:EmptyToNullConverter.Instance}}" />
<TextBlock Grid.Column="4" Style="{StaticResource Text.CellNumber}" Text="{Binding FramesText}" Margin="12,0,0,0" />
<ItemsControl Grid.Column="5" Margin="12,0,0,0" ItemsSource="{Binding Statuses}" ItemTemplate="{StaticResource Template.Status}"
ItemsPanel="{StaticResource Panel.Row}" VerticalAlignment="Center" Focusable="False" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ui:EmptyState Grid.Row="3" Message="{l:Loc Library.Empty}" Visibility="{Binding Picker.IsEmptyLibrary, Converter={StaticResource BoolToVisibility}}">
<Button Style="{StaticResource Button.Primary}" Content="{l:Loc Shell.Nav.Import}" Command="{Binding OpenImportCommand}" ToolTip="{l:Loc Tooltips.Nav.Import}" />
</ui:EmptyState>
<ui:EmptyState Grid.Row="3" Message="{l:Loc Editor.Picker.NoMatch}" Visibility="{Binding Picker.IsNoMatch, Converter={StaticResource BoolToVisibility}}">
<Button Content="{l:Loc Editor.Picker.Clear}" Command="{Binding Picker.ClearCommand}" ToolTip="{l:Loc Tooltips.Editor.Picker.Clear}" />
</ui:EmptyState>
<ui:EmptyState Grid.Row="3" Message="{l:Loc Library.Empty}" Visibility="{Binding Picker.IsEmptyLibrary, Converter={StaticResource BoolToVisibility}}">
<Button Style="{StaticResource Button.Primary}" Content="{l:Loc Shell.Nav.Import}" Command="{Binding OpenImportCommand}" ToolTip="{l:Loc Tooltips.Nav.Import}" />
</ui:EmptyState>
<ui:EmptyState Grid.Row="3" Message="{l:Loc Editor.Picker.NoMatch}" Visibility="{Binding Picker.IsNoMatch, Converter={StaticResource BoolToVisibility}}">
<Button Content="{l:Loc Editor.Picker.Clear}" Command="{Binding Picker.ClearCommand}" ToolTip="{l:Loc Tooltips.Editor.Picker.Clear}" />
</ui:EmptyState>
</Grid>
</Grid>
</Border>
</UserControl>
@@ -49,6 +49,14 @@ public partial class SequencePickerView : UserControl
e.Handled = true;
}
/// <summary>A double-click on a project of the Workspace group opens it (the left button only).</summary>
private void OnProjectDoubleClick(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton != MouseButton.Left || sender is not ListBoxItem { DataContext: Workspace.WorkspaceProjectItem item } || Section is not { } section) return;
if (section.Picker.OpenProjectCommand.CanExecute(item)) section.Picker.OpenProjectCommand.Execute(item);
e.Handled = true;
}
/// <summary>Esc anywhere in the picker: the search first, then back to the open sequence.</summary>
private void OnPreviewKeyDown(object sender, KeyEventArgs e)
{
@@ -1,8 +1,11 @@
using System.Collections.ObjectModel;
using System.IO;
using System.Windows.Input;
using System.Windows.Threading;
using Chronos.App.Library;
using Chronos.App.Shell;
using Chronos.App.Workspace;
using Chronos.Core.Diagnostics;
using Chronos.Core.Model;
using Chronos.Data;
using Chronos.Data.Repositories;
@@ -11,10 +14,14 @@ using Chronos.Ui.Mvvm;
namespace Chronos.App.Sections;
/// <summary>
/// The sequence picker of the Edit section (owner review 1, R7): this PC's sequences and, while signed in, the server's
/// sequences without a copy here, newest first, searched by title, camera or tag as the user types (after 250 ms, like
/// the Library) and read page by page as the list scrolls. One sequence is chosen and opened; when the list loads, the
/// open sequence is selected, else the one edited last (pages are read until it is listed), else the first.
/// The sequence picker of the Edit section (owner review 1, R7), in two groups (owner review 2, R8): the Workspace, the
/// projects this PC's workspace holds, each with where it stands against its home (read after the list shows), the one
/// saved last first; and the Library, this PC's sequences and, while signed in, the server's sequences without a copy
/// here, newest first, read page by page as the list scrolls. Both are searched by what the user types (after 250 ms,
/// like the Library): projects by their name or their sequence's title, sequences by title, camera or tag. A project
/// opens as it is; a sequence opens in the workspace (its project opened last, else "Open in workspace" asks). When the
/// list loads, the open project and sequence are selected, else the one edited last (pages are read until it is
/// listed), else the first.
/// </summary>
public sealed class SequencePickerViewModel : LocalizedViewModel
{
@@ -25,9 +32,12 @@ public sealed class SequencePickerViewModel : LocalizedViewModel
private LibraryPager? _pager;
private string _searchText = string.Empty;
private SequenceItem? _selected;
private WorkspaceProjectItem? _selectedProject;
private bool _isLoading;
private bool _hasLoaded;
private Task _loading = Task.CompletedTask;
private Task _workspaceLoading = Task.CompletedTask;
private Task _workspaceStates = Task.CompletedTask;
private int _pageSize = LibraryPager.DefaultPageSize;
/// <summary>Counts reloads, so a reload that a newer one replaced stops reading pages.</summary>
@@ -40,6 +50,8 @@ public sealed class SequencePickerViewModel : LocalizedViewModel
_searchDelay.Tick += (_, _) => _ = ReloadAsync();
_open = new AsyncRelayCommand(() => (Selected ?? Items.FirstOrDefault()) is { } item ? _section.PickAsync(item) : Task.CompletedTask, () => Items.Count > 0);
OpenItemCommand = new AsyncRelayCommand((p, _) => p is SequenceItem item ? _section.PickAsync(item) : Task.CompletedTask);
OpenProjectCommand = new AsyncRelayCommand((p, _) => (p as WorkspaceProjectItem ?? SelectedProject) is { } item ? _section.PickProjectAsync(item) : Task.CompletedTask);
RemoveCopyCommand = new AsyncRelayCommand((p, _) => (p as WorkspaceProjectItem ?? SelectedProject) is { } item ? _section.RemoveProjectCopyAsync(item) : Task.CompletedTask);
SearchOpenCommand = new AsyncRelayCommand(OpenFromSearchAsync);
ClearCommand = new RelayCommand(() => SearchText = string.Empty);
}
@@ -47,6 +59,31 @@ public sealed class SequencePickerViewModel : LocalizedViewModel
/// <summary>The sequences listed, in order.</summary>
public ObservableCollection<SequenceItem> Items { get; } = [];
/// <summary>The projects of the workspace listed (the Workspace group), the one saved last first.</summary>
public ObservableCollection<WorkspaceProjectItem> WorkspaceItems { get; } = [];
/// <summary>The Workspace group shows (it lists a project).</summary>
public bool HasWorkspaceItems => WorkspaceItems.Count > 0;
public WorkspaceProjectItem? SelectedProject
{
get => _selectedProject;
set => Set(ref _selectedProject, value);
}
/// <summary>Opens a project of the Workspace group (double-click, Enter in its list), else the selected one.</summary>
public ICommand OpenProjectCommand { get; }
/// <summary>"Remove local copy…" of a project of the Workspace group (its menu, Delete in its list), also one that cannot open.</summary>
public ICommand RemoveCopyCommand { get; }
/// <summary>The Workspace group read last, then its projects' states (tests wait for it).</summary>
public async Task WorkspaceLoadedAsync()
{
await _workspaceLoading;
await _workspaceStates;
}
/// <summary>Title, camera or tag text; the list follows a moment after the last key.</summary>
public string SearchText
{
@@ -73,10 +110,10 @@ public sealed class SequencePickerViewModel : LocalizedViewModel
}
/// <summary>There is no sequence at all: Import is offered.</summary>
public bool IsEmptyLibrary => _hasLoaded && !_isLoading && Items.Count == 0 && string.IsNullOrWhiteSpace(_searchText);
public bool IsEmptyLibrary => _hasLoaded && !_isLoading && Items.Count == 0 && WorkspaceItems.Count == 0 && string.IsNullOrWhiteSpace(_searchText);
/// <summary>The search matches nothing: Clear search is offered.</summary>
public bool IsNoMatch => _hasLoaded && !_isLoading && Items.Count == 0 && !string.IsNullOrWhiteSpace(_searchText);
public bool IsNoMatch => _hasLoaded && !_isLoading && Items.Count == 0 && WorkspaceItems.Count == 0 && !string.IsNullOrWhiteSpace(_searchText);
/// <summary>The list read last (capture and tests wait for it).</summary>
public Task Loading => _loading;
@@ -120,6 +157,7 @@ public sealed class SequencePickerViewModel : LocalizedViewModel
{
if (_searchDelay.IsEnabled) await ReloadAsync();
else await _loading;
await _workspaceLoading;
}
/// <summary>The next page, when the list scrolled near its end.</summary>
@@ -134,18 +172,24 @@ public sealed class SequencePickerViewModel : LocalizedViewModel
{
_searchDelay.Stop();
_pager?.Cancel();
// The projects' states still being read stop asking.
_generation++;
base.Dispose();
}
private async Task OpenFromSearchAsync()
{
await SettleAsync();
if (_section.ShowsPicker && (Selected ?? Items.FirstOrDefault()) is { } item) await _section.PickAsync(item);
if (!_section.ShowsPicker) return;
if ((Selected ?? Items.FirstOrDefault()) is { } item) await _section.PickAsync(item);
// Only projects match what was typed: the first of them.
else if ((SelectedProject ?? WorkspaceItems.FirstOrDefault()) is { } project) await _section.PickProjectAsync(project);
}
private async Task LoadFirstAsync()
{
var generation = _generation;
_workspaceLoading = LoadWorkspaceAsync(generation);
var filter = new LibraryFilter { Text = string.IsNullOrWhiteSpace(_searchText) ? null : _searchText.Trim(), Sort = SequenceSort.Newest };
_merge.Reset(filter, Shell.Library.RemoteSequences);
if (Shell.Services.Database is not { } db)
@@ -209,6 +253,73 @@ public sealed class SequencePickerViewModel : LocalizedViewModel
}
}
/// <summary>
/// The Workspace group: the workspace's projects matching the search, then each one's state as its home tells it
/// (filled in as they come; a read a newer one replaced stops).
/// </summary>
private async Task LoadWorkspaceAsync(int generation)
{
var services = Shell.Services;
if (!services.Workspace.IsAvailable || services.Database is not { } db)
{
ClearWorkspace();
return;
}
var text = _searchText.Trim();
var items = new List<WorkspaceProjectItem>();
try
{
foreach (var entry in (await services.Workspace.ListAsync()).OrderByDescending(e => e.Saved))
{
var row = await db.Sequences.GetAsync(entry.SequenceId);
var item = new WorkspaceProjectItem(entry, row is null ? null : new SequenceItem(row, services.Thumbnails));
if (text.Length > 0 && !item.Name.Contains(text, StringComparison.CurrentCultureIgnoreCase)
&& !item.SequenceTitle.Contains(text, StringComparison.CurrentCultureIgnoreCase))
continue;
items.Add(item);
}
}
catch (Exception ex) when (ex is IOException or InvalidDataException or UnauthorizedAccessException or DatabaseException)
{
Log.Warning("workspace", "The workspace could not be listed", ex);
if (generation == _generation) ClearWorkspace();
return;
}
if (generation != _generation) return;
WorkspaceItems.Clear();
foreach (var item in items) WorkspaceItems.Add(item);
SelectedProject = WorkspaceItems.FirstOrDefault(i => i.ProjectId == _section.OpenProjectId) ?? WorkspaceItems.FirstOrDefault();
OnPropertyChanged(nameof(HasWorkspaceItems));
RaiseStates();
_workspaceStates = ReadStatesAsync(items, generation);
}
/// <summary>Each listed project's state, asked of its home one after the other (a home may make a read wait a few seconds).</summary>
private async Task ReadStatesAsync(IReadOnlyList<WorkspaceProjectItem> items, int generation)
{
foreach (var item in items)
{
if (generation != _generation) return;
// This Chronos cannot read its working state: there is no state to ask for.
if (!item.IsReadable) continue;
try
{
item.Status = await Shell.Services.Workspace.StatusAsync(item.ProjectId);
}
catch (Exception ex) when (ex is not OutOfMemoryException)
{
Log.Info("workspace", $"The state of project {item.ProjectId} could not be read: {ex.Message}");
}
}
}
private void ClearWorkspace()
{
WorkspaceItems.Clear();
SelectedProject = null;
OnPropertyChanged(nameof(HasWorkspaceItems));
}
/// <summary>The sequence selected first: the open one, else the one edited last.</summary>
private Guid? Wanted => _section.OpenSequenceId ?? Shell.Services.Settings.LastEditedSequence;
+59 -4
View File
@@ -11,6 +11,7 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Chronos;component/Editor/EditorStyles.xaml" />
<ResourceDictionary Source="pack://application:,,,/Chronos;component/Workspace/WorkspaceDialogs.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
@@ -27,7 +28,8 @@
The open sequence stays laid out behind the picker (hidden, not collapsed: collapsing it would shrink the preview
and render it again when it comes back), and while a switch is under way (the progress bar shows).
-->
<Grid x:Name="EditorHost">
<!-- Behind an open dialog the editor takes neither clicks nor the keyboard. -->
<Grid x:Name="EditorHost" IsEnabled="{Binding IsContentEnabled}">
<Grid.Style>
<Style TargetType="Grid">
<Style.Triggers>
@@ -51,6 +53,8 @@
<KeyBinding Key="D1" Modifiers="Control+Shift" Command="{Binding ActualSizeCommand}" />
<KeyBinding Key="R" Modifiers="Control" Command="{Binding RenderCommand}" />
<KeyBinding Key="A" Modifiers="Control+Shift" Command="{Binding AnalyseCommand}" />
<!-- Owner review 2, R8: Save version of the workspace project. -->
<KeyBinding Key="S" Modifiers="Control" Command="{Binding Project.SaveVersionCommand}" />
<!-- Steps by number; no Alt+NumPad bindings, which type characters into text fields. -->
<KeyBinding Key="D1" Modifiers="Alt" Command="{Binding GoToStepCommand}" CommandParameter="1" />
<KeyBinding Key="D2" Modifiers="Alt" Command="{Binding GoToStepCommand}" CommandParameter="2" />
@@ -64,6 +68,7 @@
</Grid.InputBindings>
<Grid.RowDefinitions>
<RowDefinition Height="52" />
<RowDefinition Height="Auto" />
<RowDefinition Height="44" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
@@ -94,6 +99,38 @@
Foreground="{DynamicResource Brush.TextMuted}" />
</Grid>
</Button>
<!-- Owner review 2, R8: the workspace project, where it stands, and its menu (versions, sync, history, projects, the local copy). -->
<Button x:Name="ProjectButton" DockPanel.Dock="Left" Style="{StaticResource Button.Subtle}" Margin="0,0,12,0" Padding="8,0" MaxWidth="280" Height="30"
VerticalAlignment="Center" Click="OnOpenProjectMenu" ToolTip="{Binding Project.MenuToolTip}" AutomationProperties.Name="{Binding Project.MenuName}"
Visibility="{Binding HasProject, Converter={StaticResource BoolToVisibility}}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Project.Name}" FontWeight="SemiBold" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" />
<ui:StatusGlyph Grid.Column="1" Kind="{Binding Project.StateKind}" Text="{Binding Project.StateText}" FontSize="12" Margin="8,0,0,0" VerticalAlignment="Center"
infra:LiveRegion.Text="{Binding Project.StateText}" AutomationProperties.LiveSetting="Polite" />
<ui:Icon Grid.Column="2" Glyph="{StaticResource Icon.ChevronDown}" Size="14" Margin="6,0,0,0" VerticalAlignment="Center" Foreground="{DynamicResource Brush.TextMuted}" />
</Grid>
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="{l:Loc Editor.Project.SaveVersion}" Command="{Binding Project.SaveVersionCommand}" InputGestureText="Ctrl+S"
ToolTip="{Binding Project.SaveVersionToolTip}" ToolTipService.ShowOnDisabled="True" />
<MenuItem Header="{l:Loc Editor.Project.Sync}" Command="{Binding Project.SyncCommand}" ToolTip="{Binding Project.StateToolTip}" ToolTipService.ShowOnDisabled="True" />
<MenuItem Header="{l:Loc Editor.Project.History}" Command="{Binding Project.HistoryCommand}" ToolTip="{l:Loc Tooltips.Editor.Project.History}" />
<Separator />
<MenuItem Header="{l:Loc Editor.Project.Open}" Command="{Binding Project.OpenProjectCommand}" ToolTip="{l:Loc Tooltips.Editor.Project.Open}" />
<MenuItem Header="{l:Loc Editor.Project.New}" Command="{Binding Project.NewProjectCommand}" ToolTip="{l:Loc Tooltips.Editor.Project.New}" />
<MenuItem Header="{l:Loc Editor.Project.Rename}" Command="{Binding Project.RenameCommand}" ToolTip="{l:Loc Tooltips.Editor.Project.Rename}" />
<MenuItem Header="{l:Loc Editor.Project.Delete}" Command="{Binding Project.DeleteCommand}" ToolTip="{Binding Project.DeleteToolTip}"
ToolTipService.ShowOnDisabled="True" />
<Separator />
<MenuItem Header="{l:Loc Editor.Project.RemoveCopy}" Command="{Binding Project.RemoveCopyCommand}" ToolTip="{l:Loc Tooltips.Editor.Project.RemoveCopy}" />
</ContextMenu>
</Button.ContextMenu>
</Button>
<ui:StatusGlyph DockPanel.Dock="Left" Kind="Remote" Text="{Binding RemoteText}" ToolTip="{Binding RemoteToolTip}" FontSize="{StaticResource Size.Body}" Margin="0,0,12,0"
MaxWidth="220" VerticalAlignment="Center" Visibility="{Binding IsRemote, Converter={StaticResource BoolToVisibility}}" />
<TextBlock Text="{Binding Summary}" Style="{StaticResource Text.Secondary}" FontSize="{StaticResource Size.Body}" VerticalAlignment="Center"
@@ -127,12 +164,23 @@
</StackPanel>
</Grid>
<!-- Owner review 2, R8: the library's frames moved past the workspace's; Update media copies them again (positions follow their photos). -->
<Border Grid.Row="1" Style="{StaticResource Border.Card}" Padding="12,6" Margin="0,0,0,8"
Visibility="{Binding Project.HasMediaUpdate, Converter={StaticResource BoolToVisibility}, FallbackValue=Collapsed}">
<DockPanel>
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Compact}" Content="{l:Loc Editor.Workspace.UpdateMedia}" Command="{Binding Project.UpdateMediaCommand}"
ToolTip="{l:Loc Tooltips.Editor.Workspace.UpdateMedia}" ToolTipService.ShowOnDisabled="True" />
<ui:StatusGlyph Kind="Warning" Text="{Binding Project.MediaUpdateText}" ToolTip="{l:Loc Tooltips.Editor.Workspace.MediaChanged}" VerticalAlignment="Center"
infra:LiveRegion.Text="{Binding Project.MediaUpdateText}" AutomationProperties.LiveSetting="Polite" />
</DockPanel>
</Border>
<!-- The path (owner review 1, R7): one row of steps, each with where it stands; any step opens at any time (Alt+n, ←/→ in the bar). -->
<ListBox x:Name="Steps" Grid.Row="1" Style="{StaticResource ListBox.Steps}" ItemsSource="{Binding Tabs}" SelectedItem="{Binding SelectedTab}"
<ListBox x:Name="Steps" Grid.Row="2" Style="{StaticResource ListBox.Steps}" ItemsSource="{Binding Tabs}" SelectedItem="{Binding SelectedTab}"
ItemContainerStyle="{StaticResource ListBoxItem.Step}" Margin="0,0,0,8" AutomationProperties.Name="{l:Loc Editor.Path}" KeyDown="OnStepsKeyDown"
PreviewKeyDown="OnStepsPreviewKeyDown" PreviewMouseLeftButtonDown="OnStepsPreviewMouseDown" SelectionChanged="OnStepsSelectionChanged" />
<Grid Grid.Row="2">
<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="{StaticResource Editor.Grid.Panel}" />
@@ -269,6 +317,13 @@
</Grid>
<!-- The picker (owner review 1, R7): without an open sequence, or over it after Change sequence. -->
<sections:SequencePickerView x:Name="Picker" Visibility="{Binding ShowsPicker, Converter={StaticResource BoolToVisibility}}" />
<sections:SequencePickerView x:Name="Picker" Visibility="{Binding ShowsPicker, Converter={StaticResource BoolToVisibility}}" IsEnabled="{Binding IsContentEnabled}" />
<!-- In-window dialogs (Open in workspace, the project menu's) over a scrim; the keyboard stays inside the dialog. -->
<Grid Visibility="{Binding IsDialogOpen, Converter={StaticResource BoolToVisibility}}" KeyboardNavigation.TabNavigation="Cycle"
KeyboardNavigation.ControlTabNavigation="Cycle" KeyboardNavigation.DirectionalNavigation="Contained">
<Border Background="{DynamicResource Brush.Scrim}" />
<ContentPresenter x:Name="DialogHost" Content="{Binding Dialog}" Margin="20" />
</Grid>
</Grid>
</UserControl>
+27 -2
View File
@@ -26,6 +26,7 @@ public partial class SequenceView : UserControl
EditorRoot.AddHandler(MouseLeftButtonUpEvent, new MouseButtonEventHandler((_, _) => EndEditRun()), handledEventsToo: true);
EditorRoot.AddHandler(KeyUpEvent, new KeyEventHandler((_, _) => EndEditRun()), handledEventsToo: true);
EditorRoot.IsKeyboardFocusWithinChanged += OnEditorFocusWithinChanged;
DataContextChanged += OnDataContextChanged;
}
private EditorViewModel? Editor => (DataContext as SequenceViewModel)?.Editor;
@@ -88,11 +89,12 @@ public partial class SequenceView : UserControl
/// <summary>
/// Space plays or pauses, arrows step a frame (BRIEF §12.3) — unless a text field or a control that uses the key has
/// it, or the picker covers the editor.
/// it, or the picker or a dialog covers the editor.
/// </summary>
private void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Handled || IsPicking || Editor is not { } editor || Keyboard.Modifiers != ModifierKeys.None || e.OriginalSource is TextBoxBase) return;
if (e.Handled || IsPicking || (DataContext as SequenceViewModel)?.IsDialogOpen == true || Editor is not { } editor || Keyboard.Modifiers != ModifierKeys.None
|| e.OriginalSource is TextBoxBase) return;
var command = e.Key switch
{
Key.Space => editor.PlayCommand,
@@ -201,6 +203,29 @@ public partial class SequenceView : UserControl
private void EndEditRun() => Editor?.Session.EndEditRun();
/// <summary>The project button (▾ beside the title) opens its menu under itself.</summary>
private void OnOpenProjectMenu(object sender, RoutedEventArgs e)
{
if (sender is not Button { ContextMenu: { } menu } button) return;
menu.DataContext = button.DataContext;
menu.PlacementTarget = button;
menu.Placement = PlacementMode.Bottom;
menu.IsOpen = true;
}
/// <summary>A dialog that opens takes the keyboard: its first field or button.</summary>
private void OnSectionChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName != nameof(SequenceViewModel.Dialog) || DataContext is not SequenceViewModel { Dialog: not null } || !IsVisible) return;
Dispatcher.BeginInvoke(DispatcherPriority.Input, () => DialogHost.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)));
}
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (e.OldValue is SequenceViewModel old) old.PropertyChanged -= OnSectionChanged;
if (e.NewValue is SequenceViewModel section) section.PropertyChanged += OnSectionChanged;
}
/// <summary>The preview renders at the size it is shown, in device pixels.</summary>
private void OnPreviewSizeChanged(object sender, SizeChangedEventArgs e)
{
+452 -26
View File
@@ -2,15 +2,19 @@ using System.ComponentModel;
using System.Net;
using System.Windows.Input;
using System.Windows.Threading;
using Chronos.App.Archiving;
using Chronos.App.Editor;
using Chronos.App.Infrastructure;
using Chronos.App.Library;
using Chronos.App.Shell;
using Chronos.App.Workspace;
using Chronos.Core.Diagnostics;
using Chronos.Core.Export;
using Chronos.Core.Imaging;
using Chronos.Core.Imaging.Decoders;
using Chronos.Core.Localization;
using Chronos.Core.Model;
using Chronos.Data;
using Chronos.Data.Jobs;
using Chronos.Data.Sync;
using Chronos.Protocol.Client;
@@ -20,18 +24,24 @@ namespace Chronos.App.Sections;
/// <summary>
/// The Edit section (BRIEF §12.3; owner review 1, R7, formerly Sequence): opens the sequence the Library, Jobs, the
/// Server screen or its own picker chose into an <see cref="EditorViewModel"/> (from this PC's archive, or a server
/// sequence with this PC's proxies). The next sequence is read first; only then does the open one close, after its
/// last edit is stored. Without a sequence, or after Change sequence, it shows the picker (the editor stays open behind
/// it until another sequence opens). A server sequence whose proxies are missing or out of date fetches them first and
/// opens once they are here, the open sequence staying open meanwhile. A failed open is reported once and leaves the
/// open sequence open; an edit that cannot be saved is never dropped without the user's confirmation, and never written
/// after they chose to drop it. The step each sequence showed is kept for the rest of the run.
/// Server screen or its own picker chose into an <see cref="EditorViewModel"/>. A sequence of this PC's archive opens as a
/// project of the workspace (owner review 2, R8: editing never happens inside the library): the project of that sequence
/// opened last here; else, after "Open in workspace" asked which project (Main, another of its home, or a new one) and
/// which media, the project is checked out and its media copied by a job, and it opens once they are here. A server
/// sequence opens with this PC's proxies (the workspace takes server homes in phase 5b), and a capture (sample data
/// without an engine) opens the library as before. The next sequence is read first; only then does the open one close,
/// after its last edit is stored. Without a sequence, or after Change sequence, it shows the picker (the editor stays
/// open behind it until another sequence opens). A server sequence whose proxies are missing or out of date fetches them
/// first and opens once they are here, the open sequence staying open meanwhile; a workspace copy is followed the same
/// way. A failed open is reported once and leaves the open sequence open; an edit that cannot be saved is never dropped
/// without the user's confirmation, and never written after they chose to drop it. The step each sequence showed is
/// kept for the rest of the run. The section's in-window dialogs (Open in workspace, the project menu's) show over it.
/// </summary>
public sealed class SequenceViewModel : SectionViewModel
{
private readonly Dispatcher _dispatcher = Dispatcher.CurrentDispatcher;
private readonly Dictionary<Guid, StepMemory> _steps = [];
private readonly WorkspaceUi _workspaceUi;
private EditorViewModel? _editor;
private Guid? _openId;
private bool _isLoading;
@@ -41,16 +51,27 @@ public sealed class SequenceViewModel : SectionViewModel
/// <summary>The shell's <see cref="ShellViewModel.SequenceRequests"/> this section has answered.</summary>
private int _seenRequests;
private Task _switch = Task.CompletedTask;
private ProxyFetch? _fetch;
private PendingOpen? _fetch;
private ArchiveDialogViewModel? _dialog;
/// <summary>Dialogs that show once the open one closes (<see cref="OpenDialogWhenFree"/>), oldest first.</summary>
private readonly Queue<ArchiveDialogViewModel> _waiting = new();
/// <summary>The project the next open of its sequence takes (the picker's Workspace group, a project file, the project menu).</summary>
private ProjectRequest? _requested;
/// <summary>What to do with the editor of the project asked for once it opens (a project file's settings to apply), until another sequence opens.</summary>
private (ProjectRequest Request, Action<EditorViewModel> Action)? _afterOpen;
public SequenceViewModel(ShellViewModel shell)
: base(SectionKey.Edit, "Icon.Sequence")
{
Shell = shell;
_workspaceUi = new WorkspaceUi(this);
Picker = new SequencePickerViewModel(this);
OpenImportCommand = new RelayCommand(() => Shell.Navigate(SectionKey.Import));
OpenJobsCommand = new RelayCommand(() => Shell.Navigate(SectionKey.Jobs));
ChangeSequenceCommand = new RelayCommand(() => IsPicking = true, () => _editor is not null && !_isLoading && !_isPicking);
ChangeSequenceCommand = new RelayCommand(() => IsPicking = true, () => _editor is not null && !_isLoading && !_isPicking && _dialog is null);
CancelPickCommand = new RelayCommand(KeepOpenSequence, () => CanCancelPick);
shell.PropertyChanged += OnShellChanged;
}
@@ -97,6 +118,29 @@ public sealed class SequenceViewModel : SectionViewModel
/// <summary>The id of the open sequence; null when none is open.</summary>
public Guid? OpenSequenceId => _editor is null ? null : _openId;
/// <summary>The workspace project open in the editor; null when none is (a server sequence, a capture's library sequence).</summary>
public Guid? OpenProjectId => (_editor?.Session.Source as WorkspaceSequenceSource)?.ProjectId;
/// <summary>The section's in-window dialog (Open in workspace, the project menu's); null when none is open.</summary>
public ArchiveDialogViewModel? Dialog
{
get => _dialog;
private set
{
if (!Set(ref _dialog, value)) return;
OnPropertyChanged(nameof(IsDialogOpen));
OnPropertyChanged(nameof(IsContentEnabled));
}
}
public bool IsDialogOpen => _dialog is not null;
/// <summary>The editor and the picker behind an open dialog take neither clicks nor keyboard focus.</summary>
public bool IsContentEnabled => _dialog is null;
/// <summary>What the project menus of this section's editors ask of it.</summary>
internal IWorkspaceUi WorkspaceDialogs => _workspaceUi;
public bool IsLoading
{
get => _isLoading;
@@ -129,8 +173,8 @@ public sealed class SequenceViewModel : SectionViewModel
/// <summary>The server sequence whose proxies are on their way before it opens; null when none.</summary>
public string? FetchingTitle => _fetch?.Title;
/// <summary>"Getting the proxies · Harbour sunset".</summary>
public string? FetchingText => _fetch is { } fetch ? string.Join(Loc.Separator, Loc.L("Editor.Proxies.Fetching"), fetch.Title) : null;
/// <summary>"Getting the proxies · Harbour sunset", "Copying to the workspace · Harbour sunset".</summary>
public string? FetchingText => _fetch is { } fetch ? string.Join(Loc.Separator, Loc.L(fetch.TextKey), fetch.Title) : null;
/// <summary>The open sequence has an edit not stored yet (the save follows each change after a moment, and retries after a failure).</summary>
public bool HasPendingSave => _editor?.Session.HasPendingSave == true;
@@ -149,19 +193,92 @@ public sealed class SequenceViewModel : SectionViewModel
/// <summary>
/// Shows <paramref name="sequenceId"/> in the editor, as the Library does, and returns its editor once open; null
/// when it did not open (the reason was reported, or the open sequence's unsaved edit was kept) or waits for its
/// proxies.
/// proxies or its workspace copy. <paramref name="project"/> names the workspace project to open (else the one opened
/// last, else the user is asked); <paramref name="whenOpened"/> runs on its editor once it opens, now or after the
/// copy, unless another sequence opens first.
/// </summary>
public async Task<EditorViewModel?> ShowAsync(Guid sequenceId)
public async Task<EditorViewModel?> ShowAsync(Guid sequenceId, ProjectRequest? project = null, Action<EditorViewModel>? whenOpened = null)
{
_afterOpen = whenOpened is null ? null : (project ?? new ProjectRequest(sequenceId), whenOpened);
if (project is not null && project.SequenceId == sequenceId && !IsOpen(project))
{
_requested = project;
// Another project of the open sequence: it replaces the open one (its last edit stored first).
if (_openId == sequenceId)
{
// Edit on screen without asking the shell for the open sequence again (that would end a choice in the picker).
Shell.Navigate(SectionKey.Edit);
await OpenAsync(sequenceId, reload: true);
return Opened(sequenceId, project);
}
}
Shell.OpenSequence(sequenceId);
// Already the sequence asked for but not open (the shell did not change, so nothing started): opening it again is
// what is asked now, unless its proxies are on their way (it opens when they are here).
if (_openId != sequenceId && _switch.IsCompleted && Shell.CurrentSequenceId == sequenceId && !Fetching(sequenceId)) _ = OpenAsync(sequenceId);
await Settled(_switch);
if (_openId != sequenceId) return null;
return Opened(sequenceId, project);
}
/// <summary>Opens workspace project <paramref name="projectId"/> of <paramref name="sequenceId"/> (checked out and copied first when it is not here).</summary>
public Task<EditorViewModel?> OpenProjectAsync(Guid sequenceId, Guid projectId) => ShowAsync(sequenceId, new ProjectRequest(sequenceId, projectId));
/// <summary>The project chosen in the picker's Workspace group: the open one simply shows again, another opens.</summary>
public async Task PickProjectAsync(WorkspaceProjectItem item)
{
ArgumentNullException.ThrowIfNull(item);
if (_editor is not null && item.ProjectId == OpenProjectId)
{
KeepOpenSequence();
return;
}
// A copy a newer Chronos wrote neither opens nor goes from here: the toast says so, nothing is offered over it.
if (item.IsNewer)
{
Shell.Notify(Loc.L("Editor.Workspace.OpenFailed"), Loc.L("Errors.Workspace.NewerCopy"), isError: true);
return;
}
// A copy whose working state cannot be read cannot open: its removal plan is what it offers.
if (item.IsDamaged)
{
await RemoveProjectCopyAsync(item);
return;
}
await OpenProjectAsync(item.SequenceId, item.ProjectId);
}
/// <summary>The project <paramref name="request"/> asks for is the open one (any project of it when it asks none; a library sequence counts as Main).</summary>
private bool IsOpen(ProjectRequest request) => _editor is { } editor && _openId == request.SequenceId && Satisfies(request, editor);
/// <summary><paramref name="editor"/> holds the project <paramref name="request"/> asks for.</summary>
private static bool Satisfies(ProjectRequest request, EditorViewModel editor)
{
if (editor.Session.Content.Sequence.Id != request.SequenceId) return false;
var workspace = editor.Session.Source as WorkspaceSequenceSource;
if (request.ProjectId is { } id) return workspace?.ProjectId == id;
return !request.Main || workspace is not { Workspace.IsMain: false };
}
/// <summary>
/// The editor of <paramref name="sequenceId"/> when it is the open one (a choice of another ends), its pending action
/// run; null while the project <paramref name="request"/> asks for is not the open one yet (its copy runs).
/// </summary>
private EditorViewModel? Opened(Guid sequenceId, ProjectRequest? request)
{
if (_openId != sequenceId || Editor is not { } editor) return null;
// Another project of it still on its way (its copy runs) leaves the picker on screen, with the line saying so.
if (request is not null && !Satisfies(request, editor)) return null;
// Asking for the open sequence ends a choice of another.
IsPicking = false;
return Editor;
RunAfterOpen(editor);
return editor;
}
private void RunAfterOpen(EditorViewModel editor)
{
if (_afterOpen is not { } pending || !Satisfies(pending.Request, editor)) return;
_afterOpen = null;
pending.Action(editor);
}
/// <summary>
@@ -193,7 +310,7 @@ public sealed class SequenceViewModel : SectionViewModel
if (services.Engine is not { } engine || services.Database is not { } db) throw new InvalidOperationException(Loc.L("Editor.Error.NoEngine"));
var followed = _fetch is { } current && current.RemoteId == remoteId ? current.JobId : Guid.Empty;
StopFetch();
var fetch = new ProxyFetch(remoteId, title, engine);
var fetch = new PendingOpen(remoteId, title, engine, "Editor.Proxies.Fetching", null);
fetch.Handler = job => _dispatcher.BeginInvoke(() => OnFetchChanged(fetch, job));
engine.JobChanged += fetch.Handler;
_fetch = fetch;
@@ -271,11 +388,84 @@ public sealed class SequenceViewModel : SectionViewModel
{
Shell.PropertyChanged -= OnShellChanged;
StopFetch();
_dialog?.Dispose();
while (_waiting.TryDequeue(out var waiting)) waiting.Dispose();
Editor?.Dispose();
Picker.Dispose();
base.Dispose();
}
/// <summary>Shows <paramref name="dialog"/> over the section (one at a time: an open one is closed first).</summary>
internal void OpenDialog(ArchiveDialogViewModel dialog)
{
_dialog?.Dispose();
Dialog = dialog;
}
/// <summary>
/// Shows <paramref name="dialog"/> now when no dialog is open, else once the open one (and those waiting before it)
/// closed: what the background found (a conflict an automatic sync met) never replaces what the user is doing.
/// </summary>
internal void OpenDialogWhenFree(ArchiveDialogViewModel dialog)
{
if (_dialog is null) OpenDialog(dialog);
else _waiting.Enqueue(dialog);
}
/// <summary>Closes <paramref name="dialog"/> if it is still the open one; the next one waiting shows (one closed meanwhile is skipped).</summary>
internal void CloseDialog(ArchiveDialogViewModel dialog)
{
if (!ReferenceEquals(_dialog, dialog)) return;
dialog.Dispose();
Dialog = null;
while (_waiting.TryDequeue(out var next))
{
if (next.IsClosed) continue;
OpenDialog(next);
break;
}
}
/// <summary>
/// "Remove local copy" of a project of the picker's Workspace group: the open project's goes through its menu; another,
/// even one that cannot open (its copy failed, or the library no longer has it), gets the same plan and choices here.
/// </summary>
public async Task RemoveProjectCopyAsync(WorkspaceProjectItem item)
{
ArgumentNullException.ThrowIfNull(item);
if (_editor?.Project is { } menu && menu.ProjectId == item.ProjectId)
{
menu.RemoveCopyCommand.Execute(null);
return;
}
var workspace = Shell.Services.Workspace;
var (projectId, name) = (item.ProjectId, item.Name);
try
{
var plan = await workspace.PlanRemovalAsync(projectId);
// A damaged copy is named as it is still known, never by its folder's id (none when nothing knows it).
var shown = plan.Damaged ? plan.KnownName : name;
OpenDialog(new RemoveCopyDialogViewModel(plan, discard => RemoveCopyAsync(projectId, shown, discard), async () =>
{
await workspace.SendAllAsync(projectId);
await RemoveCopyAsync(projectId, shown, discard: false);
}, () => plan.Damaged ? RemoveCopyDialogViewModel.ConfirmDiscard(_workspaceUi, plan) : RemoveCopyDialogViewModel.ConfirmDiscard(_workspaceUi, name),
d => CloseDialog(d)));
}
catch (Exception ex) when (ex is not OutOfMemoryException)
{
Log.Warning("workspace", $"The removal of project {projectId} could not be planned", ex);
Shell.Notify(Loc.L("Editor.Workspace.RemoveFailed"), WorkspaceText.Failure(ex), isError: true);
}
async Task RemoveCopyAsync(Guid id, string? project, bool discard)
{
await workspace.RemoveLocalCopyAsync(id, discard);
Shell.Notify(Loc.L("Editor.Workspace.Removed"), project);
_ = Picker.ReloadAsync();
}
}
protected override void OnActivated()
{
OpenRequested();
@@ -349,9 +539,11 @@ public sealed class SequenceViewModel : SectionViewModel
}
/// <summary>
/// Where <paramref name="sequenceId"/> lives: this PC's index, else a sequence of the signed-in server whose proxies
/// this PC keeps (Server screen, "Open with proxies"), edited through the server (BRIEF §14.5), or only shown when the
/// account may not change it. Null when the proxies are not here yet: they are being fetched (<see cref="FetchProxiesAsync"/>).
/// Where <paramref name="sequenceId"/> lives: this PC's index (opened as a workspace project,
/// <see cref="OpenWorkspaceAsync"/>; in a capture, the library itself), else a sequence of the signed-in server whose
/// proxies this PC keeps (Server screen, "Open with proxies"), edited through the server (BRIEF §14.5), or only shown
/// when the account may not change it. Null when it cannot open yet: its proxies are being fetched
/// (<see cref="FetchProxiesAsync"/>), its workspace copy runs, or the user closed "Open in workspace".
/// </summary>
private async Task<(ISequenceSource Source, string Title)?> OpenSourceAsync(AppServices services, Guid sequenceId)
{
@@ -360,10 +552,19 @@ public sealed class SequenceViewModel : SectionViewModel
var decoder = processing?.Archive.Decoder ?? DecoderFactory.CreateClient(null);
if (await db.Sequences.GetAsync(sequenceId) is { } row)
{
if (services.Workspace.IsEnabled) return await OpenWorkspaceAsync(services, services.Workspace, db, decoder, row);
var local = new LocalSequenceSource(db, sequenceId, decoder, services.Engine, processing?.Archive);
local.HeroChanged += OnHeroChanged;
return (local, row.DisplayTitle);
}
// A workspace project whose sequence left the index (its trash emptied, its folder gone): not a server's sequence to
// fetch; its local copy can only be removed (the picker's Remove local copy).
if (_requested is { ProjectId: { } projectId } asked && asked.SequenceId == sequenceId && services.Workspace.IsEnabled
&& await services.Workspace.FindAsync(projectId) is not null)
{
_requested = null;
throw new InvalidOperationException(Loc.L("Errors.Workspace.SequenceGone"));
}
var sync = services.Sync;
if (sync.Server is not { } server || sync.Service is not { } service || sync.ConnectEditor() is not { } api)
throw new InvalidOperationException(Loc.L("Editor.Error.SignedOut"));
@@ -386,20 +587,188 @@ public sealed class SequenceViewModel : SectionViewModel
}
}
/// <summary>The proxy download for an open waiting on it moved: opens the sequence once it is done, says why not when it failed.</summary>
private void OnFetchChanged(ProxyFetch fetch, Job job)
/// <summary>
/// A sequence of this PC's archive opens as a project of the workspace (owner review 2, R8): the project asked for
/// (<see cref="_requested"/>), else the one of the sequence opened last here. One not here yet, or whose media are gone,
/// is checked out and its media copied by a job, after "Open in workspace" asked which project when the sequence has
/// none here (Main is made from the sequence's settings as they are, so edits made in the library before carry over);
/// it opens once the copy is done. Null while it cannot open yet.
/// </summary>
private async Task<(ISequenceSource Source, string Title)?> OpenWorkspaceAsync(AppServices services, WorkspaceHost workspace, ChronosDatabase db,
ImageDecoder decoder, Sequence row)
{
var request = TakeRequest(row.Id);
var entry = request switch
{
{ ProjectId: { } id } => await workspace.FindAsync(id),
{ Main: true } => (await workspace.ProjectsOfAsync(row.Id)).FirstOrDefault(p => p.IsMain),
_ => await workspace.LastUsedAsync(row.Id),
};
// 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,
// with Remove local copy for a damaged one, when nothing else could be chosen (Main asked for, or the home has no
// other project); otherwise "Open in workspace" lists Main as it is, disabled, and offers the others.
WorkspaceEntry? unreadableMain = null;
if (entry is null && request?.ProjectId is null && await UnreadableMainAsync(workspace, row.Id) is { } main)
{
if (request is { Main: true } || (await workspace.HomeProjectsAsync(row.Id)).All(p => p.IsMain))
{
RefuseUnreadable(main);
_afterOpen = null;
Shell.KeepSequence(OpenSequenceId);
return null;
}
unreadableMain = main;
}
if (entry is { HasMedia: true })
{
workspace.Remember(row.Id, entry.ProjectId);
return (new WorkspaceSequenceSource(workspace.Sync, entry.ProjectId, db, decoder, services.Engine), row.DisplayTitle);
}
var projectId = entry?.ProjectId ?? request?.ProjectId;
string? newName = null;
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.
Log.Info("workspace", $"Project {wanted} is not a project of sequence {row.Id} here; its Main opens instead");
projectId = null;
if (_afterOpen is { } pending && pending.Request.SequenceId == row.Id) _afterOpen = (ProjectRequest.MainOf(row.Id), pending.Action);
}
else if (entry is null && projectId is null && request is not { Main: true })
{
if (await AskProjectAsync(workspace, row, unreadableMain) is not { } choice)
{
_afterOpen = null;
Shell.KeepSequence(OpenSequenceId);
return null;
}
(projectId, newName) = (choice.ProjectId, choice.NewName);
}
WorkspaceCheckout checkout;
try
{
checkout = await workspace.CheckoutAsync(row.Id, projectId, newName);
}
catch (WorkspaceException ex) when (ex.FolderRefused)
{
// Nothing was written: the way on is another workspace folder, offered from the refusal.
Log.Info("workspace", $"Sequence {row.Id} not checked out: {ex.Message}");
Shell.Notify(Loc.L("Editor.Workspace.OpenFailed"), ex.Message, Loc.L("Editor.Workspace.ChooseFolder"), Loc.L("Tooltips.Editor.Workspace.ChooseFolder"),
() => _ = WorkspaceFolderChange.ChooseAsync(Shell), isError: true);
_afterOpen = null;
Shell.KeepSequence(OpenSequenceId);
return null;
}
await FollowCopyAsync(row.Id, row.DisplayTitle, checkout.Project.Id, checkout.Copy);
return null;
}
/// <summary>The workspace's copy of the sequence's Main when this Chronos cannot read it (damaged, or a newer Chronos's); null otherwise.</summary>
private static async Task<WorkspaceEntry?> UnreadableMainAsync(WorkspaceHost workspace, Guid sequenceId)
{
if ((await workspace.HomeProjectsAsync(sequenceId)).FirstOrDefault(p => p.IsMain) is not { } main) return null;
return await workspace.FindAsync(main.Id) is { IsReadable: false } copy ? copy : null;
}
/// <summary>
/// Why a copy this Chronos cannot read does not open: a newer Chronos's is left as it is (nothing is offered over it), a
/// damaged one offers Remove local copy, whose Discard keeps its files aside.
/// </summary>
private void RefuseUnreadable(WorkspaceEntry copy)
{
Log.Info("workspace", $"Project {copy.ProjectId} here cannot be read by this Chronos ({(copy.Newer ? "newer" : "damaged")}): it is not opened");
if (copy.Newer)
{
Shell.Notify(Loc.L("Editor.Workspace.OpenFailed"), Loc.L("Errors.Workspace.NewerCopy"), isError: true);
return;
}
var item = new WorkspaceProjectItem(copy, null);
Shell.Notify(Loc.L("Editor.Workspace.OpenFailed"), Loc.L("Errors.Workspace.Damaged"), Loc.L("Editor.Project.RemoveCopy"),
Loc.L("Tooltips.Editor.Project.RemoveCopy"), () => _ = RemoveProjectCopyAsync(item), isError: true);
}
/// <summary>
/// "Open in workspace": the projects of the sequence's home, the media, what their copy writes and the room the
/// workspace's drive has; null when closed without a choice. <paramref name="unreadableMain"/>, the copy of Main here
/// this Chronos cannot read, is listed disabled, why in its tooltip.
/// </summary>
private async Task<OpenChoice?> AskProjectAsync(WorkspaceHost workspace, Sequence row, WorkspaceEntry? unreadableMain = null)
{
var projects = await workspace.HomeProjectsAsync(row.Id);
WorkspaceCopyFacts? copy = null;
try
{
copy = await workspace.CopyFactsAsync(row.Id);
}
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 {row.Id} could not be measured: {ex.Message}");
}
var unreadable = unreadableMain is { } main
? new Dictionary<Guid, string>
{
[main.ProjectId] = Loc.L(main.Newer ? "Tooltips.Editor.Workspace.State.NewerCopy" : "Tooltips.Editor.Workspace.State.DamagedCopy"),
}
: null;
var dialog = new OpenInWorkspaceDialogViewModel(row.DisplayTitle, projects, d => CloseDialog(d), copy: copy, unreadable: unreadable);
// The picker or the open sequence shows behind the dialog meanwhile, not the progress bar.
IsLoading = false;
OpenDialog(dialog);
try
{
return await dialog.Choice;
}
finally
{
IsLoading = true;
}
}
/// <summary>The project the next open of <paramref name="sequenceId"/> takes, taken once; null when none was asked for.</summary>
private ProjectRequest? TakeRequest(Guid sequenceId)
{
if (_requested is not { } request || request.SequenceId != sequenceId) return null;
_requested = null;
return request;
}
/// <summary>Follows the workspace copy of a project's media (the picker's line, a toast): the project opens once it is done.</summary>
private async Task FollowCopyAsync(Guid sequenceId, string title, Guid projectId, Job copy)
{
var engine = Shell.Services.Engine ?? throw new InvalidOperationException(Loc.L("Editor.Error.NoEngine"));
StopFetch();
var fetch = new PendingOpen(sequenceId, title, engine, "Editor.Workspace.Copying", projectId) { JobId = copy.Id };
fetch.Handler = job => _dispatcher.BeginInvoke(() => OnFetchChanged(fetch, job));
engine.JobChanged += fetch.Handler;
_fetch = fetch;
OnFetchingChanged();
Shell.Notify(Loc.L("Editor.Workspace.Copying"), title, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"), () => Shell.Navigate(SectionKey.Jobs));
// A copy that ended before it was followed here is handled now.
if (Shell.Services.Database is { } db && await db.Jobs.GetAsync(copy.Id) is { State: JobState.Done or JobState.Failed or JobState.Cancelled } ended)
OnFetchChanged(fetch, ended);
}
/// <summary>
/// The proxy download or workspace copy an open waits on moved: opens the sequence (the project copied) once it is done,
/// says why not when it failed.
/// </summary>
private void OnFetchChanged(PendingOpen fetch, Job job)
{
if (!ReferenceEquals(fetch, _fetch) || job.Id != fetch.JobId || job.State is not (JobState.Done or JobState.Failed or JobState.Cancelled)) return;
StopFetch();
// A first copy of a project's media the user cancelled removes what it wrote itself, once it has stopped (the job).
switch (job.State)
{
// Opened only when it is still the sequence asked for; otherwise the next visit opens it from the cache.
// Opened only when it is still the sequence asked for; otherwise the next visit opens it (from the cache, from the workspace).
case JobState.Done when Shell.CurrentSequenceId == fetch.RemoteId && IsSelected:
if (fetch.ProjectId is { } projectId) _requested = new ProjectRequest(fetch.RemoteId, projectId);
_ = OpenAsync(fetch.RemoteId, reload: true);
break;
case JobState.Failed:
Shell.Notify(Loc.L("Editor.Proxies.Failed"), job.Error ?? fetch.Title, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"),
() => Shell.Navigate(SectionKey.Jobs), isError: true);
Shell.Notify(Loc.L(fetch.ProjectId is null ? "Editor.Proxies.Failed" : "Editor.Workspace.CopyFailed"), job.Error ?? fetch.Title, Loc.L("Shell.Nav.Jobs"),
Loc.L("Tooltips.Nav.Jobs"), () => Shell.Navigate(SectionKey.Jobs), isError: true);
break;
}
}
@@ -492,11 +861,16 @@ public sealed class SequenceViewModel : SectionViewModel
throw;
}
if (_steps.TryGetValue(sequenceId, out var memory)) editor.RestoreSteps(memory);
// A workspace project's menu (▾ beside the title): its state, versions, sync and copies.
if (session.Source is WorkspaceSequenceSource workspace) editor.Project = new ProjectMenuViewModel(services.Workspace, workspace, session, _workspaceUi);
_openId = sequenceId;
Editor = editor;
services.Settings.LastEditedSequence = sequenceId;
services.SavePreferences();
if (_afterOpen is { } after && after.Request.SequenceId != sequenceId) _afterOpen = null;
RunAfterOpen(editor);
await editor.AttachJobsAsync();
if (editor.Project is { } project) await project.RefreshAsync();
}
catch (Exception ex) when (ex is not OutOfMemoryException)
{
@@ -514,17 +888,69 @@ public sealed class SequenceViewModel : SectionViewModel
}
}
/// <summary>A proxy download an open waits on, with its engine subscription.</summary>
private sealed class ProxyFetch(Guid remoteId, string title, JobEngine engine)
/// <summary>
/// A job an open waits on, with its engine subscription: a server sequence's proxy download, or the workspace copy of a
/// project's media (<see cref="ProjectId"/>: the project that opens when it is done).
/// </summary>
private sealed class PendingOpen(Guid remoteId, string title, JobEngine engine, string textKey, Guid? projectId)
{
/// <summary>The sequence that opens when the job is done.</summary>
public Guid RemoteId { get; } = remoteId;
public string Title { get; } = title;
public JobEngine Engine { get; } = engine;
/// <summary>What the picker's line says is on its way.</summary>
public string TextKey { get; } = textKey;
public Guid? ProjectId { get; } = projectId;
public Guid JobId { get; set; }
public Action<Job>? Handler { get; set; }
}
/// <summary>What the project menu of an editor of this section asks of it: its dialogs, the shell's confirmations and toasts, opening and closing projects.</summary>
private sealed class WorkspaceUi(SequenceViewModel section) : IWorkspaceUi
{
public ArchiveDialogViewModel? Dialog => section.Dialog;
public void ShowDialog(ArchiveDialogViewModel dialog) => section.OpenDialog(dialog);
public void ShowDialogWhenFree(ArchiveDialogViewModel dialog) => section.OpenDialogWhenFree(dialog);
public void CloseDialog(ArchiveDialogViewModel dialog) => section.CloseDialog(dialog);
public bool Confirm(ConfirmRequest request) => section.Shell.Services.Dialogs.Confirm(request);
public void Notify(string title, string? message = null, string? actionText = null, string? actionToolTip = null, Action? action = null, bool isError = false) =>
section.Shell.Notify(title, message, actionText, actionToolTip, action, isError);
public async Task OpenProjectAsync(Guid sequenceId, Guid projectId) => await section.OpenProjectAsync(sequenceId, projectId);
public async Task<bool> CloseProjectAsync()
{
if (!await section.ConfirmCloseAsync()) return false;
await section.CloseAsync();
// Coming back to Edit shows the picker rather than opening the project again.
section.Shell.KeepSequence(null);
return true;
}
public async Task SequenceChangedAsync(Guid sequenceId)
{
if (section.Shell.Services.Database is not { } db || await db.Sequences.GetAsync(sequenceId) is not { } row) return;
if (section.Shell.Library.Items.FirstOrDefault(i => i.Id == row.Id) is { } item) item.Update(row);
}
}
}
/// <summary>
/// The workspace project an open of <see cref="SequenceId"/> takes (owner review 2, R8): <see cref="ProjectId"/>, else the
/// sequence's Main when <see cref="Main"/> (a <c>.chronos</c> file of format 1 applies to Main), else the one opened last.
/// </summary>
public sealed record ProjectRequest(Guid SequenceId, Guid? ProjectId = null, bool Main = false)
{
public static ProjectRequest MainOf(Guid sequenceId) => new(sequenceId, null, Main: true);
}
@@ -520,6 +520,34 @@
</HeaderedContentControl>
</StackPanel>
<!-- ================= Workspace (owner review 2, R8) ================= -->
<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). -->
<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>
</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.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>
</StackPanel>
<!-- ================= Server ================= -->
<StackPanel Style="{StaticResource Page}" Visibility="{Binding Page, Converter={x:Static shell:EqualsToVisibilityConverter.Instance}, ConverterParameter=Server}">
<HeaderedContentControl Style="{StaticResource Setting.Row}" Header="{l:Loc Settings.Server.Default}">
+44 -1
View File
@@ -8,6 +8,7 @@ using Chronos.App.Infrastructure;
using Chronos.App.Server;
using Chronos.App.Settings;
using Chronos.App.Shell;
using Chronos.App.Workspace;
using Chronos.Core.Archiving;
using Chronos.Core.Diagnostics;
using Chronos.Core.Import;
@@ -86,6 +87,7 @@ 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.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",
@@ -166,6 +168,9 @@ public sealed class SettingsViewModel : SectionViewModel
// Saving applies them to the log files (App.SaveSettings).
Logs = new LogSettingsRows(_s, Save);
// ---- Workspace ----
WorkspaceRows = new WorkspaceSettingsRows(_s, Save, () => Shell.Services.Workspace.Root, OpenWorkspaceFolder, ChangeWorkspaceFolderAsync);
// ---- Storage ----
CacheFolder = new EditableField(CacheStore.Folder(shell.Services.Environment, _s), v => ArchiveLocations.Validate(v), v =>
{
@@ -718,6 +723,31 @@ public sealed class SettingsViewModel : SectionViewModel
private set => Set(ref _cacheUsageText, value);
}
// ---------------- Workspace ----------------
/// <summary>Settings › Workspace (owner review 2, R8): the folder, Sync automatically and Kept versions.</summary>
public WorkspaceSettingsRows WorkspaceRows { get; }
/// <summary>Shows the workspace folder in Explorer (made, with its manifest, when the workspace was never used).</summary>
private void OpenWorkspaceFolder()
{
try
{
ShellActions.Reveal(Shell.Services.Workspace.Store.Root);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException)
{
Shell.ReportError(ex);
}
}
/// <summary>Another workspace folder, after its plan (nothing is moved): Edit lists its projects from then on.</summary>
private async Task ChangeWorkspaceFolderAsync()
{
await WorkspaceFolderChange.ChooseAsync(Shell);
WorkspaceRows.Refresh();
}
// ---------------- Server ----------------
public EditableField DefaultServer { get; }
@@ -1176,7 +1206,7 @@ public sealed class SettingsViewModel : SectionViewModel
[
JobKind.Render, JobKind.Import, JobKind.Download, JobKind.UploadCommit, JobKind.Scan, JobKind.Rebuild, JobKind.Verify, JobKind.LightAnalyse,
JobKind.DeepAnalyse, JobKind.Thumbs, JobKind.Proxies, JobKind.Maintenance, JobKind.Duplicates, JobKind.Orphans, JobKind.Adopt, JobKind.Move,
JobKind.Backup, JobKind.Cleanup, JobKind.EmptyTrash, JobKind.Convert,
JobKind.Backup, JobKind.Cleanup, JobKind.EmptyTrash, JobKind.Convert, JobKind.WorkspaceCopy,
];
/// <summary>Stores <paramref name="level"/> for <paramref name="kind"/>, keeping only the levels that differ from the defaults.</summary>
@@ -1534,6 +1564,9 @@ public sealed class SettingsViewModel : SectionViewModel
case SettingsPage.Updates:
_s.CheckForUpdates = defaults.CheckForUpdates;
break;
case SettingsPage.Workspace:
WorkspaceRows.Reset();
break;
case SettingsPage.Advanced:
Logs.Reset();
break;
@@ -1611,6 +1644,9 @@ public sealed class SettingsViewModel : SectionViewModel
LastEditedSequence = _s.LastEditedSequence,
FirstRunCompleted = _s.FirstRunCompleted,
JobsClearedAt = _s.JobsClearedAt,
// The workspace holds this PC's work: its folder stays where it is (moving it is its own operation).
WorkspaceFolder = _s.WorkspaceFolder,
WorkspaceRecent = _s.WorkspaceRecent,
};
// Start with Windows lives in the registry, not in the settings file: its default is off.
Startup.SetEnabled(false);
@@ -1642,6 +1678,7 @@ public sealed class SettingsViewModel : SectionViewModel
_interfacePriority?.Update();
foreach (var row in JobPriorities) row.Refresh();
Logs.Refresh();
WorkspaceRows.Refresh();
UpdatePreview();
LoadCertificates();
OnAllPropertiesChanged();
@@ -1656,6 +1693,8 @@ public sealed class SettingsViewModel : SectionViewModel
// Secrets and machine-bound values stay on this PC.
copy.ProtectedToken = null;
copy.Window = null;
copy.WorkspaceFolder = null;
copy.WorkspaceRecent = [];
var path = Path.Combine(folder, $"Chronos settings {DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)}.json");
await Task.Run(() => AtomicFile.WriteAllText(path, copy.ToJson()));
Shell.Notify(Loc.L("Settings.Export.Done"), Path.GetFileName(path), Loc.L("Library.Export.Show"), Loc.L("Tooltips.Library.ShowExport"), () => ShellActions.Reveal(path));
@@ -1688,6 +1727,9 @@ public sealed class SettingsViewModel : SectionViewModel
imported.RailCollapsed = _s.RailCollapsed;
imported.LastEditedSequence = _s.LastEditedSequence;
imported.FirstRunCompleted = _s.FirstRunCompleted;
// The workspace is this PC's: its folder and the projects opened last stay.
imported.WorkspaceFolder = _s.WorkspaceFolder;
imported.WorkspaceRecent = _s.WorkspaceRecent;
ApplyAll(imported);
// Settings of a PC never rewrite the shared archive.json: the imported templates and sizes are the defaults of new
// archives, and the rows show the own settings of the archive at the (possibly imported) archive folder.
@@ -1717,6 +1759,7 @@ public sealed class SettingsViewModel : SectionViewModel
foreach (var row in Formats) row.Refresh();
foreach (var row in MissingExtensions) row.Refresh();
Logs.Refresh();
WorkspaceRows.Refresh();
ArchiveRoot.Refresh();
FolderTemplate.Refresh();
FileTemplate.Refresh();