Browse Source

Merge branch 'SearchResources' of https://github.com/miloush/ILSpy

pull/2990/head
Daniel Grunwald 2 years ago
parent
commit
de9b24a65c
  1. 8
      ILSpy/Controls/ResourceObjectTable.xaml
  2. 29
      ILSpy/Controls/ResourceObjectTable.xaml.cs
  3. 8
      ILSpy/Controls/ResourceStringTable.xaml
  4. 29
      ILSpy/Controls/ResourceStringTable.xaml.cs
  5. 2
      ILSpy/Properties/Resources.zh-Hans.resx

8
ILSpy/Controls/ResourceObjectTable.xaml

@ -27,16 +27,22 @@
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition /> <RowDefinition />
<RowDefinition /> <RowDefinition />
<RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Content="{x:Static properties:Resources.OtherResources}" <Label Content="{x:Static properties:Resources.OtherResources}"
FontFamily="Segoe UI" FontFamily="Segoe UI"
FontWeight="Bold" FontWeight="Bold"
FontSize="12pt" /> FontSize="12pt" />
<local:SearchBox x:Name="resourceFilterBox"
FontFamily="Segoe UI"
FontSize="9pt"
Grid.Row="1"
TextChanged="OnFilterTextChanged" />
<ListView Name="resourceListView" <ListView Name="resourceListView"
FontFamily="Segoe UI" FontFamily="Segoe UI"
FontSize="9pt" FontSize="9pt"
Foreground="Black" Foreground="Black"
Grid.Row="1" Grid.Row="2"
AlternationCount="2" AlternationCount="2"
ItemContainerStyle="{StaticResource alternatingWithBinding}" ItemContainerStyle="{StaticResource alternatingWithBinding}"
local:SortableGridViewColumn.SortMode="Automatic"> local:SortableGridViewColumn.SortMode="Automatic">

29
ILSpy/Controls/ResourceObjectTable.xaml.cs

@ -18,9 +18,12 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input; using System.Windows.Input;
namespace ICSharpCode.ILSpy.Controls namespace ICSharpCode.ILSpy.Controls
@ -30,6 +33,9 @@ namespace ICSharpCode.ILSpy.Controls
/// </summary> /// </summary>
public partial class ResourceObjectTable : UserControl public partial class ResourceObjectTable : UserControl
{ {
ICollectionView filteredView;
string filter;
public ResourceObjectTable(IEnumerable resources, FrameworkElement container) public ResourceObjectTable(IEnumerable resources, FrameworkElement container)
{ {
InitializeComponent(); InitializeComponent();
@ -38,7 +44,22 @@ namespace ICSharpCode.ILSpy.Controls
if (!double.IsNaN(container.ActualWidth)) if (!double.IsNaN(container.ActualWidth))
Width = Math.Max(container.ActualWidth - 45, 0); Width = Math.Max(container.ActualWidth - 45, 0);
MaxHeight = container.ActualHeight; 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) private void OnParentSizeChanged(object sender, SizeChangedEventArgs e)
@ -49,6 +70,12 @@ namespace ICSharpCode.ILSpy.Controls
MaxHeight = e.NewSize.Height; MaxHeight = e.NewSize.Height;
} }
private void OnFilterTextChanged(object sender, TextChangedEventArgs e)
{
filter = resourceFilterBox.Text;
filteredView?.Refresh();
}
void ExecuteCopy(object sender, ExecutedRoutedEventArgs args) void ExecuteCopy(object sender, ExecutedRoutedEventArgs args)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

8
ILSpy/Controls/ResourceStringTable.xaml

@ -27,15 +27,21 @@
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition /> <RowDefinition />
<RowDefinition /> <RowDefinition />
<RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Content="{x:Static properties:Resources.StringTable}" <Label Content="{x:Static properties:Resources.StringTable}"
FontFamily="Segoe UI" FontFamily="Segoe UI"
FontWeight="Bold" FontWeight="Bold"
FontSize="12pt" /> FontSize="12pt" />
<local:SearchBox x:Name="resourceFilterBox"
FontFamily="Segoe UI"
FontSize="9pt"
Grid.Row="1"
TextChanged="OnFilterTextChanged" />
<ListView Name="resourceListView" <ListView Name="resourceListView"
FontFamily="Segoe UI" FontFamily="Segoe UI"
FontSize="9pt" FontSize="9pt"
Grid.Row="1" Grid.Row="2"
AlternationCount="2" AlternationCount="2"
ItemContainerStyle="{StaticResource alternatingWithBinding}" ItemContainerStyle="{StaticResource alternatingWithBinding}"
local:SortableGridViewColumn.SortMode="Automatic"> local:SortableGridViewColumn.SortMode="Automatic">

29
ILSpy/Controls/ResourceStringTable.xaml.cs

@ -18,9 +18,12 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input; using System.Windows.Input;
namespace ICSharpCode.ILSpy.Controls namespace ICSharpCode.ILSpy.Controls
@ -30,6 +33,9 @@ namespace ICSharpCode.ILSpy.Controls
/// </summary> /// </summary>
public partial class ResourceStringTable : UserControl public partial class ResourceStringTable : UserControl
{ {
ICollectionView filteredView;
string filter;
public ResourceStringTable(IEnumerable strings, FrameworkElement container) public ResourceStringTable(IEnumerable strings, FrameworkElement container)
{ {
InitializeComponent(); InitializeComponent();
@ -38,7 +44,22 @@ namespace ICSharpCode.ILSpy.Controls
if (!double.IsNaN(container.ActualWidth)) if (!double.IsNaN(container.ActualWidth))
Width = Math.Max(container.ActualWidth - 45, 0); Width = Math.Max(container.ActualWidth - 45, 0);
MaxHeight = container.ActualHeight; 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) private void OnParentSizeChanged(object sender, SizeChangedEventArgs e)
@ -49,6 +70,12 @@ namespace ICSharpCode.ILSpy.Controls
MaxHeight = e.NewSize.Height; MaxHeight = e.NewSize.Height;
} }
private void OnFilterTextChanged(object sender, TextChangedEventArgs e)
{
filter = resourceFilterBox.Text;
filteredView?.Refresh();
}
void ExecuteCopy(object sender, ExecutedRoutedEventArgs args) void ExecuteCopy(object sender, ExecutedRoutedEventArgs args)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

2
ILSpy/Properties/Resources.zh-Hans.resx

@ -1058,4 +1058,4 @@
<data name="_Window" xml:space="preserve"> <data name="_Window" xml:space="preserve">
<value>窗口(_W)</value> <value>窗口(_W)</value>
</data> </data>
</root> </root>
Loading…
Cancel
Save