Skip to content

Commit

Permalink
Merge branch 'SearchResources' of https://github.com/miloush/ILSpy
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrunwald committed May 28, 2023
2 parents 10129ea + 515c962 commit de9b24a
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
8 changes: 7 additions & 1 deletion ILSpy/Controls/ResourceObjectTable.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Label Content="{x:Static properties:Resources.OtherResources}"
FontFamily="Segoe UI"
FontWeight="Bold"
FontSize="12pt" />
<local:SearchBox x:Name="resourceFilterBox"
FontFamily="Segoe UI"
FontSize="9pt"
Grid.Row="1"
TextChanged="OnFilterTextChanged" />
<ListView Name="resourceListView"
FontFamily="Segoe UI"
FontSize="9pt"
Foreground="Black"
Grid.Row="1"
Grid.Row="2"
AlternationCount="2"
ItemContainerStyle="{StaticResource alternatingWithBinding}"
local:SortableGridViewColumn.SortMode="Automatic">
Expand Down
29 changes: 28 additions & 1 deletion ILSpy/Controls/ResourceObjectTable.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;

namespace ICSharpCode.ILSpy.Controls
Expand All @@ -30,6 +33,9 @@ namespace ICSharpCode.ILSpy.Controls
/// </summary>
public partial class ResourceObjectTable : UserControl
{
ICollectionView filteredView;
string filter;

public ResourceObjectTable(IEnumerable resources, FrameworkElement container)
{
InitializeComponent();
Expand All @@ -38,7 +44,22 @@ public ResourceObjectTable(IEnumerable resources, FrameworkElement container)
if (!double.IsNaN(container.ActualWidth))
Width = Math.Max(container.ActualWidth - 45, 0);
MaxHeight = container.ActualHeight;
resourceListView.ItemsSource = resources;

filteredView = CollectionViewSource.GetDefaultView(resources);
filteredView.Filter = OnResourceFilter;
resourceListView.ItemsSource = filteredView;
}

private bool OnResourceFilter(object obj)
{
if (string.IsNullOrEmpty(filter))
return true;

if (obj is TreeNodes.ResourcesFileTreeNode.SerializedObjectRepresentation item)
return item.Key?.Contains(filter, StringComparison.OrdinalIgnoreCase) == true ||
item.Value?.Contains(filter, StringComparison.OrdinalIgnoreCase) == true;

return false; // make it obvious search is not working
}

private void OnParentSizeChanged(object sender, SizeChangedEventArgs e)
Expand All @@ -49,6 +70,12 @@ private void OnParentSizeChanged(object sender, SizeChangedEventArgs e)
MaxHeight = e.NewSize.Height;
}

private void OnFilterTextChanged(object sender, TextChangedEventArgs e)
{
filter = resourceFilterBox.Text;
filteredView?.Refresh();
}

void ExecuteCopy(object sender, ExecutedRoutedEventArgs args)
{
StringBuilder sb = new StringBuilder();
Expand Down
8 changes: 7 additions & 1 deletion ILSpy/Controls/ResourceStringTable.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Label Content="{x:Static properties:Resources.StringTable}"
FontFamily="Segoe UI"
FontWeight="Bold"
FontSize="12pt" />
<local:SearchBox x:Name="resourceFilterBox"
FontFamily="Segoe UI"
FontSize="9pt"
Grid.Row="1"
TextChanged="OnFilterTextChanged" />
<ListView Name="resourceListView"
FontFamily="Segoe UI"
FontSize="9pt"
Grid.Row="1"
Grid.Row="2"
AlternationCount="2"
ItemContainerStyle="{StaticResource alternatingWithBinding}"
local:SortableGridViewColumn.SortMode="Automatic">
Expand Down
29 changes: 28 additions & 1 deletion ILSpy/Controls/ResourceStringTable.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;

namespace ICSharpCode.ILSpy.Controls
Expand All @@ -30,6 +33,9 @@ namespace ICSharpCode.ILSpy.Controls
/// </summary>
public partial class ResourceStringTable : UserControl
{
ICollectionView filteredView;
string filter;

public ResourceStringTable(IEnumerable strings, FrameworkElement container)
{
InitializeComponent();
Expand All @@ -38,7 +44,22 @@ public ResourceStringTable(IEnumerable strings, FrameworkElement container)
if (!double.IsNaN(container.ActualWidth))
Width = Math.Max(container.ActualWidth - 45, 0);
MaxHeight = container.ActualHeight;
resourceListView.ItemsSource = strings;

filteredView = CollectionViewSource.GetDefaultView(strings);
filteredView.Filter = OnResourceFilter;
resourceListView.ItemsSource = filteredView;
}

private bool OnResourceFilter(object obj)
{
if (string.IsNullOrEmpty(filter))
return true;

if (obj is KeyValuePair<string, string> item)
return item.Key?.Contains(filter, StringComparison.OrdinalIgnoreCase) == true ||
item.Value?.Contains(filter, StringComparison.OrdinalIgnoreCase) == true;

return false; // make it obvious search is not working
}

private void OnParentSizeChanged(object sender, SizeChangedEventArgs e)
Expand All @@ -49,6 +70,12 @@ private void OnParentSizeChanged(object sender, SizeChangedEventArgs e)
MaxHeight = e.NewSize.Height;
}

private void OnFilterTextChanged(object sender, TextChangedEventArgs e)
{
filter = resourceFilterBox.Text;
filteredView?.Refresh();
}

void ExecuteCopy(object sender, ExecutedRoutedEventArgs args)
{
StringBuilder sb = new StringBuilder();
Expand Down
2 changes: 1 addition & 1 deletion ILSpy/Properties/Resources.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1058,4 +1058,4 @@
<data name="_Window" xml:space="preserve">
<value>窗口(_W)</value>
</data>
</root>
</root>

0 comments on commit de9b24a

Please sign in to comment.