Sort attachments by folder so each folder is named once

This commit is contained in:
Thorsten Sommer 2026-09-13 17:15:32 +02:00
parent fbe3fdda4b
commit 4b5bf98847
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 16 additions and 1 deletions

View File

@ -31,7 +31,7 @@
@{
var currentFolder = string.Empty;
foreach (var fileAttachment in this.DocumentPaths)
foreach (var fileAttachment in this.OrderedAttachments)
{
var folderPath = Path.GetDirectoryName(fileAttachment.FilePath);
if (folderPath != currentFolder)

View File

@ -73,6 +73,21 @@ public partial class ReviewAttachmentsDialog : MSGComponentBase
: "border-dashed border-2 rounded-lg pa-2 mud-border-lines-default";
}
/// <summary>
/// The attachments, sorted by their folder and, within it, by their file name.
/// </summary>
/// <remarks>
/// The list below starts a new heading whenever the folder changes from one attachment to the
/// next, which names every folder exactly once -- but only as long as the attachments of a
/// folder arrive together. The set behind them keeps no order of its own to guarantee that:
/// removing one attachment already scrambles it, and one attached while this dialog is open
/// lands at its end, giving its folder a second heading further down. Sorting here is what that
/// list assumes anyway.
/// </remarks>
private IEnumerable<FileAttachment> OrderedAttachments => this.DocumentPaths
.OrderBy(attachment => Path.GetDirectoryName(attachment.FilePath) ?? string.Empty, StringComparer.OrdinalIgnoreCase)
.ThenBy(attachment => attachment.FileName, StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Attaches what the user dropped onto this dialog and answers which files that became.
/// </summary>