Browse Source

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
pull/3755/head
Siegfried Pammer 4 weeks ago
parent
commit
2ce4ccda05
  1. 6
      ILSpy.Tests/Search/SearchPaneNicetiesTests.cs
  2. 78
      ILSpy.Tests/Search/SearchPaneSortableColumnsTests.cs
  3. 4
      ILSpy.Tests/Search/SearchPaneViewTests.cs
  4. 99
      ILSpy/Search/SearchPane.axaml

6
ILSpy.Tests/Search/SearchPaneNicetiesTests.cs

@ -116,7 +116,7 @@ public class SearchPaneNicetiesTests @@ -116,7 +116,7 @@ public class SearchPaneNicetiesTests
vm.Results.Add(Dummy("Alpha"));
vm.Results.Add(Dummy("Beta"));
var input = pane.FindControl<TextBox>("SearchInput")!;
var results = pane.FindControl<ListBox>("SearchResults")!;
var results = pane.FindControl<DataGrid>("SearchResults")!;
RaiseKey(input, Key.Down, KeyModifiers.None);
Dispatcher.UIThread.RunJobs();
@ -130,7 +130,7 @@ public class SearchPaneNicetiesTests @@ -130,7 +130,7 @@ public class SearchPaneNicetiesTests
var (_, pane, vm) = await ShowPaneAsync();
vm.Results.Add(Dummy("Alpha"));
var input = pane.FindControl<TextBox>("SearchInput")!;
var results = pane.FindControl<ListBox>("SearchResults")!;
var results = pane.FindControl<DataGrid>("SearchResults")!;
results.SelectedIndex = 0;
RaiseKey(results, Key.Up, KeyModifiers.None);
@ -151,7 +151,7 @@ public class SearchPaneNicetiesTests @@ -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<ListBox>("SearchResults")!;
var results = pane.FindControl<DataGrid>("SearchResults")!;
results.SelectedItem = vm.Results.First(r => r is MemberSearchResult);
int before = workspace.Documents!.VisibleDockables!.OfType<ContentTabPage>().Count();

78
ILSpy.Tests/Search/SearchPaneSortableColumnsTests.cs

@ -0,0 +1,78 @@ @@ -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");
}
}
}

4
ILSpy.Tests/Search/SearchPaneViewTests.cs

@ -41,7 +41,7 @@ public class SearchPaneViewTests @@ -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<MainWindow>();
window.Show();
@ -59,7 +59,7 @@ public class SearchPaneViewTests @@ -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<ListBox>("SearchResults");
var results = pane.FindControl<DataGrid>("SearchResults");
((object?)results).Should().NotBeNull("the results list is the binding sink for the streaming orchestrator");
}

99
ILSpy/Search/SearchPane.axaml

@ -3,6 +3,7 @@ @@ -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 @@ @@ -55,40 +56,68 @@
Height="2" Margin="0,0,0,1"
BorderThickness="0"
MinHeight="2" />
<ListBox Grid.Row="2" Name="SearchResults"
ItemsSource="{Binding Results}"
x:CompileBindings="False">
<ListBox.ItemTemplate>
<DataTemplate>
<!-- Three icon+text cells: Name | Location | Assembly. Each cell is a
two-column Grid so the icon doesn't compress when the text gets
ellipsised. -->
<Grid ColumnDefinitions="*,8,Auto,8,Auto" Margin="2,1">
<Grid Grid.Column="0" ColumnDefinitions="Auto,4,*">
<Image Grid.Column="0" Source="{Binding Image}" Width="16" Height="16"
VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Text="{Binding Name}"
ToolTip.Tip="{Binding ToolTip}"
VerticalAlignment="Center"
TextTrimming="CharacterEllipsis" />
</Grid>
<Grid Grid.Column="2" ColumnDefinitions="Auto,4,*">
<Image Grid.Column="0" Source="{Binding LocationImage}" Width="16" Height="16"
VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Text="{Binding Location}" Foreground="{DynamicResource ILSpy.SecondaryForeground}"
VerticalAlignment="Center"
TextTrimming="CharacterEllipsis" />
</Grid>
<Grid Grid.Column="4" ColumnDefinitions="Auto,4,*">
<Image Grid.Column="0" Source="{Binding AssemblyImage}" Width="16" Height="16"
VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Text="{Binding Assembly}" Foreground="{DynamicResource ILSpy.SecondaryForeground}"
VerticalAlignment="Center"
TextTrimming="CharacterEllipsis" />
</Grid>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<!-- Results grid: clickable, sortable column headers (Name | Location | Assembly). Template
columns keep the per-field icons; SortMemberPath ties each header to the SearchResult
property it shows. No initial column sort, so rows stay in the fitness/name streaming
order until the user clicks a header. -->
<DataGrid Grid.Row="2" Name="SearchResults"
ItemsSource="{Binding Results}"
x:CompileBindings="False"
AutoGenerateColumns="False"
CanUserSortColumns="True"
CanUserResizeColumns="True"
IsReadOnly="True"
HeadersVisibility="Column"
GridLinesVisibility="None"
SelectionMode="Single">
<DataGrid.Columns>
<!-- Star widths (never Auto): an Auto column re-measures to the widest realised cell,
so it visibly jumps as rows virtualise in/out on scroll. Resizable if needed. -->
<DataGridTemplateColumn Header="{x:Static res:Resources.Name}" Width="2*"
CanUserSort="True" SortMemberPath="Name">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<!-- Two-column cell so the icon doesn't compress when the text ellipsises. -->
<Grid ColumnDefinitions="Auto,4,*" Margin="2,1">
<Image Grid.Column="0" Source="{Binding Image}" Width="16" Height="16"
VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Text="{Binding Name}"
ToolTip.Tip="{Binding ToolTip}"
VerticalAlignment="Center"
TextTrimming="CharacterEllipsis" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="{x:Static res:Resources.Location}" Width="*"
CanUserSort="True" SortMemberPath="Location">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid ColumnDefinitions="Auto,4,*" Margin="2,1">
<Image Grid.Column="0" Source="{Binding LocationImage}" Width="16" Height="16"
VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Text="{Binding Location}" Foreground="{DynamicResource ILSpy.SecondaryForeground}"
VerticalAlignment="Center"
TextTrimming="CharacterEllipsis" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="{x:Static res:Resources.Assembly}" Width="*"
CanUserSort="True" SortMemberPath="Assembly">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid ColumnDefinitions="Auto,4,*" Margin="2,1">
<Image Grid.Column="0" Source="{Binding AssemblyImage}" Width="16" Height="16"
VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Text="{Binding Assembly}" Foreground="{DynamicResource ILSpy.SecondaryForeground}"
VerticalAlignment="Center"
TextTrimming="CharacterEllipsis" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</UserControl>

Loading…
Cancel
Save