Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ICSharpCode.ILSpyX/TreeView/SharpTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,26 @@ public bool LazyLoading {
}
RaisePropertyChanged(nameof(LazyLoading));
RaisePropertyChanged(nameof(ShowExpander));
RaisePropertyChanged(nameof(ViewChildren));
}
}

/// <summary>
/// Workaround for cross platform treeview bindings.
/// </summary>
public System.Collections.IEnumerable ViewChildren {
get {
if (LazyLoading && Children.Count == 0)
return new[] { new LoadingTreeNode() };
return Children;
}
}

class LoadingTreeNode : SharpTreeNode
{
public override object Text => "Loading...";
}

bool canExpandRecursively = true;

/// <summary>
Expand Down
47 changes: 46 additions & 1 deletion ICSharpCode.ILSpyX/TreeView/SharpTreeNodeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
Expand All @@ -29,7 +30,7 @@ namespace ICSharpCode.ILSpyX.TreeView
/// <summary>
/// Collection that validates that inserted nodes do not have another parent.
/// </summary>
public sealed class SharpTreeNodeCollection : IList<SharpTreeNode>, INotifyCollectionChanged
public sealed class SharpTreeNodeCollection : IList<SharpTreeNode>, IList, INotifyCollectionChanged
{
readonly SharpTreeNode parent;
List<SharpTreeNode> list = new List<SharpTreeNode>();
Expand Down Expand Up @@ -94,6 +95,20 @@ bool ICollection<SharpTreeNode>.IsReadOnly {
get { return false; }
}

#region IList Members

public bool IsFixedSize => ((IList)list).IsFixedSize;

public bool IsReadOnly => ((IList)list).IsReadOnly;

public bool IsSynchronized => ((ICollection)list).IsSynchronized;

public object SyncRoot => ((ICollection)list).SyncRoot;

object IList.this[int index] { get => ((IList)list)[index]; set => ((IList)list)[index] = value; }
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IList indexer setter directly delegates to the underlying list without validation. This bypasses the parent node validation logic that exists in the typed indexer. Consider validating the node's parent before setting, similar to the generic indexer setter.

Suggested change
object IList.this[int index] { get => ((IList)list)[index]; set => ((IList)list)[index] = value; }
object IList.this[int index]
{
get => this[index];
set
{
if (value is not SharpTreeNode node)
throw new ArgumentException("Value must be a SharpTreeNode.", nameof(value));
this[index] = node;
}
}

Copilot uses AI. Check for mistakes.

#endregion

public int IndexOf(SharpTreeNode node)
{
if (node == null || node.modelParent != parent)
Expand Down Expand Up @@ -236,5 +251,35 @@ public void RemoveAll(Predicate<SharpTreeNode> match)
RemoveRange(firstToRemove, list.Count - firstToRemove);
}
}

public int Add(object value)
{
return ((IList)list).Add(value);
}
Comment on lines +255 to +258
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IList.Add implementation directly delegates to the underlying list without validation. This bypasses the parent node validation logic that exists in the generic Add method. Consider validating the node's parent before adding, similar to the generic Add(SharpTreeNode) method.

Copilot uses AI. Check for mistakes.

public bool Contains(object value)
{
return ((IList)list).Contains(value);
}

public int IndexOf(object value)
{
return ((IList)list).IndexOf(value);
}

public void Insert(int index, object value)
{
((IList)list).Insert(index, value);
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IList.Insert implementation directly delegates to the underlying list without validation. This bypasses the parent node validation logic that exists in the generic Insert method. Consider validating the node's parent before inserting, similar to the generic Insert(int, SharpTreeNode) method.

Suggested change
((IList)list).Insert(index, value);
if (value is SharpTreeNode node)
{
Insert(index, node);
}
else
{
throw new ArgumentException("Value must be a SharpTreeNode.", nameof(value));
}

Copilot uses AI. Check for mistakes.
}

public void Remove(object value)
{
((IList)list).Remove(value);
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IList.Remove implementation directly delegates to the underlying list without using the CollectionChanged event mechanism. This bypasses the notification logic that exists in the generic Remove method. Consider using the generic Remove method or ensuring proper event notification.

Suggested change
((IList)list).Remove(value);
// Route through the generic Remove to ensure proper notification and validation.
if (value == null || value is SharpTreeNode)
{
Remove((SharpTreeNode)value);
}

Copilot uses AI. Check for mistakes.
}

public void CopyTo(Array array, int index)
{
((ICollection)list).CopyTo(array, index);
}
}
}
4 changes: 4 additions & 0 deletions ILSpy/AboutPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ static void ShowAvailableVersion(AvailableVersionInfo availableVersion, StackPan
stackPanel.Children.Add(
new Image {
Width = 16, Height = 16,
#if CROSS_PLATFORM
Source = Images.LoadImage(Images.OK),
#else
Source = Images.OK,
#endif
Margin = new Thickness(4, 0, 4, 0)
});
stackPanel.Children.Add(
Expand Down
63 changes: 13 additions & 50 deletions ILSpy/AssemblyTree/AssemblyTreeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
using System.Reflection.Metadata.Ecma335;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Navigation;
using System.Windows.Threading;
Expand Down Expand Up @@ -57,7 +56,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree
{
[ExportToolPane]
[Shared]
public class AssemblyTreeModel : ToolPaneModel
public partial class AssemblyTreeModel : ToolPaneModel
{
public const string PaneContentId = "assemblyListPane";

Expand All @@ -72,36 +71,6 @@ public class AssemblyTreeModel : ToolPaneModel
private readonly LanguageService languageService;
private readonly IExportProvider exportProvider;

public AssemblyTreeModel(SettingsService settingsService, LanguageService languageService, IExportProvider exportProvider)
{
this.settingsService = settingsService;
this.languageService = languageService;
this.exportProvider = exportProvider;

Title = Resources.Assemblies;
ContentId = PaneContentId;
IsCloseable = false;
ShortcutKey = new KeyGesture(Key.F6);

MessageBus<NavigateToReferenceEventArgs>.Subscribers += JumpToReference;
MessageBus<SettingsChangedEventArgs>.Subscribers += (sender, e) => Settings_PropertyChanged(sender, e);
MessageBus<ApplySessionSettingsEventArgs>.Subscribers += ApplySessionSettings;
MessageBus<ActiveTabPageChangedEventArgs>.Subscribers += ActiveTabPageChanged;
MessageBus<TabPagesCollectionChangedEventArgs>.Subscribers += (_, e) => history.RemoveAll(s => !DockWorkspace.TabPages.Contains(s.TabPage));
MessageBus<ResetLayoutEventArgs>.Subscribers += ResetLayout;
MessageBus<NavigateToEventArgs>.Subscribers += (_, e) => NavigateTo(e.Request, e.InNewTabPage);
MessageBus<MainWindowLoadedEventArgs>.Subscribers += (_, _) => {
Initialize();
Show();
};

EventManager.RegisterClassHandler(typeof(Window), Hyperlink.RequestNavigateEvent, new RequestNavigateEventHandler((_, e) => NavigateTo(e)));

refreshThrottle = new(DispatcherPriority.Background, RefreshInternal);

AssemblyList = settingsService.CreateEmptyAssemblyList();
}

private void Settings_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (sender is SessionSettings sessionSettings)
Expand Down Expand Up @@ -159,6 +128,7 @@ public SharpTreeNode[] SelectedItems {
var oldSelection = selectedItems;
selectedItems = value;
OnPropertyChanged();
// TODO: OnPropertyChanged(nameof(SelectedItem));
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO comment should be addressed or removed. If this is intentional work-in-progress, it should be tracked in an issue rather than left as an inline comment.

Suggested change
// TODO: OnPropertyChanged(nameof(SelectedItem));

Copilot uses AI. Check for mistakes.
TreeView_SelectionChanged(oldSelection, selectedItems);
}
}
Expand Down Expand Up @@ -492,24 +462,6 @@ private void assemblyList_CollectionChanged(object? sender, NotifyCollectionChan
MessageBus.Send(this, new CurrentAssemblyListChangedEventArgs(e));
}

private static void LoadInitialAssemblies(AssemblyList assemblyList)
{
// Called when loading an empty assembly list; so that
// the user can see something initially.
System.Reflection.Assembly[] initialAssemblies = {
typeof(object).Assembly,
typeof(Uri).Assembly,
typeof(System.Linq.Enumerable).Assembly,
typeof(System.Xml.XmlDocument).Assembly,
typeof(System.Windows.Markup.MarkupExtension).Assembly,
typeof(System.Windows.Rect).Assembly,
typeof(System.Windows.UIElement).Assembly,
typeof(System.Windows.FrameworkElement).Assembly
};
foreach (System.Reflection.Assembly asm in initialAssemblies)
assemblyList.OpenAssembly(asm.Location);
}

public AssemblyTreeNode? FindAssemblyNode(LoadedAssembly asm)
{
return assemblyListTreeNode?.FindAssemblyNode(asm);
Expand Down Expand Up @@ -540,6 +492,7 @@ public void SelectNode(SharpTreeNode? node, bool inNewTabPage = false)
}
else
{
// TODO: ExpandAncestors(node);
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO comment should be addressed or removed. If this is intentional work-in-progress, it should be tracked in an issue rather than left as an inline comment.

Suggested change
// TODO: ExpandAncestors(node);
// Ancestors are intentionally not expanded automatically when selecting a node.

Copilot uses AI. Check for mistakes.
activeView?.ScrollIntoView(node);
SelectedItem = node;

Expand Down Expand Up @@ -978,6 +931,7 @@ private void RefreshInternal()
{
var path = GetPathForNode(SelectedItem);

// TODO: (settingsService.AssemblyListManager.LoadList(AssemblyList.ListName));
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO comment should be addressed or removed. If this is intentional work-in-progress, it should be tracked in an issue rather than left as an inline comment.

Suggested change
// TODO: (settingsService.AssemblyListManager.LoadList(AssemblyList.ListName));

Copilot uses AI. Check for mistakes.
ShowAssemblyList(settingsService.AssemblyListManager.LoadList(AssemblyList.ListName));
SelectNode(FindNodeByPath(path, true), inNewTabPage: false);

Expand All @@ -998,6 +952,15 @@ private IEnumerable<SharpTreeNode> GetTopLevelSelection()
return selection.Where(item => item.Ancestors().All(a => !selectionHash.Contains(a)));
}

// TODO: void ExpandAncestors(SharpTreeNode node)
// {
// foreach (var ancestor in node.Ancestors().Reverse())
// {
// ancestor.EnsureLazyChildren();
// ancestor.IsExpanded = true;
// }
// }
Comment on lines +955 to +962
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO comment should be addressed or removed. If this represents incomplete functionality, it should be tracked in an issue or completed before merging.

Copilot uses AI. Check for mistakes.

public void SetActiveView(AssemblyListPane activeView)
{
this.activeView = activeView;
Expand Down
83 changes: 83 additions & 0 deletions ILSpy/AssemblyTree/AssemblyTreeModel.wpf.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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.Windows;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Navigation;
using System.Windows.Threading;

using ICSharpCode.ILSpy.Properties;
using ICSharpCode.ILSpyX;

using TomsToolbox.Composition;

namespace ICSharpCode.ILSpy.AssemblyTree
{
public partial class AssemblyTreeModel
{
public AssemblyTreeModel(SettingsService settingsService, LanguageService languageService, IExportProvider exportProvider)
{
this.settingsService = settingsService;
this.languageService = languageService;
this.exportProvider = exportProvider;

Title = Resources.Assemblies;
ContentId = PaneContentId;
IsCloseable = false;
ShortcutKey = new KeyGesture(Key.F6);

MessageBus<NavigateToReferenceEventArgs>.Subscribers += JumpToReference;
MessageBus<SettingsChangedEventArgs>.Subscribers += (sender, e) => Settings_PropertyChanged(sender, e);
MessageBus<ApplySessionSettingsEventArgs>.Subscribers += ApplySessionSettings;
MessageBus<ActiveTabPageChangedEventArgs>.Subscribers += ActiveTabPageChanged;
MessageBus<TabPagesCollectionChangedEventArgs>.Subscribers += (_, e) => history.RemoveAll(s => !DockWorkspace.TabPages.Contains(s.TabPage));
MessageBus<ResetLayoutEventArgs>.Subscribers += ResetLayout;
MessageBus<NavigateToEventArgs>.Subscribers += (_, e) => NavigateTo(e.Request, e.InNewTabPage);
MessageBus<MainWindowLoadedEventArgs>.Subscribers += (_, _) => {
Initialize();
Show();
};

EventManager.RegisterClassHandler(typeof(Window), Hyperlink.RequestNavigateEvent, new RequestNavigateEventHandler((_, e) => NavigateTo(e)));

refreshThrottle = new(DispatcherPriority.Background, RefreshInternal);

AssemblyList = settingsService.CreateEmptyAssemblyList();
}

private static void LoadInitialAssemblies(AssemblyList assemblyList)
{
// Called when loading an empty assembly list; so that
// the user can see something initially.
System.Reflection.Assembly[] initialAssemblies = {
typeof(object).Assembly,
typeof(Uri).Assembly,
typeof(System.Linq.Enumerable).Assembly,
typeof(System.Xml.XmlDocument).Assembly,
typeof(System.Windows.Markup.MarkupExtension).Assembly,
typeof(System.Windows.Rect).Assembly,
typeof(System.Windows.UIElement).Assembly,
typeof(System.Windows.FrameworkElement).Assembly
};
foreach (System.Reflection.Assembly asm in initialAssemblies)
assemblyList.OpenAssembly(asm.Location);
}
}
}
2 changes: 1 addition & 1 deletion ILSpy/Commands/Pdb2XmlCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

#if DEBUG
#if DEBUG && WINDOWS

using System.Collections.Generic;
using System.Composition;
Expand Down
Loading
Loading