Browse Source

Fix bug in AddIn that causes ILSpy to infinitely be asked to load nuget packages.

pull/1707/head
Siegfried Pammer 6 years ago
parent
commit
37eae3d32f
  1. 2
      ILSpy.AddIn/Commands/OpenReferenceCommand.cs
  2. 71
      ILSpy/MainWindow.xaml.cs

2
ILSpy.AddIn/Commands/OpenReferenceCommand.cs

@ -59,12 +59,14 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -59,12 +59,14 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
OpenAssembliesInILSpy(parameters);
else
owner.ShowMessage("Could not find reference '{0}', please ensure the project and all references were built correctly!", reference.Name);
return;
}
// Handle NuGet references
var nugetRefItem = NuGetReferenceForILSpy.Detect(itemObject);
if (nugetRefItem != null) {
OpenAssembliesInILSpy(nugetRefItem.GetILSpyParameters());
return;
}
// Handle project references

71
ILSpy/MainWindow.xaml.cs

@ -53,6 +53,7 @@ namespace ICSharpCode.ILSpy @@ -53,6 +53,7 @@ namespace ICSharpCode.ILSpy
partial class MainWindow : Window
{
bool refreshInProgress;
bool handlingNugetPackageSelection;
readonly NavigationHistory<NavigationState> history = new NavigationHistory<NavigationState>();
ILSpySettings spySettingsForMainWindow_Loaded;
internal SessionSettings sessionSettings;
@ -141,7 +142,7 @@ namespace ICSharpCode.ILSpy @@ -141,7 +142,7 @@ namespace ICSharpCode.ILSpy
{
return new Button {
Command = CommandWrapper.Unwrap(command.Value),
ToolTip =Properties.Resources.ResourceManager.GetString( command.Metadata.ToolTip),
ToolTip = Properties.Resources.ResourceManager.GetString(command.Metadata.ToolTip),
Tag = command.Metadata.Tag,
Content = new Image {
Width = 16,
@ -190,8 +191,8 @@ namespace ICSharpCode.ILSpy @@ -190,8 +191,8 @@ namespace ICSharpCode.ILSpy
internal static string GetResourceString(string key)
{
var str = !string.IsNullOrEmpty(key)? Properties.Resources.ResourceManager.GetString(key):null;
return string.IsNullOrEmpty(key)|| string.IsNullOrEmpty(str) ? key : str;
var str = !string.IsNullOrEmpty(key) ? Properties.Resources.ResourceManager.GetString(key) : null;
return string.IsNullOrEmpty(key) || string.IsNullOrEmpty(str) ? key : str;
}
#endregion
@ -227,6 +228,8 @@ namespace ICSharpCode.ILSpy @@ -227,6 +228,8 @@ namespace ICSharpCode.ILSpy
CopyDataStruct* copyData = (CopyDataStruct*)lParam;
string data = new string((char*)copyData->Buffer, 0, copyData->Size / sizeof(char));
if (data.StartsWith("ILSpy:\r\n", StringComparison.Ordinal)) {
if (handlingNugetPackageSelection)
return (IntPtr)1;
data = data.Substring(8);
List<string> lines = new List<string>();
using (StringReader r = new StringReader(data)) {
@ -270,7 +273,7 @@ namespace ICSharpCode.ILSpy @@ -270,7 +273,7 @@ namespace ICSharpCode.ILSpy
i++;
}
}
LoadAssemblies(args.AssembliesToLoad, commandLineLoadedAssemblies, false);
LoadAssemblies(args.AssembliesToLoad, commandLineLoadedAssemblies, focusNode: false);
if (args.Language != null)
sessionSettings.FilterSettings.Language = Languages.GetLanguage(args.Language);
return true;
@ -283,14 +286,15 @@ namespace ICSharpCode.ILSpy @@ -283,14 +286,15 @@ namespace ICSharpCode.ILSpy
void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args, ILSpySettings spySettings = null)
{
if (nugetPackagesToLoad.Count > 0) {
LoadAssemblies(nugetPackagesToLoad, commandLineLoadedAssemblies, focusNode: false);
var relevantPackages = nugetPackagesToLoad.ToArray();
nugetPackagesToLoad.Clear();
// Show the nuget package open dialog after the command line/window message was processed.
Dispatcher.BeginInvoke(new Action(() => LoadAssemblies(relevantPackages, commandLineLoadedAssemblies, focusNode: false)), DispatcherPriority.Normal);
}
var relevantAssemblies = commandLineLoadedAssemblies.ToList();
commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore
NavigateOnLaunch(args.NavigateTo, sessionSettings.ActiveTreeViewPath, spySettings, relevantAssemblies);
if (args.Search != null)
{
if (args.Search != null) {
SearchPane.Instance.SearchTerm = args.Search;
SearchPane.Instance.Show();
}
@ -494,7 +498,7 @@ namespace ICSharpCode.ILSpy @@ -494,7 +498,7 @@ namespace ICSharpCode.ILSpy
public void ShowMessageIfUpdatesAvailableAsync(ILSpySettings spySettings, bool forceCheck = false)
{
// Don't check for updates if we're in an MSIX since they work differently
if(WindowsVersionHelper.HasPackageIdentity) {
if (WindowsVersionHelper.HasPackageIdentity) {
return;
}
@ -542,8 +546,7 @@ namespace ICSharpCode.ILSpy @@ -542,8 +546,7 @@ namespace ICSharpCode.ILSpy
ILSpySettings settings = ILSpySettings.Load();
AssemblyList list = this.assemblyListManager.LoadList(settings, name);
//Only load a new list when it is a different one
if (list.ListName != CurrentAssemblyList.ListName)
{
if (list.ListName != CurrentAssemblyList.ListName) {
ShowAssemblyList(list);
}
}
@ -805,24 +808,29 @@ namespace ICSharpCode.ILSpy @@ -805,24 +808,29 @@ namespace ICSharpCode.ILSpy
foreach (string file in fileNames) {
switch (Path.GetExtension(file)) {
case ".nupkg":
LoadedNugetPackage package = new LoadedNugetPackage(file);
var selectionDialog = new NugetPackageBrowserDialog(package);
selectionDialog.Owner = this;
if (selectionDialog.ShowDialog() != true)
break;
foreach (var entry in selectionDialog.SelectedItems) {
var nugetAsm = assemblyList.OpenAssembly("nupkg://" + file + ";" + entry.Name, entry.Stream, true);
if (nugetAsm != null) {
if (loadedAssemblies != null)
loadedAssemblies.Add(nugetAsm);
else {
var node = assemblyListTreeNode.FindAssemblyNode(nugetAsm);
if (node != null && focusNode) {
treeView.SelectedItems.Add(node);
lastNode = node;
this.handlingNugetPackageSelection = true;
try {
LoadedNugetPackage package = new LoadedNugetPackage(file);
var selectionDialog = new NugetPackageBrowserDialog(package);
selectionDialog.Owner = this;
if (selectionDialog.ShowDialog() != true)
break;
foreach (var entry in selectionDialog.SelectedItems) {
var nugetAsm = assemblyList.OpenAssembly("nupkg://" + file + ";" + entry.Name, entry.Stream, true);
if (nugetAsm != null) {
if (loadedAssemblies != null)
loadedAssemblies.Add(nugetAsm);
else {
var node = assemblyListTreeNode.FindAssemblyNode(nugetAsm);
if (node != null && focusNode) {
treeView.SelectedItems.Add(node);
lastNode = node;
}
}
}
}
} finally {
this.handlingNugetPackageSelection = false;
}
break;
default:
@ -886,7 +894,7 @@ namespace ICSharpCode.ILSpy @@ -886,7 +894,7 @@ namespace ICSharpCode.ILSpy
if (recordHistory) {
var dtState = decompilerTextView.GetState();
if(dtState != null)
if (dtState != null)
history.UpdateCurrent(new NavigationState(dtState));
history.Record(new NavigationState(treeView.SelectedItems.OfType<SharpTreeNode>()));
}
@ -968,14 +976,13 @@ namespace ICSharpCode.ILSpy @@ -968,14 +976,13 @@ namespace ICSharpCode.ILSpy
void NavigateHistory(bool forward)
{
var dtState = decompilerTextView.GetState();
if(dtState != null)
if (dtState != null)
history.UpdateCurrent(new NavigationState(dtState));
var newState = forward ? history.GoForward() : history.GoBack();
ignoreDecompilationRequests = true;
treeView.SelectedItems.Clear();
foreach (var node in newState.TreeNodes)
{
foreach (var node in newState.TreeNodes) {
treeView.SelectedItems.Add(node);
}
if (newState.TreeNodes.Any())
@ -1038,14 +1045,12 @@ namespace ICSharpCode.ILSpy @@ -1038,14 +1045,12 @@ namespace ICSharpCode.ILSpy
var pane2Height = pane2Row.Height;
//only star height values are normalized.
if (!pane1Height.IsStar || !pane2Height.IsStar)
{
if (!pane1Height.IsStar || !pane2Height.IsStar) {
return;
}
var totalHeight = pane1Height.Value + pane2Height.Value;
if (totalHeight == 0)
{
if (totalHeight == 0) {
return;
}

Loading…
Cancel
Save