Browse Source

Merge remote-tracking branch 'origin/master' into newdecompiler.

Note: due to massive conflicts, this merge effectively reverts Christoph's ILSpy.AddIn commits from 2017-03-05.
pull/863/head
Daniel Grunwald 9 years ago
parent
commit
f54c621ec4
  1. 3
      ICSharpCode.Decompiler/Output/TextTokenWriter.cs
  2. 2
      ILSpy.AddIn/license.txt
  3. 2
      ILSpy/ContextMenuEntry.cs
  4. 3
      ILSpy/ILSpy.csproj
  5. BIN
      ILSpy/Images/Copy.png
  6. BIN
      ILSpy/Images/Library.png
  7. BIN
      ILSpy/Images/OverlayStatic.png
  8. BIN
      ILSpy/Images/SearchMsdn.png
  9. 17
      ILSpy/Languages/CSharpLanguage.cs
  10. 9
      ILSpy/Languages/Language.cs
  11. 14
      ILSpy/LoadedAssembly.cs
  12. 11
      ILSpy/MainWindow.xaml
  13. 35
      ILSpy/MainWindow.xaml.cs
  14. 1
      ILSpy/SearchPane.xaml
  15. 17
      ILSpy/TextView/DecompilerTextView.cs
  16. 2
      ILSpy/TextView/DecompilerTextView.xaml
  17. 2
      ILSpy/TreeNodes/Analyzer/AnalyzeContextMenuEntry.cs
  18. 2
      ILSpy/TreeNodes/Analyzer/RemoveAnalyzeContextMenuEntry.cs
  19. 6
      ILSpy/TreeNodes/AssemblyTreeNode.cs
  20. 42
      ILSpy/TreeNodes/CopyFullyQualifiedTypeNameContextMenuEntry.cs
  21. 4
      ILSpy/TreeNodes/MethodTreeNode.cs
  22. 33
      ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs
  23. 2
      ILSpy/TreeNodes/SearchMsdnContextMenuEntry.cs
  24. 10
      ILSpy/VB/VBLanguage.cs
  25. 8
      SharpTreeView/ICSharpCode.TreeView.csproj
  26. 6
      SharpTreeView/SharpTreeView.cs
  27. 21
      SharpTreeView/SharpTreeViewAutomationPeer.cs
  28. 5
      SharpTreeView/SharpTreeViewItem.cs
  29. 77
      SharpTreeView/SharpTreeViewItemAutomationPeer.cs

3
ICSharpCode.Decompiler/Output/TextTokenWriter.cs

@ -191,7 +191,8 @@ namespace ICSharpCode.Decompiler
public override void WriteKeyword(Role role, string keyword) public override void WriteKeyword(Role role, string keyword)
{ {
if (keyword == "this" || keyword == "base") { //To make reference for 'this' and 'base' keywords in the ClassName():this() expression
if (role == ConstructorInitializer.ThisKeywordRole || role == ConstructorInitializer.BaseKeywordRole) {
if (nodeStack.Peek() is ConstructorInitializer initializer && initializer.GetSymbol() is IMember member) { if (nodeStack.Peek() is ConstructorInitializer initializer && initializer.GetSymbol() is IMember member) {
var cecil = typeSystem.GetCecil(member); var cecil = typeSystem.GetCecil(member);
if (cecil != null) { if (cecil != null) {

2
ILSpy.AddIn/license.txt

@ -3,7 +3,7 @@ The following MIT license applies to ILSpy, NRefactory and ICSharpCode.Decompile
MIT license: MIT license:
Copyright (c) 2011-2016 AlphaSierraPapa for the SharpDevelop team Copyright (c) 2011-2017 AlphaSierraPapa for the SharpDevelop team
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

2
ILSpy/ContextMenuEntry.cs

@ -109,6 +109,8 @@ namespace ICSharpCode.ILSpy
public ExportContextMenuEntryAttribute() public ExportContextMenuEntryAttribute()
: base(typeof(IContextMenuEntry)) : base(typeof(IContextMenuEntry))
{ {
// entries default to end of menu unless given specific order position
Order = double.MaxValue;
} }
public string Icon { get; set; } public string Icon { get; set; }

3
ILSpy/ILSpy.csproj

@ -191,6 +191,7 @@
<Compile Include="TreeNodes\Analyzer\Helpers.cs" /> <Compile Include="TreeNodes\Analyzer\Helpers.cs" />
<Compile Include="TreeNodes\Analyzer\ScopedWhereUsedAnalyzer.cs" /> <Compile Include="TreeNodes\Analyzer\ScopedWhereUsedAnalyzer.cs" />
<Compile Include="TreeNodes\BaseTypesEntryNode.cs" /> <Compile Include="TreeNodes\BaseTypesEntryNode.cs" />
<Compile Include="TreeNodes\CopyFullyQualifiedTypeNameContextMenuEntry.cs" />
<Compile Include="TreeNodes\DerivedTypesEntryNode.cs" /> <Compile Include="TreeNodes\DerivedTypesEntryNode.cs" />
<Compile Include="TreeNodes\FilterResult.cs" /> <Compile Include="TreeNodes\FilterResult.cs" />
<Compile Include="TreeNodes\IMemberTreeNode.cs" /> <Compile Include="TreeNodes\IMemberTreeNode.cs" />
@ -348,6 +349,8 @@
<ItemGroup> <ItemGroup>
<Resource Include="Images\Sort.png" /> <Resource Include="Images\Sort.png" />
<Resource Include="Images\SearchMsdn.png" />
<Resource Include="Images\Copy.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

BIN
ILSpy/Images/Copy.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 469 B

BIN
ILSpy/Images/Library.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 B

After

Width:  |  Height:  |  Size: 417 B

BIN
ILSpy/Images/OverlayStatic.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 315 B

After

Width:  |  Height:  |  Size: 347 B

BIN
ILSpy/Images/SearchMsdn.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 710 B

17
ILSpy/Languages/CSharpLanguage.cs

@ -377,7 +377,7 @@ namespace ICSharpCode.ILSpy
return base.WriteResourceToFile(fileName, resourceName, entryStream); return base.WriteResourceToFile(fileName, resourceName, entryStream);
} }
} }
/* /*
AstBuilder CreateAstBuilder(DecompilationOptions options, ModuleDefinition currentModule = null, TypeDefinition currentType = null, bool isSingleMember = false) AstBuilder CreateAstBuilder(DecompilationOptions options, ModuleDefinition currentModule = null, TypeDefinition currentType = null, bool isSingleMember = false)
{ {
@ -421,10 +421,12 @@ namespace ICSharpCode.ILSpy
((ComposedType)astType).PointerRank--; ((ComposedType)astType).PointerRank--;
} }
astType.AcceptVisitor(new CSharpOutputVisitor(w, FormattingOptionsFactory.CreateAllman())); astType.AcceptVisitor(new CSharpOutputVisitor(w, TypeToStringFormattingOptions));
return w.ToString(); return w.ToString();
} }
*/ static readonly CSharpFormattingOptions TypeToStringFormattingOptions = FormattingOptionsFactory.CreateEmpty();
*/
public override string FormatPropertyName(PropertyDefinition property, bool? isIndexer) public override string FormatPropertyName(PropertyDefinition property, bool? isIndexer)
{ {
if (property == null) if (property == null)
@ -455,6 +457,15 @@ namespace ICSharpCode.ILSpy
} else } else
return property.Name; return property.Name;
} }
public override string FormatMethodName(MethodDefinition method)
{
if (method == null)
throw new ArgumentNullException("method");
return (method.IsConstructor) ? method.DeclaringType.Name : method.Name;
}
/* /*
public override string FormatTypeName(TypeDefinition type) public override string FormatTypeName(TypeDefinition type)
{ {

9
ILSpy/Languages/Language.cs

@ -133,7 +133,14 @@ namespace ICSharpCode.ILSpy
throw new ArgumentNullException(nameof(property)); throw new ArgumentNullException(nameof(property));
return property.Name; return property.Name;
} }
public virtual string FormatMethodName(MethodDefinition method)
{
if (method == null)
throw new ArgumentNullException("method");
return method.Name;
}
public virtual string FormatTypeName(TypeDefinition type) public virtual string FormatTypeName(TypeDefinition type)
{ {
if (type == null) if (type == null)

14
ILSpy/LoadedAssembly.cs

@ -143,6 +143,20 @@ namespace ICSharpCode.ILSpy
private void LoadSymbols(ModuleDefinition module) private void LoadSymbols(ModuleDefinition module)
{ {
if (!module.HasDebugHeader) {
return;
}
byte[] headerBytes;
var debugHeader = module.GetDebugHeader(out headerBytes);
if (debugHeader.Type != 2) {
// the debug type is not IMAGE_DEBUG_TYPE_CODEVIEW
return;
}
if (debugHeader.MajorVersion != 0 || debugHeader.MinorVersion != 0) {
// the PDB type is not compatible with PdbReaderProvider. It is probably a Portable PDB
return;
}
// search for pdb in same directory as dll // search for pdb in same directory as dll
string pdbName = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + ".pdb"); string pdbName = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + ".pdb");
if (File.Exists(pdbName)) { if (File.Exists(pdbName)) {

11
ILSpy/MainWindow.xaml

@ -44,7 +44,7 @@
</Window.TaskbarItemInfo> </Window.TaskbarItemInfo>
<DockPanel> <DockPanel>
<!-- Main menu --> <!-- Main menu -->
<Menu DockPanel.Dock="Top" Name="mainMenu" Height="23"> <Menu DockPanel.Dock="Top" Name="mainMenu" Height="23" KeyboardNavigation.TabNavigation="None">
<MenuItem Header="_File" /> <!-- contents of file menu are added using MEF --> <MenuItem Header="_File" /> <!-- contents of file menu are added using MEF -->
<MenuItem Header="_View"> <MenuItem Header="_View">
<MenuItem Header="Show _internal types and members" IsCheckable="True" IsChecked="{Binding FilterSettings.ShowInternalApi}"> <MenuItem Header="Show _internal types and members" IsCheckable="True" IsChecked="{Binding FilterSettings.ShowInternalApi}">
@ -57,7 +57,7 @@
<!-- ToolBar --> <!-- ToolBar -->
<ToolBar <ToolBar
Name="toolBar" Name="toolBar"
DockPanel.Dock="Top" ToolBarTray.IsLocked="True"> DockPanel.Dock="Top" ToolBarTray.IsLocked="True" KeyboardNavigation.TabNavigation="None">
<ToolBar.Resources> <ToolBar.Resources>
<!-- Make images transparent if menu command is disabled --> <!-- Make images transparent if menu command is disabled -->
<Style TargetType="{x:Type Image}"> <Style TargetType="{x:Type Image}">
@ -113,6 +113,7 @@
<!-- Left pane: Tree View of assemblies and classes --> <!-- Left pane: Tree View of assemblies and classes -->
<tv:SharpTreeView <tv:SharpTreeView
Name="treeView" Name="treeView"
AutomationProperties.Name="Assemblies and Classes"
SelectionChanged="TreeView_SelectionChanged" SelectionChanged="TreeView_SelectionChanged"
ShowRoot="False" ShowRoot="False"
AllowDropOrder="True" AllowDropOrder="True"
@ -142,7 +143,7 @@
<RowDefinition Height="0" Name="bottomPaneRow" /> <RowDefinition Height="0" Name="bottomPaneRow" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Border BorderBrush="Black" BorderThickness="1" Name="updatePanel" Visibility="Collapsed"> <Border BorderBrush="Black" BorderThickness="1" Name="updatePanel" Visibility="Collapsed">
<DockPanel> <DockPanel KeyboardNavigation.TabNavigation="Contained">
<Button DockPanel.Dock="Right" Click="updatePanelCloseButtonClick" MinWidth="0">X</Button> <Button DockPanel.Dock="Right" Click="updatePanelCloseButtonClick" MinWidth="0">X</Button>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Name="updatePanelMessage" Margin="4,0" VerticalAlignment="Center">A new ILSpy version is available.</TextBlock> <TextBlock Name="updatePanelMessage" Margin="4,0" VerticalAlignment="Center">A new ILSpy version is available.</TextBlock>
@ -152,6 +153,7 @@
</Border> </Border>
<controls:DockedPane x:Name="topPane" Grid.Row="1" Title="Top" Visibility="Collapsed" <controls:DockedPane x:Name="topPane" Grid.Row="1" Title="Top" Visibility="Collapsed"
AutomationProperties.Name="Close top pane"
CloseButtonClicked="TopPane_CloseButtonClicked" Margin="0,0,0,3" CloseButtonClicked="TopPane_CloseButtonClicked" Margin="0,0,0,3"
BorderThickness="1,1,0,1" /> BorderThickness="1,1,0,1" />
@ -181,8 +183,9 @@
Visibility="{Binding Visibility, ElementName=bottomPane}" /> Visibility="{Binding Visibility, ElementName=bottomPane}" />
<controls:DockedPane x:Name="bottomPane" Grid.Row="5" Title="Bottom" Visibility="Collapsed" <controls:DockedPane x:Name="bottomPane" Grid.Row="5" Title="Bottom" Visibility="Collapsed"
AutomationProperties.Name="Close"
CloseButtonClicked="BottomPane_CloseButtonClicked" Margin="0,3,0,0" BorderThickness="1,1,0,1"/> CloseButtonClicked="BottomPane_CloseButtonClicked" Margin="0,3,0,0" BorderThickness="1,1,0,1"/>
</Grid> </Grid>
</Grid> </Grid>
</DockPanel> </DockPanel>
</Window> </Window>

35
ILSpy/MainWindow.xaml.cs

@ -850,7 +850,7 @@ namespace ICSharpCode.ILSpy
sessionSettings.WindowBounds = this.RestoreBounds; sessionSettings.WindowBounds = this.RestoreBounds;
sessionSettings.SplitterPosition = leftColumn.Width.Value / (leftColumn.Width.Value + rightColumn.Width.Value); sessionSettings.SplitterPosition = leftColumn.Width.Value / (leftColumn.Width.Value + rightColumn.Width.Value);
if (topPane.Visibility == Visibility.Visible) if (topPane.Visibility == Visibility.Visible)
sessionSettings.BottomPaneSplitterPosition = topPaneRow.Height.Value / (topPaneRow.Height.Value + textViewRow.Height.Value); sessionSettings.TopPaneSplitterPosition = topPaneRow.Height.Value / (topPaneRow.Height.Value + textViewRow.Height.Value);
if (bottomPane.Visibility == Visibility.Visible) if (bottomPane.Visibility == Visibility.Visible)
sessionSettings.BottomPaneSplitterPosition = bottomPaneRow.Height.Value / (bottomPaneRow.Height.Value + textViewRow.Height.Value); sessionSettings.BottomPaneSplitterPosition = bottomPaneRow.Height.Value / (bottomPaneRow.Height.Value + textViewRow.Height.Value);
sessionSettings.Save(); sessionSettings.Save();
@ -873,10 +873,40 @@ namespace ICSharpCode.ILSpy
} }
#region Top/Bottom Pane management #region Top/Bottom Pane management
/// <summary>
/// When grid is resized using splitter, row height value could become greater than 1.
/// As result, when a new pane is shown, both textView and pane could become very small.
/// This method normalizes two rows and ensures that height is less then 1.
/// </summary>
void NormalizePaneRowHeightValues(RowDefinition pane1Row, RowDefinition pane2Row)
{
var pane1Height = pane1Row.Height;
var pane2Height = pane2Row.Height;
//only star height values are normalized.
if (!pane1Height.IsStar || !pane2Height.IsStar)
{
return;
}
var totalHeight = pane1Height.Value + pane2Height.Value;
if (totalHeight == 0)
{
return;
}
pane1Row.Height = new GridLength(pane1Height.Value / totalHeight, GridUnitType.Star);
pane2Row.Height = new GridLength(pane2Height.Value / totalHeight, GridUnitType.Star);
}
public void ShowInTopPane(string title, object content) public void ShowInTopPane(string title, object content)
{ {
topPaneRow.MinHeight = 100; topPaneRow.MinHeight = 100;
if (sessionSettings.TopPaneSplitterPosition > 0 && sessionSettings.TopPaneSplitterPosition < 1) { if (sessionSettings.TopPaneSplitterPosition > 0 && sessionSettings.TopPaneSplitterPosition < 1) {
//Ensure all 3 blocks are in fair conditions
NormalizePaneRowHeightValues(bottomPaneRow, textViewRow);
textViewRow.Height = new GridLength(1 - sessionSettings.TopPaneSplitterPosition, GridUnitType.Star); textViewRow.Height = new GridLength(1 - sessionSettings.TopPaneSplitterPosition, GridUnitType.Star);
topPaneRow.Height = new GridLength(sessionSettings.TopPaneSplitterPosition, GridUnitType.Star); topPaneRow.Height = new GridLength(sessionSettings.TopPaneSplitterPosition, GridUnitType.Star);
} }
@ -907,6 +937,9 @@ namespace ICSharpCode.ILSpy
{ {
bottomPaneRow.MinHeight = 100; bottomPaneRow.MinHeight = 100;
if (sessionSettings.BottomPaneSplitterPosition > 0 && sessionSettings.BottomPaneSplitterPosition < 1) { if (sessionSettings.BottomPaneSplitterPosition > 0 && sessionSettings.BottomPaneSplitterPosition < 1) {
//Ensure all 3 blocks are in fair conditions
NormalizePaneRowHeightValues(topPaneRow, textViewRow);
textViewRow.Height = new GridLength(1 - sessionSettings.BottomPaneSplitterPosition, GridUnitType.Star); textViewRow.Height = new GridLength(1 - sessionSettings.BottomPaneSplitterPosition, GridUnitType.Star);
bottomPaneRow.Height = new GridLength(sessionSettings.BottomPaneSplitterPosition, GridUnitType.Star); bottomPaneRow.Height = new GridLength(sessionSettings.BottomPaneSplitterPosition, GridUnitType.Star);
} }

1
ILSpy/SearchPane.xaml

@ -21,6 +21,7 @@
<StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal"> <StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal">
<Label Margin="0,-1" Target="searchModeComboBox">_Search for:</Label> <Label Margin="0,-1" Target="searchModeComboBox">_Search for:</Label>
<ComboBox Width="100" Name="searchModeComboBox" Margin="1" <ComboBox Width="100" Name="searchModeComboBox" Margin="1"
TextSearch.TextPath="Name"
SelectionChanged="SearchModeComboBox_SelectionChanged"> SelectionChanged="SearchModeComboBox_SelectionChanged">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate> <DataTemplate>

17
ILSpy/TextView/DecompilerTextView.cs

@ -28,6 +28,7 @@ using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
@ -99,6 +100,10 @@ namespace ICSharpCode.ILSpy.TextView
textEditor.SetBinding(Control.FontSizeProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFontSize") }); textEditor.SetBinding(Control.FontSizeProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFontSize") });
textEditor.SetBinding(TextEditor.WordWrapProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("EnableWordWrap") }); textEditor.SetBinding(TextEditor.WordWrapProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("EnableWordWrap") });
// disable Tab editing command (useless for read-only editor); allow using tab for focus navigation instead
RemoveEditCommand(EditingCommands.TabForward);
RemoveEditCommand(EditingCommands.TabBackward);
textMarkerService = new TextMarkerService(textEditor.TextArea.TextView); textMarkerService = new TextMarkerService(textEditor.TextArea.TextView);
textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService); textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService); textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
@ -115,7 +120,17 @@ namespace ICSharpCode.ILSpy.TextView
textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService); textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService); textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
} }
void RemoveEditCommand(RoutedUICommand command)
{
var handler = textEditor.TextArea.DefaultInputHandler.Editing;
var inputBinding = handler.InputBindings.FirstOrDefault(b => b.Command == command);
if (inputBinding != null)
handler.InputBindings.Remove(inputBinding);
var commandBinding = handler.CommandBindings.FirstOrDefault(b => b.Command == command);
if (commandBinding != null)
handler.CommandBindings.Remove(commandBinding);
}
#endregion #endregion
#region Line margin #region Line margin

2
ILSpy/TextView/DecompilerTextView.xaml

@ -8,7 +8,7 @@
<Grid> <Grid>
<Border BorderThickness="1,1,0,1" BorderBrush="#FF828790"> <Border BorderThickness="1,1,0,1" BorderBrush="#FF828790">
<Grid> <Grid>
<ae:TextEditor Name="textEditor" FontFamily="Consolas" FontSize="10pt" IsReadOnly="True" <ae:TextEditor Name="textEditor" AutomationProperties.Name="Decompilation" FontFamily="Consolas" FontSize="10pt" IsReadOnly="True"
Background="{DynamicResource {x:Static SystemColors.InfoBrushKey}}" Background="{DynamicResource {x:Static SystemColors.InfoBrushKey}}"
Foreground="{DynamicResource {x:Static SystemColors.InfoTextBrushKey}}"> Foreground="{DynamicResource {x:Static SystemColors.InfoTextBrushKey}}">
<ae:TextEditor.Resources> <ae:TextEditor.Resources>

2
ILSpy/TreeNodes/Analyzer/AnalyzeContextMenuEntry.cs

@ -21,7 +21,7 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
[ExportContextMenuEntryAttribute(Header = "Analyze", Icon = "images/Search.png")] [ExportContextMenuEntry(Header = "Analyze", Icon = "images/Search.png", Category = "Analyze", Order = 100)]
internal sealed class AnalyzeContextMenuEntry : IContextMenuEntry internal sealed class AnalyzeContextMenuEntry : IContextMenuEntry
{ {
public bool IsVisible(TextViewContext context) public bool IsVisible(TextViewContext context)

2
ILSpy/TreeNodes/Analyzer/RemoveAnalyzeContextMenuEntry.cs

@ -20,7 +20,7 @@ using System.Linq;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
[ExportContextMenuEntryAttribute(Header = "Remove", Icon = "images/Delete.png")] [ExportContextMenuEntry(Header = "Remove", Icon = "images/Delete.png", Category = "Analyze", Order = 200)]
internal sealed class RemoveAnalyzeContextMenuEntry : IContextMenuEntry internal sealed class RemoveAnalyzeContextMenuEntry : IContextMenuEntry
{ {
public bool IsVisible(TextViewContext context) public bool IsVisible(TextViewContext context)

6
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -295,7 +295,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
} }
} }
[ExportContextMenuEntryAttribute(Header = "_Remove", Icon = "images/Delete.png")] [ExportContextMenuEntry(Header = "_Remove", Icon = "images/Delete.png")]
sealed class RemoveAssembly : IContextMenuEntry sealed class RemoveAssembly : IContextMenuEntry
{ {
public bool IsVisible(TextViewContext context) public bool IsVisible(TextViewContext context)
@ -352,7 +352,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
} }
} }
[ExportContextMenuEntry(Header = "_Load Dependencies")] [ExportContextMenuEntry(Header = "_Load Dependencies", Category = "Dependencies")]
sealed class LoadDependencies : IContextMenuEntry sealed class LoadDependencies : IContextMenuEntry
{ {
public bool IsVisible(TextViewContext context) public bool IsVisible(TextViewContext context)
@ -383,7 +383,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
} }
} }
[ExportContextMenuEntry(Header = "_Add To Main List")] [ExportContextMenuEntry(Header = "_Add To Main List", Category = "Dependencies")]
sealed class AddToMainList : IContextMenuEntry sealed class AddToMainList : IContextMenuEntry
{ {
public bool IsVisible(TextViewContext context) public bool IsVisible(TextViewContext context)

42
ILSpy/TreeNodes/CopyFullyQualifiedTypeNameContextMenuEntry.cs

@ -0,0 +1,42 @@
using System.Windows;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes
{
[ExportContextMenuEntry(Header = "Copy FQ Name", Icon = "images/Copy.png", Order = 9999)]
public class CopyFullyQualifiedTypeNameContextMenuEntry : IContextMenuEntry
{
public bool IsVisible(TextViewContext context)
{
return GetTypeNodeFromContext(context) != null;
}
public bool IsEnabled(TextViewContext context) => true;
public void Execute(TextViewContext context)
{
var typeDefinition = GetTypeNodeFromContext(context)?.TypeDefinition;
if (typeDefinition == null) return;
Clipboard.SetText(GetFullyQualifiedName(typeDefinition));
}
private TypeTreeNode GetTypeNodeFromContext(TextViewContext context)
{
return context.SelectedTreeNodes?.Length == 1 ? context.SelectedTreeNodes[0] as TypeTreeNode : null;
}
/// <summary>
/// Resolve full type name using .NET type representation for nested types.
/// </summary>
private string GetFullyQualifiedName(TypeDefinition typeDefinition)
{
if (typeDefinition.IsNested)
{
return $"{GetFullyQualifiedName(typeDefinition.DeclaringType)}+{typeDefinition.Name}";
}
return $"{typeDefinition.Namespace}.{typeDefinition.Name}";
}
}
}

4
ILSpy/TreeNodes/MethodTreeNode.cs

@ -71,7 +71,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
b.Append(") : "); b.Append(") : ");
b.Append(language.TypeToString(method.ReturnType, false, method.MethodReturnType)); b.Append(language.TypeToString(method.ReturnType, false, method.MethodReturnType));
b.Append(method.MetadataToken.ToSuffixString()); b.Append(method.MetadataToken.ToSuffixString());
return HighlightSearchMatch(method.Name, b.ToString()); return HighlightSearchMatch(language.FormatMethodName(method), b.ToString());
} }
public override object Icon public override object Icon
@ -95,7 +95,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
if (method.IsSpecialName && if (method.IsSpecialName &&
(method.Name == ".ctor" || method.Name == ".cctor")) { (method.Name == ".ctor" || method.Name == ".cctor")) {
return Images.GetIcon(MemberIcon.Constructor, GetOverlayIcon(method.Attributes), false); return Images.GetIcon(MemberIcon.Constructor, GetOverlayIcon(method.Attributes), method.IsStatic);
} }
if (method.HasPInvokeInfo) if (method.HasPInvokeInfo)

33
ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs

@ -27,6 +27,8 @@ using System.Resources;
using ICSharpCode.Decompiler; using ICSharpCode.Decompiler;
using ICSharpCode.ILSpy.Controls; using ICSharpCode.ILSpy.Controls;
using ICSharpCode.ILSpy.TextView;
using Microsoft.Win32;
using Mono.Cecil; using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes namespace ICSharpCode.ILSpy.TreeNodes
@ -111,6 +113,37 @@ namespace ICSharpCode.ILSpy.TreeNodes
otherEntries.Add(new SerializedObjectRepresentation(keyString, entryType, entry.Value.ToString())); otherEntries.Add(new SerializedObjectRepresentation(keyString, entryType, entry.Value.ToString()));
} }
} }
public override bool Save(DecompilerTextView textView)
{
EmbeddedResource er = this.Resource as EmbeddedResource;
if (er != null) {
SaveFileDialog dlg = new SaveFileDialog();
dlg.FileName = DecompilerTextView.CleanUpName(er.Name);
dlg.Filter = "Resources file (*.resources)|*.resources|Resource XML file|*.resx";
if (dlg.ShowDialog() == true) {
Stream s = er.GetResourceStream();
s.Position = 0;
switch (dlg.FilterIndex) {
case 1:
using (var fs = dlg.OpenFile()) {
s.CopyTo(fs);
}
break;
case 2:
var reader = new ResourceReader(s);
using (var writer = new ResXResourceWriter(dlg.OpenFile())) {
foreach (DictionaryEntry entry in reader) {
writer.AddResource(entry.Key.ToString(), entry.Value);
}
}
break;
}
}
return true;
}
return false;
}
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{ {

2
ILSpy/TreeNodes/SearchMsdnContextMenuEntry.cs

@ -21,7 +21,7 @@ using System.Diagnostics;
namespace ICSharpCode.ILSpy.TreeNodes namespace ICSharpCode.ILSpy.TreeNodes
{ {
[ExportContextMenuEntryAttribute(Header = "Search MSDN...", Icon = "images/Search.png")] [ExportContextMenuEntry(Header = "Search MSDN...", Icon = "images/SearchMsdn.png", Order = 9999)]
internal sealed class SearchMsdnContextMenuEntry : IContextMenuEntry internal sealed class SearchMsdnContextMenuEntry : IContextMenuEntry
{ {
private static string msdnAddress = "http://msdn.microsoft.com/en-us/library/{0}"; private static string msdnAddress = "http://msdn.microsoft.com/en-us/library/{0}";

10
ILSpy/VB/VBLanguage.cs

@ -400,7 +400,15 @@ namespace ICSharpCode.ILSpy.VB
Settings = settings Settings = settings
}); });
} }
public override string FormatMethodName(MethodDefinition method)
{
if (method == null)
throw new ArgumentNullException("method");
return (method.IsConstructor) ? method.DeclaringType.Name : method.Name;
}
public override string FormatTypeName(TypeDefinition type) public override string FormatTypeName(TypeDefinition type)
{ {
if (type == null) if (type == null)

8
SharpTreeView/ICSharpCode.TreeView.csproj

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
@ -31,6 +31,8 @@
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="System.Xaml" /> <Reference Include="System.Xaml" />
<Reference Include="UIAutomationProvider" />
<Reference Include="UIAutomationTypes" />
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
@ -58,8 +60,10 @@
<Compile Include="SharpTreeNodeCollection.cs" /> <Compile Include="SharpTreeNodeCollection.cs" />
<Compile Include="SharpTreeNodeView.cs" /> <Compile Include="SharpTreeNodeView.cs" />
<Compile Include="SharpTreeView.cs" /> <Compile Include="SharpTreeView.cs" />
<Compile Include="SharpTreeViewAutomationPeer.cs" />
<Compile Include="SharpTreeViewItem.cs" /> <Compile Include="SharpTreeViewItem.cs" />
<Compile Include="SharpTreeViewTextSearch.cs" /> <Compile Include="SharpTreeViewTextSearch.cs" />
<Compile Include="SharpTreeViewItemAutomationPeer.cs" />
<Compile Include="TreeFlattener.cs" /> <Compile Include="TreeFlattener.cs" />
<Compile Include="TreeTraversal.cs" /> <Compile Include="TreeTraversal.cs" />
</ItemGroup> </ItemGroup>
@ -69,4 +73,4 @@
<None Include="license.txt" /> <None Include="license.txt" />
</ItemGroup> </ItemGroup>
</Project> </Project>

6
SharpTreeView/SharpTreeView.cs

@ -362,8 +362,12 @@ namespace ICSharpCode.TreeView
return null; return null;
} }
protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
{
return new SharpTreeViewAutomationPeer(this);
}
#region Track selection #region Track selection
protected override void OnSelectionChanged(SelectionChangedEventArgs e) protected override void OnSelectionChanged(SelectionChangedEventArgs e)
{ {
foreach (SharpTreeNode node in e.RemovedItems) { foreach (SharpTreeNode node in e.RemovedItems) {

21
SharpTreeView/SharpTreeViewAutomationPeer.cs

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
namespace ICSharpCode.TreeView
{
class SharpTreeViewAutomationPeer : FrameworkElementAutomationPeer
{
internal SharpTreeViewAutomationPeer(SharpTreeView owner ): base(owner)
{
}
//private SharpTreeView SharpTreeView { get { return (SharpTreeView)base.Owner; } }
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Tree;
}
}
}

5
SharpTreeView/SharpTreeViewItem.cs

@ -40,6 +40,11 @@ namespace ICSharpCode.TreeView
} }
} }
protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
{
return new SharpTreeViewItemAutomationPeer(this);
}
#region Mouse #region Mouse
Point startPoint; Point startPoint;

77
SharpTreeView/SharpTreeViewItemAutomationPeer.cs

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
namespace ICSharpCode.TreeView
{
class SharpTreeViewItemAutomationPeer : FrameworkElementAutomationPeer, IExpandCollapseProvider
{
internal SharpTreeViewItemAutomationPeer(SharpTreeViewItem owner)
: base(owner)
{
SharpTreeViewItem.DataContextChanged += OnDataContextChanged;
SharpTreeNode node = SharpTreeViewItem.DataContext as SharpTreeNode;
if (node == null) return;
node.PropertyChanged += OnPropertyChanged;
}
private SharpTreeViewItem SharpTreeViewItem { get { return (SharpTreeViewItem)base.Owner; } }
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.TreeItem;
}
public override object GetPattern(PatternInterface patternInterface)
{
if (patternInterface == PatternInterface.ExpandCollapse)
return this;
return base.GetPattern(patternInterface);
}
public void Collapse()
{
}
public void Expand()
{
}
public ExpandCollapseState ExpandCollapseState {
get {
SharpTreeNode node = SharpTreeViewItem.DataContext as SharpTreeNode;
if (node == null || !node.ShowExpander)
return ExpandCollapseState.LeafNode;
return node.IsExpanded ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
}
}
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName != "IsExpanded") return;
SharpTreeNode node = sender as SharpTreeNode;
if (node == null || node.Children.Count == 0) return;
bool newValue = node.IsExpanded;
bool oldValue = !newValue;
RaisePropertyChangedEvent(
ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
oldValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed,
newValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed);
}
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
SharpTreeNode oldNode = e.OldValue as SharpTreeNode;
if (oldNode != null)
oldNode.PropertyChanged -= OnPropertyChanged;
SharpTreeNode newNode = e.NewValue as SharpTreeNode;
if (newNode != null)
newNode.PropertyChanged += OnPropertyChanged;
}
}
}
Loading…
Cancel
Save