From 2ce4ccda05b0c8235804d74414b09e9a39d222d8 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 9 Jun 2026 08:02:04 +0200 Subject: [PATCH] Show search results in a grid with sortable column headers The search panel rendered hits in a bare ListBox with no headers, so the only ordering was the fixed fitness/name streaming order chosen at search time -- the user could not re-sort by Name, Location or Assembly. Replace the ListBox with the app's standard sortable Avalonia DataGrid (mirroring OpenFromGacDialog / MetadataTablePage): three template columns that keep the per-field icons, each with a SortMemberPath so clicking a header sorts by Name / Location / Assembly. No initial column sort is applied, so the default fitness ranking is preserved until the user clicks a header. The code-behind is unchanged: ListBox and DataGrid share the SelectingItemsControl surface, so the existing selection / activation / keyboard / middle-click handlers port as-is (verified by the existing search niceties tests now running against the DataGrid). Assisted-by: Claude:claude-opus-4-8:Claude Code --- ILSpy.Tests/Search/SearchPaneNicetiesTests.cs | 6 +- .../Search/SearchPaneSortableColumnsTests.cs | 78 +++++++++++++++ ILSpy.Tests/Search/SearchPaneViewTests.cs | 4 +- ILSpy/Search/SearchPane.axaml | 99 ++++++++++++------- 4 files changed, 147 insertions(+), 40 deletions(-) create mode 100644 ILSpy.Tests/Search/SearchPaneSortableColumnsTests.cs diff --git a/ILSpy.Tests/Search/SearchPaneNicetiesTests.cs b/ILSpy.Tests/Search/SearchPaneNicetiesTests.cs index 6623bd23e..1ca3f6f6f 100644 --- a/ILSpy.Tests/Search/SearchPaneNicetiesTests.cs +++ b/ILSpy.Tests/Search/SearchPaneNicetiesTests.cs @@ -116,7 +116,7 @@ public class SearchPaneNicetiesTests vm.Results.Add(Dummy("Alpha")); vm.Results.Add(Dummy("Beta")); var input = pane.FindControl("SearchInput")!; - var results = pane.FindControl("SearchResults")!; + var results = pane.FindControl("SearchResults")!; RaiseKey(input, Key.Down, KeyModifiers.None); Dispatcher.UIThread.RunJobs(); @@ -130,7 +130,7 @@ public class SearchPaneNicetiesTests var (_, pane, vm) = await ShowPaneAsync(); vm.Results.Add(Dummy("Alpha")); var input = pane.FindControl("SearchInput")!; - var results = pane.FindControl("SearchResults")!; + var results = pane.FindControl("SearchResults")!; results.SelectedIndex = 0; RaiseKey(results, Key.Up, KeyModifiers.None); @@ -151,7 +151,7 @@ public class SearchPaneNicetiesTests await Waiters.WaitForAsync(() => vm.Results.Any(r => r is MemberSearchResult), timeout: TimeSpan.FromSeconds(30)); - var results = pane.FindControl("SearchResults")!; + var results = pane.FindControl("SearchResults")!; results.SelectedItem = vm.Results.First(r => r is MemberSearchResult); int before = workspace.Documents!.VisibleDockables!.OfType().Count(); diff --git a/ILSpy.Tests/Search/SearchPaneSortableColumnsTests.cs b/ILSpy.Tests/Search/SearchPaneSortableColumnsTests.cs new file mode 100644 index 000000000..d410fcde5 --- /dev/null +++ b/ILSpy.Tests/Search/SearchPaneSortableColumnsTests.cs @@ -0,0 +1,78 @@ +// Copyright (c) 2026 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System.Linq; +using System.Threading.Tasks; + +using Avalonia.Controls; +using Avalonia.Headless.NUnit; + +using AwesomeAssertions; + +using ICSharpCode.ILSpy.Properties; +using ICSharpCode.ILSpyX.Search; + +using ILSpy.AppEnv; +using ILSpy.Search; +using ILSpy.Views; + +using NUnit.Framework; + +namespace ICSharpCode.ILSpy.Tests.Search; + +/// +/// The search results must render in a grid with clickable, sortable column headers +/// (Name / Location / Assembly), so the user can re-order hits after a search instead of being +/// stuck with the fixed fitness/name streaming order. This guards the wiring we own — the column +/// set, their SortMemberPaths, and that sorting is enabled; the header-click reordering +/// itself is Avalonia's DataGrid sort (used identically by OpenFromGacDialog/MetadataTablePage). +/// +[TestFixture] +public class SearchPaneSortableColumnsTests +{ + [AvaloniaTest] + public async Task Results_Render_In_A_Grid_With_Sortable_Name_Location_Assembly_Columns() + { + var window = AppComposition.Current.GetExport(); + window.Show(); + AppComposition.Current.GetExport() + .ShowToolPane(SearchPaneModel.PaneContentId); + var pane = await window.WaitForComponent(); + + var grid = pane.FindControl("SearchResults"); + ((object?)grid).Should().NotBeNull("the results must be hosted in a DataGrid so the column headers are sortable"); + grid!.CanUserSortColumns.Should().BeTrue("the grid must allow the user to sort by clicking a header"); + + // One sortable column per visible field, keyed to the SearchResult property it shows. + var byPath = grid.Columns.ToDictionary(c => c.SortMemberPath); + foreach (var (path, header) in new[] { + (nameof(SearchResult.Name), Resources.Name), + (nameof(SearchResult.Location), Resources.Location), + (nameof(SearchResult.Assembly), Resources.Assembly), + }) + { + byPath.Should().ContainKey(path, $"there must be a column sorted by {path}"); + var column = byPath[path]; + column.CanUserSort.Should().BeTrue($"the {path} header must be clickable to sort"); + column.Header.Should().Be(header, $"the {path} column header text"); + column.Width.IsAuto.Should().BeFalse( + $"the {path} column must not be Auto-width: Auto re-measures to the widest realised " + + "cell, so the column visibly jumps as rows virtualise in and out on scroll"); + } + } +} diff --git a/ILSpy.Tests/Search/SearchPaneViewTests.cs b/ILSpy.Tests/Search/SearchPaneViewTests.cs index 69cd8aaf0..a5fa59f21 100644 --- a/ILSpy.Tests/Search/SearchPaneViewTests.cs +++ b/ILSpy.Tests/Search/SearchPaneViewTests.cs @@ -41,7 +41,7 @@ public class SearchPaneViewTests // The pane's contract — used by every downstream commit in this series — is // that the view exposes three named controls bound to the view-model: a TextBox // for the query (SearchInput), a ComboBox for the mode picker (SearchModePicker), - // and a ListBox that renders incoming results (SearchResults). + // and a DataGrid that renders incoming results (SearchResults). var window = AppComposition.Current.GetExport(); window.Show(); @@ -59,7 +59,7 @@ public class SearchPaneViewTests modePicker!.ItemCount.Should().Be(12, "the picker must populate from SearchPaneModel.SearchModes — twelve entries"); - var results = pane.FindControl("SearchResults"); + var results = pane.FindControl("SearchResults"); ((object?)results).Should().NotBeNull("the results list is the binding sink for the streaming orchestrator"); } diff --git a/ILSpy/Search/SearchPane.axaml b/ILSpy/Search/SearchPane.axaml index e9926d8ba..a56226fbe 100644 --- a/ILSpy/Search/SearchPane.axaml +++ b/ILSpy/Search/SearchPane.axaml @@ -3,6 +3,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:search="using:ILSpy.Search" + xmlns:res="using:ICSharpCode.ILSpy.Properties" mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="200" x:Class="ILSpy.Search.SearchPane" x:DataType="search:SearchPaneModel"> @@ -55,40 +56,68 @@ Height="2" Margin="0,0,0,1" BorderThickness="0" MinHeight="2" /> - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +