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

2
ICSharpCode.Decompiler/ILAst/ILAstTypes.cs

@ -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;
if (method.DeclaringType != null) {
method.DeclaringType.WriteTo(output, true, true); method.DeclaringType.WriteTo(output, true, true);
output.Write("::"); 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)

62
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,6 +142,26 @@ namespace ICSharpCode.ILSpy
MainWindow.Instance.JumpToReference(result.Member); MainWindow.Instance.JumpToReference(result.Member);
} }
} }
protected override void OnKeyDown(KeyEventArgs e)
{
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;
}
}
void SearchBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Down && listBox.HasItems) {
e.Handled = true;
listBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
listBox.SelectedIndex = 0;
}
} }
sealed class RunningSearch sealed class RunningSearch
@ -139,16 +170,20 @@ namespace ICSharpCode.ILSpy
readonly CancellationTokenSource cts = new CancellationTokenSource(); readonly CancellationTokenSource cts = new CancellationTokenSource();
readonly LoadedAssembly[] assemblies; readonly LoadedAssembly[] assemblies;
readonly string searchTerm; readonly string searchTerm;
readonly int searchMode;
readonly Language language; readonly Language language;
public readonly ObservableCollection<SearchResult> Results = new ObservableCollection<SearchResult>(); public readonly ObservableCollection<SearchResult> Results = new ObservableCollection<SearchResult>();
int resultCount; int resultCount;
public RunningSearch(LoadedAssembly[] assemblies, string searchTerm, Language language) public RunningSearch(LoadedAssembly[] assemblies, string searchTerm, int searchMode, Language language)
{ {
this.dispatcher = Dispatcher.CurrentDispatcher; this.dispatcher = Dispatcher.CurrentDispatcher;
this.assemblies = assemblies; this.assemblies = assemblies;
this.searchTerm = searchTerm; this.searchTerm = searchTerm;
this.language = language; this.language = language;
this.searchMode = searchMode;
this.Results.Add(new SearchResult { Name = "Searching..." });
} }
public void Cancel() public void Cancel()
@ -172,6 +207,10 @@ namespace ICSharpCode.ILSpy
} catch (OperationCanceledException) { } catch (OperationCanceledException) {
// ignore cancellation // ignore cancellation
} }
// remove the 'Searching...' entry
dispatcher.BeginInvoke(
DispatcherPriority.Normal,
new Action(delegate { this.Results.RemoveAt(this.Results.Count - 1); }));
} }
void AddResult(SearchResult result) void AddResult(SearchResult result)
@ -182,7 +221,7 @@ namespace ICSharpCode.ILSpy
} }
dispatcher.BeginInvoke( dispatcher.BeginInvoke(
DispatcherPriority.Normal, DispatcherPriority.Normal,
new Action(delegate { this.Results.Add(result); })); new Action(delegate { this.Results.Insert(this.Results.Count - 1, result); }));
cts.Token.ThrowIfCancellationRequested(); cts.Token.ThrowIfCancellationRequested();
} }
@ -196,7 +235,7 @@ namespace ICSharpCode.ILSpy
void PerformSearch(TypeDefinition type) void PerformSearch(TypeDefinition type)
{ {
if (IsMatch(type.Name)) { if (searchMode == SearchMode_Type && IsMatch(type.Name)) {
AddResult(new SearchResult { AddResult(new SearchResult {
Member = type, Member = type,
Image = TypeTreeNode.GetIcon(type), Image = TypeTreeNode.GetIcon(type),
@ -210,6 +249,9 @@ namespace ICSharpCode.ILSpy
PerformSearch(nestedType); PerformSearch(nestedType);
} }
if (searchMode == SearchMode_Type)
return;
foreach (FieldDefinition field in type.Fields) { foreach (FieldDefinition field in type.Fields) {
if (IsMatch(field.Name)) { if (IsMatch(field.Name)) {
AddResult(new SearchResult { AddResult(new SearchResult {
@ -257,7 +299,7 @@ namespace ICSharpCode.ILSpy
} }
} }
class SearchResult : INotifyPropertyChanged sealed class SearchResult : INotifyPropertyChanged, IMemberTreeNode
{ {
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged { event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged {
add { } add { }
@ -276,13 +318,15 @@ namespace ICSharpCode.ILSpy
return Name; 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();
} }
} }
} }

36
ILSpy/SearchPane.xaml

@ -1,12 +1,28 @@
<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>
@ -25,5 +41,5 @@
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
</DockPanel> </Grid>
</UserControl> </UserControl>
Loading…
Cancel
Save