merge: card import and archive manager screens (card pool, plan, verified erase and format, server destination, tree, charts, maintenance)

Union of the Tooltips resources; sample data keeps the sync server and the
simulated cards; the import test names App.Infrastructure.Formatting fully now
that a test namespace of the same name exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-03 11:01:34 +00:00
commit 828c64a485
57 files changed
+8742 -23

No files matched your search

+525 -3
View File
@@ -2,8 +2,530 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:Titano.Ui.Controls;assembly=Titano.Ui"
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui">
<Grid Margin="20">
<ui:EmptyState Message="{l:Loc Archive.Empty}" />
xmlns:v="clr-namespace:Titano.Ui.Visuals;assembly=Titano.Ui"
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui"
xmlns:ar="clr-namespace:Titano.App.Archiving"
xmlns:shell="clr-namespace:Titano.App.Shell">
<UserControl.Resources>
<Style x:Key="Text.PanelHeading" TargetType="TextBlock" BasedOn="{StaticResource Text.Section}">
<Setter Property="FontSize" Value="13" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style x:Key="Button.Bar" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Height" Value="30" />
<Setter Property="Margin" Value="0,0,8,0" />
</Style>
<Style x:Key="Button.Tool" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Margin" Value="0,0,8,8" />
</Style>
<!-- Rows that only show text: focusable, so the arrow keys move through a long list. -->
<Style x:Key="ListBoxItem.Preview" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem.Row}">
<Setter Property="Padding" Value="0" />
<Setter Property="AutomationProperties.Name" Value="{Binding To}" />
</Style>
<!-- Report rows with their own buttons: Tab reaches every button. -->
<Style x:Key="ListBoxItem.Duplicate" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem.PlainRow}">
<Setter Property="AutomationProperties.Name" Value="{Binding Row.Title}" />
</Style>
<!-- A filter menu: its values, each checked while chosen. -->
<Style x:Key="MenuItem.Choice" TargetType="MenuItem" BasedOn="{StaticResource {x:Type MenuItem}}">
<Setter Property="Header" Value="{Binding Label}" />
<Setter Property="IsChecked" Value="{Binding IsChecked, Mode=OneWay}" />
<Setter Property="Command" Value="{Binding Command}" />
<Setter Property="ToolTip" Value="{l:Loc Tooltips.Archive.FilterChoice}" />
<Setter Property="ToolTipService.ShowOnDisabled" Value="True" />
</Style>
<!-- Dialog card (DESIGN §4: Surface, Stroke, radius 12, 24 px shadow, two buttons). -->
<Style x:Key="Border.Dialog" TargetType="Border">
<Setter Property="Background" Value="{DynamicResource Brush.Surface}" />
<Setter Property="BorderBrush" Value="{DynamicResource Brush.Stroke}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="CornerRadius" Value="{StaticResource Radius.Dialog}" />
<Setter Property="Padding" Value="24,18,24,20" />
<Setter Property="Effect" Value="{StaticResource Shadow.Popup}" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<DataTemplate DataType="{x:Type ar:RebuildDialogViewModel}">
<Border Style="{StaticResource Border.Dialog}" Width="520">
<StackPanel>
<TextBlock Text="{l:Loc Archive.Rebuild.Heading}" Style="{StaticResource Text.Title}" />
<ItemsControl ItemsSource="{Binding FactRows}" Focusable="False" Margin="0,14,0,0">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type ar:DialogFact}">
<Grid Margin="0,0,0,8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource Grid.LabelColumn}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Label}" Style="{StaticResource Text.Label}" />
<TextBlock Grid.Column="1" Text="{Binding Value}" TextTrimming="CharacterEllipsis" ToolTip="{Binding Value}" Typography.NumeralAlignment="Tabular" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBlock Text="{Binding BusyText}" Foreground="{DynamicResource Brush.TextMuted}" Visibility="{Binding BusyText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,18,0,0">
<Button Content="{l:Loc Archive.Dialog.Cancel}" Command="{Binding CloseCommand}" ToolTip="{Binding CloseToolTip}" IsDefault="True" IsCancel="True"
MinWidth="96" />
<Button Style="{StaticResource Button.Primary}" Content="{l:Loc Archive.Rebuild.Start}" Command="{Binding RebuildCommand}" ToolTip="{Binding RebuildToolTip}"
MinWidth="96" Margin="8,0,0,0" />
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
<DataTemplate DataType="{x:Type ar:RenameDialogViewModel}">
<Border Style="{StaticResource Border.Dialog}" Width="720" MaxHeight="560">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="{Binding Heading}" Style="{StaticResource Text.Title}" />
<Grid Grid.Row="1" Margin="0,14,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource Grid.LabelColumn}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="{l:Loc Archive.Rename.Template}" Style="{StaticResource Text.Label}" />
<TextBox Grid.Column="1" Style="{StaticResource TextBox.Mono}" Text="{Binding Template.Text, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}"
shell:EditBehavior.Field="{Binding Template}" ToolTip="{Binding Template.ToolTip}" AutomationProperties.Name="{l:Loc Archive.Rename.Template}" />
</Grid>
<TextBlock Grid.Row="2" Text="{Binding SummaryText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,12,0,6" Typography.NumeralAlignment="Tabular" />
<ListBox Grid.Row="3" ItemsSource="{Binding Rows}" ItemContainerStyle="{StaticResource ListBoxItem.Preview}" MinHeight="120"
AutomationProperties.Name="{l:Loc Archive.Rename.Preview}">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type ar:RenameRow}">
<Grid Height="30" TextElement.FontSize="12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="120" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" MinWidth="120" />
</Grid.ColumnDefinitions>
<TextBlock Style="{StaticResource Text.Cell}" Text="{Binding From}" Foreground="{DynamicResource Brush.TextMuted}" ToolTip="{Binding From}" />
<ui:Icon Grid.Column="1" Glyph="{StaticResource Icon.Forward}" Margin="10,0" Foreground="{DynamicResource Brush.TextFaint}" />
<TextBlock Grid.Column="2" Style="{StaticResource Text.Cell}" Text="{Binding To}" ToolTip="{Binding To}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<DockPanel Grid.Row="4" Margin="0,16,0,0">
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Primary}" Content="{l:Loc Archive.Rename.Apply}" Command="{Binding ApplyCommand}"
ToolTip="{Binding ApplyToolTip}" MinWidth="96" Margin="8,0,0,0" />
<Button DockPanel.Dock="Right" Content="{l:Loc Archive.Dialog.Cancel}" Command="{Binding CloseCommand}" ToolTip="{Binding CloseToolTip}" IsCancel="True"
MinWidth="96" />
<TextBlock Text="{Binding BusyText}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" />
</DockPanel>
</Grid>
</Border>
</DataTemplate>
<DataTemplate DataType="{x:Type ar:RetagDialogViewModel}">
<Border Style="{StaticResource Border.Dialog}" Width="520">
<StackPanel>
<TextBlock Text="{Binding Heading}" Style="{StaticResource Text.Title}" />
<Grid Margin="0,14,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource Grid.LabelColumn}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="{l:Loc Archive.Retag.Add}" Style="{StaticResource Text.Label}" />
<TextBox Grid.Column="1" Text="{Binding Add.Text, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}" shell:EditBehavior.Field="{Binding Add}"
ToolTip="{Binding Add.ToolTip}" AutomationProperties.Name="{l:Loc Archive.Retag.Add}" />
<TextBlock Grid.Row="1" Text="{l:Loc Archive.Retag.Remove}" Style="{StaticResource Text.Label}" Margin="0,10,14,0" />
<TextBox Grid.Row="1" Grid.Column="1" Margin="0,10,0,0" Text="{Binding Remove.Text, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}"
shell:EditBehavior.Field="{Binding Remove}" ToolTip="{Binding Remove.ToolTip}" AutomationProperties.Name="{l:Loc Archive.Retag.Remove}" />
</Grid>
<TextBlock Text="{Binding SummaryText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,12,0,0" Typography.NumeralAlignment="Tabular" />
<DockPanel Margin="0,18,0,0">
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Primary}" Content="{l:Loc Archive.Retag.Apply}" Command="{Binding ApplyCommand}"
ToolTip="{Binding ApplyToolTip}" MinWidth="96" Margin="8,0,0,0" />
<Button DockPanel.Dock="Right" Content="{l:Loc Archive.Dialog.Cancel}" Command="{Binding CloseCommand}" ToolTip="{Binding CloseToolTip}" IsCancel="True"
MinWidth="96" />
<TextBlock Text="{Binding BusyText}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" />
</DockPanel>
</StackPanel>
</Border>
</DataTemplate>
</UserControl.Resources>
<Grid>
<Grid Margin="20,16" IsEnabled="{Binding IsContentEnabled}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- ===================== Toolbar (Archive.html: one row) ===================== -->
<DockPanel Margin="0,0,0,4">
<ComboBox DockPanel.Dock="Left" Width="220" VerticalAlignment="Top" ItemsSource="{Binding Archives}" SelectedItem="{Binding SelectedArchive}" DisplayMemberPath="Name"
ToolTip="{Binding ArchiveToolTip}" AutomationProperties.Name="{l:Loc Archive.Toolbar.Archive}" Margin="0,0,8,8" />
<Border DockPanel.Dock="Left" Width="1" Height="22" Background="{DynamicResource Brush.Stroke}" Margin="4,5,12,0" VerticalAlignment="Top" />
<WrapPanel>
<Button Style="{StaticResource Button.Tool}" Content="{l:Loc Archive.Toolbar.Scan}" Command="{Binding ScanCommand}" ToolTip="{Binding ScanToolTip}" />
<Button Style="{StaticResource Button.Tool}" Content="{l:Loc Archive.Toolbar.Rebuild}" Command="{Binding RebuildCommand}" ToolTip="{l:Loc Tooltips.Archive.Rebuild}" />
<Button Style="{StaticResource Button.Tool}" Content="{l:Loc Archive.Toolbar.Verify}" Command="{Binding VerifyCommand}" ToolTip="{Binding VerifyToolTip}" />
<Button Style="{StaticResource Button.Tool}" Content="{l:Loc Archive.Toolbar.Duplicates}" Command="{Binding FindDuplicatesCommand}"
ToolTip="{Binding DuplicatesToolTip}" />
<Button Style="{StaticResource Button.Tool}" Content="{l:Loc Archive.Toolbar.Orphans}" Command="{Binding FindOrphansCommand}" ToolTip="{Binding OrphansToolTip}" />
<Button Style="{StaticResource Button.Tool}" Click="OnOpenMenu" ToolTip="{l:Loc Tooltips.Archive.Adopt}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{l:Loc Archive.Toolbar.AdoptMenu}" />
<ui:Icon Glyph="{StaticResource Icon.ChevronDown}" Margin="6,0,0,0" />
</StackPanel>
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="{l:Loc Archive.Adopt.InPlace}" Command="{Binding AdoptCommand}" ToolTip="{l:Loc Tooltips.Archive.AdoptInPlace}" ToolTipService.ShowOnDisabled="True" />
<MenuItem Header="{l:Loc Archive.Adopt.Copy}" Command="{Binding CopyFolderCommand}" ToolTip="{l:Loc Tooltips.Archive.AdoptCopy}" ToolTipService.ShowOnDisabled="True" />
</ContextMenu>
</Button.ContextMenu>
</Button>
<Button x:Name="MaintenanceButton" Style="{StaticResource Button.Tool}" Click="OnOpenMenu" ToolTip="{l:Loc Tooltips.Archive.Maintenance}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{l:Loc Archive.Toolbar.Maintenance}" />
<ui:Icon Glyph="{StaticResource Icon.ChevronDown}" Margin="6,0,0,0" />
</StackPanel>
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="{l:Loc Archive.Maintenance.Run}" Command="{Binding MaintenanceCommand}" ToolTip="{Binding MaintenanceRunToolTip}" ToolTipService.ShowOnDisabled="True" />
<MenuItem Header="{l:Loc Archive.Maintenance.DryRun}" Command="{Binding MaintenanceDryRunCommand}" ToolTip="{l:Loc Tooltips.Archive.MaintenanceDryRun}" ToolTipService.ShowOnDisabled="True" />
<MenuItem Header="{l:Loc Archive.Maintenance.Proxies}" Command="{Binding RebuildProxiesCommand}" ToolTip="{Binding RebuildProxiesToolTip}" ToolTipService.ShowOnDisabled="True" />
<MenuItem Header="{l:Loc Archive.Maintenance.Backup}" Command="{Binding BackupCommand}" ToolTip="{l:Loc Tooltips.Archive.Backup}" ToolTipService.ShowOnDisabled="True" />
<Separator />
<MenuItem Header="{l:Loc Archive.Maintenance.Relink}" Command="{Binding RelinkCommand}" ToolTip="{l:Loc Tooltips.Archive.Relink}" ToolTipService.ShowOnDisabled="True" />
</ContextMenu>
</Button.ContextMenu>
</Button>
</WrapPanel>
</DockPanel>
<!-- Overview or maintenance, and when the archive was last scanned. -->
<DockPanel Grid.Row="1" Margin="0,0,0,12" Visibility="{Binding HasArchive, Converter={StaticResource BoolToVisibility}}">
<v:SegmentedControl DockPanel.Dock="Left" SelectedIndex="{Binding ViewIndex}" AutomationProperties.Name="{l:Loc Archive.View.Name}">
<v:SegmentedItem Content="{l:Loc Archive.View.Overview}" ToolTip="{l:Loc Tooltips.Archive.Overview}" AutomationProperties.Name="{l:Loc Archive.View.Overview}" />
<v:SegmentedItem Content="{l:Loc Archive.View.Maintenance}" ToolTip="{l:Loc Tooltips.Archive.MaintenanceView}"
AutomationProperties.Name="{l:Loc Archive.View.Maintenance}" />
</v:SegmentedControl>
<TextBlock Text="{Binding LastScanText}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="14,0,0,0"
TextTrimming="CharacterEllipsis" Typography.NumeralAlignment="Tabular" ToolTip="{l:Loc Tooltips.Archive.LastScan}" />
</DockPanel>
<!-- ===================== Overview: tree, figures, charts ===================== -->
<Grid Grid.Row="2" Visibility="{Binding IsOverview, Converter={StaticResource BoolToVisibility}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.3*" MinWidth="200" MaxWidth="320" />
<ColumnDefinition Width="14" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Style="{StaticResource Border.Panel}" Padding="6,8">
<ListBox x:Name="Tree" ItemsSource="{Binding TreeRows}" SelectionMode="Extended" SelectionChanged="OnTreeSelectionChanged" PreviewKeyDown="OnTreeKeyDown"
AutomationProperties.Name="{l:Loc Archive.Tree.Name}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="MinHeight" Value="32" />
<Setter Property="Padding" Value="6,0" />
<Setter Property="ToolTip" Value="{Binding RowToolTip}" />
<Setter Property="AutomationProperties.Name" Value="{Binding Title}" />
<Setter Property="AutomationProperties.HelpText" Value="{Binding Detail}" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type ar:ArchiveTreeRowViewModel}">
<Grid Margin="{Binding IndentMargin}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="24" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button x:Name="Toggle" Style="{StaticResource Button.IconSubtle}" Width="22" Height="22" MinWidth="22" ui:ButtonIcon.Glyph="{StaticResource Icon.ChevronRight}"
Command="{Binding ToggleCommand}" ToolTip="{Binding ToggleToolTip}" AutomationProperties.Name="{Binding ToggleToolTip}" Visibility="Hidden"
Focusable="False" />
<TextBlock x:Name="Title" Grid.Column="1" Text="{Binding Title}" TextTrimming="CharacterEllipsis" VerticalAlignment="Center" />
<TextBlock x:Name="Detail" Grid.Column="2" Text="{Binding Detail}" Style="{StaticResource Text.Secondary}" VerticalAlignment="Center" Margin="8,0,0,0"
Visibility="Collapsed" Typography.NumeralAlignment="Tabular" />
<ui:StatusGlyph x:Name="State" Grid.Column="2" Kind="{Binding AvailabilityKind}" Text="{Binding AvailabilityText}" VerticalAlignment="Center"
Margin="8,0,0,0" ToolTip="{Binding AvailabilityToolTip}" Visibility="Collapsed" />
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding HasChildren}" Value="True">
<Setter TargetName="Toggle" Property="Visibility" Value="Visible" />
</DataTrigger>
<DataTrigger Binding="{Binding IsExpanded}" Value="True">
<Setter TargetName="Toggle" Property="ui:ButtonIcon.Glyph" Value="{StaticResource Icon.ChevronDown}" />
</DataTrigger>
<DataTrigger Binding="{Binding IsArchive}" Value="True">
<Setter TargetName="Title" Property="FontWeight" Value="SemiBold" />
<Setter TargetName="State" Property="Visibility" Value="Visible" />
<Setter TargetName="Toggle" Property="Visibility" Value="Collapsed" />
</DataTrigger>
<DataTrigger Binding="{Binding IsYear}" Value="True">
<Setter TargetName="Title" Property="FontWeight" Value="SemiBold" />
<Setter TargetName="Detail" Property="Visibility" Value="Visible" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Border>
<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Figure tiles (Archive.html). -->
<ItemsControl ItemsSource="{Binding Tiles}" Focusable="False" Margin="0,0,-10,0">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type ar:ArchiveTile}">
<Border Style="{StaticResource Border.Panel}" Padding="14,8" Margin="0,0,10,0" ToolTip="{Binding Caption}">
<StackPanel>
<!-- A narrow tile (the window at its minimum width) shrinks the figure rather than cutting it. -->
<Viewbox StretchDirection="DownOnly" HorizontalAlignment="Left">
<TextBlock Text="{Binding Value}" FontSize="24" FontWeight="SemiBold" Typography.NumeralAlignment="Tabular" />
</Viewbox>
<TextBlock Text="{Binding Caption}" Style="{StaticResource Text.Secondary}" TextWrapping="Wrap" />
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Grid Grid.Row="1" Margin="0,12,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1.2*" />
<ColumnDefinition Width="12" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Style="{StaticResource Border.Panel}" Padding="14,10">
<DockPanel>
<TextBlock DockPanel.Dock="Top" Text="{l:Loc Archive.Chart.Months}" Style="{StaticResource Text.PanelHeading}" Margin="0,0,0,8" />
<v:HeatmapStrip Rows="{Binding MonthRows}" ColumnLabels="{Binding MonthLabels}" ValueFormatter="{Binding CountFormatter}" MaxCellSize="18"
ToolTip="{l:Loc Tooltips.Archive.Months}" AutomationProperties.Name="{l:Loc Archive.Chart.Months}" />
</DockPanel>
</Border>
<Border Grid.Column="2" Style="{StaticResource Border.Panel}" Padding="14,10">
<DockPanel>
<TextBlock DockPanel.Dock="Top" Text="{l:Loc Archive.Chart.Storage}" Style="{StaticResource Text.PanelHeading}" Margin="0,0,0,8" />
<v:BarChart Items="{Binding StorageBars}" MinimumOpacity="0.55" BarThickness="12" ToolTip="{l:Loc Tooltips.Archive.Storage}"
AutomationProperties.Name="{l:Loc Archive.Chart.Storage}" />
</DockPanel>
</Border>
</Grid>
<Grid Grid.Row="2" Margin="0,12,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="12" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Style="{StaticResource Border.Panel}" Padding="14,10">
<DockPanel>
<TextBlock DockPanel.Dock="Top" Text="{l:Loc Archive.Chart.Cameras}" Style="{StaticResource Text.PanelHeading}" Margin="0,0,0,8" />
<v:BarChart Items="{Binding CameraBars}" BrushKey="Brush.Sun" MinimumOpacity="0.45" BarThickness="12" ToolTip="{l:Loc Tooltips.Archive.Cameras}"
AutomationProperties.Name="{l:Loc Archive.Chart.Cameras}" />
</DockPanel>
</Border>
<Border Grid.Column="2" Style="{StaticResource Border.Panel}" Padding="14,10">
<DockPanel>
<TextBlock DockPanel.Dock="Top" Text="{l:Loc Archive.Chart.Formats}" Style="{StaticResource Text.PanelHeading}" Margin="0,0,0,8" />
<v:BarChart Items="{Binding FormatBars}" MinimumOpacity="0.35" BarThickness="12" ToolTip="{l:Loc Tooltips.Archive.Formats}"
AutomationProperties.Name="{l:Loc Archive.Chart.Formats}" />
</DockPanel>
</Border>
</Grid>
</Grid>
</Grid>
<!-- ===================== Maintenance: health, recent runs, duplicates, orphans ===================== -->
<Grid Grid.Row="2" Visibility="{Binding IsMaintenance, Converter={StaticResource BoolToVisibility}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="14" />
<ColumnDefinition Width="1.1*" />
</Grid.ColumnDefinitions>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border Style="{StaticResource Border.Panel}" Padding="16,12">
<StackPanel>
<TextBlock Text="{l:Loc Archive.Health.Title}" Style="{StaticResource Text.PanelHeading}" Margin="0,0,0,8" />
<ItemsControl ItemsSource="{Binding Health}" Focusable="False">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type ar:HealthLineViewModel}">
<DockPanel Height="32">
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Row}" Margin="8,0,0,0" Content="{Binding FixText}" Command="{Binding FixCommand}"
ToolTip="{Binding FixToolTip}" Visibility="{Binding HasFix, Converter={StaticResource BoolToVisibility}}" />
<ui:StatusGlyph Kind="{Binding Kind}" Text="{Binding Text}" FontSize="13" VerticalAlignment="Center" ToolTip="{Binding KindToolTip}" />
</DockPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Border>
<Border Grid.Row="1" Style="{StaticResource Border.Panel}" Padding="16,12" Margin="0,14,0,0">
<DockPanel>
<DockPanel DockPanel.Dock="Top" Margin="0,0,0,8">
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Row}" Margin="0" Content="{l:Loc Archive.Recent.History}" Command="{Binding HistoryCommand}"
ToolTip="{l:Loc Tooltips.Archive.History}" />
<TextBlock Text="{l:Loc Archive.Recent.Title}" Style="{StaticResource Text.PanelHeading}" />
</DockPanel>
<TextBlock DockPanel.Dock="Top" Text="{l:Loc Archive.Recent.Empty}" Foreground="{DynamicResource Brush.TextMuted}"
Visibility="{Binding HasRecent, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
<ItemsControl ItemsSource="{Binding Recent}" Focusable="False">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type ar:MaintenanceRow}">
<Grid Height="28">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="90" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding DateText}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" />
<TextBlock Grid.Column="1" Text="{Binding Text}" Margin="12,0" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" ToolTip="{Binding Text}" />
<TextBlock Grid.Column="2" Text="{Binding StateText}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DockPanel>
</Border>
</Grid>
<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border Style="{StaticResource Border.Panel}" Padding="16,12">
<DockPanel>
<DockPanel DockPanel.Dock="Top" Margin="0,0,0,8">
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Row}" Margin="8,0,0,0" Content="{l:Loc Archive.Duplicates.Mark}"
Command="{Binding MarkDuplicatesCommand}" ToolTip="{Binding MarkDuplicatesToolTip}" />
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Row}" Margin="0" Content="{l:Loc Archive.Find.Run}" Command="{Binding FindDuplicatesCommand}"
ToolTip="{Binding DuplicatesToolTip}" Visibility="{Binding IsSearching, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Row}" Margin="0" Content="{l:Loc Archive.Find.Cancel}" Command="{Binding CancelSearchCommand}"
ToolTip="{l:Loc Tooltips.Archive.CancelSearch}" Visibility="{Binding IsSearching, Converter={StaticResource BoolToVisibility}}" />
<TextBlock Text="{l:Loc Archive.Duplicates.Title}" Style="{StaticResource Text.PanelHeading}" />
<TextBlock Text="{Binding DuplicatesText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0" VerticalAlignment="Center" />
</DockPanel>
<ListBox ItemsSource="{Binding Duplicates}" ItemContainerStyle="{StaticResource ListBoxItem.Duplicate}" AutomationProperties.Name="{l:Loc Archive.Duplicates.Title}"
KeyboardNavigation.TabNavigation="Continue">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type ar:DuplicateRowViewModel}">
<DockPanel Height="44">
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Row}" Content="{l:Loc Archive.Duplicates.Folder}" Command="{Binding RevealCommand}"
ToolTip="{l:Loc Tooltips.Archive.DuplicateFolder}" />
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Row}" Content="{l:Loc Archive.Duplicates.Open}" Command="{Binding OpenCommand}"
ToolTip="{l:Loc Tooltips.Archive.DuplicateOpen}" />
<StackPanel VerticalAlignment="Center">
<TextBlock TextTrimming="CharacterEllipsis">
<Run Text="{Binding Row.Title, Mode=OneWay}" FontWeight="SemiBold" />
<Run Text="{Binding Row.Detail, Mode=OneWay}" Foreground="{DynamicResource Brush.TextMuted}" />
</TextBlock>
<TextBlock Text="{Binding Places}" Style="{StaticResource Text.Secondary}" TextTrimming="CharacterEllipsis" ToolTip="{Binding Places}" />
</StackPanel>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
</Border>
<Border Grid.Row="1" Style="{StaticResource Border.Panel}" Padding="16,12" Margin="0,14,0,0">
<DockPanel>
<DockPanel DockPanel.Dock="Top" Margin="0,0,0,8">
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Row}" Margin="0" Content="{l:Loc Archive.Find.Run}" Command="{Binding FindOrphansCommand}"
ToolTip="{Binding OrphansToolTip}" Visibility="{Binding IsSearching, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Row}" Margin="0" Content="{l:Loc Archive.Find.Cancel}" Command="{Binding CancelSearchCommand}"
ToolTip="{l:Loc Tooltips.Archive.CancelSearch}" Visibility="{Binding IsSearching, Converter={StaticResource BoolToVisibility}}" />
<TextBlock Text="{l:Loc Archive.Orphans.Title}" Style="{StaticResource Text.PanelHeading}" />
<TextBlock Text="{Binding OrphansText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0" VerticalAlignment="Center" />
</DockPanel>
<ListBox ItemsSource="{Binding Orphans}" ItemContainerStyle="{StaticResource ListBoxItem.Duplicate}" AutomationProperties.Name="{l:Loc Archive.Orphans.Title}"
KeyboardNavigation.TabNavigation="Continue">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type ar:OrphanRowViewModel}">
<DockPanel Height="44">
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Row}" Content="{Binding FixText}" Command="{Binding FixCommand}" ToolTip="{Binding FixToolTip}" />
<StackPanel VerticalAlignment="Center">
<TextBlock Text="{Binding Row.Title}" FontWeight="SemiBold" TextTrimming="CharacterEllipsis" ToolTip="{Binding Row.Title}" />
<ui:StatusGlyph Kind="{Binding Kind}" Text="{Binding Row.Detail}" FontSize="12" ToolTip="{Binding KindText}" />
</StackPanel>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
</Border>
</Grid>
</Grid>
<!-- ===================== Mass operations on the selected, filtered set ===================== -->
<Border Grid.Row="3" Style="{StaticResource Border.Panel}" Padding="14,8,6,0" Margin="0,14,0,0" MinHeight="48"
Visibility="{Binding IsOverview, Converter={StaticResource BoolToVisibility}}">
<WrapPanel VerticalAlignment="Center">
<TextBlock Text="{l:Loc Archive.Set.Label}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" Margin="0,0,10,8" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" BorderBrush="{DynamicResource Brush.Accent}" Click="OnOpenMenu" ToolTip="{l:Loc Tooltips.Archive.Set}"
AutomationProperties.Name="{l:Loc Archive.Set.Filter}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding SetText}" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" MaxWidth="260" TextTrimming="CharacterEllipsis" />
<ui:Icon Glyph="{StaticResource Icon.ChevronDown}" Margin="6,0,0,0" />
</StackPanel>
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="{l:Loc Library.Filter.Camera}" ItemsSource="{Binding CameraChoices}" ItemContainerStyle="{StaticResource MenuItem.Choice}"
ToolTip="{l:Loc Tooltips.Archive.FilterCamera}" />
<MenuItem Header="{l:Loc Library.Filter.Status}" ItemsSource="{Binding StatusChoices}" ItemContainerStyle="{StaticResource MenuItem.Choice}"
ToolTip="{l:Loc Tooltips.Archive.FilterStatus}" />
<MenuItem Header="{l:Loc Library.Filter.Tags}" ItemsSource="{Binding TagChoices}" ItemContainerStyle="{StaticResource MenuItem.Choice}"
ToolTip="{l:Loc Tooltips.Archive.FilterTag}" />
<Separator />
<MenuItem Header="{l:Loc Archive.Set.ClearFilter}" Command="{Binding ClearFilterCommand}" ToolTip="{l:Loc Tooltips.Archive.ClearFilter}" ToolTipService.ShowOnDisabled="True" />
</ContextMenu>
</Button.ContextMenu>
</Button>
<Border Width="1" Height="22" Background="{DynamicResource Brush.Stroke}" Margin="4,0,12,8" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Analyse}" Command="{Binding AnalyseSetCommand}" ToolTip="{Binding AnalyseSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Proxies}" Command="{Binding ProxiesSetCommand}" ToolTip="{Binding ProxiesSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Thumbnails}" Command="{Binding ThumbnailsSetCommand}"
ToolTip="{Binding ThumbnailsSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Verify}" Command="{Binding VerifySetCommand}" ToolTip="{Binding VerifySetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Rename}" Command="{Binding RenameSetCommand}" ToolTip="{Binding RenameSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Move}" Command="{Binding MoveSetCommand}" ToolTip="{Binding MoveSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Retag}" Command="{Binding RetagSetCommand}" ToolTip="{Binding RetagSetToolTip}" />
<Button Style="{StaticResource Button.Bar}" Margin="0,0,8,8" Content="{l:Loc Archive.Set.Export}" Command="{Binding ExportSetCommand}" ToolTip="{Binding ExportSetToolTip}" />
</WrapPanel>
</Border>
<ui:EmptyState Grid.Row="2" Message="{l:Loc Archive.Empty}" Visibility="{Binding IsEmpty, Converter={StaticResource BoolToVisibility}}">
<Button Style="{StaticResource Button.Primary}" Content="{l:Loc Archive.Toolbar.Adopt}" Command="{Binding AdoptCommand}" ToolTip="{l:Loc Tooltips.Archive.Adopt}" />
</ui:EmptyState>
</Grid>
<!-- In-window dialogs (rebuild, rename, retag) 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>
+97 -1
View File
@@ -1,8 +1,104 @@
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Threading;
using Titano.App.Archiving;
namespace Titano.App.Sections;
public partial class ArchiveView : UserControl
{
public ArchiveView() => InitializeComponent();
private bool _restoring;
private string? _focusKey;
public ArchiveView()
{
InitializeComponent();
DataContextChanged += OnDataContextChanged;
Tree.GotKeyboardFocus += (_, e) =>
{
if (e.NewFocus is ListBoxItem { DataContext: ArchiveTreeRowViewModel row }) _focusKey = row.Node.Key;
};
}
private ArchiveViewModel? Model => DataContext as ArchiveViewModel;
/// <summary>"Adopt folder ▾", "Maintenance ▾" and the set filter open their menu under themselves.</summary>
private void OnOpenMenu(object sender, RoutedEventArgs e)
{
if (sender is not Button { ContextMenu: { } menu } button) return;
menu.DataContext = DataContext;
menu.PlacementTarget = button;
menu.Placement = PlacementMode.Bottom;
menu.IsOpen = true;
}
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (e.OldValue is ArchiveViewModel old)
{
old.RowsRebuilt -= RestoreSelection;
old.PropertyChanged -= OnModelChanged;
}
if (e.NewValue is ArchiveViewModel model)
{
model.RowsRebuilt += RestoreSelection;
model.PropertyChanged += OnModelChanged;
}
}
/// <summary>The selected tree rows are the set the mass operations act on.</summary>
private void OnTreeSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!_restoring) Model?.SetSelection(Tree.SelectedItems.OfType<ArchiveTreeRowViewModel>());
}
/// <summary>The rows were rebuilt (a reload, a year opened or closed): the list shows the same selection and keeps the keyboard where it was.</summary>
private void RestoreSelection()
{
if (Model is not { } model) return;
// The rebuild removed the focused row's container; the keyboard goes back to the row with the same key.
var refocus = Tree.IsKeyboardFocusWithin || Keyboard.FocusedElement is null ? _focusKey : null;
_restoring = true;
try
{
Tree.SelectedItems.Clear();
foreach (var row in model.TreeRows.Where(model.IsSelectedRow)) Tree.SelectedItems.Add(row);
}
finally
{
_restoring = false;
}
if (refocus is null || model.TreeRows.FirstOrDefault(r => r.Node.Key == refocus) is not { } again) return;
Dispatcher.BeginInvoke(DispatcherPriority.Input, () =>
{
Tree.ScrollIntoView(again);
(Tree.ItemContainerGenerator.ContainerFromItem(again) as ListBoxItem)?.Focus();
});
}
/// <summary>On a year: Right opens it, Left closes it, Enter toggles it.</summary>
private void OnTreeKeyDown(object sender, KeyEventArgs e)
{
if (Model is not { } model || Keyboard.FocusedElement is not ListBoxItem { DataContext: ArchiveTreeRowViewModel row } || !row.HasChildren || row.IsArchive) return;
var toggle = e.Key switch
{
Key.Right => !row.IsExpanded,
Key.Left => row.IsExpanded,
Key.Enter => true,
_ => false,
};
if (!toggle) return;
model.Toggle(row);
e.Handled = true;
}
/// <summary>A dialog that opens takes the keyboard: its first field or button.</summary>
private void OnModelChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName != nameof(ArchiveViewModel.Dialog) || Model?.Dialog is null || !IsVisible) return;
Dispatcher.BeginInvoke(DispatcherPriority.Input, () => DialogHost.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)));
}
}
+857 -3
View File
@@ -1,9 +1,863 @@
using System.Collections.ObjectModel;
using System.IO;
using System.Windows.Input;
using System.Windows.Threading;
using Titano.App.Archiving;
using Titano.App.Infrastructure;
using Titano.App.Jobs;
using Titano.App.Library;
using Titano.App.Shell;
using Titano.Core.Archiving;
using Titano.Core.Diagnostics;
using Titano.Core.IO;
using Titano.Core.Localization;
using Titano.Core.Model;
using Titano.Data;
using Titano.Data.Archiving;
using Titano.Data.Archiving.Jobs;
using Titano.Data.Processing;
using Titano.Data.Repositories;
using Titano.Ui.Mvvm;
using Titano.Ui.Visuals;
namespace Titano.App.Sections;
/// <summary>Archive manager (BRIEF §12.5).</summary>
public sealed class ArchiveViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.Archive, "Icon.Archive")
/// <summary>
/// Archive manager (BRIEF §12.5, Archive.html): the archive's tree (years, sequences) with its availability, its
/// figures and charts, mass operations on the selected and filtered set (analyse, proxies, thumbnails, verify, rename,
/// move, retag, CSV), and the operations on the whole archive as jobs (scan, rebuild with its dialog, verify,
/// maintenance), plus the maintenance view: index health, duplicates and orphans with safe fixes, recent runs. The
/// tree selection is only ever changed by the user: reloads and expanding keep it.
/// </summary>
public sealed class ArchiveViewModel : SectionViewModel
{
public ShellViewModel Shell { get; } = shell;
private const int RecentCount = 6;
private const int PageSize = 1000;
private static readonly TimeSpan ReloadDelay = TimeSpan.FromSeconds(2);
/// <summary>Keys of the selected tree nodes (stable across reloads).</summary>
private readonly HashSet<string> _selection = new(StringComparer.Ordinal);
private readonly DispatcherTimer _reloadDelay;
private HashSet<Guid> _sequenceIds = [];
private ArchiveSetFilter _filter = new();
private bool _rebuildingRows;
private CancellationTokenSource? _search;
private IReadOnlyList<Core.Model.Archive> _archives = [];
private Core.Model.Archive? _archive;
private ArchiveAvailability _availability = ArchiveAvailability.Offline;
private ArchiveStats? _stats;
private ArchiveTree? _tree;
private int _viewIndex;
private bool _loaded;
private Task _load = Task.CompletedTask;
private bool _jobEvents;
private string _lastScanText = string.Empty;
private ArchiveDialogViewModel? _dialog;
private IReadOnlyList<ArchiveTile> _tiles = [];
private IReadOnlyList<ChartRow> _months = [];
private IReadOnlyList<ChartItem> _storage = [];
private IReadOnlyList<ChartItem> _cameras = [];
private IReadOnlyList<ChartItem> _formats = [];
private IReadOnlyList<HealthLineViewModel> _health = [];
private IReadOnlyList<MaintenanceRow> _recent = [];
private IReadOnlyList<DuplicateRowViewModel>? _duplicates;
private IReadOnlyList<OrphanRowViewModel>? _orphans;
private bool _findingDuplicates;
private bool _findingOrphans;
public ArchiveViewModel(ShellViewModel shell)
: base(SectionKey.Archive, "Icon.Archive")
{
Shell = shell;
_reloadDelay = new DispatcherTimer { Interval = ReloadDelay };
_reloadDelay.Tick += (_, _) =>
{
_reloadDelay.Stop();
_ = LoadAsync();
};
ScanCommand = new AsyncRelayCommand(() => QueueAsync(a => ArchiveJobs.Scan(a)), IsOnline);
RebuildCommand = new AsyncRelayCommand(() => OpenRebuildDialogAsync(), () => _archive is not null);
VerifyCommand = new AsyncRelayCommand(() => QueueAsync(a => ArchiveJobs.Verify(a)), IsOnline);
AdoptCommand = new AsyncRelayCommand(AdoptAsync);
CopyFolderCommand = new RelayCommand(CopyFolder, () => _archive is not null);
BackupCommand = new AsyncRelayCommand(BackupAsync, () => Services.Database is not null);
MaintenanceCommand = new AsyncRelayCommand(() => QueueAsync(a => ArchiveJobs.Maintenance(a)), IsOnline);
MaintenanceDryRunCommand = new AsyncRelayCommand(() => QueueAsync(a => ArchiveJobs.Maintenance(a, dryRun: true)), () => _archive is not null);
RebuildProxiesCommand = new AsyncRelayCommand(() => QueueSetAsync(ids => ArchiveJobs.Proxies(ids, _archive!.Name, force: true), All()), IsOnline);
ClearFilterCommand = new RelayCommand(() => Filter = new ArchiveSetFilter(), () => !_filter.IsEmpty);
RelinkCommand = new AsyncRelayCommand(RelinkAsync);
HistoryCommand = new RelayCommand(() => Shell.Navigate(SectionKey.Jobs));
AnalyseSetCommand = new AsyncRelayCommand(() => QueueSetAsync(ids => ProcessingJobs.DeepAnalysis(ids, SetLabel()), Set()), HasSet);
ProxiesSetCommand = new AsyncRelayCommand(() => QueueSetAsync(ids => ArchiveJobs.Proxies(ids, SetLabel()), Set()), HasSet);
ThumbnailsSetCommand = new AsyncRelayCommand(() => QueueSetAsync(ids => ArchiveJobs.Thumbnails(ids, SetLabel()), Set()), HasSet);
VerifySetCommand = new AsyncRelayCommand(() => QueueSetAsync(ids => ArchiveJobs.Verify(_archive!, ids), Set()), HasSet);
RenameSetCommand = new AsyncRelayCommand(() => OpenRenameDialogAsync(RenameMode.Titles), () => HasSet() && IsOnline());
MoveSetCommand = new AsyncRelayCommand(() => OpenRenameDialogAsync(RenameMode.Folders), () => HasSet() && IsOnline());
RetagSetCommand = new RelayCommand(OpenRetag, () => HasSet() && IsOnline());
ExportSetCommand = new AsyncRelayCommand(ExportAsync, HasSet);
FindDuplicatesCommand = new AsyncRelayCommand(FindDuplicatesAsync, () => _archive is not null && _search is null);
FindOrphansCommand = new AsyncRelayCommand(FindOrphansAsync, () => IsOnline() && _search is null);
CancelSearchCommand = new RelayCommand(() => _search?.Cancel(), () => _search is not null);
MarkDuplicatesCommand = new AsyncRelayCommand(() => QueueAsync(a => ArchiveJobs.Maintenance(a)), IsOnline);
}
public ShellViewModel Shell { get; }
private AppServices Services => Shell.Services;
// ---------------- Toolbar ----------------
public IReadOnlyList<Core.Model.Archive> Archives { get => _archives; private set => Set(ref _archives, value); }
public Core.Model.Archive? SelectedArchive
{
get => _archive;
set
{
if (value is null || value == _archive) return;
_archive = value;
_duplicates = null;
_orphans = null;
_ = LoadAsync();
}
}
public bool HasArchive => _archive is not null;
public string ArchiveToolTip => _archive is null ? Loc.L("Tooltips.Archive.Pick") : Loc.L("Tooltips.Archive.PickRoot", _archive.RootPath);
/// <summary>0 = overview (tree and figures), 1 = maintenance.</summary>
public int ViewIndex
{
get => _viewIndex;
set
{
if (!Set(ref _viewIndex, value)) return;
OnPropertyChanged(nameof(IsOverview));
OnPropertyChanged(nameof(IsMaintenance));
}
}
public bool IsOverview => HasArchive && _viewIndex == 0;
public bool IsMaintenance => HasArchive && _viewIndex == 1;
/// <summary>"Last scan 29/09/2026 07:12 · 14 min".</summary>
public string LastScanText { get => _lastScanText; private set => Set(ref _lastScanText, value); }
public string ScanToolTip => WhenOnline("Tooltips.Archive.Scan");
public string VerifyToolTip => WhenOnline("Tooltips.Archive.Verify");
public string MaintenanceRunToolTip => WhenOnline("Tooltips.Archive.MaintenanceRun");
public string RebuildProxiesToolTip => WhenOnline("Tooltips.Archive.MaintenanceProxies");
public string MarkDuplicatesToolTip => WhenOnline("Tooltips.Archive.MarkDuplicates");
public string DuplicatesToolTip => _search is not null ? Loc.L("Archive.Blocked.Searching") : Loc.L("Tooltips.Archive.Duplicates");
public string OrphansToolTip => _search is not null ? Loc.L("Archive.Blocked.Searching") : WhenOnline("Tooltips.Archive.Orphans");
public string AnalyseSetToolTip => WhenSet("Tooltips.Archive.SetAnalyse");
public string ProxiesSetToolTip => WhenSet("Tooltips.Archive.SetProxies");
public string ThumbnailsSetToolTip => WhenSet("Tooltips.Archive.SetThumbnails");
public string VerifySetToolTip => WhenSet("Tooltips.Archive.SetVerify");
public string ExportSetToolTip => WhenSet("Tooltips.Archive.SetExport");
public string RenameSetToolTip => WhenSet("Tooltips.Archive.SetRename", needsOnline: true);
public string MoveSetToolTip => WhenSet("Tooltips.Archive.SetMove", needsOnline: true);
public string RetagSetToolTip => WhenSet("Tooltips.Archive.SetRetag", needsOnline: true);
public ICommand ScanCommand { get; }
public ICommand RebuildCommand { get; }
public ICommand VerifyCommand { get; }
public ICommand AdoptCommand { get; }
/// <summary>"Adopt folder ▾ › Copy into the layout": the Import screen copies the folder into the archive with its templates.</summary>
public ICommand CopyFolderCommand { get; }
public ICommand BackupCommand { get; }
public ICommand MaintenanceCommand { get; }
public ICommand MaintenanceDryRunCommand { get; }
public ICommand RebuildProxiesCommand { get; }
public ICommand RelinkCommand { get; }
public ICommand HistoryCommand { get; }
// ---------------- Overview ----------------
public ObservableCollection<ArchiveTreeRowViewModel> TreeRows { get; } = [];
public IReadOnlyList<ArchiveTile> Tiles { get => _tiles; private set => Set(ref _tiles, value); }
public IReadOnlyList<ChartRow> MonthRows { get => _months; private set => Set(ref _months, value); }
public IReadOnlyList<string> MonthLabels => ArchiveFigures.MonthLabels();
public IReadOnlyList<ChartItem> StorageBars { get => _storage; private set => Set(ref _storage, value); }
public IReadOnlyList<ChartItem> CameraBars { get => _cameras; private set => Set(ref _cameras, value); }
public IReadOnlyList<ChartItem> FormatBars { get => _formats; private set => Set(ref _formats, value); }
/// <summary>Photos per month in the culture's digits.</summary>
public Func<double, string> CountFormatter { get; } = v => Formatting.Count((long)v);
/// <summary>"412 sequences · all", "36 sequences", "Harbour sunset", each followed by the filter ("· Canon EOS R5").</summary>
public string SetText
{
get
{
var set = Set();
var selected = SelectedNodes().ToList();
var text = selected.Count == 0 || selected.Any(n => n.Kind == TreeNodeKind.Archive)
? Loc.Plural("Archive.Set.All", set.Count)
: set.Count == 1 ? set[0].DisplayTitle : Loc.Plural("Shell.Status.Sequences", set.Count);
return _filter.IsEmpty ? text : text + " · " + _filter.Describe();
}
}
/// <summary>Camera, status and tag on top of the tree selection.</summary>
public ArchiveSetFilter Filter
{
get => _filter;
private set
{
if (!Set(ref _filter, value)) return;
OnSetChanged();
}
}
public IReadOnlyList<FilterChoice> CameraChoices => Choices(
(_tree?.Root.Sequences() ?? []).Select(ArchiveSetFilter.CameraOf).Distinct(StringComparer.Ordinal).Order(StringComparer.CurrentCultureIgnoreCase),
c => c, c => _filter.Camera == c, c => _filter with { Camera = c });
public IReadOnlyList<FilterChoice> StatusChoices => Choices(
Enum.GetValues<StatusFilter>().Where(f => f != StatusFilter.Any), ArchiveSetFilter.StatusLabel, f => _filter.Status == f,
f => _filter with { Status = f });
public IReadOnlyList<FilterChoice> TagChoices => Choices(
(_tree?.Root.Sequences() ?? []).SelectMany(q => q.Tags).Distinct(StringComparer.OrdinalIgnoreCase).Order(StringComparer.CurrentCultureIgnoreCase),
t => t, t => string.Equals(_filter.Tag, t, StringComparison.OrdinalIgnoreCase), t => _filter with { Tag = t });
public ICommand ClearFilterCommand { get; }
public ICommand AnalyseSetCommand { get; }
public ICommand ProxiesSetCommand { get; }
public ICommand ThumbnailsSetCommand { get; }
public ICommand VerifySetCommand { get; }
public ICommand RenameSetCommand { get; }
public ICommand MoveSetCommand { get; }
public ICommand RetagSetCommand { get; }
public ICommand ExportSetCommand { get; }
/// <summary>The view reports the rows the user selected; the list's own clearing while rows are rebuilt is not a choice.</summary>
public void SetSelection(IEnumerable<ArchiveTreeRowViewModel> rows)
{
if (_rebuildingRows) return;
_selection.Clear();
foreach (var row in rows) _selection.Add(row.Node.Key);
OnSetChanged();
}
/// <summary>Whether a visible row is part of the selection (the view restores the list's selection after a rebuild).</summary>
public bool IsSelectedRow(ArchiveTreeRowViewModel row) => _selection.Contains(row.Node.Key);
/// <summary>Raised after the rows were rebuilt; the view selects the rows of <see cref="IsSelectedRow"/> again.</summary>
public event Action? RowsRebuilt;
/// <summary>Expands or collapses a year (Right/Left/Enter on its row, or its arrow).</summary>
public void Toggle(ArchiveTreeRowViewModel row) => Toggle(row.Node);
// ---------------- Maintenance view ----------------
public IReadOnlyList<HealthLineViewModel> Health { get => _health; private set => Set(ref _health, value); }
public IReadOnlyList<MaintenanceRow> Recent
{
get => _recent;
private set
{
if (Set(ref _recent, value)) OnPropertyChanged(nameof(HasRecent));
}
}
public bool HasRecent => _recent.Count > 0;
public IReadOnlyList<DuplicateRowViewModel>? Duplicates
{
get => _duplicates;
private set
{
if (Set(ref _duplicates, value)) OnPropertyChanged(nameof(DuplicatesText));
}
}
public IReadOnlyList<OrphanRowViewModel>? Orphans
{
get => _orphans;
private set
{
if (Set(ref _orphans, value)) OnPropertyChanged(nameof(OrphansText));
}
}
/// <summary>A duplicates or orphans search runs; it can be cancelled.</summary>
public bool IsSearching => _search is not null;
/// <summary>"3 groups", "None found", or empty before the first search.</summary>
public string DuplicatesText => _findingDuplicates ? Loc.L("Archive.Find.Searching")
: _duplicates is null ? string.Empty
: _duplicates.Count == 0 ? Loc.L("Archive.Find.None")
: Loc.Plural("Archive.Duplicates.Groups", _duplicates.Count);
public string OrphansText => _findingOrphans ? Loc.L("Archive.Find.Searching")
: _orphans is null ? string.Empty
: _orphans.Count == 0 ? Loc.L("Archive.Find.None")
: Loc.Plural("Archive.Orphans.Count", _orphans.Count);
public ICommand FindDuplicatesCommand { get; }
public ICommand FindOrphansCommand { get; }
public ICommand CancelSearchCommand { get; }
public ICommand MarkDuplicatesCommand { get; }
// ---------------- Dialogs ----------------
/// <summary>The open in-window dialog (rebuild, rename, retag); null when none.</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 screen behind an open dialog takes neither clicks nor keyboard focus.</summary>
public bool IsContentEnabled => _dialog is null;
public bool IsEmpty => _loaded && _archive is null;
// ---------------- Lifecycle ----------------
protected override void OnActivated()
{
if (_loaded) return;
_ = LoadAsync();
}
/// <summary>Reads archives, figures, tree, health and recent maintenance of the selected archive; joins a read in progress.</summary>
public Task LoadAsync() => _load.IsCompleted ? _load = ReadAsync() : _load;
private async Task ReadAsync()
{
if (Services.Database is not { } db) return;
try
{
AttachJobEvents();
Archives = await db.Archives.ListAsync();
_archive = _archive is { } current ? Archives.FirstOrDefault(a => a.Id == current.Id) : null;
_archive ??= CurrentArchive.Pick(Archives, Services.Settings.LastArchivePath);
if (_archive is not { } archive) return;
var root = archive.RootPath;
_availability = await Task.Run(() => ArchiveVolume.Probe(new ArchivePaths(root)));
_stats = await db.Sequences.GetStatsAsync(archive.Id);
var sequences = await ListSequencesAsync(db, archive.Id);
var withoutProxies = await db.Sequences.CountAsync(new SequenceQuery { ArchiveId = archive.Id, WithoutStatus = SequenceStatus.ProxiesBuilt });
ShowFigures(_stats, withoutProxies);
ShowTree(ArchiveTree.Build(archive, _availability, sequences));
await LoadRecentAsync(db, archive);
}
catch (DatabaseException ex)
{
Log.Warning("archive", "Archive figures unavailable", ex);
}
finally
{
_loaded = true;
OnPropertyChanged(string.Empty);
CommandManager.InvalidateRequerySuggested();
}
}
/// <summary>Opens the rebuild dialog (BRIEF §12.5) and counts, off the UI thread, the sidecars the rebuild will read.</summary>
public async Task<RebuildDialogViewModel?> OpenRebuildDialogAsync()
{
if (_archive is not { } archive || Services.Engine is not { } engine) return null;
var dialog = new RebuildDialogViewModel(archive, _availability, _stats?.Sequences ?? 0, async () =>
{
var request = ArchiveJobs.Rebuild(archive);
await engine.EnqueueAsync(request);
Queued(request.Kind, archive.Name);
}, CloseDialog);
OpenDialog(dialog);
await dialog.CountAsync();
return dialog;
}
/// <summary>Shows reports computed elsewhere (capture).</summary>
public void ShowReports(IReadOnlyList<DuplicateGroup> duplicates, OrphanReport orphans, IReadOnlyList<SequenceLocation> locations)
{
Duplicates = DuplicateRows(duplicates, locations);
Orphans = OrphanRows(orphans, locations);
}
public override void Dispose()
{
_reloadDelay.Stop();
_search?.Cancel();
if (_jobEvents && Services.Jobs is { } jobs) jobs.JobChanged -= OnJobChanged;
_dialog?.Dispose();
base.Dispose();
}
private static async Task<List<Sequence>> ListSequencesAsync(TitanoDatabase db, Guid archiveId)
{
var all = new List<Sequence>();
string? cursor = null;
do
{
var page = await db.Sequences.ListAsync(new SequenceQuery { ArchiveId = archiveId, Sort = SequenceSort.Newest, Limit = PageSize, Cursor = cursor });
all.AddRange(page.Items);
cursor = page.NextCursor;
}
while (cursor is not null);
return all;
}
private void ShowFigures(ArchiveStats stats, int withoutProxies)
{
Tiles = ArchiveFigures.Tiles(stats);
MonthRows = [.. ArchiveFigures.PhotosPerMonth(stats, DateTime.Today).Select(r => new ChartRow(r.Label, r.Values, r.ToolTips))];
StorageBars = Bars(ArchiveFigures.StorageByYear(stats));
CameraBars = Bars(ArchiveFigures.ByCamera(stats));
FormatBars = Bars(ArchiveFigures.ByFormat(stats));
Health =
[
.. ArchiveFigures.Health(stats, withoutProxies).Select(line => new HealthLineViewModel(line, line.Action switch
{
HealthAction.Verify => new AsyncRelayCommand(() => QueueStatusAsync(SequenceStatus.Verified, ids => ArchiveJobs.Verify(_archive!, ids))),
HealthAction.Proxies => new AsyncRelayCommand(() => QueueStatusAsync(SequenceStatus.ProxiesBuilt, ids => ArchiveJobs.Proxies(ids, CountLabel(ids)))),
HealthAction.Analyse => new AsyncRelayCommand(() => QueueStatusAsync(SequenceStatus.AnalyzedLight, ids => ProcessingJobs.LightAnalysis(ids, CountLabel(ids)))),
HealthAction.Duplicates => FindDuplicatesCommand,
HealthAction.Orphans => FindOrphansCommand,
_ => null,
})),
];
}
private static IReadOnlyList<ChartItem> Bars(IReadOnlyList<BarValue> values) =>
[.. values.Select(v => new ChartItem(v.Label, v.Value, v.ValueText, v.ToolTip))];
/// <summary>A reloaded tree keeps the open years and the selection (nodes that still exist).</summary>
private void ShowTree(ArchiveTree tree)
{
var expanded = _tree?.Root.Key == tree.Root.Key ? _tree.ExpandedKeys() : null;
if (expanded is not null) tree.Expand(expanded);
else
{
_selection.Clear();
if (tree.Root.Children.Count > 0) tree.Root.Children[0].IsExpanded = true;
}
_tree = tree;
_sequenceIds = [.. tree.Root.Sequences().Select(q => q.Id)];
RebuildRows();
}
/// <summary>
/// The visible rows again (after a reload or a toggle). Selected rows that are now hidden — the user collapsed their
/// year — leave the selection, so the set is always what the list shows selected.
/// </summary>
private void RebuildRows()
{
_rebuildingRows = true;
try
{
TreeRows.Clear();
if (_tree is null) return;
foreach (var node in _tree.Visible()) TreeRows.Add(new ArchiveTreeRowViewModel(node, _tree.Availability, Toggle));
_selection.IntersectWith(TreeRows.Select(r => r.Node.Key));
}
finally
{
_rebuildingRows = false;
}
RowsRebuilt?.Invoke();
OnSetChanged();
}
private void Toggle(ArchiveTreeNode node)
{
if (node.Kind == TreeNodeKind.Archive) return;
node.IsExpanded = !node.IsExpanded;
RebuildRows();
}
/// <summary>The set changed (selection, filter or tree): its text, the filter menus and the mass commands follow.</summary>
private void OnSetChanged()
{
OnPropertyChanged(nameof(SetText));
OnPropertyChanged(nameof(CameraChoices));
OnPropertyChanged(nameof(StatusChoices));
OnPropertyChanged(nameof(TagChoices));
OnPropertyChanged(nameof(AnalyseSetToolTip));
OnPropertyChanged(nameof(ProxiesSetToolTip));
OnPropertyChanged(nameof(ThumbnailsSetToolTip));
OnPropertyChanged(nameof(VerifySetToolTip));
OnPropertyChanged(nameof(ExportSetToolTip));
OnPropertyChanged(nameof(RenameSetToolTip));
OnPropertyChanged(nameof(MoveSetToolTip));
OnPropertyChanged(nameof(RetagSetToolTip));
CommandManager.InvalidateRequerySuggested();
}
private IEnumerable<ArchiveTreeNode> SelectedNodes() => TreeRows.Where(r => _selection.Contains(r.Node.Key)).Select(r => r.Node);
/// <summary>One filter menu: each value checked when chosen; choosing it again clears it.</summary>
private IReadOnlyList<FilterChoice> Choices<T>(IEnumerable<T> values, Func<T, string> label, Func<T, bool> isChosen, Func<T?, ArchiveSetFilter> choose) =>
[
.. values.Select(v =>
{
var chosen = isChosen(v);
return new FilterChoice(label(v), chosen, new RelayCommand(() => Filter = choose(chosen ? default : v)));
}),
];
private async Task LoadRecentAsync(TitanoDatabase db, Core.Model.Archive archive)
{
var jobs = new List<Job>();
foreach (var kind in MaintenanceReports.MaintenanceKinds)
jobs.AddRange((await db.Jobs.ListAsync(null, kind, RecentCount)).Items.Where(j => j.TargetIds.Contains(archive.Id)));
Recent = MaintenanceReports.Recent(jobs, RecentCount);
var scan = jobs.Where(j => j.Kind == JobKind.Scan && j is { State: JobState.Done, Finished: not null, Started: not null })
.MaxBy(j => j.Finished);
LastScanText = scan is { Started: { } started, Finished: { } finished }
? Loc.L("Archive.LastScan", Formatting.Date(finished) + " " + Formatting.TimeOfDay(finished), Formatting.Duration(finished - started))
: string.Empty;
}
private void AttachJobEvents()
{
if (_jobEvents || Services.Jobs is not { } jobs) return;
jobs.JobChanged += OnJobChanged;
_jobEvents = true;
}
/// <summary>
/// A finished job on this archive or its sequences changes the figures: read them again once the jobs settle (a
/// burst of analyses after an import reloads once). Jobs of other archives are none of this screen's business.
/// </summary>
private void OnJobChanged(Job job)
{
if (job.State is not (JobState.Done or JobState.Failed)) return;
if (job.Kind is not (JobKind.Scan or JobKind.Rebuild or JobKind.Verify or JobKind.Maintenance or JobKind.Import or JobKind.Proxies or JobKind.Thumbs
or JobKind.LightAnalyse or JobKind.DeepAnalyse)) return;
System.Windows.Application.Current?.Dispatcher.BeginInvoke(() =>
{
if (_archive is not { } archive || !job.TargetIds.Any(id => id == archive.Id || _sequenceIds.Contains(id))) return;
if (!IsSelected)
{
_loaded = false;
return;
}
_reloadDelay.Stop();
_reloadDelay.Start();
});
}
// ---------------- Actions ----------------
private bool IsOnline() => _archive is not null && _availability == ArchiveAvailability.Online;
/// <summary>A command's tooltip, or why it is disabled: these commands write to the archive or read all of it.</summary>
private string WhenOnline(string key) => _archive is null || IsOnline() ? Loc.L(key) : Loc.L("Archive.Blocked.NotOnline");
private bool HasSet() => _archive is not null && _tree is not null && Set().Count > 0;
/// <summary>A mass command's tooltip, or why it is disabled (an empty set; for writes, an archive that is not online).</summary>
private string WhenSet(string key, bool needsOnline = false) =>
_tree is not null && !HasSet() ? Loc.L("Archive.Blocked.EmptySet")
: needsOnline ? WhenOnline(key)
: Loc.L(key);
/// <summary>The set the mass operations act on: the selected rows' sequences (all when nothing is selected), filtered.</summary>
private IReadOnlyList<Sequence> Set() => _tree is null ? [] : [.. ArchiveTree.SetOf(_tree, SelectedNodes()).Where(_filter.Matches)];
private IReadOnlyList<Sequence> All() => _tree is null ? [] : ArchiveTree.SetOf(_tree, []);
private string SetLabel() => SetText;
private async Task QueueAsync(Func<Core.Model.Archive, ArchiveJobRequest> build)
{
if (Services.Engine is not { } engine || _archive is not { } archive) return;
var request = build(archive);
await engine.EnqueueAsync(request);
Queued(request.Kind, request.Label ?? archive.Name);
}
private async Task QueueSetAsync(Func<IReadOnlyList<Guid>, ArchiveJobRequest> build, IReadOnlyList<Sequence> set)
{
if (Services.Engine is not { } engine || set.Count == 0) return;
var request = build([.. set.Select(s => s.Id)]);
await engine.EnqueueAsync(request);
Queued(request.Kind, request.Label ?? SetLabel());
}
/// <summary>Health fixes act on every sequence that misses a status (never verified, no proxies), page by page.</summary>
private async Task QueueStatusAsync(SequenceStatus missing, Func<IReadOnlyList<Guid>, ArchiveJobRequest> build)
{
if (Services.Database is not { } db || _archive is not { } archive) return;
var all = new List<Sequence>();
string? cursor = null;
do
{
var page = await db.Sequences.ListAsync(new SequenceQuery { ArchiveId = archive.Id, WithoutStatus = missing, Limit = PageSize, Cursor = cursor });
all.AddRange(page.Items);
cursor = page.NextCursor;
}
while (cursor is not null);
await QueueSetAsync(build, all);
}
private static string CountLabel(IReadOnlyList<Guid> ids) => Loc.Plural("Shell.Status.Sequences", ids.Count);
private void Queued(JobKind kind, string label) =>
Shell.Notify(Loc.L("Library.Queued", JobText.Kind(kind), label), actionText: Loc.L("Shell.Nav.Jobs"), actionToolTip: Loc.L("Tooltips.Nav.Jobs"),
action: () => Shell.Navigate(SectionKey.Jobs));
/// <summary>Opens Rename or Move on the set and waits for its dry run.</summary>
public async Task OpenRenameDialogAsync(RenameMode mode)
{
if (Services.Archives is not { } archives || _archive is not { } archive) return;
var dialog = new RenameDialogViewModel(mode, archives, archive, Set(), Applied, CloseDialog);
OpenDialog(dialog);
await dialog.PlanAsync();
}
private void OpenRetag()
{
if (Services.Archives is not { } archives) return;
OpenDialog(new RetagDialogViewModel(archives, Set(), Applied, CloseDialog));
}
private void OpenDialog(ArchiveDialogViewModel dialog)
{
_dialog?.Dispose();
Dialog = dialog;
}
private async Task Applied(int changed)
{
Shell.Notify(Loc.Plural("Archive.Applied", changed));
await LoadAsync();
await Shell.Library.RefreshAsync();
}
/// <summary>Closes <paramref name="dialog"/> if it is still the open one (an apply that finishes late closes nothing else).</summary>
private void CloseDialog(ArchiveDialogViewModel dialog)
{
if (!ReferenceEquals(_dialog, dialog)) return;
dialog.Dispose();
Dialog = null;
}
private async Task AdoptAsync()
{
var folder = Services.Dialogs.PickFolder(Loc.L("Library.Adopt.Title"));
if (folder is null) return;
if (await ArchiveActions.TryAsync(Shell, s => s.AdoptAsync(folder)))
{
_archive = null;
await LoadAsync();
}
}
/// <summary>Copies a folder tree into the archive's layout: the Import screen plans it with the archive's templates.</summary>
private void CopyFolder()
{
var folder = Services.Dialogs.PickFolder(Loc.L("Archive.Copy.Title"));
if (folder is null) return;
Shell.Navigate(SectionKey.Import);
_ = Shell.Import.ImportFolderAsync(folder);
}
/// <summary>A consistent copy of the index next to the data folder (the same backup as Settings › Advanced).</summary>
private async Task BackupAsync()
{
if (Services.Database is not { } db) return;
try
{
var path = await db.BackupAsync(Services.Environment.BackupDirectory);
Shell.Notify(Loc.L("Settings.Advanced.BackupDone"), Path.GetFileName(path), Loc.L("Library.Export.Show"), Loc.L("Tooltips.Library.ShowExport"),
() => ShellActions.Reveal(path));
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or DatabaseException or NotSupportedException)
{
Log.Warning("archive", "Database backup failed", ex);
Shell.Notify(Loc.L("Archive.Backup.Failed"), ex.Message);
}
}
/// <summary>A moved archive keeps its id: opening it at the new root relinks every sequence (BRIEF §12.5 Move archive).</summary>
private async Task RelinkAsync()
{
if (Services.Archives is not { } archives) return;
var folder = Services.Dialogs.PickFolder(Loc.L("Archive.Relink.Title"));
if (folder is null) return;
try
{
var archive = await Task.Run(() => archives.OpenAsync(folder));
Services.Settings.LastArchivePath = archive.RootPath;
Services.SaveSettings();
_archive = archive;
await Services.QueueScanAsync(archive, full: false);
Shell.Notify(Loc.L("Archive.Relink.Done", archive.Name), archive.RootPath);
await LoadAsync();
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or DatabaseException)
{
Log.Warning("archive", $"Relinking {folder} failed", ex);
Shell.Notify(Loc.L("Archive.Relink.Failed"), ex.Message);
}
}
private async Task ExportAsync()
{
var set = Set();
var folder = Services.Dialogs.PickFolder(Loc.L("Library.Export.Title"));
if (folder is null || set.Count == 0) return;
var path = Path.Combine(folder, $"Titano sequences {DateTime.Now:yyyy-MM-dd HHmm}.csv");
var csv = LibraryViewModel.Csv(set);
await Task.Run(() => AtomicFile.WriteAllText(path, csv));
Shell.Notify(Loc.L("Library.Export.Done"), Path.GetFileName(path), Loc.L("Library.Export.Show"), Loc.L("Tooltips.Library.ShowExport"),
() => ShellActions.Reveal(path));
}
/// <summary>Duplicates by hash across the archive (a read of the index); cancellable.</summary>
private async Task FindDuplicatesAsync()
{
if (Services.Archives is not { } archives || Services.Database is not { } db || _archive is not { } archive) return;
ViewIndex = 1;
_findingDuplicates = true;
var search = StartSearch();
try
{
var groups = await Task.Run(() => archives.FindDuplicatesAsync(archive.Id, search.Token), search.Token);
Duplicates = DuplicateRows(groups, await db.Sequences.ListLocationsAsync(archive.Id, search.Token));
Log.Info("archive", $"Duplicates search in {archive.RootPath}: {groups.Count} group(s)");
}
catch (OperationCanceledException) when (search.IsCancellationRequested)
{
}
catch (DatabaseException ex)
{
Shell.ReportError(ex);
}
finally
{
_findingDuplicates = false;
EndSearch(search);
}
}
/// <summary>Orphans: every sequence folder against its sidecar and the index (a walk of the archive); cancellable.</summary>
private async Task FindOrphansAsync()
{
if (Services.Archives is not { } archives || Services.Database is not { } db || _archive is not { } archive) return;
ViewIndex = 1;
_findingOrphans = true;
var search = StartSearch();
try
{
var report = await Task.Run(() => archives.FindOrphansAsync(archive.Id, search.Token), search.Token);
Orphans = OrphanRows(report, await db.Sequences.ListLocationsAsync(archive.Id, search.Token));
Log.Info("archive", $"Orphans search in {archive.RootPath}: {report.UnindexedFiles} unlisted, {report.MissingFiles} missing, "
+ $"{report.MissingSequences.Count} rows without sidecar, {report.UnindexedFolders.Count} new folders");
}
catch (OperationCanceledException) when (search.IsCancellationRequested)
{
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or ArchiveOfflineException or DatabaseException)
{
Log.Warning("archive", "Orphan search failed", ex);
Shell.Notify(Loc.L("Archive.Orphans.Failed"), ex.Message);
}
finally
{
_findingOrphans = false;
EndSearch(search);
}
}
private CancellationTokenSource StartSearch()
{
_search = new CancellationTokenSource();
OnSearchChanged();
return _search;
}
private void EndSearch(CancellationTokenSource search)
{
if (ReferenceEquals(_search, search)) _search = null;
search.Dispose();
OnSearchChanged();
}
private void OnSearchChanged()
{
OnPropertyChanged(nameof(IsSearching));
OnPropertyChanged(nameof(DuplicatesText));
OnPropertyChanged(nameof(OrphansText));
OnPropertyChanged(nameof(DuplicatesToolTip));
OnPropertyChanged(nameof(OrphansToolTip));
CommandManager.InvalidateRequerySuggested();
}
private IReadOnlyList<DuplicateRowViewModel> DuplicateRows(IReadOnlyList<DuplicateGroup> groups, IReadOnlyList<SequenceLocation> locations) =>
[
.. MaintenanceReports.Duplicates(groups, locations).Select(row => new DuplicateRowViewModel(row,
new RelayCommand(() => Shell.OpenSequence(row.SequenceId)),
new RelayCommand(() =>
{
if (_archive is { } archive && locations.FirstOrDefault(l => l.Id == row.SequenceId) is { } location)
ShellActions.Reveal(new ArchivePaths(archive.RootPath).Sequence(location.Folder).Folder);
}))),
];
private IReadOnlyList<OrphanRowViewModel> OrphanRows(OrphanReport report, IReadOnlyList<SequenceLocation> locations) =>
[.. MaintenanceReports.Orphans(report, locations).Select(row => new OrphanRowViewModel(row, new AsyncRelayCommand(() => FixAsync(row))))];
/// <summary>The safe fix of an orphan line; removing an index row asks first (its sidecar is gone, its files are not touched).</summary>
private async Task FixAsync(OrphanRow row)
{
if (Services.Archives is not { } archives || _archive is not { } archive) return;
try
{
switch (row.Kind)
{
case OrphanKind.UnlistedFiles or OrphanKind.MissingFiles when row.SequenceId is { } id:
await Task.Run(() => archives.ReconcileAsync(id));
break;
case OrphanKind.MissingSequence when row.SequenceId is { } id:
var confirmed = Services.Dialogs.Confirm(new ConfirmRequest
{
Heading = Loc.L("Archive.Confirm.RemoveHeading", row.Title),
Message = Loc.L("Archive.Confirm.RemoveMessage"),
SafeText = Loc.L("Archive.Confirm.Keep"),
SafeToolTip = Loc.L("Tooltips.Archive.KeepRow"),
ActionText = Loc.L("Archive.Confirm.Remove"),
ActionToolTip = Loc.L("Tooltips.Archive.Orphans.MissingSequence"),
IsDestructive = true,
});
if (!confirmed) return;
await Task.Run(() => archives.RemoveMissingSequencesAsync(archive.Id, [id]));
break;
case OrphanKind.NewFolder:
await Services.QueueScanAsync(archive, full: false);
Queued(JobKind.Scan, archive.Name);
return;
default:
return;
}
Orphans = Orphans?.Where(o => o.Row != row).ToList();
await LoadAsync();
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or ArchiveOfflineException or DatabaseException
or ArgumentException)
{
Log.Warning("archive", $"Fixing {row.Title} failed", ex);
Shell.Notify(Loc.L("Archive.Orphans.FixFailed"), ex.Message);
}
}
}
+587 -3
View File
@@ -2,8 +2,592 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:Titano.Ui.Controls;assembly=Titano.Ui"
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui">
<Grid Margin="20">
<ui:EmptyState Message="{l:Loc Import.Empty}" />
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui"
xmlns:imp="clr-namespace:Titano.App.Import"
xmlns:shell="clr-namespace:Titano.App.Shell">
<UserControl.InputBindings>
<KeyBinding Key="Enter" Modifiers="Control" Command="{Binding StartCommand}" />
</UserControl.InputBindings>
<UserControl.Resources>
<!-- Devices list entry (Import.html): 54 px, Surface fill, Stroke border; selected = accent border. -->
<Style x:Key="ListBoxItem.Device" TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="Height" Value="54" />
<Setter Property="Margin" Value="0,0,0,8" />
<Setter Property="Padding" Value="12,0" />
<Setter Property="Background" Value="{DynamicResource Brush.Surface}" />
<Setter Property="ToolTip" Value="{Binding StateText}" />
<Setter Property="AutomationProperties.Name" Value="{Binding Title}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border x:Name="Bd" Background="{DynamicResource Brush.Surface}" BorderThickness="1" BorderBrush="{DynamicResource Brush.Stroke}"
CornerRadius="{StaticResource Radius.Control}" Padding="{TemplateBinding Padding}">
<ContentPresenter VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Brush.Card}" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Brush.Card}" />
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource Brush.Accent}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- One form line: a label column at least 116 px wide, as wide as the longest label of the form, then the controls (Import.html grid). -->
<Style x:Key="Import.Row" TargetType="HeaderedContentControl">
<Setter Property="Focusable" Value="False" />
<Setter Property="Margin" Value="0,0,0,10" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="HeaderedContentControl">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="116" SharedSizeGroup="ImportLabel" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="{TemplateBinding Header}" Style="{StaticResource Text.Label}" TextTrimming="None" VerticalAlignment="Top" Margin="0,6,12,0" />
<ContentPresenter Grid.Column="1" VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="Import.Choice" TargetType="FrameworkElement">
<Setter Property="Margin" Value="0,4,18,4" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style TargetType="RadioButton" BasedOn="{StaticResource {x:Type RadioButton}}">
<Setter Property="Margin" Value="0,4,18,4" />
</Style>
<Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
<Setter Property="Margin" Value="0,4,18,4" />
</Style>
<Style x:Key="TextBox.Small" TargetType="TextBox" BasedOn="{StaticResource TextBox.Number}">
<Setter Property="Width" Value="56" />
<Setter Property="Height" Value="30" />
<Setter Property="Margin" Value="6,0" />
</Style>
<!-- Session table columns, shared by header and rows. -->
<Style x:Key="Session.Grid" TargetType="Grid">
<Setter Property="Height" Value="34" />
</Style>
<Style x:Key="ListBoxItem.Session" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem.PlainRow}">
<Setter Property="AutomationProperties.Name" Value="{Binding Row.TimeText}" />
</Style>
<!-- Show plan and failure rows: focusable, so the arrow keys move through a long list. -->
<Style x:Key="ListBoxItem.PlanRow" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem.Row}">
<Setter Property="Padding" Value="0" />
<Setter Property="AutomationProperties.Name" Value="{Binding Source}" />
</Style>
<Style x:Key="ListBoxItem.Failure" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem.Row}">
<Setter Property="Padding" Value="0" />
<Setter Property="AutomationProperties.Name" Value="{Binding}" />
</Style>
<!-- "Folder…" (Import.html): transparent, 1 px dashed Stroke border. -->
<Style x:Key="Button.Dashed" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Rectangle x:Name="Edge" Fill="Transparent" Stroke="{DynamicResource Brush.Stroke}" StrokeThickness="1" StrokeDashArray="4 3" RadiusX="6" RadiusY="6" />
<ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="Center" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Edge" Property="Fill" Value="{DynamicResource Brush.Card}" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="True">
<Setter TargetName="Edge" Property="Stroke" Value="{DynamicResource Brush.Accent}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.4" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid Margin="20,16">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.36*" MinWidth="220" MaxWidth="300" />
<ColumnDefinition Width="16" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- ===================== Devices ===================== -->
<DockPanel>
<DockPanel DockPanel.Dock="Top" Height="32" Margin="0,0,0,8">
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Icon}" ui:ButtonIcon.Glyph="{StaticResource Icon.Refresh}" Command="{Binding RefreshCommand}"
ToolTip="{l:Loc Tooltips.Import.Refresh}" AutomationProperties.Name="{l:Loc Import.Devices.Refresh}" />
<TextBlock Text="{l:Loc Import.Devices.Title}" Style="{StaticResource Text.Section}" VerticalAlignment="Center" />
</DockPanel>
<CheckBox DockPanel.Dock="Bottom" Margin="0,8,0,0" IsChecked="{Binding AutoImport}" IsEnabled="{Binding CanAutoImport}" ToolTip="{Binding AutoImportToolTip}"
VerticalContentAlignment="Top">
<TextBlock Text="{l:Loc Import.Devices.Auto}" TextWrapping="Wrap" Foreground="{DynamicResource Brush.TextMuted}" />
</CheckBox>
<ScrollViewer VerticalScrollBarVisibility="Auto" Focusable="False" IsEnabled="{Binding CanChangeSource}">
<StackPanel>
<ListBox ItemsSource="{Binding Sources}" SelectedItem="{Binding SelectedSource}" ItemContainerStyle="{StaticResource ListBoxItem.Device}"
AutomationProperties.Name="{l:Loc Import.Devices.Title}">
<!-- The surrounding ScrollViewer scrolls the list and "Folder…" together (Import.html: Folder… follows the cards). -->
<ListBox.Template>
<ControlTemplate TargetType="ListBox">
<ItemsPresenter />
</ControlTemplate>
</ListBox.Template>
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type imp:ImportSource}">
<Grid x:Name="Root">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:Icon x:Name="Glyph" Glyph="{StaticResource Icon.Card}" Size="18" Margin="0,0,10,0" VerticalAlignment="Center" />
<StackPanel Grid.Column="1" VerticalAlignment="Center">
<TextBlock Text="{Binding Title}" FontWeight="SemiBold" TextTrimming="CharacterEllipsis" />
<TextBlock Text="{Binding Subtitle}" Style="{StaticResource Text.Secondary}" TextTrimming="CharacterEllipsis" Margin="0,2,0,0" />
</StackPanel>
<ui:StatusGlyph x:Name="State" Grid.Column="2" Kind="Online" Margin="8,0,0,0" VerticalAlignment="Center" ToolTip="{Binding StateText}" />
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Kind}" Value="Drive">
<Setter TargetName="Glyph" Property="Glyph" Value="{StaticResource Icon.Drive}" />
<Setter TargetName="State" Property="Kind" Value="Offline" />
<Setter TargetName="Root" Property="TextElement.Foreground" Value="{DynamicResource Brush.TextMuted}" />
</DataTrigger>
<DataTrigger Binding="{Binding Kind}" Value="Folder">
<Setter TargetName="Glyph" Property="Glyph" Value="{StaticResource Icon.Folder}" />
<Setter TargetName="State" Property="Visibility" Value="Collapsed" />
</DataTrigger>
<DataTrigger Binding="{Binding IsKnown}" Value="False">
<Setter TargetName="State" Property="Kind" Value="Offline" />
</DataTrigger>
<DataTrigger Binding="{Binding IsInserted}" Value="False">
<Setter TargetName="Root" Property="Opacity" Value="0.6" />
<Setter TargetName="State" Property="Kind" Value="Offline" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button Style="{StaticResource Button.Dashed}" Height="44" HorizontalContentAlignment="Left" Command="{Binding PickFolderCommand}" ToolTip="{l:Loc Tooltips.Import.Folder}">
<StackPanel Orientation="Horizontal">
<ui:Icon Glyph="{StaticResource Icon.Folder}" Margin="0,0,10,0" Foreground="{DynamicResource Brush.TextMuted}" />
<TextBlock Text="{l:Loc Import.Devices.Folder}" Foreground="{DynamicResource Brush.TextMuted}" />
</StackPanel>
</Button>
</StackPanel>
</ScrollViewer>
</DockPanel>
<!-- ===================== Profile, form and plan ===================== -->
<Border Grid.Column="2" Style="{StaticResource Border.Panel}" Padding="20,16">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Profile header: nickname (or its field for a new card), identity, Edit ▾. -->
<DockPanel Margin="0,0,0,14" MinHeight="32">
<Button x:Name="EditButton" DockPanel.Dock="Right" Click="OnOpenMenu" IsEnabled="{Binding CanEditProfile}" ToolTip="{Binding EditToolTip}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{l:Loc Import.Profile.Edit}" VerticalAlignment="Center" />
<ui:Icon Glyph="{StaticResource Icon.ChevronDown}" Margin="6,0,0,0" />
</StackPanel>
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="{l:Loc Import.Profile.Rename}" Command="{Binding RenameCommand}" ToolTip="{l:Loc Tooltips.Import.Rename}" />
<MenuItem Header="{l:Loc Import.Profile.Camera}" Command="{Binding FollowCameraCommand}" IsCheckable="False" IsChecked="{Binding FollowsCamera, Mode=OneWay}"
ToolTip="{Binding FollowCameraToolTip}" ToolTipService.ShowOnDisabled="True" />
<MenuItem Header="{l:Loc Import.Profile.CopyFrom}" ItemsSource="{Binding OtherCards}" ToolTip="{l:Loc Tooltips.Import.CopyFrom}">
<MenuItem.ItemContainerStyle>
<Style TargetType="MenuItem" BasedOn="{StaticResource {x:Type MenuItem}}">
<Setter Property="Header" Value="{Binding Name}" />
<Setter Property="Command" Value="{Binding Command}" />
<Setter Property="ToolTip" Value="{l:Loc Tooltips.Import.CopyFrom}" />
</Style>
</MenuItem.ItemContainerStyle>
</MenuItem>
<Separator />
<MenuItem Header="{l:Loc Import.Profile.Forget}" Command="{Binding ForgetCommand}" ToolTip="{l:Loc Tooltips.Import.Forget}" />
</ContextMenu>
</Button.ContextMenu>
</Button>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Text="{Binding SourceTitle}" Style="{StaticResource Text.Title}" VerticalAlignment="Center" MaxWidth="320" TextTrimming="CharacterEllipsis"
Visibility="{Binding IsNicknameOpen, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
<TextBox x:Name="NicknameBox" Width="240" Text="{Binding Nickname.Text, UpdateSourceTrigger=PropertyChanged}" shell:EditBehavior.Field="{Binding Nickname}"
ui:Field.Placeholder="{l:Loc Import.Profile.Nickname}" ToolTip="{Binding Nickname.ToolTip}" AutomationProperties.Name="{l:Loc Import.Profile.Nickname}"
Visibility="{Binding IsNicknameOpen, Converter={StaticResource BoolToVisibility}}" />
</StackPanel>
<TextBlock Text="{Binding IdentityText}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" Margin="12,0,12,0"
TextTrimming="CharacterEllipsis" ToolTip="{Binding IdentityText}" />
</DockPanel>
<!-- The form (Import.html grid). -->
<StackPanel Grid.Row="1" IsEnabled="{Binding IsFormEnabled}" Grid.IsSharedSizeScope="True">
<HeaderedContentControl Style="{StaticResource Import.Row}" Header="{l:Loc Import.Label.Destination}">
<WrapPanel>
<RadioButton GroupName="Destination" Content="{l:Loc Import.Destination.Archive}" IsChecked="{Binding IsArchiveDestination}"
IsEnabled="{Binding CanUseArchive}" ToolTip="{Binding ArchiveToolTip}" />
<RadioButton GroupName="Destination" Content="{l:Loc Import.Destination.Folder}" IsChecked="{Binding IsFolderDestination}"
ToolTip="{l:Loc Tooltips.Import.FolderDestination}" Margin="0,4,8,4" />
<TextBox Width="190" Height="30" Text="{Binding FolderPath.Text, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}"
shell:EditBehavior.Field="{Binding FolderPath}" ToolTip="{Binding FolderPath.ToolTip}" AutomationProperties.Name="{l:Loc Import.Destination.Folder}"
ui:Field.Placeholder="{l:Loc Import.Destination.FolderPlaceholder}" />
<Button Style="{StaticResource Button.Icon}" Width="30" MinWidth="30" Height="30" Margin="6,0,18,0" Content="…" Command="{Binding ChooseDestinationCommand}"
ToolTip="{l:Loc Tooltips.Import.ChooseFolder}" AutomationProperties.Name="{l:Loc Import.Destination.Choose}" />
<RadioButton GroupName="Destination" IsChecked="{Binding IsServerDestination}" IsEnabled="{Binding CanUseServer}" ToolTip="{Binding ServerToolTip}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{l:Loc Import.Destination.Server}" />
<ui:Icon Glyph="{StaticResource Icon.Server}" Margin="10,0,6,0" Foreground="{DynamicResource Brush.Accent}" />
<TextBlock Text="{Binding ServerName}" Foreground="{DynamicResource Brush.Accent}" />
</StackPanel>
</RadioButton>
</WrapPanel>
</HeaderedContentControl>
<HeaderedContentControl Style="{StaticResource Import.Row}" Header="{l:Loc Import.Label.Scan}">
<WrapPanel>
<CheckBox Content="{l:Loc Import.Scan.Subfolders}" IsChecked="{Binding IncludeSubfolders}" ToolTip="{l:Loc Tooltips.Import.Subfolders}" />
<CheckBox Content="{l:Loc Import.Scan.Sessions}" IsChecked="{Binding SplitSessions}" ToolTip="{l:Loc Tooltips.Import.Sessions}" />
<StackPanel Orientation="Horizontal" Style="{StaticResource Import.Choice}" IsEnabled="{Binding SplitSessions}">
<TextBlock Text="{l:Loc Import.Scan.Gap}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" />
<TextBox Style="{StaticResource TextBox.Small}" Text="{Binding GapMinutes.Text, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}"
shell:EditBehavior.Field="{Binding GapMinutes}" ToolTip="{Binding GapMinutes.ToolTip}" AutomationProperties.Name="{l:Loc Import.Scan.GapName}" />
<TextBlock Text="{l:Loc Import.Scan.Minutes}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal" Style="{StaticResource Import.Choice}">
<TextBlock Text="{l:Loc Import.Scan.Minimum}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" />
<TextBox Style="{StaticResource TextBox.Small}" Text="{Binding MinimumFrames.Text, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}"
shell:EditBehavior.Field="{Binding MinimumFrames}" ToolTip="{Binding MinimumFrames.ToolTip}" AutomationProperties.Name="{l:Loc Import.Scan.MinimumName}" />
<TextBlock Text="{l:Loc Import.Scan.Frames}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" />
</StackPanel>
<CheckBox Content="{l:Loc Import.Scan.Verify}" IsChecked="{Binding VerifyCopies}" ToolTip="{l:Loc Tooltips.Import.Verify}" />
</WrapPanel>
</HeaderedContentControl>
<HeaderedContentControl Style="{StaticResource Import.Row}" Header="{l:Loc Import.Label.Names}">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="140" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" MinWidth="140" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox Style="{StaticResource TextBox.Mono}" Height="30" Text="{Binding FolderTemplate.Text, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}"
shell:EditBehavior.Field="{Binding FolderTemplate}" ToolTip="{Binding FolderTemplate.ToolTip}" GotKeyboardFocus="OnFolderTemplateFocus"
AutomationProperties.Name="{l:Loc Import.Names.Folder}" />
<TextBlock Grid.Column="1" Text="/" Foreground="{DynamicResource Brush.TextFaint}" Margin="10,0" VerticalAlignment="Center" />
<TextBox Grid.Column="2" Style="{StaticResource TextBox.Mono}" Height="30"
Text="{Binding FileTemplate.Text, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}" shell:EditBehavior.Field="{Binding FileTemplate}"
ToolTip="{Binding FileTemplate.ToolTip}" GotKeyboardFocus="OnFileTemplateFocus" AutomationProperties.Name="{l:Loc Import.Names.File}" />
<Button x:Name="TokensButton" Grid.Column="3" Style="{StaticResource Button.Icon}" Width="30" MinWidth="30" Height="30" Margin="10,0,0,0" Content="{}{ }"
Click="OnOpenMenu" ToolTip="{l:Loc Tooltips.Import.Tokens}" AutomationProperties.Name="{l:Loc Import.Names.Tokens}">
<Button.ContextMenu>
<ContextMenu ItemsSource="{Binding Tokens}" MaxHeight="420">
<ContextMenu.ItemContainerStyle>
<Style TargetType="MenuItem" BasedOn="{StaticResource {x:Type MenuItem}}">
<Setter Property="Header" Value="{Binding Text}" />
<Setter Property="ToolTip" Value="{Binding ToolTip}" />
<Setter Property="Command" Value="{Binding DataContext.InsertTokenCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}" />
<Setter Property="CommandParameter" Value="{Binding}" />
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
</Button.ContextMenu>
</Button>
</Grid>
<TextBlock Text="{Binding NamePreview}" Style="{StaticResource Text.Secondary}" Foreground="{DynamicResource Brush.TextFaint}" Margin="0,6,0,0"
TextTrimming="CharacterEllipsis" ToolTip="{Binding NamePreview}" />
</StackPanel>
</HeaderedContentControl>
<HeaderedContentControl Style="{StaticResource Import.Row}" Header="{l:Loc Import.Label.Duplicates}">
<WrapPanel>
<RadioButton GroupName="Duplicates" Content="{l:Loc Import.Duplicates.Skip}" IsChecked="{Binding SkipDuplicates}" ToolTip="{l:Loc Tooltips.Import.Skip}" />
<RadioButton GroupName="Duplicates" Content="{l:Loc Import.Duplicates.Again}" IsChecked="{Binding ImportDuplicatesAgain}" ToolTip="{l:Loc Tooltips.Import.Again}" />
</WrapPanel>
</HeaderedContentControl>
<HeaderedContentControl Style="{StaticResource Import.Row}" Header="{l:Loc Import.Label.After}" Margin="0">
<WrapPanel>
<RadioButton GroupName="After" Content="{l:Loc Import.After.Keep}" IsChecked="{Binding KeepCard}" ToolTip="{l:Loc Tooltips.Import.Keep}" />
<RadioButton GroupName="After" Content="{l:Loc Import.After.Delete}" IsChecked="{Binding DeleteImported}" IsEnabled="{Binding CardActionsApply}"
ToolTip="{Binding DeleteChoiceToolTip}" />
<RadioButton GroupName="After" Content="{l:Loc Import.After.Format}" IsChecked="{Binding FormatCard}" IsEnabled="{Binding CardActionsApply}"
ToolTip="{Binding FormatChoiceToolTip}" />
<Border Width="1" Height="20" Background="{DynamicResource Brush.Stroke}" Margin="0,0,18,0" VerticalAlignment="Center" />
<CheckBox Content="{l:Loc Import.After.Eject}" IsChecked="{Binding Eject}" ToolTip="{l:Loc Tooltips.Import.EjectChoice}" />
<CheckBox Content="{l:Loc Import.After.Deep}" IsChecked="{Binding DeepAnalysis}" IsEnabled="{Binding IsArchiveDestination}" ToolTip="{Binding DeepToolTip}" />
</WrapPanel>
</HeaderedContentControl>
</StackPanel>
<!-- ===================== Plan panel ===================== -->
<Border Grid.Row="2" Style="{StaticResource Border.Card}" Padding="16,14" Margin="0,14,0,0" IsEnabled="{Binding IsPlanPanelEnabled}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<DockPanel Margin="0,0,0,10">
<TextBlock DockPanel.Dock="Left" Text="{l:Loc Import.Plan.Title}" Style="{StaticResource Text.Section}" VerticalAlignment="Center" />
<TextBlock DockPanel.Dock="Right" Text="{Binding SpaceText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="12,0,0,0" VerticalAlignment="Center"
ToolTip="{l:Loc Tooltips.Import.Space}" Visibility="{Binding IsSpaceShort, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
<ui:StatusGlyph DockPanel.Dock="Right" Kind="Warning" Text="{Binding SpaceText}" FontSize="13" Margin="12,0,0,0" VerticalAlignment="Center"
ToolTip="{l:Loc Tooltips.Import.Space}" Visibility="{Binding IsSpaceShort, Converter={StaticResource BoolToVisibility}}" />
<TextBlock DockPanel.Dock="Right" Text="{Binding ImportedBeforeText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="12,0,0,0" VerticalAlignment="Center"
ToolTip="{l:Loc Tooltips.Import.ImportedBefore}" />
<ui:StatusGlyph DockPanel.Dock="Right" Kind="{Binding DuplicatesKind}" Text="{Binding DuplicatesText}" FontSize="13" Margin="12,0,0,0" VerticalAlignment="Center"
ToolTip="{l:Loc Tooltips.Import.Duplicates}" Visibility="{Binding HasPlan, Converter={StaticResource BoolToVisibility}}" />
<TextBlock Text="{Binding TotalsText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="12,0,0,0" VerticalAlignment="Center"
Typography.NumeralAlignment="Tabular" TextTrimming="CharacterEllipsis" ToolTip="{Binding TotalsText}" />
</DockPanel>
<!-- No source, reading the card, or the reason no plan can be made. -->
<StackPanel Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="{Binding ShowsStatus, Converter={StaticResource BoolToVisibility}}">
<TextBlock Text="{Binding StatusText}" Foreground="{DynamicResource Brush.TextMuted}" TextAlignment="Center" TextWrapping="Wrap" MaxWidth="420" />
<ProgressBar IsIndeterminate="{Binding IsBusyPlanning}" Width="240" Margin="0,12,0,0"
Visibility="{Binding IsBusyPlanning, Converter={StaticResource BoolToVisibility}}" />
</StackPanel>
<!-- Sessions of the plan with editable titles. -->
<Grid Grid.Row="1" Visibility="{Binding HasPlan, Converter={StaticResource BoolToVisibility}}" Grid.IsSharedSizeScope="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid TextElement.FontSize="12" Margin="0,0,0,4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1.35*" MinWidth="110" />
<ColumnDefinition Width="0.85*" MinWidth="70" />
<ColumnDefinition Width="0.6*" MinWidth="56" />
<ColumnDefinition Width="0.8*" MinWidth="64" />
<ColumnDefinition Width="1.9*" MinWidth="150" />
<ColumnDefinition Width="Auto" SharedSizeGroup="SessionAction" />
</Grid.ColumnDefinitions>
<TextBlock Style="{StaticResource Text.Header}" Text="{l:Loc Import.Session.Column.Session}" />
<TextBlock Grid.Column="1" Style="{StaticResource Text.Header}" Text="{l:Loc Import.Session.Column.Frames}" Margin="10,0,0,0" />
<TextBlock Grid.Column="2" Style="{StaticResource Text.Header}" Text="{l:Loc Import.Session.Column.Size}" Margin="10,0,0,0" TextAlignment="Right" />
<TextBlock Grid.Column="3" Style="{StaticResource Text.Header}" Text="{l:Loc Import.Session.Column.Camera}" Margin="10,0,0,0" />
<TextBlock Grid.Column="4" Style="{StaticResource Text.Header}" Text="{l:Loc Import.Session.Column.Sequence}" Margin="10,0,0,0" />
</Grid>
<ListBox Grid.Row="1" ItemsSource="{Binding Sessions}" ItemContainerStyle="{StaticResource ListBoxItem.Session}" AutomationProperties.Name="{l:Loc Import.Plan.Title}"
KeyboardNavigation.TabNavigation="Continue">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type imp:ImportSessionRowViewModel}">
<Grid Style="{StaticResource Session.Grid}" TextElement.FontSize="12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1.35*" MinWidth="110" />
<ColumnDefinition Width="0.85*" MinWidth="70" />
<ColumnDefinition Width="0.6*" MinWidth="56" />
<ColumnDefinition Width="0.8*" MinWidth="64" />
<ColumnDefinition Width="1.9*" MinWidth="150" />
<ColumnDefinition Width="Auto" SharedSizeGroup="SessionAction" />
</Grid.ColumnDefinitions>
<TextBlock Style="{StaticResource Text.Cell}" Text="{Binding Row.TimeText}" ToolTip="{Binding Row.TimeText}" />
<TextBlock Grid.Column="1" Style="{StaticResource Text.Cell}" Text="{Binding Row.FramesText}" Margin="10,0,0,0" />
<TextBlock Grid.Column="2" Style="{StaticResource Text.CellNumber}" Text="{Binding Row.SizeText}" Margin="10,0,0,0" />
<TextBlock Grid.Column="3" Style="{StaticResource Text.Cell}" Text="{Binding Row.CameraText}" Margin="10,0,0,0" ToolTip="{Binding Row.CameraText}" />
<DockPanel Grid.Column="4" Margin="10,0,0,0">
<TextBlock x:Name="Target" DockPanel.Dock="Right" Text="{l:Loc Import.Session.NewShort}" Foreground="{DynamicResource Brush.Accent}"
VerticalAlignment="Center" Margin="8,0,0,0" ToolTip="{Binding Row.TargetText}" />
<TextBox Height="26" Padding="8,0" Text="{Binding Title.Text, UpdateSourceTrigger=PropertyChanged}" shell:EditBehavior.Field="{Binding Title}"
IsEnabled="{Binding IsEditable}" ui:Field.Placeholder="{Binding Placeholder}" ToolTip="{Binding TitleToolTip}" ToolTipService.ShowOnDisabled="True"
AutomationProperties.Name="{l:Loc Import.Session.Column.Sequence}" />
</DockPanel>
<Button Grid.Column="5" Style="{StaticResource Button.Row}" Margin="8,0,0,0" Content="{l:Loc Import.Session.Merge}" Command="{Binding MergeCommand}"
ToolTip="{Binding MergeToolTip}" Visibility="{Binding HasMerge, Converter={StaticResource BoolToVisibility}}" />
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Row.IsNew}" Value="False">
<Setter TargetName="Target" Property="Text" Value="{l:Loc Import.Session.AddsShort}" />
<Setter TargetName="Target" Property="Foreground" Value="{DynamicResource Brush.TextMuted}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
<!-- The verification result and the after-import actions. -->
<Grid Grid.Row="1" Grid.RowSpan="2" DataContext="{Binding Result}" Visibility="{Binding DataContext.IsDone, RelativeSource={RelativeSource AncestorType=UserControl}, Converter={StaticResource BoolToVisibility}}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<ui:StatusGlyph Kind="{Binding ResultKind}" Text="{Binding ResultText}" FontSize="16" FontWeight="SemiBold" ToolTip="{l:Loc Tooltips.Import.Result}" />
<TextBlock Text="{Binding DetailText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="14,0,0,0" VerticalAlignment="Center" />
</StackPanel>
<ListBox Grid.Row="1" ItemsSource="{Binding Failures}" Margin="0,8,0,0" ItemContainerStyle="{StaticResource ListBoxItem.Failure}"
Visibility="{Binding HasFailures, Converter={StaticResource BoolToVisibility}}" AutomationProperties.Name="{l:Loc Import.Result.FailuresName}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Style="{StaticResource Text.Cell}" Foreground="{DynamicResource Brush.Error}" Height="28" Padding="0,6,0,0" ToolTip="{Binding}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Grid.Row="2" Margin="0,10,0,0" Visibility="{Binding OffersCheck, Converter={StaticResource BoolToVisibility}}">
<TextBlock Text="{Binding EraseText}" Typography.NumeralAlignment="Tabular" />
<TextBlock Text="{Binding BusyText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,4,0,0"
Visibility="{Binding BusyText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
<ItemsControl ItemsSource="{Binding KeptReasons}" Focusable="False" MaxHeight="80" Margin="0,4,0,0">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ui:StatusGlyph Kind="Warning" Text="{Binding}" FontSize="12" ToolTip="{l:Loc Tooltips.Import.Kept}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
<WrapPanel Grid.Row="3" Margin="0,12,0,0">
<Button Content="{l:Loc Import.Result.Check}" Command="{Binding CheckCommand}" ToolTip="{Binding CheckToolTip}" Margin="0,0,8,0"
Visibility="{Binding OffersCheck, Converter={StaticResource BoolToVisibility}}" />
<Button Style="{StaticResource Button.Destructive}" Content="{Binding DeleteText}" Command="{Binding DeleteCommand}" ToolTip="{Binding DeleteToolTip}"
Margin="0,0,8,0" Visibility="{Binding OffersDelete, Converter={StaticResource BoolToVisibility}}" />
<Button Style="{StaticResource Button.Destructive}" Content="{l:Loc Import.Result.Format}" Command="{Binding FormatCommand}" ToolTip="{Binding FormatToolTip}"
Margin="0,0,8,0" Visibility="{Binding OffersFormat, Converter={StaticResource BoolToVisibility}}" />
<Button Command="{Binding EjectCommand}" ToolTip="{Binding EjectToolTip}" Margin="0,0,8,0">
<StackPanel Orientation="Horizontal">
<ui:Icon Glyph="{StaticResource Icon.Eject}" Margin="0,0,6,0" />
<TextBlock Text="{l:Loc Import.Result.Eject}" />
</StackPanel>
</Button>
<Button Content="{l:Loc Import.Result.Library}" Command="{Binding OpenLibraryCommand}" ToolTip="{l:Loc Tooltips.Import.Library}" Margin="0,0,8,0" />
<Button Content="{l:Loc Import.Result.New}" Command="{Binding DataContext.NewImportCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
ToolTip="{l:Loc Tooltips.Import.New}" />
</WrapPanel>
</Grid>
<!-- The import failed or was cancelled. -->
<StackPanel Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="{Binding IsFailed, Converter={StaticResource BoolToVisibility}}">
<ui:StatusGlyph Kind="Failed" Text="{Binding ErrorText}" FontSize="13" HorizontalAlignment="Center" ToolTip="{l:Loc Tooltips.Import.Failed}" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,12,0,0">
<Button Content="{l:Loc Import.Failed.Retry}" Command="{Binding RetryCommand}" ToolTip="{l:Loc Tooltips.Import.Retry}" Margin="0,0,8,0" />
<Button Content="{l:Loc Shell.Nav.Jobs}" Command="{Binding Shell.NavigateCommand}" CommandParameter="Jobs" ToolTip="{l:Loc Tooltips.Nav.Jobs}" />
</StackPanel>
</StackPanel>
<!-- Footer: Show plan and Import, or the progress while copying. -->
<DockPanel Grid.Row="2" Margin="0,10,0,0" Visibility="{Binding HasPlan, Converter={StaticResource BoolToVisibility}}">
<Button x:Name="ShowPlanButton" DockPanel.Dock="Left" Content="{l:Loc Import.Plan.Show}" Command="{Binding ShowPlanCommand}" ToolTip="{l:Loc Tooltips.Import.ShowPlan}"
Visibility="{Binding IsRunning, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Primary}" Height="36" Padding="22,0" Content="{Binding StartText}" Command="{Binding StartCommand}"
ToolTip="{Binding StartToolTip}" Visibility="{Binding IsRunning, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
<Button DockPanel.Dock="Right" Content="{l:Loc Import.Progress.Cancel}" Command="{Binding CancelCommand}" ToolTip="{l:Loc Tooltips.Import.Cancel}" Margin="12,0,0,0"
Visibility="{Binding IsRunning, Converter={StaticResource BoolToVisibility}}" />
<Grid Visibility="{Binding IsRunning, Converter={StaticResource BoolToVisibility}}" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ProgressBar Maximum="1" Value="{Binding Progress, Mode=OneWay}" VerticalAlignment="Center" />
<TextBlock Grid.Column="1" Text="{Binding ProgressText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="12,0,0,0" Typography.NumeralAlignment="Tabular" />
</Grid>
</DockPanel>
</Grid>
</Border>
<!-- ===================== Show plan ===================== -->
<Border Grid.RowSpan="3" Style="{StaticResource Border.Panel}" Background="{DynamicResource Brush.Surface}" Padding="0" Margin="-8"
Visibility="{Binding IsDetailsOpen, Converter={StaticResource BoolToVisibility}}" KeyboardNavigation.TabNavigation="Cycle"
KeyboardNavigation.ControlTabNavigation="Cycle" KeyboardNavigation.DirectionalNavigation="Contained">
<Border.InputBindings>
<KeyBinding Key="Escape" Command="{Binding CloseDetailsCommand}" />
</Border.InputBindings>
<Grid DataContext="{Binding Details}" Margin="16,12" Grid.IsSharedSizeScope="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<DockPanel>
<Button x:Name="ClosePlanButton" DockPanel.Dock="Right" Style="{StaticResource Button.IconSubtle}" ui:ButtonIcon.Glyph="{StaticResource Icon.Close}"
Command="{Binding DataContext.CloseDetailsCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" ToolTip="{l:Loc Tooltips.Import.ClosePlan}"
AutomationProperties.Name="{l:Loc Import.Details.Close}" />
<TextBlock Text="{l:Loc Import.Details.Title}" Style="{StaticResource Text.Title}" VerticalAlignment="Center" />
<TextBlock Text="{Binding TotalsText}" Foreground="{DynamicResource Brush.TextMuted}" Margin="14,0,0,0" VerticalAlignment="Center" TextTrimming="CharacterEllipsis"
Typography.NumeralAlignment="Tabular" />
</DockPanel>
<ItemsControl Grid.Row="1" ItemsSource="{Binding Conflicts}" Focusable="False" Margin="0,8,0,0" MaxHeight="96">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ui:StatusGlyph Kind="Warning" Text="{Binding}" FontSize="12" Margin="0,2" ToolTip="{l:Loc Tooltips.Import.Conflict}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Grid Grid.Row="2" Margin="0,10,0,4" TextElement.FontSize="12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1.2*" MinWidth="140" />
<ColumnDefinition Width="1.8*" MinWidth="180" />
<ColumnDefinition Width="0.8*" MinWidth="90" />
<ColumnDefinition Width="0.5*" MinWidth="64" />
<ColumnDefinition Width="Auto" SharedSizeGroup="PlanAction" />
</Grid.ColumnDefinitions>
<TextBlock Style="{StaticResource Text.Header}" Text="{l:Loc Import.Details.Column.Source}" />
<TextBlock Grid.Column="1" Style="{StaticResource Text.Header}" Text="{l:Loc Import.Details.Column.Destination}" Margin="10,0,0,0" />
<TextBlock Grid.Column="2" Style="{StaticResource Text.Header}" Text="{l:Loc Import.Details.Column.Action}" Margin="10,0,0,0" />
<TextBlock Grid.Column="3" Style="{StaticResource Text.Header}" Text="{l:Loc Import.Session.Column.Size}" Margin="10,0,0,0" TextAlignment="Right" />
</Grid>
<ListBox x:Name="PlanRows" Grid.Row="3" ItemsSource="{Binding Rows}" ItemContainerStyle="{StaticResource ListBoxItem.PlanRow}" AutomationProperties.Name="{l:Loc Import.Details.Title}"
KeyboardNavigation.TabNavigation="Continue">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type imp:PlanDetailRow}">
<Grid x:Name="Row" Height="30" TextElement.FontSize="12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1.2*" MinWidth="140" />
<ColumnDefinition Width="1.8*" MinWidth="180" />
<ColumnDefinition Width="0.8*" MinWidth="90" />
<ColumnDefinition Width="0.5*" MinWidth="64" />
<ColumnDefinition Width="Auto" SharedSizeGroup="PlanAction" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="Source" Style="{StaticResource Text.Cell}" Text="{Binding Source}" ToolTip="{Binding Source}" />
<TextBlock Grid.Column="1" Style="{StaticResource Text.Cell}" Text="{Binding Destination}" Margin="10,0,0,0" ToolTip="{Binding Destination}" />
<TextBlock x:Name="Action" Grid.Column="2" Style="{StaticResource Text.Cell}" Text="{Binding ActionText}" Margin="10,0,0,0" />
<TextBlock Grid.Column="3" Style="{StaticResource Text.CellNumber}" Text="{Binding SizeText}" Margin="10,0,0,0" />
<Button x:Name="Split" Grid.Column="4" Style="{StaticResource Button.Row}" Margin="10,0,4,0" Content="{l:Loc Import.Details.Split}"
Command="{Binding DataContext.SplitCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="{Binding}"
ToolTip="{l:Loc Tooltips.Import.Split}" Visibility="Hidden" />
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding CanSplit}" Value="True">
<Setter TargetName="Split" Property="Visibility" Value="Visible" />
</DataTrigger>
<DataTrigger Binding="{Binding Kind}" Value="Session">
<Setter TargetName="Source" Property="FontWeight" Value="SemiBold" />
<Setter TargetName="Row" Property="Height" Value="34" />
</DataTrigger>
<DataTrigger Binding="{Binding IsSkipped}" Value="True">
<Setter TargetName="Row" Property="Opacity" Value="0.6" />
<Setter TargetName="Action" Property="Foreground" Value="{DynamicResource Brush.TextMuted}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Border>
</Grid>
</Border>
</Grid>
</UserControl>
+55 -1
View File
@@ -1,8 +1,62 @@
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Threading;
namespace Titano.App.Sections;
public partial class ImportView : UserControl
{
public ImportView() => InitializeComponent();
private bool _nicknameOpen;
public ImportView()
{
InitializeComponent();
DataContextChanged += OnDataContextChanged;
}
private ImportViewModel? Model => DataContext as ImportViewModel;
/// <summary>"Edit ▾" and "{ }" open their menu under themselves.</summary>
private void OnOpenMenu(object sender, RoutedEventArgs e)
{
if (sender is not Button { ContextMenu: { } menu } button) return;
menu.DataContext = DataContext;
menu.PlacementTarget = button;
menu.Placement = PlacementMode.Bottom;
menu.IsOpen = true;
}
/// <summary>The "{ }" menu writes into the template field used last.</summary>
private void OnFolderTemplateFocus(object sender, KeyboardFocusChangedEventArgs e) => Model?.SetActiveTemplate(folder: true);
private void OnFileTemplateFocus(object sender, KeyboardFocusChangedEventArgs e) => Model?.SetActiveTemplate(folder: false);
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (e.OldValue is INotifyPropertyChanged old) old.PropertyChanged -= OnModelChanged;
if (e.NewValue is INotifyPropertyChanged model) model.PropertyChanged += OnModelChanged;
}
/// <summary>
/// Keyboard focus follows what opens: the nickname field when it appears (a new card, Rename), and "Show plan"
/// (focus returns to its button when it closes).
/// </summary>
private void OnModelChanged(object? sender, PropertyChangedEventArgs e)
{
if (Model is not { } model) return;
if (e.PropertyName is nameof(ImportViewModel.IsNicknameOpen) or "")
{
var opened = model.IsNicknameOpen && !_nicknameOpen;
_nicknameOpen = model.IsNicknameOpen;
if (opened && IsVisible) FocusLater(NicknameBox);
}
if (e.PropertyName is nameof(ImportViewModel.IsDetailsOpen) && IsVisible)
FocusLater(model.IsDetailsOpen ? ClosePlanButton : ShowPlanButton);
}
/// <summary>After layout: an element that just became visible cannot take focus yet.</summary>
private void FocusLater(UIElement element) => Dispatcher.BeginInvoke(DispatcherPriority.Input, () => element.Focus());
}
File diff suppressed because it is too large. Load diff