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. 8
      ICSharpCode.Decompiler/ILAst/ILAstTypes.cs
  2. 32
      ILSpy/Images/Images.cs
  3. 3
      ILSpy/MainWindow.xaml
  4. 4
      ILSpy/MainWindow.xaml.cs
  5. 288
      ILSpy/SearchPane.cs
  6. 42
      ILSpy/SearchPane.xaml

8
ICSharpCode.Decompiler/ILAst/ILAstTypes.cs

@ -230,7 +230,7 @@ namespace ICSharpCode.Decompiler.ILAst
{ {
if (input == null) if (input == null)
throw new ArgumentNullException("Input is null!"); throw new ArgumentNullException("Input is null!");
List<ILRange> ranges = input.Where(r => r != null).OrderBy(r => r.From).ToList(); List<ILRange> ranges = input.Where(r => r != null).OrderBy(r => r.From).ToList();
for (int i = 0; i < ranges.Count - 1;) { for (int i = 0; i < ranges.Count - 1;) {
ILRange curr = ranges[i]; ILRange curr = ranges[i];
@ -424,8 +424,10 @@ namespace ICSharpCode.Decompiler.ILAst
} }
} else if (Operand is MethodReference) { } else if (Operand is MethodReference) {
MethodReference method = (MethodReference)Operand; MethodReference method = (MethodReference)Operand;
method.DeclaringType.WriteTo(output, true, true); if (method.DeclaringType != null) {
output.Write("::"); method.DeclaringType.WriteTo(output, true, true);
output.Write("::");
}
output.WriteReference(method.Name, method); output.WriteReference(method.Name, method);
} else if (Operand is FieldReference) { } else if (Operand is FieldReference) {
FieldReference field = (FieldReference)Operand; FieldReference field = (FieldReference)Operand;

32
ILSpy/Images/Images.cs

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

3
ILSpy/MainWindow.xaml

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

4
ILSpy/MainWindow.xaml.cs

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

288
ILSpy/SearchPane.cs

@ -61,9 +61,15 @@ namespace ICSharpCode.ILSpy
} }
} }
const int SearchMode_Type = 0;
const int SearchMode_Member = 1;
private SearchPane() private SearchPane()
{ {
InitializeComponent(); 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() public void Show()
@ -89,6 +95,11 @@ namespace ICSharpCode.ILSpy
((SearchPane)o).StartSearch((string)e.NewValue); ((SearchPane)o).StartSearch((string)e.NewValue);
} }
void SearchModeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
StartSearch(this.SearchTerm);
}
void StartSearch(string searchTerm) void StartSearch(string searchTerm)
{ {
if (currentSearch != null) { if (currentSearch != null) {
@ -99,7 +110,7 @@ namespace ICSharpCode.ILSpy
listBox.ItemsSource = null; listBox.ItemsSource = null;
} else { } else {
MainWindow mainWindow = MainWindow.Instance; 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; listBox.ItemsSource = currentSearch.Results;
new Thread(currentSearch.Run).Start(); new Thread(currentSearch.Run).Start();
} }
@ -118,7 +129,7 @@ namespace ICSharpCode.ILSpy
void ListBox_KeyDown(object sender, KeyEventArgs e) void ListBox_KeyDown(object sender, KeyEventArgs e)
{ {
if (e.Key == Key.Space || e.Key == Key.Return) { if (e.Key == Key.Return) {
e.Handled = true; e.Handled = true;
JumpToSelectedItem(); JumpToSelectedItem();
} }
@ -131,158 +142,191 @@ namespace ICSharpCode.ILSpy
MainWindow.Instance.JumpToReference(result.Member); 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)
{
this.dispatcher = Dispatcher.CurrentDispatcher;
this.assemblies = assemblies;
this.searchTerm = searchTerm;
this.language = language;
}
public void Cancel() protected override void OnKeyDown(KeyEventArgs e)
{ {
cts.Cancel(); base.OnKeyDown(e);
} if (e.Key == Key.T && e.KeyboardDevice.Modifiers == ModifierKeys.Control) {
searchModeComboBox.SelectedIndex = SearchMode_Type;
public void Run() e.Handled = true;
{ } else if (e.Key == Key.M && e.KeyboardDevice.Modifiers == ModifierKeys.Control) {
try { searchModeComboBox.SelectedIndex = SearchMode_Member;
foreach (var loadedAssembly in assemblies) { e.Handled = true;
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
} }
} }
void AddResult(SearchResult result) void SearchBox_PreviewKeyDown(object sender, KeyEventArgs e)
{ {
if (++resultCount == 1000) { if (e.Key == Key.Down && listBox.HasItems) {
result = new SearchResult { Name = "Search aborted, more than 1000 results found." }; e.Handled = true;
cts.Cancel(); listBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
listBox.SelectedIndex = 0;
} }
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;
} }
void PerformSearch(TypeDefinition type) sealed class RunningSearch
{ {
if (IsMatch(type.Name)) { readonly Dispatcher dispatcher;
AddResult(new SearchResult { readonly CancellationTokenSource cts = new CancellationTokenSource();
Member = type, readonly LoadedAssembly[] assemblies;
Image = TypeTreeNode.GetIcon(type), readonly string searchTerm;
Name = language.TypeToString(type, includeNamespace: false), readonly int searchMode;
LocationImage = type.DeclaringType != null ? TypeTreeNode.GetIcon(type.DeclaringType) : Images.Namespace, readonly Language language;
Location = type.DeclaringType != null ? language.TypeToString(type.DeclaringType, includeNamespace: true) : type.Namespace 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..." });
} }
foreach (TypeDefinition nestedType in type.NestedTypes) { public void Cancel()
PerformSearch(nestedType); {
cts.Cancel();
} }
foreach (FieldDefinition field in type.Fields) { public void Run()
if (IsMatch(field.Name)) { {
AddResult(new SearchResult { try {
Member = field, foreach (var loadedAssembly in assemblies) {
Image = FieldTreeNode.GetIcon(field), AssemblyDefinition asm = loadedAssembly.AssemblyDefinition;
Name = field.Name, if (asm == null)
LocationImage = TypeTreeNode.GetIcon(type), continue;
Location = language.TypeToString(type, includeNamespace: true) 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); }));
} }
foreach (PropertyDefinition property in type.Properties) {
if (IsMatch(property.Name)) { void AddResult(SearchResult result)
AddResult(new SearchResult { {
Member = property, if (++resultCount == 1000) {
Image = PropertyTreeNode.GetIcon(property), result = new SearchResult { Name = "Search aborted, more than 1000 results found." };
Name = property.Name, cts.Cancel();
LocationImage = TypeTreeNode.GetIcon(type),
Location = language.TypeToString(type, includeNamespace: true)
});
} }
dispatcher.BeginInvoke(
DispatcherPriority.Normal,
new Action(delegate { this.Results.Insert(this.Results.Count - 1, result); }));
cts.Token.ThrowIfCancellationRequested();
} }
foreach (EventDefinition ev in type.Events) {
if (IsMatch(ev.Name)) { bool IsMatch(string text)
AddResult(new SearchResult { {
Member = ev, if (text.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) >= 0)
Image = EventTreeNode.GetIcon(ev), return true;
Name = ev.Name, else
LocationImage = TypeTreeNode.GetIcon(type), return false;
Location = language.TypeToString(type, includeNamespace: true)
});
}
} }
foreach (MethodDefinition method in type.Methods) {
if (IsMatch(method.Name)) { void PerformSearch(TypeDefinition type)
{
if (searchMode == SearchMode_Type && IsMatch(type.Name)) {
AddResult(new SearchResult { AddResult(new SearchResult {
Member = method, Member = type,
Image = MethodTreeNode.GetIcon(method), Image = TypeTreeNode.GetIcon(type),
Name = method.Name, Name = language.TypeToString(type, includeNamespace: false),
LocationImage = TypeTreeNode.GetIcon(type), LocationImage = type.DeclaringType != null ? TypeTreeNode.GetIcon(type.DeclaringType) : Images.Namespace,
Location = language.TypeToString(type, includeNamespace: true) Location = type.DeclaringType != null ? language.TypeToString(type.DeclaringType, includeNamespace: true) : type.Namespace
}); });
} }
foreach (TypeDefinition nestedType in type.NestedTypes) {
PerformSearch(nestedType);
}
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 (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 { }
}
public MemberReference Member { get; set; }
public string Location { get; set; } sealed class SearchResult : INotifyPropertyChanged, IMemberTreeNode
public string Name { get; set; }
public ImageSource Image { get; set; }
public ImageSource LocationImage { get; set; }
public override string ToString()
{ {
return Name; event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged {
add { }
remove { }
}
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 override string ToString()
{
return Name;
}
} }
} }
[ExportMainMenuCommand(Menu = "_View", Header = "_Search", MenuIcon="Images/Find.png", MenuCategory = "ShowPane", MenuOrder = 100)] [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 @@
<UserControl x:Class="ICSharpCode.ILSpy.SearchPane" <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">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <Grid>
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" <Grid.RowDefinitions>
xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls" <RowDefinition Height="21" />
x:Name="self"> <RowDefinition Height="*" />
<DockPanel> </Grid.RowDefinitions>
<controls:SearchBox DockPanel.Dock="Top" WatermarkText="Search" WatermarkColor="Gray" ToolTip="Search" <Grid.ColumnDefinitions>
Text="{Binding SearchTerm, ElementName=self}" x:Name="searchBox" /> <ColumnDefinition Width="*" />
<ListBox Name="listBox" HorizontalContentAlignment="Stretch" SelectionMode="Single" MouseDoubleClick="ListBox_MouseDoubleClick" KeyDown="ListBox_KeyDown"> <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> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/> <ColumnDefinition Width="20" />
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Image Width="16" Height="16" Source="{Binding Image}" HorizontalAlignment="Left" /> <Image Width="16" Height="16" Source="{Binding Image}" HorizontalAlignment="Left" />
<TextBlock Text="{Binding Name}" Grid.Column="1" /> <TextBlock Text="{Binding Name}" Grid.Column="1" />
@ -25,5 +41,5 @@
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
</DockPanel> </Grid>
</UserControl> </UserControl>
Loading…
Cancel
Save