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 @@ -323,9 +323,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
64 changes: 63 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 => this[index]; set => this[index] = (SharpTreeNode)value; }

#endregion

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

public int Add(object value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
if (!(value is SharpTreeNode node))
throw new ArgumentException("Value must be a SharpTreeNode", nameof(value));
Add(node);
return list.IndexOf(node);
}

public bool Contains(object value)
{
return value is SharpTreeNode node && Contains(node);
}

public int IndexOf(object value)
{
return value is SharpTreeNode node ? IndexOf(node) : -1;
}

public void Insert(int index, object value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
if (!(value is SharpTreeNode node))
throw new ArgumentException("Value must be a SharpTreeNode", nameof(value));
Insert(index, node);
}

public void Remove(object value)
{
if (value is SharpTreeNode node)
Remove(node);
}

public void CopyTo(Array array, int index)
{
if (array is SharpTreeNode[] nodes)
{
CopyTo(nodes, index);
}
else
{
((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
69 changes: 19 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 @@ -74,36 +73,6 @@ public class AssemblyTreeModel : ToolPaneModel

private static Dispatcher UIThreadDispatcher => Application.Current.Dispatcher;

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 @@ -161,6 +130,9 @@ public SharpTreeNode[] SelectedItems {
var oldSelection = selectedItems;
selectedItems = value;
OnPropertyChanged();
#if CROSS_PLATFORM
OnPropertyChanged(nameof(SelectedItem));
#endif
TreeView_SelectionChanged(oldSelection, selectedItems);
}
}
Expand Down Expand Up @@ -494,24 +466,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 @@ -542,10 +496,16 @@ public void SelectNode(SharpTreeNode? node, bool inNewTabPage = false)
}
else
{
#if CROSS_PLATFORM
ExpandAncestors(node);
#endif
activeView?.ScrollIntoView(node);
SelectedItem = node;

UIThreadDispatcher.BeginInvoke(DispatcherPriority.Background, () => {
#if CROSS_PLATFORM
SelectedItem = node;
#endif
activeView?.ScrollIntoView(node);
});
}
Expand Down Expand Up @@ -1011,6 +971,15 @@ private IEnumerable<SharpTreeNode> GetTopLevelSelection()
return selection.Where(item => item.Ancestors().All(a => !selectionHash.Contains(a)));
}

void ExpandAncestors(SharpTreeNode node)
{
foreach (var ancestor in node.Ancestors().Reverse())
{
ancestor.EnsureLazyChildren();
ancestor.IsExpanded = true;
}
}

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