Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(UI): Use AssemblyWarning when AssemblyReference load faulted #3013

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
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
49 changes: 49 additions & 0 deletions ILSpy/Images/AssemblyLoading.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions ILSpy/Images/AssemblyLoading.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" ?>
<DrawingGroup xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<DrawingGroup.ClipGeometry>
<RectangleGeometry Rect="0.0,0.0,16.0,16.0"/>
</DrawingGroup.ClipGeometry>
<GeometryDrawing Brush="#fff6f6f6">
<GeometryDrawing.Geometry>
<PathGeometry Figures="M 16 3 v 9 H 8 V 9 H 6 v 2 H 0 V 4 h 6 v 2 h 2 V 3 h 8 z" FillRule="Nonzero"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="#ff424242">
<GeometryDrawing.Geometry>
<PathGeometry Figures="M 1 5 h 4 v 5 H 1 z M 9 4 h 6 v 7 H 9 z M 6 7 h 2 v 1 H 6 z" FillRule="Nonzero"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="#fff6f6f6">
<GeometryDrawing.Geometry>
<PathGeometry Figures="m 16 12 c 0 2.2055 -1.7945 4 -4 4 C 9.7945 16 8 14.2055 8 12 A 3.995 3.995 0 0 1 8.544 10 H 8 v -2 H 12 V 12 h -2 c 0 1.103 0.896999 2 2 2 c 1.103 0 2 -0.897 2 -2 c 0 -0.672 -0.3345 -1.295 -0.895 -1.667 l -0.4165 -0.277 l 1.1075 -1.666 l 0.4165 0.2765 A 3.996 3.996 0 0 1 16 12 Z" FillRule="Nonzero"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<DrawingGroup Transform="0.49999992,0.0,0.0,0.49999992,8.000001,8.000001">
<GeometryDrawing Brush="#ff00539c">
<GeometryDrawing.Geometry>
<PathGeometry Figures="m 15 8 c 0 3.859 -3.141 7 -7 7 C 4.14 15 1 11.859 1 8 A 7 7 0 0 1 3.12 3 H 1 V 1 H 7 V 7 H 5 V 4.002 A 5.01 5.01 0 0 0 3 8 c 0 2.757 2.243 5 5 5 c 2.757 0 5 -2.243 5 -5 A 4.993 4.993 0 0 0 10.764 3.833 L 11.871 2.167 A 6.989 6.989 0 0 1 15 8 Z" FillRule="Nonzero"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingGroup>
1 change: 1 addition & 0 deletions ILSpy/Images/Images.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static ImageSource Load(string icon)

public static readonly ImageSource Assembly = Load("Assembly");
public static readonly ImageSource AssemblyWarning = Load("AssemblyWarning");
public static readonly ImageSource AssemblyLoading = Load(nameof(AssemblyLoading));
public static readonly ImageSource FindAssembly = Load("FindAssembly");

public static readonly ImageSource Library = Load("Library");
Expand Down
39 changes: 34 additions & 5 deletions ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// 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
Expand All @@ -35,9 +35,18 @@ namespace ICSharpCode.ILSpy.TreeNodes
/// </summary>
public sealed class AssemblyReferenceTreeNode : ILSpyTreeNode
{
private enum LoadState
{
Unloaded,
Loading,
Loadded,
Failed
}
readonly MetadataModule module;
readonly AssemblyReference r;
readonly AssemblyTreeNode parentAssembly;
MetadataFile referencedModule;
private LoadState state;

public AssemblyReferenceTreeNode(MetadataModule module, AssemblyReference r, AssemblyTreeNode parentAssembly)
{
Expand All @@ -53,7 +62,27 @@ public override object Text {
get { return Language.EscapeName(r.Name) + GetSuffixString(r.Handle); }
}

public override object Icon => ImagesProvider.Assembly;
public override object Icon {
get {
if (state == LoadState.Unloaded)
{
state = LoadState.Loading;
Dispatcher.CurrentDispatcher.BeginInvoke(() => {
var resolver = parentAssembly.LoadedAssembly.GetAssemblyResolver();
referencedModule = resolver.Resolve(r);
state = referencedModule is null
? LoadState.Failed
: LoadState.Loadded;
RaisePropertyChanged(nameof(Icon));
}, DispatcherPriority.Background);
}
return state switch {
LoadState.Loadded => Images.Assembly,
LoadState.Failed => Images.AssemblyWarning,
_ => Images.AssemblyLoading,
};
}
}

public override bool ShowExpander {
get {
Expand All @@ -65,7 +94,7 @@ public override bool ShowExpander {
// while the list of references is updated causes problems with WPF's ListView rendering.
// Moving the assembly resolving out of the "add assembly reference"-loop by using the
// dispatcher fixes the issue.
Dispatcher.CurrentDispatcher.BeginInvoke((Action)EnsureLazyChildren, DispatcherPriority.Normal);
Dispatcher.CurrentDispatcher.BeginInvoke(EnsureLazyChildren, DispatcherPriority.Normal);
}
return base.ShowExpander;
}
Expand Down