Browse Source

Merge branch 'master' of git://github.com/icsharpcode/ILSpy into Debugger

pull/191/merge
Eusebiu Marcu 14 years ago
parent
commit
a0f2bee87d
  1. 6
      ICSharpCode.Decompiler/ILAst/ILAstTypes.cs
  2. 32
      ILSpy/Images/Images.cs
  3. 3
      ILSpy/MainWindow.xaml
  4. 4
      ILSpy/MainWindow.xaml.cs
  5. 280
      ILSpy/SearchPane.cs
  6. 42
      ILSpy/SearchPane.xaml

6
ICSharpCode.Decompiler/ILAst/ILAstTypes.cs

@ -424,8 +424,10 @@ namespace ICSharpCode.Decompiler.ILAst @@ -424,8 +424,10 @@ namespace ICSharpCode.Decompiler.ILAst
}
} else if (Operand is MethodReference) {
MethodReference method = (MethodReference)Operand;
method.DeclaringType.WriteTo(output, true, true);
output.Write("::");
if (method.DeclaringType != null) {
method.DeclaringType.WriteTo(output, true, true);
output.Write("::");
}
output.WriteReference(method.Name, method);
} else if (Operand is FieldReference) {
FieldReference field = (FieldReference)Operand;

32
ILSpy/Images/Images.cs

@ -67,22 +67,22 @@ namespace ICSharpCode.ILSpy @@ -67,22 +67,22 @@ namespace ICSharpCode.ILSpy
public static readonly BitmapImage Enum = LoadBitmap("Enum");
private static readonly BitmapImage Field = LoadBitmap("Field");
private static readonly BitmapImage FieldReadOnly = LoadBitmap("FieldReadOnly");
private static readonly BitmapImage Literal = LoadBitmap("Literal");
private static readonly BitmapImage EnumValue = LoadBitmap("EnumValue");
private static readonly BitmapImage Method = LoadBitmap("Method");
private static readonly BitmapImage Constructor = LoadBitmap("Constructor");
private static readonly BitmapImage VirtualMethod = LoadBitmap("VirtualMethod");
private static readonly BitmapImage Operator = LoadBitmap("Operator");
private static readonly BitmapImage ExtensionMethod = LoadBitmap("ExtensionMethod");
private static readonly BitmapImage PInvokeMethod = LoadBitmap("PInvokeMethod");
private static readonly BitmapImage Property = LoadBitmap("Property");
private static readonly BitmapImage Indexer = LoadBitmap("Indexer");
private static readonly BitmapImage Event = LoadBitmap("Event");
public static readonly BitmapImage Field = LoadBitmap("Field");
public static readonly BitmapImage FieldReadOnly = LoadBitmap("FieldReadOnly");
public static readonly BitmapImage Literal = LoadBitmap("Literal");
public static readonly BitmapImage EnumValue = LoadBitmap("EnumValue");
public static readonly BitmapImage Method = LoadBitmap("Method");
public static readonly BitmapImage Constructor = LoadBitmap("Constructor");
public static readonly BitmapImage VirtualMethod = LoadBitmap("VirtualMethod");
public static readonly BitmapImage Operator = LoadBitmap("Operator");
public static readonly BitmapImage ExtensionMethod = LoadBitmap("ExtensionMethod");
public static readonly BitmapImage PInvokeMethod = LoadBitmap("PInvokeMethod");
public static readonly BitmapImage Property = LoadBitmap("Property");
public static readonly BitmapImage Indexer = LoadBitmap("Indexer");
public static readonly BitmapImage Event = LoadBitmap("Event");
private static readonly BitmapImage OverlayProtected = LoadBitmap("OverlayProtected");
private static readonly BitmapImage OverlayInternal = LoadBitmap("OverlayInternal");

3
ILSpy/MainWindow.xaml

@ -33,6 +33,9 @@ @@ -33,6 +33,9 @@
Command="BrowseForward"
CanExecute="ForwardCommandCanExecute"
Executed="ForwardCommandExecuted" />
<CommandBinding
Command="Search"
Executed="SearchCommandExecuted" />
</Window.CommandBindings>
<DockPanel>
<!-- Main menu -->

4
ILSpy/MainWindow.xaml.cs

@ -506,6 +506,10 @@ namespace ICSharpCode.ILSpy @@ -506,6 +506,10 @@ namespace ICSharpCode.ILSpy
}
}
void SearchCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
SearchPane.Instance.Show();
}
#endregion
#region Decompile (TreeView_SelectionChanged)

280
ILSpy/SearchPane.cs

@ -61,9 +61,15 @@ namespace ICSharpCode.ILSpy @@ -61,9 +61,15 @@ namespace ICSharpCode.ILSpy
}
}
const int SearchMode_Type = 0;
const int SearchMode_Member = 1;
private SearchPane()
{
InitializeComponent();
searchModeComboBox.Items.Add(new { Image = Images.Class, Name = "Type" });
searchModeComboBox.Items.Add(new { Image = Images.Property, Name = "Member" });
searchModeComboBox.SelectedIndex = SearchMode_Type;
}
public void Show()
@ -89,6 +95,11 @@ namespace ICSharpCode.ILSpy @@ -89,6 +95,11 @@ namespace ICSharpCode.ILSpy
((SearchPane)o).StartSearch((string)e.NewValue);
}
void SearchModeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
StartSearch(this.SearchTerm);
}
void StartSearch(string searchTerm)
{
if (currentSearch != null) {
@ -99,7 +110,7 @@ namespace ICSharpCode.ILSpy @@ -99,7 +110,7 @@ namespace ICSharpCode.ILSpy
listBox.ItemsSource = null;
} else {
MainWindow mainWindow = MainWindow.Instance;
currentSearch = new RunningSearch(mainWindow.CurrentAssemblyList.GetAssemblies(), searchTerm, mainWindow.CurrentLanguage);
currentSearch = new RunningSearch(mainWindow.CurrentAssemblyList.GetAssemblies(), searchTerm, searchModeComboBox.SelectedIndex, mainWindow.CurrentLanguage);
listBox.ItemsSource = currentSearch.Results;
new Thread(currentSearch.Run).Start();
}
@ -118,7 +129,7 @@ namespace ICSharpCode.ILSpy @@ -118,7 +129,7 @@ namespace ICSharpCode.ILSpy
void ListBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space || e.Key == Key.Return) {
if (e.Key == Key.Return) {
e.Handled = true;
JumpToSelectedItem();
}
@ -131,158 +142,191 @@ namespace ICSharpCode.ILSpy @@ -131,158 +142,191 @@ namespace ICSharpCode.ILSpy
MainWindow.Instance.JumpToReference(result.Member);
}
}
}
sealed class RunningSearch
{
readonly Dispatcher dispatcher;
readonly CancellationTokenSource cts = new CancellationTokenSource();
readonly LoadedAssembly[] assemblies;
readonly string searchTerm;
readonly Language language;
public readonly ObservableCollection<SearchResult> Results = new ObservableCollection<SearchResult>();
int resultCount;
public RunningSearch(LoadedAssembly[] assemblies, string searchTerm, Language language)
protected override void OnKeyDown(KeyEventArgs e)
{
this.dispatcher = Dispatcher.CurrentDispatcher;
this.assemblies = assemblies;
this.searchTerm = searchTerm;
this.language = language;
base.OnKeyDown(e);
if (e.Key == Key.T && e.KeyboardDevice.Modifiers == ModifierKeys.Control) {
searchModeComboBox.SelectedIndex = SearchMode_Type;
e.Handled = true;
} else if (e.Key == Key.M && e.KeyboardDevice.Modifiers == ModifierKeys.Control) {
searchModeComboBox.SelectedIndex = SearchMode_Member;
e.Handled = true;
}
}
public void Cancel()
void SearchBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
cts.Cancel();
if (e.Key == Key.Down && listBox.HasItems) {
e.Handled = true;
listBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
listBox.SelectedIndex = 0;
}
}
public void Run()
sealed class RunningSearch
{
try {
foreach (var loadedAssembly in assemblies) {
AssemblyDefinition asm = loadedAssembly.AssemblyDefinition;
if (asm == null)
continue;
CancellationToken cancellationToken = cts.Token;
foreach (TypeDefinition type in asm.MainModule.Types) {
cancellationToken.ThrowIfCancellationRequested();
PerformSearch(type);
}
}
} catch (OperationCanceledException) {
// ignore cancellation
readonly Dispatcher dispatcher;
readonly CancellationTokenSource cts = new CancellationTokenSource();
readonly LoadedAssembly[] assemblies;
readonly string searchTerm;
readonly int searchMode;
readonly Language language;
public readonly ObservableCollection<SearchResult> Results = new ObservableCollection<SearchResult>();
int resultCount;
public RunningSearch(LoadedAssembly[] assemblies, string searchTerm, int searchMode, Language language)
{
this.dispatcher = Dispatcher.CurrentDispatcher;
this.assemblies = assemblies;
this.searchTerm = searchTerm;
this.language = language;
this.searchMode = searchMode;
this.Results.Add(new SearchResult { Name = "Searching..." });
}
}
void AddResult(SearchResult result)
{
if (++resultCount == 1000) {
result = new SearchResult { Name = "Search aborted, more than 1000 results found." };
public void Cancel()
{
cts.Cancel();
}
dispatcher.BeginInvoke(
DispatcherPriority.Normal,
new Action(delegate { this.Results.Add(result); }));
cts.Token.ThrowIfCancellationRequested();
}
bool IsMatch(string text)
{
if (text.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) >= 0)
return true;
else
return false;
}
public void Run()
{
try {
foreach (var loadedAssembly in assemblies) {
AssemblyDefinition asm = loadedAssembly.AssemblyDefinition;
if (asm == null)
continue;
CancellationToken cancellationToken = cts.Token;
foreach (TypeDefinition type in asm.MainModule.Types) {
cancellationToken.ThrowIfCancellationRequested();
PerformSearch(type);
}
}
} catch (OperationCanceledException) {
// ignore cancellation
}
// remove the 'Searching...' entry
dispatcher.BeginInvoke(
DispatcherPriority.Normal,
new Action(delegate { this.Results.RemoveAt(this.Results.Count - 1); }));
}
void PerformSearch(TypeDefinition type)
{
if (IsMatch(type.Name)) {
AddResult(new SearchResult {
Member = type,
Image = TypeTreeNode.GetIcon(type),
Name = language.TypeToString(type, includeNamespace: false),
LocationImage = type.DeclaringType != null ? TypeTreeNode.GetIcon(type.DeclaringType) : Images.Namespace,
Location = type.DeclaringType != null ? language.TypeToString(type.DeclaringType, includeNamespace: true) : type.Namespace
});
void AddResult(SearchResult result)
{
if (++resultCount == 1000) {
result = new SearchResult { Name = "Search aborted, more than 1000 results found." };
cts.Cancel();
}
dispatcher.BeginInvoke(
DispatcherPriority.Normal,
new Action(delegate { this.Results.Insert(this.Results.Count - 1, result); }));
cts.Token.ThrowIfCancellationRequested();
}
foreach (TypeDefinition nestedType in type.NestedTypes) {
PerformSearch(nestedType);
bool IsMatch(string text)
{
if (text.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) >= 0)
return true;
else
return false;
}
foreach (FieldDefinition field in type.Fields) {
if (IsMatch(field.Name)) {
void PerformSearch(TypeDefinition type)
{
if (searchMode == SearchMode_Type && IsMatch(type.Name)) {
AddResult(new SearchResult {
Member = field,
Image = FieldTreeNode.GetIcon(field),
Name = field.Name,
LocationImage = TypeTreeNode.GetIcon(type),
Location = language.TypeToString(type, includeNamespace: true)
Member = type,
Image = TypeTreeNode.GetIcon(type),
Name = language.TypeToString(type, includeNamespace: false),
LocationImage = type.DeclaringType != null ? TypeTreeNode.GetIcon(type.DeclaringType) : Images.Namespace,
Location = type.DeclaringType != null ? language.TypeToString(type.DeclaringType, includeNamespace: true) : type.Namespace
});
}
}
foreach (PropertyDefinition property in type.Properties) {
if (IsMatch(property.Name)) {
AddResult(new SearchResult {
Member = property,
Image = PropertyTreeNode.GetIcon(property),
Name = property.Name,
LocationImage = TypeTreeNode.GetIcon(type),
Location = language.TypeToString(type, includeNamespace: true)
});
foreach (TypeDefinition nestedType in type.NestedTypes) {
PerformSearch(nestedType);
}
}
foreach (EventDefinition ev in type.Events) {
if (IsMatch(ev.Name)) {
AddResult(new SearchResult {
Member = ev,
Image = EventTreeNode.GetIcon(ev),
Name = ev.Name,
LocationImage = TypeTreeNode.GetIcon(type),
Location = language.TypeToString(type, includeNamespace: true)
});
if (searchMode == SearchMode_Type)
return;
foreach (FieldDefinition field in type.Fields) {
if (IsMatch(field.Name)) {
AddResult(new SearchResult {
Member = field,
Image = FieldTreeNode.GetIcon(field),
Name = field.Name,
LocationImage = TypeTreeNode.GetIcon(type),
Location = language.TypeToString(type, includeNamespace: true)
});
}
}
}
foreach (MethodDefinition method in type.Methods) {
if (IsMatch(method.Name)) {
AddResult(new SearchResult {
Member = method,
Image = MethodTreeNode.GetIcon(method),
Name = method.Name,
LocationImage = TypeTreeNode.GetIcon(type),
Location = language.TypeToString(type, includeNamespace: true)
});
foreach (PropertyDefinition property in type.Properties) {
if (IsMatch(property.Name)) {
AddResult(new SearchResult {
Member = property,
Image = PropertyTreeNode.GetIcon(property),
Name = property.Name,
LocationImage = TypeTreeNode.GetIcon(type),
Location = language.TypeToString(type, includeNamespace: true)
});
}
}
foreach (EventDefinition ev in type.Events) {
if (IsMatch(ev.Name)) {
AddResult(new SearchResult {
Member = ev,
Image = EventTreeNode.GetIcon(ev),
Name = ev.Name,
LocationImage = TypeTreeNode.GetIcon(type),
Location = language.TypeToString(type, includeNamespace: true)
});
}
}
foreach (MethodDefinition method in type.Methods) {
if (IsMatch(method.Name)) {
AddResult(new SearchResult {
Member = method,
Image = MethodTreeNode.GetIcon(method),
Name = method.Name,
LocationImage = TypeTreeNode.GetIcon(type),
Location = language.TypeToString(type, includeNamespace: true)
});
}
}
}
}
}
class SearchResult : INotifyPropertyChanged
{
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged {
add { }
remove { }
}
sealed class SearchResult : INotifyPropertyChanged, IMemberTreeNode
{
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged {
add { }
remove { }
}
public MemberReference Member { get; set; }
public MemberReference Member { get; set; }
public string Location { get; set; }
public string Name { get; set; }
public ImageSource Image { get; set; }
public ImageSource LocationImage { get; set; }
public string Location { get; set; }
public string Name { get; set; }
public ImageSource Image { get; set; }
public ImageSource LocationImage { get; set; }
public override string ToString()
{
return Name;
public override string ToString()
{
return Name;
}
}
}
[ExportMainMenuCommand(Menu = "_View", Header = "_Search", MenuIcon="Images/Find.png", MenuCategory = "ShowPane", MenuOrder = 100)]
sealed class ShowSearchCommand : SimpleCommand
[ExportToolbarCommand(ToolTip = "Search (F3)", ToolbarIcon = "Images/Find.png", ToolbarCategory = "View", ToolbarOrder = 100)]
sealed class ShowSearchCommand : CommandWrapper
{
public override void Execute(object parameter)
public ShowSearchCommand()
: base(NavigationCommands.Search)
{
SearchPane.Instance.Show();
}
}
}

42
ILSpy/SearchPane.xaml

@ -1,19 +1,35 @@ @@ -1,19 +1,35 @@
<UserControl x:Class="ICSharpCode.ILSpy.SearchPane"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls"
x:Name="self">
<DockPanel>
<controls:SearchBox DockPanel.Dock="Top" WatermarkText="Search" WatermarkColor="Gray" ToolTip="Search"
Text="{Binding SearchTerm, ElementName=self}" x:Name="searchBox" />
<ListBox Name="listBox" HorizontalContentAlignment="Stretch" SelectionMode="Single" MouseDoubleClick="ListBox_MouseDoubleClick" KeyDown="ListBox_KeyDown">
<UserControl x:Class="ICSharpCode.ILSpy.SearchPane" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls" x:Name="self">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="21" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<controls:SearchBox DockPanel.Dock="Top" WatermarkText="Search" WatermarkColor="Gray" ToolTip="Search" Text="{Binding SearchTerm, ElementName=self}" x:Name="searchBox" Grid.Column="0" Grid.Row="0" UpdateDelay="0:0:0.1" PreviewKeyDown="SearchBox_PreviewKeyDown" />
<StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal">
<Label Margin="0,-1">Search _for:</Label>
<ComboBox Name="searchModeComboBox" Width="100" SelectionChanged="SearchModeComboBox_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Width="16" Height="16" Source="{Binding Image}" Margin="0,0,4,0" />
<TextBlock Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
<ListBox Name="listBox" HorizontalContentAlignment="Stretch" SelectionMode="Single" MouseDoubleClick="ListBox_MouseDoubleClick" KeyDown="ListBox_KeyDown" Grid.Row="1" Grid.ColumnSpan="2">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Width="16" Height="16" Source="{Binding Image}" HorizontalAlignment="Left" />
<TextBlock Text="{Binding Name}" Grid.Column="1" />
@ -25,5 +41,5 @@ @@ -25,5 +41,5 @@
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
</Grid>
</UserControl>
Loading…
Cancel
Save