Skip to content

Commit 7ad4ccc

Browse files
Add CompareView and FrozenContent flag
1 parent aff9649 commit 7ad4ccc

File tree

11 files changed

+626
-25
lines changed

11 files changed

+626
-25
lines changed

ILSpy/AssemblyTree/AssemblyTreeModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,11 @@ public void DecompileSelectedNodes(DecompilerTextViewState? newState = null)
794794
{
795795
var activeTabPage = DockWorkspace.ActiveTabPage;
796796

797+
if (activeTabPage.FrozenContent)
798+
{
799+
activeTabPage = DockWorkspace.AddTabPage();
800+
}
801+
797802
activeTabPage.SupportsLanguageSwitching = true;
798803

799804
if (SelectedItems.Length == 1)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2025 AlphaSierraPapa for the SharpDevelop Team
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
// software and associated documentation files (the "Software"), to deal in the Software
5+
// without restriction, including without limitation the rights to use, copy, modify, merge,
6+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7+
// to whom the Software is furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in all copies or
10+
// substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17+
// DEALINGS IN THE SOFTWARE.
18+
19+
using System.Composition;
20+
21+
using ICSharpCode.ILSpy.AssemblyTree;
22+
using ICSharpCode.ILSpy.Docking;
23+
using ICSharpCode.ILSpy.TreeNodes;
24+
using ICSharpCode.ILSpy.ViewModels;
25+
using ICSharpCode.ILSpy.Views;
26+
27+
namespace ICSharpCode.ILSpy
28+
{
29+
[ExportContextMenuEntry(Header = "Compare...", Order = 9999)]
30+
[Shared]
31+
internal sealed class CompareContextMenuEntry(AssemblyTreeModel assemblyTreeModel, DockWorkspace dockWorkspace) : IContextMenuEntry
32+
{
33+
public void Execute(TextViewContext context)
34+
{
35+
var left = ((AssemblyTreeNode)context.SelectedTreeNodes[0]).LoadedAssembly;
36+
var right = ((AssemblyTreeNode)context.SelectedTreeNodes[1]).LoadedAssembly;
37+
38+
var tabPage = dockWorkspace.AddTabPage();
39+
40+
tabPage.Title = $"Compare {left.Text} - {right.Text}";
41+
tabPage.SupportsLanguageSwitching = false;
42+
tabPage.FrozenContent = true;
43+
var compareView = new CompareView();
44+
compareView.DataContext = new CompareViewModel(assemblyTreeModel, left, right);
45+
tabPage.Content = compareView;
46+
}
47+
48+
public bool IsEnabled(TextViewContext context)
49+
{
50+
return true;
51+
}
52+
53+
public bool IsVisible(TextViewContext context)
54+
{
55+
return context.SelectedTreeNodes is [AssemblyTreeNode { LoadedAssembly.IsLoadedAsValidAssembly: true }, AssemblyTreeNode { LoadedAssembly.IsLoadedAsValidAssembly: true }];
56+
}
57+
}
58+
}

ILSpy/Commands/SearchMsdnContextMenuEntry.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
// DEALINGS IN THE SOFTWARE.
1818

1919
using System.Linq;
20-
using System.Threading;
2120

2221
using ICSharpCode.ILSpy.Properties;
2322
using ICSharpCode.ILSpy.TreeNodes;

ILSpy/Docking/DockWorkspace.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ private void TabPages_CollectionChanged(object sender, NotifyCollectionChangedEv
118118
}
119119
}
120120

121-
public void AddTabPage(TabPageModel tabPage = null)
121+
public TabPageModel AddTabPage(TabPageModel tabPage = null)
122122
{
123-
tabPages.Add(tabPage ?? exportProvider.GetExportedValue<TabPageModel>());
123+
TabPageModel item = tabPage ?? exportProvider.GetExportedValue<TabPageModel>();
124+
tabPages.Add(item);
125+
return item;
124126
}
125127

126128
public ReadOnlyObservableCollection<TabPageModel> TabPages { get; }

ILSpy/Images/Images.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
namespace ICSharpCode.ILSpy
2727
{
28+
using ICSharpCode.Decompiler.TypeSystem;
29+
2830
static class Images
2931
{
3032
private static readonly Rect iconRect = new Rect(0, 0, 16, 16);
@@ -212,6 +214,27 @@ public static ImageSource GetIcon(MemberIcon icon, AccessOverlayIcon overlay, bo
212214
return memberIconCache.GetIcon(icon, overlay, isStatic);
213215
}
214216

217+
public static AccessOverlayIcon GetOverlayIcon(Accessibility accessibility)
218+
{
219+
switch (accessibility)
220+
{
221+
case Accessibility.Public:
222+
return AccessOverlayIcon.Public;
223+
case Accessibility.Internal:
224+
return AccessOverlayIcon.Internal;
225+
case Accessibility.ProtectedAndInternal:
226+
return AccessOverlayIcon.PrivateProtected;
227+
case Accessibility.Protected:
228+
return AccessOverlayIcon.Protected;
229+
case Accessibility.ProtectedOrInternal:
230+
return AccessOverlayIcon.ProtectedInternal;
231+
case Accessibility.Private:
232+
return AccessOverlayIcon.Private;
233+
default:
234+
return AccessOverlayIcon.CompilerControlled;
235+
}
236+
}
237+
215238
private static ImageSource GetIcon(string baseImage, string overlay = null, bool isStatic = false)
216239
{
217240
ImageSource baseImageSource = Load(baseImage);

ILSpy/TreeNodes/MethodTreeNode.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,6 @@ public static ImageSource GetIcon(IMethod method)
7373
GetOverlayIcon(method.Accessibility), method.IsStatic);
7474
}
7575

76-
internal static AccessOverlayIcon GetOverlayIcon(Accessibility accessibility)
77-
{
78-
switch (accessibility)
79-
{
80-
case Accessibility.Public:
81-
return AccessOverlayIcon.Public;
82-
case Accessibility.Internal:
83-
return AccessOverlayIcon.Internal;
84-
case Accessibility.ProtectedAndInternal:
85-
return AccessOverlayIcon.PrivateProtected;
86-
case Accessibility.Protected:
87-
return AccessOverlayIcon.Protected;
88-
case Accessibility.ProtectedOrInternal:
89-
return AccessOverlayIcon.ProtectedInternal;
90-
case Accessibility.Private:
91-
return AccessOverlayIcon.Private;
92-
default:
93-
return AccessOverlayIcon.CompilerControlled;
94-
}
95-
}
96-
9776
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
9877
{
9978
language.DecompileMethod(MethodDefinition, output, options);

0 commit comments

Comments
 (0)