mirror of https://github.com/icsharpcode/ILSpy.git
182 changed files with 2225 additions and 1814 deletions
@ -1,3 +1,5 @@
@@ -1,3 +1,5 @@
|
||||
@rem This file can be used to trigger the commit hook's formatting, |
||||
@rem modifying the local formatting even if not committing all changes. |
||||
pushd %~dp0\.. |
||||
"%ProgramFiles%\Git\usr\bin\bash.exe" BuildTools\pre-commit --format |
||||
popd |
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
using System.Collections.Generic; |
||||
using System.Collections.Specialized; |
||||
using System.Linq; |
||||
|
||||
using ICSharpCode.ILSpy.Util; |
||||
using ICSharpCode.ILSpyX; |
||||
using ICSharpCode.ILSpyX.TreeView; |
||||
|
||||
namespace ICSharpCode.ILSpy.Analyzers; |
||||
|
||||
public sealed class AnalyzerRootNode : AnalyzerTreeNode |
||||
{ |
||||
public AnalyzerRootNode() |
||||
{ |
||||
MessageBus<CurrentAssemblyListChangedEventArgs>.Subscribers += (sender, e) => CurrentAssemblyList_Changed(sender, e); |
||||
} |
||||
|
||||
void CurrentAssemblyList_Changed(object sender, NotifyCollectionChangedEventArgs e) |
||||
{ |
||||
if (e.Action == NotifyCollectionChangedAction.Reset) |
||||
{ |
||||
this.Children.Clear(); |
||||
} |
||||
else |
||||
{ |
||||
var removedAssemblies = e.OldItems?.Cast<LoadedAssembly>().ToArray() ?? []; |
||||
var addedAssemblies = e.NewItems?.Cast<LoadedAssembly>().ToArray() ?? []; |
||||
|
||||
HandleAssemblyListChanged(removedAssemblies, addedAssemblies); |
||||
} |
||||
} |
||||
|
||||
public override bool HandleAssemblyListChanged(ICollection<LoadedAssembly> removedAssemblies, ICollection<LoadedAssembly> addedAssemblies) |
||||
{ |
||||
this.Children.RemoveAll( |
||||
delegate (SharpTreeNode n) { |
||||
AnalyzerTreeNode an = n as AnalyzerTreeNode; |
||||
return an == null || !an.HandleAssemblyListChanged(removedAssemblies, addedAssemblies); |
||||
}); |
||||
return true; |
||||
} |
||||
} |
@ -1,178 +0,0 @@
@@ -1,178 +0,0 @@
|
||||
// Copyright (c) 2011 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:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Collections.Specialized; |
||||
using System.Linq; |
||||
using System.Windows; |
||||
|
||||
using ICSharpCode.Decompiler.TypeSystem; |
||||
using ICSharpCode.ILSpy.Analyzers.TreeNodes; |
||||
using ICSharpCode.ILSpy.Docking; |
||||
using ICSharpCode.ILSpy.ViewModels; |
||||
using ICSharpCode.ILSpyX; |
||||
using ICSharpCode.ILSpy.Controls.TreeView; |
||||
using ICSharpCode.ILSpyX.TreeView; |
||||
|
||||
namespace ICSharpCode.ILSpy.Analyzers |
||||
{ |
||||
/// <summary>
|
||||
/// Analyzer tree view.
|
||||
/// </summary>
|
||||
public class AnalyzerTreeView : SharpTreeView |
||||
{ |
||||
FilterSettings filterSettings; |
||||
|
||||
public AnalyzerTreeView() |
||||
{ |
||||
this.ShowRoot = false; |
||||
this.Root = new AnalyzerRootNode { Language = MainWindow.Instance.CurrentLanguage }; |
||||
this.BorderThickness = new Thickness(0); |
||||
ContextMenuProvider.Add(this); |
||||
MainWindow.Instance.CurrentAssemblyListChanged += MainWindow_Instance_CurrentAssemblyListChanged; |
||||
DockWorkspace.Instance.PropertyChanged += DockWorkspace_PropertyChanged; |
||||
filterSettings = MainWindow.Instance.SessionSettings.FilterSettings; |
||||
filterSettings.PropertyChanged += FilterSettings_PropertyChanged; |
||||
} |
||||
|
||||
private void DockWorkspace_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) |
||||
{ |
||||
switch (e.PropertyName) |
||||
{ |
||||
case nameof(DockWorkspace.Instance.ActiveTabPage): |
||||
filterSettings.PropertyChanged -= FilterSettings_PropertyChanged; |
||||
filterSettings = DockWorkspace.Instance.ActiveTabPage.FilterSettings; |
||||
filterSettings.PropertyChanged += FilterSettings_PropertyChanged; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
private void FilterSettings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) |
||||
{ |
||||
switch (e.PropertyName) |
||||
{ |
||||
case "Language": |
||||
case "LanguageVersion": |
||||
((AnalyzerRootNode)this.Root).Language = MainWindow.Instance.CurrentLanguage; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
void MainWindow_Instance_CurrentAssemblyListChanged(object sender, NotifyCollectionChangedEventArgs e) |
||||
{ |
||||
if (e.Action == NotifyCollectionChangedAction.Reset) |
||||
{ |
||||
this.Root.Children.Clear(); |
||||
} |
||||
else |
||||
{ |
||||
List<LoadedAssembly> removedAssemblies = new List<LoadedAssembly>(); |
||||
if (e.OldItems != null) |
||||
removedAssemblies.AddRange(e.OldItems.Cast<LoadedAssembly>()); |
||||
List<LoadedAssembly> addedAssemblies = new List<LoadedAssembly>(); |
||||
if (e.NewItems != null) |
||||
addedAssemblies.AddRange(e.NewItems.Cast<LoadedAssembly>()); |
||||
((AnalyzerRootNode)this.Root).HandleAssemblyListChanged(removedAssemblies, addedAssemblies); |
||||
} |
||||
} |
||||
|
||||
public void Show() |
||||
{ |
||||
DockWorkspace.Instance.ShowToolPane(AnalyzerPaneModel.PaneContentId); |
||||
} |
||||
|
||||
public void Show(AnalyzerTreeNode node) |
||||
{ |
||||
Show(); |
||||
|
||||
node.IsExpanded = true; |
||||
this.Root.Children.Add(node); |
||||
this.SelectedItem = node; |
||||
this.FocusNode(node); |
||||
} |
||||
|
||||
public void ShowOrFocus(AnalyzerTreeNode node) |
||||
{ |
||||
if (node is AnalyzerEntityTreeNode) |
||||
{ |
||||
var an = node as AnalyzerEntityTreeNode; |
||||
var found = this.Root.Children.OfType<AnalyzerEntityTreeNode>().FirstOrDefault(n => n.Member == an.Member); |
||||
if (found != null) |
||||
{ |
||||
Show(); |
||||
|
||||
found.IsExpanded = true; |
||||
this.SelectedItem = found; |
||||
this.FocusNode(found); |
||||
return; |
||||
} |
||||
} |
||||
Show(node); |
||||
} |
||||
|
||||
public void Analyze(IEntity entity) |
||||
{ |
||||
if (entity == null) |
||||
{ |
||||
throw new ArgumentNullException(nameof(entity)); |
||||
} |
||||
|
||||
if (entity.MetadataToken.IsNil) |
||||
{ |
||||
MessageBox.Show(Properties.Resources.CannotAnalyzeMissingRef, "ILSpy"); |
||||
return; |
||||
} |
||||
|
||||
switch (entity) |
||||
{ |
||||
case ITypeDefinition td: |
||||
ShowOrFocus(new AnalyzedTypeTreeNode(td)); |
||||
break; |
||||
case IField fd: |
||||
if (!fd.IsConst) |
||||
ShowOrFocus(new AnalyzedFieldTreeNode(fd)); |
||||
break; |
||||
case IMethod md: |
||||
ShowOrFocus(new AnalyzedMethodTreeNode(md)); |
||||
break; |
||||
case IProperty pd: |
||||
ShowOrFocus(new AnalyzedPropertyTreeNode(pd)); |
||||
break; |
||||
case IEvent ed: |
||||
ShowOrFocus(new AnalyzedEventTreeNode(ed)); |
||||
break; |
||||
default: |
||||
throw new ArgumentOutOfRangeException(nameof(entity), $"Entity {entity.GetType().FullName} is not supported."); |
||||
} |
||||
} |
||||
|
||||
sealed class AnalyzerRootNode : AnalyzerTreeNode |
||||
{ |
||||
public override bool HandleAssemblyListChanged(ICollection<LoadedAssembly> removedAssemblies, ICollection<LoadedAssembly> addedAssemblies) |
||||
{ |
||||
this.Children.RemoveAll( |
||||
delegate (SharpTreeNode n) { |
||||
AnalyzerTreeNode an = n as AnalyzerTreeNode; |
||||
return an == null || !an.HandleAssemblyListChanged(removedAssemblies, addedAssemblies); |
||||
}); |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
<treeView:SharpTreeView |
||||
x:Class="ICSharpCode.ILSpy.Analyzers.AnalyzerTreeView" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||
xmlns:toms="urn:TomsToolbox" |
||||
xmlns:treeView="clr-namespace:ICSharpCode.ILSpy.Controls.TreeView" |
||||
xmlns:analyzers="clr-namespace:ICSharpCode.ILSpy.Analyzers" |
||||
mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" |
||||
d:DataContext="{d:DesignInstance analyzers:AnalyzerTreeViewModel}" |
||||
ShowRoot="False" |
||||
BorderThickness="0" |
||||
Root="{Binding Root}" |
||||
toms:MultiSelectorExtensions.SelectionBinding="{Binding SelectedItems}" |
||||
SelectedItem="{Binding SelectedItem, Mode=TwoWay}" |
||||
SelectionChanged="AnalyzerTreeView_OnSelectionChanged"> |
||||
|
||||
<UIElement.InputBindings> |
||||
<KeyBinding Key="R" Modifiers="Control" Command="{Binding AnalyzeCommand}" /> |
||||
</UIElement.InputBindings> |
||||
|
||||
</treeView:SharpTreeView> |
@ -0,0 +1,130 @@
@@ -0,0 +1,130 @@
|
||||
// Copyright (c) 2019 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:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Collections.ObjectModel; |
||||
using System.ComponentModel.Composition; |
||||
using System.Linq; |
||||
using System.Windows; |
||||
using System.Windows.Input; |
||||
|
||||
using ICSharpCode.Decompiler.TypeSystem; |
||||
using ICSharpCode.ILSpy.Analyzers.TreeNodes; |
||||
using ICSharpCode.ILSpy.TreeNodes; |
||||
using ICSharpCode.ILSpy.ViewModels; |
||||
|
||||
using TomsToolbox.Wpf; |
||||
|
||||
namespace ICSharpCode.ILSpy.Analyzers |
||||
{ |
||||
[ExportToolPane] |
||||
[PartCreationPolicy(CreationPolicy.Shared)] |
||||
[Export] |
||||
public class AnalyzerTreeViewModel : ToolPaneModel |
||||
{ |
||||
private AnalyzerTreeNode selectedItem; |
||||
|
||||
public const string PaneContentId = "analyzerPane"; |
||||
|
||||
public AnalyzerTreeViewModel() |
||||
{ |
||||
ContentId = PaneContentId; |
||||
Title = Properties.Resources.Analyze; |
||||
ShortcutKey = new(Key.R, ModifierKeys.Control); |
||||
AssociatedCommand = ILSpyCommands.Analyze; |
||||
} |
||||
|
||||
public AnalyzerRootNode Root { get; } = new(); |
||||
|
||||
public AnalyzerTreeNode SelectedItem { |
||||
get => selectedItem; |
||||
set => SetProperty(ref selectedItem, value); |
||||
} |
||||
|
||||
public ICommand AnalyzeCommand => new DelegateCommand(AnalyzeSelected); |
||||
|
||||
public ObservableCollection<AnalyzerTreeNode> SelectedItems { get; } = []; |
||||
|
||||
private void AnalyzeSelected() |
||||
{ |
||||
foreach (var node in SelectedItems.OfType<IMemberTreeNode>()) |
||||
{ |
||||
Analyze(node.Member); |
||||
} |
||||
} |
||||
|
||||
void AddOrSelect(AnalyzerTreeNode node) |
||||
{ |
||||
Show(); |
||||
|
||||
AnalyzerTreeNode target = default; |
||||
|
||||
if (node is AnalyzerEntityTreeNode { Member: { } member }) |
||||
{ |
||||
target = this.Root.Children.OfType<AnalyzerEntityTreeNode>().FirstOrDefault(item => item.Member == member); |
||||
} |
||||
|
||||
if (target == null) |
||||
{ |
||||
this.Root.Children.Add(node); |
||||
target = node; |
||||
} |
||||
|
||||
target.IsExpanded = true; |
||||
this.SelectedItem = target; |
||||
} |
||||
|
||||
public void Analyze(IEntity entity) |
||||
{ |
||||
if (entity == null) |
||||
{ |
||||
throw new ArgumentNullException(nameof(entity)); |
||||
} |
||||
|
||||
if (entity.MetadataToken.IsNil) |
||||
{ |
||||
MessageBox.Show(Properties.Resources.CannotAnalyzeMissingRef, "ILSpy"); |
||||
return; |
||||
} |
||||
|
||||
switch (entity) |
||||
{ |
||||
case ITypeDefinition td: |
||||
AddOrSelect(new AnalyzedTypeTreeNode(td)); |
||||
break; |
||||
case IField fd: |
||||
if (!fd.IsConst) |
||||
AddOrSelect(new AnalyzedFieldTreeNode(fd)); |
||||
break; |
||||
case IMethod md: |
||||
AddOrSelect(new AnalyzedMethodTreeNode(md)); |
||||
break; |
||||
case IProperty pd: |
||||
AddOrSelect(new AnalyzedPropertyTreeNode(pd)); |
||||
break; |
||||
case IEvent ed: |
||||
AddOrSelect(new AnalyzedEventTreeNode(ed)); |
||||
break; |
||||
default: |
||||
throw new ArgumentOutOfRangeException(nameof(entity), $@"Entity {entity.GetType().FullName} is not supported."); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
@ -1,11 +1,13 @@
@@ -1,11 +1,13 @@
|
||||
namespace ICSharpCode.ILSpy.Commands |
||||
using ICSharpCode.ILSpy.Util; |
||||
|
||||
namespace ICSharpCode.ILSpy.Commands |
||||
{ |
||||
public class SetThemeCommand : SimpleCommand |
||||
{ |
||||
public override void Execute(object parameter) |
||||
{ |
||||
if (parameter is string theme) |
||||
MainWindow.Instance.SessionSettings.Theme = theme; |
||||
SettingsService.Instance.SessionSettings.Theme = theme; |
||||
} |
||||
} |
||||
} |
||||
|
@ -1,44 +0,0 @@
@@ -1,44 +0,0 @@
|
||||
// Copyright (c) 2018 Siegfried Pammer
|
||||
//
|
||||
// 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:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE
|
||||
|
||||
using System; |
||||
using System.Globalization; |
||||
using System.Windows; |
||||
using System.Windows.Data; |
||||
|
||||
namespace ICSharpCode.ILSpy.Controls |
||||
{ |
||||
public class BoolToVisibilityConverter : IValueConverter |
||||
{ |
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
||||
{ |
||||
if (!(parameter is Visibility notVisible)) |
||||
notVisible = Visibility.Collapsed; |
||||
if (!(value is bool b)) |
||||
return notVisible; |
||||
return b ? Visibility.Visible : notVisible; |
||||
} |
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
||||
{ |
||||
if (!(value is Visibility visibility)) |
||||
return false; |
||||
return visibility == Visibility.Visible; |
||||
} |
||||
} |
||||
} |
@ -1,46 +0,0 @@
@@ -1,46 +0,0 @@
|
||||
// Copyright (c) 2020 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:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Globalization; |
||||
using System.Windows; |
||||
using System.Windows.Data; |
||||
using System.Windows.Markup; |
||||
|
||||
namespace ICSharpCode.ILSpy.Controls.TreeView |
||||
{ |
||||
public class CollapsedWhenFalse : MarkupExtension, IValueConverter |
||||
{ |
||||
public static CollapsedWhenFalse Instance = new CollapsedWhenFalse(); |
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider) |
||||
{ |
||||
return Instance; |
||||
} |
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
||||
{ |
||||
return (bool)value ? Visibility.Visible : Visibility.Collapsed; |
||||
} |
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue