mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
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 Codepull/3755/head
4 changed files with 147 additions and 40 deletions
@ -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; |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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 <c>SortMemberPath</c>s, and that sorting is enabled; the header-click reordering
|
||||||
|
/// itself is Avalonia's DataGrid sort (used identically by OpenFromGacDialog/MetadataTablePage).
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class SearchPaneSortableColumnsTests |
||||||
|
{ |
||||||
|
[AvaloniaTest] |
||||||
|
public async Task Results_Render_In_A_Grid_With_Sortable_Name_Location_Assembly_Columns() |
||||||
|
{ |
||||||
|
var window = AppComposition.Current.GetExport<MainWindow>(); |
||||||
|
window.Show(); |
||||||
|
AppComposition.Current.GetExport<global::ILSpy.Docking.DockWorkspace>() |
||||||
|
.ShowToolPane(SearchPaneModel.PaneContentId); |
||||||
|
var pane = await window.WaitForComponent<SearchPane>(); |
||||||
|
|
||||||
|
var grid = pane.FindControl<DataGrid>("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"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue