Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<PackageVersion Include="ktsu.Extensions" Version="1.5.31" />
<PackageVersion Include="ktsu.ThemeProvider" Version="2.0.20" />
<PackageVersion Include="ktsu.ThemeProvider.ImGui" Version="2.0.20" />
<PackageVersion Include="ktsu.Semantics.Color" Version="2.7.10" />
<PackageVersion Include="ktsu.Semantics.Paths" Version="2.7.10" />
<PackageVersion Include="ktsu.Semantics.Strings" Version="2.7.10" />
<PackageVersion Include="ktsu.Semantics.Quantities" Version="2.7.10" />
<PackageVersion Include="ktsu.Semantics.Color" Version="2.8.0" />
<PackageVersion Include="ktsu.Semantics.Paths" Version="2.8.0" />
<PackageVersion Include="ktsu.Semantics.Strings" Version="2.8.0" />
<PackageVersion Include="ktsu.Semantics.Quantities" Version="2.8.0" />
<PackageVersion Include="ktsu.CaseConverter" Version="1.3.22" />
<PackageVersion Include="Hexa.NET.ImGui" Version="2.2.9" />
<PackageVersion Include="Hexa.NET.ImGuizmo" Version="2.2.9" />
Expand Down
21 changes: 11 additions & 10 deletions ImGui.Popups/FilesystemBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,18 +346,20 @@ private void DrawFileTable()
/// <param name="contents">The filesystem entries to order.</param>
/// <returns>The ordered entries.</returns>
/// <remarks>
/// The secondary sort key is the entry's string value rather than the entry itself because
/// <see cref="IAbsolutePath"/> does not implement <see cref="IComparable{T}"/>. Sorting by the entry
/// would make LINQ fall back to <see cref="Comparer{T}.Default"/>, which calls the non-generic
/// <see cref="IComparable.CompareTo(object)"/> on the underlying semantic string, which throws
/// <see cref="ArgumentException"/> when handed a path object in ktsu.Semantics.Strings 2.7.10 and
/// earlier. Sorting on the string value also gives case-insensitive display order.
/// The secondary sort key is the entry's string value rather than the entry itself. Sorting by the
/// entry makes LINQ fall back to <see cref="Comparer{T}.Default"/>, because <see cref="IAbsolutePath"/>
/// implements neither <see cref="IComparable{T}"/> of itself nor of <see cref="IPath"/> — the
/// <see cref="IComparable{T}"/> that ktsu.Semantics.Paths declares on <see cref="IPath"/> only helps
/// collections typed as <see cref="IPath"/> exactly. Every comparison would therefore box through the
/// non-generic <see cref="IComparable.CompareTo(object)"/>, which additionally threw
/// <see cref="ArgumentException"/> before ktsu.Semantics.Strings 2.7.11 (ktsu-dev/ImGuiApp#273).
/// Sorting on the string value also gives case-insensitive display order.
/// </remarks>
internal static Collection<IAbsolutePath> SortContents(IEnumerable<IAbsolutePath> contents) =>
contents
.OrderBy(p => p is not AbsoluteDirectoryPath)
.ThenBy(p => p.ToString(), StringComparer.OrdinalIgnoreCase)
.ThenBy(p => p.ToString(), StringComparer.Ordinal)
.ThenBy(p => p.WeakString, StringComparer.OrdinalIgnoreCase)
.ThenBy(p => p.WeakString, StringComparer.Ordinal)
.ToCollection();

/// <summary>
Expand Down Expand Up @@ -390,8 +392,7 @@ private void DrawContentRow(IAbsolutePath path, ImGuiSelectableFlags flags)
ImGui.TableNextColumn();
AbsoluteDirectoryPath? directory = path as AbsoluteDirectoryPath;
AbsoluteFilePath? file = path as AbsoluteFilePath;
string displayPath = directory?.WeakString ?? file?.WeakString ?? string.Empty;
displayPath = displayPath.RemovePrefix(CurrentDirectory.WeakString).Trim(Path.DirectorySeparatorChar);
string displayPath = path.WeakString.RemovePrefix(CurrentDirectory.WeakString).Trim(Path.DirectorySeparatorChar);

if (directory is not null)
{
Expand Down
8 changes: 4 additions & 4 deletions tests/ImGui.Popups.Tests/FilesystemBrowserSortTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void SortContents_ListsDirectoriesBeforeFiles()
MakeDirectory("alpha"),
];

List<string> sorted = [.. ImGuiPopups.FilesystemBrowser.SortContents(contents).Select(p => Path.GetFileName(p.ToString()!))];
List<string> sorted = [.. ImGuiPopups.FilesystemBrowser.SortContents(contents).Select(p => Path.GetFileName(p.WeakString))];

CollectionAssert.AreEqual(new List<string> { "alpha", "zebra", "a.txt", "b.txt" }, sorted);
}
Expand All @@ -70,7 +70,7 @@ public void SortContents_SortsByNameIgnoringCase()
MakeFile("Banana.txt"),
];

List<string> sorted = [.. ImGuiPopups.FilesystemBrowser.SortContents(contents).Select(p => Path.GetFileName(p.ToString()!))];
List<string> sorted = [.. ImGuiPopups.FilesystemBrowser.SortContents(contents).Select(p => Path.GetFileName(p.WeakString))];

CollectionAssert.AreEqual(new List<string> { "apple.txt", "Banana.txt", "Zebra.txt" }, sorted);
}
Expand All @@ -90,8 +90,8 @@ public void SortContents_EntriesDifferingOnlyByCase_OrderIsDeterministic()
MakeFile("b.txt"),
];

List<string> sorted = [.. ImGuiPopups.FilesystemBrowser.SortContents(contents).Select(p => p.ToString()!)];
List<string> sortedReversed = [.. ImGuiPopups.FilesystemBrowser.SortContents(reversed).Select(p => p.ToString()!)];
List<string> sorted = [.. ImGuiPopups.FilesystemBrowser.SortContents(contents).Select(p => p.WeakString)];
List<string> sortedReversed = [.. ImGuiPopups.FilesystemBrowser.SortContents(reversed).Select(p => p.WeakString)];

CollectionAssert.AreEqual(sorted, sortedReversed);
}
Expand Down
Loading