feat(import): import a whole folder as one sequence per format

Owner review 2, R9: Import › Folder… gains a "Group" choice for picked
folders: Sessions (as before) or Whole folder. A whole folder, with its
subfolders when Subfolders is on, becomes one sequence per file format;
camera bodies and pauses are ignored, while RAW+JPEG of the same shots
stays two sequences so no frame is ever doubled. Only the user's splits
break it, and Merge joins a split part back.

The planner implements it (ImportOptions.Grouping, Core, Linux-tested):
the session key is "folder-" plus a hash of this PC's name, the full
path and the format, so an interrupted or repeated import continues the
same sequence; the default title is the folder's name. The plan shows
one row per format with the format and the number of cameras. Cards and
drives always import by sessions; the choice is not part of a card
profile and a folder starts on Sessions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-10-26 22:00:55 +01:00
1 parent 5209579631
commit 445dfd41a3
14 files changed
+419 -26

No files matched your search

+8 -1
View File
@@ -15,13 +15,18 @@ public enum ImportDestinationKind
/// <summary>
/// The Import form (Import.html): scan, sessions, names, duplicates and after-import choices. Remembered per card as
/// its <see cref="CardProfile"/>; a session gap of 0 minutes in a profile means "do not split into sessions".
/// its <see cref="CardProfile"/>; a session gap of 0 minutes in a profile means "do not split into sessions". The
/// grouping is not in a profile: a card always imports by sessions, and a picked folder starts with them.
/// </summary>
public sealed record ImportChoices
{
public ImportDestinationKind Destination { get; init; } = ImportDestinationKind.Archive;
public string? FolderPath { get; init; }
public bool IncludeSubfolders { get; init; } = true;
/// <summary>"Group" (a picked folder only): its sessions, or the whole folder as one sequence per format.</summary>
public ImportGrouping Grouping { get; init; } = ImportGrouping.Sessions;
public bool SplitSessions { get; init; } = true;
public int GapMinutes { get; init; } = 45;
public int MinimumFrames { get; init; } = 8;
@@ -78,6 +83,7 @@ public sealed record ImportChoices
IncludeSubfolders = IncludeSubfolders,
VerifyCopies = VerifyCopies,
Duplicates = Duplicates,
Grouping = Grouping,
Titles = titles ?? new Dictionary<string, string>(),
SplitBefore = splits ?? new HashSet<string>(),
MergeAt = merges ?? new HashSet<string>(),
@@ -88,6 +94,7 @@ public sealed record ImportChoices
previous.Destination != Destination
|| (Destination == ImportDestinationKind.Folder && !string.Equals(previous.FolderPath, FolderPath, StringComparison.OrdinalIgnoreCase))
|| previous.IncludeSubfolders != IncludeSubfolders
|| previous.Grouping != Grouping
|| previous.SplitSessions != SplitSessions
|| (SplitSessions && previous.GapMinutes != GapMinutes)
|| previous.MinimumFrames != MinimumFrames
+33 -7
View File
@@ -1,4 +1,5 @@
using Chronos.App.Infrastructure;
using Chronos.App.Settings;
using Chronos.Core.Archiving;
using Chronos.Core.Import;
using Chronos.Core.Localization;
@@ -40,7 +41,8 @@ public sealed record PlanTotals(int Sessions, int Photos, int CopyCount, long Co
}
/// <summary>One row of the session table: what the planner grouped and where it goes.</summary>
/// <param name="DefaultTitle">Title the sequence gets when the user types none (its folder name).</param>
/// <param name="Title">The title the user typed; null when none.</param>
/// <param name="DefaultTitle">Title the sequence gets when the user types none (a whole folder's name, else its folder name).</param>
/// <param name="IsNew">The session starts a new sequence (false: it continues one imported before).</param>
/// <param name="FirstPath">Card path of the session's first photo (where a merge joins it to the previous session).</param>
/// <param name="MergesInto">Number of the earlier session of the same camera and format it can merge into; null for none.</param>
@@ -116,10 +118,19 @@ public static class ImportPlans
],
};
/// <summary>The plan with the typed session titles (when no template uses <c>{title}</c>, so no name changes).</summary>
/// <summary>
/// The plan with the typed session titles (when no template uses <c>{title}</c>, so no name changes); a session
/// without one keeps its default title (a whole folder's name).
/// </summary>
public static ImportPlan WithTitles(ImportPlan plan, IReadOnlyDictionary<string, string> titles) => plan with
{
Sessions = [.. plan.Sessions.Select(s => s with { Title = titles.TryGetValue(s.SessionKey, out var t) && !string.IsNullOrWhiteSpace(t) ? t.Trim() : null })],
Sessions =
[
.. plan.Sessions.Select(s => s with
{
Title = titles.TryGetValue(s.SessionKey, out var t) && !string.IsNullOrWhiteSpace(t) ? t.Trim() : s.DefaultTitle,
}),
],
};
/// <param name="existingFolders">Folders of sequences already in the archive (a session there continues it).</param>
@@ -135,20 +146,35 @@ public static class ImportPlans
ImportDestinationKind.Folder => s.Folder,
_ => Loc.L(isNew ? "Import.Session.New" : "Import.Session.Adds", s.Folder),
};
return new PlanSessionRow(s.Number, s.SessionKey, s.Title, leaf, TimeText(s), FramesText(s), Formatting.Bytes(s.Items.Sum(i => i.Size)),
PathTemplate.CameraName(s.CameraMake, s.CameraModel), target, isNew, s.Items.Count > 0 ? s.Items[0].SourcePath : string.Empty,
// The field shows a typed title only; the default (a whole folder's name, else the folder's) is its placeholder.
var typed = s.Title is { } title && title != s.DefaultTitle ? title : null;
return new PlanSessionRow(s.Number, s.SessionKey, typed, s.DefaultTitle ?? leaf, TimeText(s), FramesText(s),
Formatting.Bytes(s.Items.Sum(i => i.Size)), CameraText(plan, s), target, isNew, s.Items.Count > 0 ? s.Items[0].SourcePath : string.Empty,
MergeTarget(plan, s)?.Number);
}),
];
/// <summary>
/// "Canon EOS R5"; for a whole folder, one row per format, the format too and how many bodies took the photos:
/// "Canon EOS R5 · CR3", "2 cameras · JPEG".
/// </summary>
private static string CameraText(ImportPlan plan, PlannedSession s)
{
var camera = PathTemplate.CameraName(s.CameraMake, s.CameraModel);
if (plan.Grouping != ImportGrouping.WholeFolder) return camera;
var bodies = s.Cameras > 1 ? Loc.Plural("Import.Session.Cameras", s.Cameras) : camera;
return string.Join(Loc.Separator, new[] { bodies, FormatNames.Of(s.Format) }.Where(t => t.Length > 0));
}
/// <summary>
/// The session <paramref name="session"/> joins when the user merges it (BRIEF §13): the one before it of the same
/// camera body and format, whose last photo precedes its first; sessions of other cameras or formats never merge.
/// A whole folder's parts (split by the user) join the part before them of the same format, whatever the camera.
/// </summary>
public static PlannedSession? MergeTarget(ImportPlan plan, PlannedSession session) =>
plan.Sessions.TakeWhile(s => !ReferenceEquals(s, session))
.LastOrDefault(s => s.CameraMake == session.CameraMake && s.CameraModel == session.CameraModel && s.CameraSerial == session.CameraSerial
&& s.Format == session.Format);
.LastOrDefault(s => s.Format == session.Format && (plan.Grouping == ImportGrouping.WholeFolder
|| (s.CameraMake == session.CameraMake && s.CameraModel == session.CameraModel && s.CameraSerial == session.CameraSerial)));
/// <summary>"Show plan": every file and where it goes, with the conflicts the plan resolved or reports.</summary>
public static PlanDetails Details(ImportPlan plan, ImportDestinationKind destination, bool verify)
+13 -3
View File
@@ -355,17 +355,27 @@
</WrapPanel>
</HeaderedContentControl>
<!-- A picked folder only: its sessions, or the whole folder as one sequence per format. -->
<HeaderedContentControl Style="{StaticResource Import.Row}" Header="{l:Loc Import.Label.Group}"
Visibility="{Binding CanGroupFolder, Converter={StaticResource BoolToVisibility}}">
<WrapPanel>
<RadioButton Content="{l:Loc Import.Group.Sessions}" IsChecked="{Binding GroupBySessions}" ToolTip="{l:Loc Tooltips.Import.GroupSessions}" />
<RadioButton Content="{l:Loc Import.Group.WholeFolder}" IsChecked="{Binding GroupWholeFolder}" ToolTip="{l:Loc Tooltips.Import.WholeFolder}" />
</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}">
<CheckBox Content="{l:Loc Import.Scan.Sessions}" IsChecked="{Binding SplitSessions}" IsEnabled="{Binding SessionsApply}"
ToolTip="{Binding SessionsToolTip}" />
<StackPanel Orientation="Horizontal" Style="{StaticResource Import.Choice}" IsEnabled="{Binding GapApplies}">
<TextBlock Text="{l:Loc Import.Scan.Gap}" Style="{StaticResource Text.Unit}" />
<TextBox x:Name="GapBox" 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}" Style="{StaticResource Text.Unit}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Style="{StaticResource Import.Choice}">
<StackPanel Orientation="Horizontal" Style="{StaticResource Import.Choice}" IsEnabled="{Binding SessionsApply}">
<TextBlock Text="{l:Loc Import.Scan.Minimum}" Style="{StaticResource Text.Unit}" />
<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}" />
+56 -5
View File
@@ -120,8 +120,10 @@ public sealed class ImportViewModel : SectionViewModel
// The path is checked only while Folder is the destination; typing one chooses Folder, as "…" does.
FolderPath = new EditableField(string.Empty, text => IsFolderDestination ? ArchiveLocations.Validate(text) : null,
text => Choices = _choices with { FolderPath = text, Destination = ImportDestinationKind.Folder }, () => Loc.L("Tooltips.Import.FolderPath"));
GapMinutes = NumberField(1, 24 * 60, () => _choices.GapMinutes, n => Choices = _choices with { GapMinutes = n }, "Tooltips.Import.Gap");
MinimumFrames = NumberField(1, 1000, () => _choices.MinimumFrames, n => Choices = _choices with { MinimumFrames = n }, "Tooltips.Import.MinimumFrames");
GapMinutes = NumberField(1, 24 * 60, () => _choices.GapMinutes, n => Choices = _choices with { GapMinutes = n },
() => SessionToolTip("Tooltips.Import.Gap"));
MinimumFrames = NumberField(1, 1000, () => _choices.MinimumFrames, n => Choices = _choices with { MinimumFrames = n },
() => SessionToolTip("Tooltips.Import.MinimumFrames"));
FolderTemplate = new EditableField(_choices.FolderTemplate, t => NamingPreview.Validate(t, isFolder: true),
t => Choices = _choices with { FolderTemplate = t }, () => Loc.L("Tooltips.Import.FolderTemplate"));
FileTemplate = new EditableField(_choices.FileTemplate, t => NamingPreview.Validate(t, isFolder: false),
@@ -264,6 +266,11 @@ public sealed class ImportViewModel : SectionViewModel
if (previous == value) return;
_choices = value;
if (value.Destination != previous.Destination) FolderPath.Refresh();
if (value.Grouping != previous.Grouping)
{
GapMinutes.Refresh();
MinimumFrames.Refresh();
}
OnPropertyChanged(string.Empty);
if (value.NeedsNewPlan(previous) || (value.TitlesChangeNames != previous.TitlesChangeNames && _titles.Count > 0)) SchedulePlan();
else ApplyPlan();
@@ -320,6 +327,37 @@ public sealed class ImportViewModel : SectionViewModel
set => Choices = _choices with { IncludeSubfolders = value };
}
/// <summary>"Group" is offered for a picked folder only (BRIEF §12.4): a card or a drive always splits into sessions.</summary>
public bool CanGroupFolder => _selected?.Kind == SourceKind.Folder;
public bool GroupBySessions
{
get => !IsWholeFolder;
set
{
if (value) SetGrouping(ImportGrouping.Sessions);
}
}
/// <summary>The picked folder is one sequence per format: camera bodies and pauses are ignored.</summary>
public bool GroupWholeFolder
{
get => IsWholeFolder;
set
{
if (value && CanGroupFolder) SetGrouping(ImportGrouping.WholeFolder);
}
}
private bool IsWholeFolder => CanGroupFolder && _choices.Grouping == ImportGrouping.WholeFolder;
/// <summary>Sessions, their gap and their minimum do not apply to a whole folder.</summary>
public bool SessionsApply => !IsWholeFolder;
public bool GapApplies => SessionsApply && _choices.SplitSessions;
public string SessionsToolTip => SessionToolTip("Tooltips.Import.Sessions");
public bool SplitSessions
{
get => _choices.SplitSessions;
@@ -340,6 +378,18 @@ public sealed class ImportViewModel : SectionViewModel
public IReadOnlyList<TokenItem> Tokens { get; }
public ICommand InsertTokenCommand { get; }
private void SetGrouping(ImportGrouping grouping)
{
if (_choices.Grouping == grouping) return;
// Splits and merges were made on the other grouping's sessions.
_splits.Clear();
_merges.Clear();
Choices = _choices with { Grouping = grouping };
}
/// <summary>A session control's tooltip, or why it does not apply to a whole folder.</summary>
private string SessionToolTip(string key) => IsWholeFolder ? Loc.L("Import.Blocked.WholeFolder") : Loc.L(key);
/// <summary>The view tells which template field the "{ }" menu writes into.</summary>
public void SetActiveTemplate(bool folder) => _activeTemplateIsFolder = folder;
@@ -966,7 +1016,8 @@ public sealed class ImportViewModel : SectionViewModel
{
if (!cts.IsCancellationRequested) SetStatus(ImportPhase.Planning, Loc.Plural("Import.Status.ReadingCount", n));
});
var options = _choices.ToOptions(_titles, _splits, _merges);
// A card or a drive is always planned by sessions, whatever a folder chose before.
var options = _choices.ToOptions(_titles, _splits, _merges) with { Grouping = IsWholeFolder ? ImportGrouping.WholeFolder : ImportGrouping.Sessions };
var cardId = _selected.Kind == SourceKind.Card ? await RegisteredCardIdAsync() : null;
try
{
@@ -1456,11 +1507,11 @@ public sealed class ImportViewModel : SectionViewModel
else dispatcher.BeginInvoke(action);
}
private static EditableField NumberField(int min, int max, Func<int> current, Action<int> commit, string toolTipKey) =>
private static EditableField NumberField(int min, int max, Func<int> current, Action<int> commit, Func<string> toolTip) =>
new(current().ToString(Loc.Culture),
text => int.TryParse(text.Trim(), NumberStyles.Integer, Loc.Culture, out var n) && n >= min && n <= max
? null
: Loc.L("Errors.Number.Range", min.ToString("N0", Loc.Culture), max.ToString("N0", Loc.Culture)),
text => commit(int.Parse(text.Trim(), NumberStyles.Integer, Loc.Culture)),
() => Loc.L(toolTipKey));
toolTip);
}