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. 223
      ILSpy/MainWindow.xaml.cs

2
ILSpy.AddIn/Commands/OpenReferenceCommand.cs

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

223
ILSpy/MainWindow.xaml.cs

@ -53,26 +53,27 @@ namespace ICSharpCode.ILSpy
partial class MainWindow : Window partial class MainWindow : Window
{ {
bool refreshInProgress; bool refreshInProgress;
bool handlingNugetPackageSelection;
readonly NavigationHistory<NavigationState> history = new NavigationHistory<NavigationState>(); readonly NavigationHistory<NavigationState> history = new NavigationHistory<NavigationState>();
ILSpySettings spySettingsForMainWindow_Loaded; ILSpySettings spySettingsForMainWindow_Loaded;
internal SessionSettings sessionSettings; internal SessionSettings sessionSettings;
internal AssemblyListManager assemblyListManager; internal AssemblyListManager assemblyListManager;
AssemblyList assemblyList; AssemblyList assemblyList;
AssemblyListTreeNode assemblyListTreeNode; AssemblyListTreeNode assemblyListTreeNode;
readonly DecompilerTextView decompilerTextView; readonly DecompilerTextView decompilerTextView;
static MainWindow instance; static MainWindow instance;
public static MainWindow Instance { public static MainWindow Instance {
get { return instance; } get { return instance; }
} }
public SessionSettings SessionSettings { public SessionSettings SessionSettings {
get { return sessionSettings; } get { return sessionSettings; }
} }
public MainWindow() public MainWindow()
{ {
instance = this; instance = this;
@ -80,28 +81,28 @@ namespace ICSharpCode.ILSpy
this.spySettingsForMainWindow_Loaded = spySettings; this.spySettingsForMainWindow_Loaded = spySettings;
this.sessionSettings = new SessionSettings(spySettings); this.sessionSettings = new SessionSettings(spySettings);
this.assemblyListManager = new AssemblyListManager(spySettings); this.assemblyListManager = new AssemblyListManager(spySettings);
this.Icon = new BitmapImage(new Uri("pack://application:,,,/ILSpy;component/images/ILSpy.ico")); this.Icon = new BitmapImage(new Uri("pack://application:,,,/ILSpy;component/images/ILSpy.ico"));
this.DataContext = sessionSettings; this.DataContext = sessionSettings;
InitializeComponent(); InitializeComponent();
decompilerTextView = App.ExportProvider.GetExportedValue<DecompilerTextView>(); decompilerTextView = App.ExportProvider.GetExportedValue<DecompilerTextView>();
mainPane.Content = decompilerTextView; mainPane.Content = decompilerTextView;
if (sessionSettings.SplitterPosition > 0 && sessionSettings.SplitterPosition < 1) { if (sessionSettings.SplitterPosition > 0 && sessionSettings.SplitterPosition < 1) {
leftColumn.Width = new GridLength(sessionSettings.SplitterPosition, GridUnitType.Star); leftColumn.Width = new GridLength(sessionSettings.SplitterPosition, GridUnitType.Star);
rightColumn.Width = new GridLength(1 - sessionSettings.SplitterPosition, GridUnitType.Star); rightColumn.Width = new GridLength(1 - sessionSettings.SplitterPosition, GridUnitType.Star);
} }
sessionSettings.FilterSettings.PropertyChanged += filterSettings_PropertyChanged; sessionSettings.FilterSettings.PropertyChanged += filterSettings_PropertyChanged;
InitMainMenu(); InitMainMenu();
InitToolbar(); InitToolbar();
ContextMenuProvider.Add(treeView, decompilerTextView); ContextMenuProvider.Add(treeView, decompilerTextView);
this.Loaded += MainWindow_Loaded; this.Loaded += MainWindow_Loaded;
} }
void SetWindowBounds(Rect bounds) void SetWindowBounds(Rect bounds)
{ {
this.Left = bounds.Left; this.Left = bounds.Left;
@ -109,9 +110,9 @@ namespace ICSharpCode.ILSpy
this.Width = bounds.Width; this.Width = bounds.Width;
this.Height = bounds.Height; this.Height = bounds.Height;
} }
#region Toolbar extensibility #region Toolbar extensibility
void InitToolbar() void InitToolbar()
{ {
int navigationPos = 0; int navigationPos = 0;
@ -134,14 +135,14 @@ namespace ICSharpCode.ILSpy
} }
} }
} }
} }
Button MakeToolbarItem(Lazy<ICommand, IToolbarCommandMetadata> command) Button MakeToolbarItem(Lazy<ICommand, IToolbarCommandMetadata> command)
{ {
return new Button { return new Button {
Command = CommandWrapper.Unwrap(command.Value), 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, Tag = command.Metadata.Tag,
Content = new Image { Content = new Image {
Width = 16, Width = 16,
@ -151,9 +152,9 @@ namespace ICSharpCode.ILSpy
}; };
} }
#endregion #endregion
#region Main Menu extensibility #region Main Menu extensibility
void InitMainMenu() void InitMainMenu()
{ {
var mainMenuCommands = App.ExportProvider.GetExports<ICommand, IMainMenuCommandMetadata>("MainMenuCommand"); var mainMenuCommands = App.ExportProvider.GetExports<ICommand, IMainMenuCommandMetadata>("MainMenuCommand");
@ -190,8 +191,8 @@ namespace ICSharpCode.ILSpy
internal static string GetResourceString(string key) internal static string GetResourceString(string key)
{ {
var str = !string.IsNullOrEmpty(key)? Properties.Resources.ResourceManager.GetString(key):null; var str = !string.IsNullOrEmpty(key) ? Properties.Resources.ResourceManager.GetString(key) : null;
return string.IsNullOrEmpty(key)|| string.IsNullOrEmpty(str) ? key : str; return string.IsNullOrEmpty(key) || string.IsNullOrEmpty(str) ? key : str;
} }
#endregion #endregion
@ -217,16 +218,18 @@ namespace ICSharpCode.ILSpy
SetWindowBounds(sessionSettings.WindowBounds); SetWindowBounds(sessionSettings.WindowBounds);
else else
SetWindowBounds(SessionSettings.DefaultWindowBounds); SetWindowBounds(SessionSettings.DefaultWindowBounds);
this.WindowState = sessionSettings.WindowState; this.WindowState = sessionSettings.WindowState;
} }
unsafe IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) unsafe IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{ {
if (msg == NativeMethods.WM_COPYDATA) { if (msg == NativeMethods.WM_COPYDATA) {
CopyDataStruct* copyData = (CopyDataStruct*)lParam; CopyDataStruct* copyData = (CopyDataStruct*)lParam;
string data = new string((char*)copyData->Buffer, 0, copyData->Size / sizeof(char)); string data = new string((char*)copyData->Buffer, 0, copyData->Size / sizeof(char));
if (data.StartsWith("ILSpy:\r\n", StringComparison.Ordinal)) { if (data.StartsWith("ILSpy:\r\n", StringComparison.Ordinal)) {
if (handlingNugetPackageSelection)
return (IntPtr)1;
data = data.Substring(8); data = data.Substring(8);
List<string> lines = new List<string>(); List<string> lines = new List<string>();
using (StringReader r = new StringReader(data)) { using (StringReader r = new StringReader(data)) {
@ -247,17 +250,17 @@ namespace ICSharpCode.ILSpy
return IntPtr.Zero; return IntPtr.Zero;
} }
#endregion #endregion
public AssemblyList CurrentAssemblyList { public AssemblyList CurrentAssemblyList {
get { return assemblyList; } get { return assemblyList; }
} }
public event NotifyCollectionChangedEventHandler CurrentAssemblyListChanged; public event NotifyCollectionChangedEventHandler CurrentAssemblyListChanged;
List<LoadedAssembly> commandLineLoadedAssemblies = new List<LoadedAssembly>(); List<LoadedAssembly> commandLineLoadedAssemblies = new List<LoadedAssembly>();
List<string> nugetPackagesToLoad = new List<string>(); List<string> nugetPackagesToLoad = new List<string>();
bool HandleCommandLineArguments(CommandLineArguments args) bool HandleCommandLineArguments(CommandLineArguments args)
{ {
int i = 0; int i = 0;
@ -270,12 +273,12 @@ namespace ICSharpCode.ILSpy
i++; i++;
} }
} }
LoadAssemblies(args.AssembliesToLoad, commandLineLoadedAssemblies, false); LoadAssemblies(args.AssembliesToLoad, commandLineLoadedAssemblies, focusNode: false);
if (args.Language != null) if (args.Language != null)
sessionSettings.FilterSettings.Language = Languages.GetLanguage(args.Language); sessionSettings.FilterSettings.Language = Languages.GetLanguage(args.Language);
return true; return true;
} }
/// <summary> /// <summary>
/// Called on startup or when passed arguments via WndProc from a second instance. /// Called on startup or when passed arguments via WndProc from a second instance.
/// In the format case, spySettings is non-null; in the latter it is null. /// In the format case, spySettings is non-null; in the latter it is null.
@ -283,14 +286,15 @@ namespace ICSharpCode.ILSpy
void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args, ILSpySettings spySettings = null) void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args, ILSpySettings spySettings = null)
{ {
if (nugetPackagesToLoad.Count > 0) { if (nugetPackagesToLoad.Count > 0) {
LoadAssemblies(nugetPackagesToLoad, commandLineLoadedAssemblies, focusNode: false); var relevantPackages = nugetPackagesToLoad.ToArray();
nugetPackagesToLoad.Clear(); 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(); var relevantAssemblies = commandLineLoadedAssemblies.ToList();
commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore
NavigateOnLaunch(args.NavigateTo, sessionSettings.ActiveTreeViewPath, spySettings, relevantAssemblies); NavigateOnLaunch(args.NavigateTo, sessionSettings.ActiveTreeViewPath, spySettings, relevantAssemblies);
if (args.Search != null) if (args.Search != null) {
{
SearchPane.Instance.SearchTerm = args.Search; SearchPane.Instance.SearchTerm = args.Search;
SearchPane.Instance.Show(); SearchPane.Instance.Show();
} }
@ -448,12 +452,12 @@ namespace ICSharpCode.ILSpy
void OpenAssemblies(ILSpySettings spySettings) void OpenAssemblies(ILSpySettings spySettings)
{ {
HandleCommandLineArgumentsAfterShowList(App.CommandLineArguments, spySettings); HandleCommandLineArgumentsAfterShowList(App.CommandLineArguments, spySettings);
AvalonEditTextOutput output = new AvalonEditTextOutput(); AvalonEditTextOutput output = new AvalonEditTextOutput();
if (FormatExceptions(App.StartupExceptions.ToArray(), output)) if (FormatExceptions(App.StartupExceptions.ToArray(), output))
decompilerTextView.ShowText(output); decompilerTextView.ShowText(output);
} }
bool FormatExceptions(App.ExceptionData[] exceptions, ITextOutput output) bool FormatExceptions(App.ExceptionData[] exceptions, ITextOutput output)
{ {
var stringBuilder = new StringBuilder(); var stringBuilder = new StringBuilder();
@ -468,7 +472,7 @@ namespace ICSharpCode.ILSpy
{ {
if (exceptions.Length == 0) return false; if (exceptions.Length == 0) return false;
bool first = true; bool first = true;
foreach (var item in exceptions) { foreach (var item in exceptions) {
if (first) if (first)
first = false; first = false;
@ -484,17 +488,17 @@ namespace ICSharpCode.ILSpy
} else } else
output.AppendLine(item.Exception.ToString()); output.AppendLine(item.Exception.ToString());
} }
return true; return true;
} }
#region Update Check #region Update Check
string updateAvailableDownloadUrl; string updateAvailableDownloadUrl;
public void ShowMessageIfUpdatesAvailableAsync(ILSpySettings spySettings, bool forceCheck = false) public void ShowMessageIfUpdatesAvailableAsync(ILSpySettings spySettings, bool forceCheck = false)
{ {
// Don't check for updates if we're in an MSIX since they work differently // Don't check for updates if we're in an MSIX since they work differently
if(WindowsVersionHelper.HasPackageIdentity) { if (WindowsVersionHelper.HasPackageIdentity) {
return; return;
} }
@ -506,12 +510,12 @@ namespace ICSharpCode.ILSpy
} }
result.ContinueWith(task => AdjustUpdateUIAfterCheck(task, forceCheck), TaskScheduler.FromCurrentSynchronizationContext()); result.ContinueWith(task => AdjustUpdateUIAfterCheck(task, forceCheck), TaskScheduler.FromCurrentSynchronizationContext());
} }
void updatePanelCloseButtonClick(object sender, RoutedEventArgs e) void updatePanelCloseButtonClick(object sender, RoutedEventArgs e)
{ {
updatePanel.Visibility = Visibility.Collapsed; updatePanel.Visibility = Visibility.Collapsed;
} }
void downloadOrCheckUpdateButtonClick(object sender, RoutedEventArgs e) void downloadOrCheckUpdateButtonClick(object sender, RoutedEventArgs e)
{ {
if (updateAvailableDownloadUrl != null) { if (updateAvailableDownloadUrl != null) {
@ -536,30 +540,29 @@ namespace ICSharpCode.ILSpy
} }
} }
#endregion #endregion
public void ShowAssemblyList(string name) public void ShowAssemblyList(string name)
{ {
ILSpySettings settings = ILSpySettings.Load(); ILSpySettings settings = ILSpySettings.Load();
AssemblyList list = this.assemblyListManager.LoadList(settings, name); AssemblyList list = this.assemblyListManager.LoadList(settings, name);
//Only load a new list when it is a different one //Only load a new list when it is a different one
if (list.ListName != CurrentAssemblyList.ListName) if (list.ListName != CurrentAssemblyList.ListName) {
{
ShowAssemblyList(list); ShowAssemblyList(list);
} }
} }
void ShowAssemblyList(AssemblyList assemblyList) void ShowAssemblyList(AssemblyList assemblyList)
{ {
history.Clear(); history.Clear();
this.assemblyList = assemblyList; this.assemblyList = assemblyList;
assemblyList.assemblies.CollectionChanged += assemblyList_Assemblies_CollectionChanged; assemblyList.assemblies.CollectionChanged += assemblyList_Assemblies_CollectionChanged;
assemblyListTreeNode = new AssemblyListTreeNode(assemblyList); assemblyListTreeNode = new AssemblyListTreeNode(assemblyList);
assemblyListTreeNode.FilterSettings = sessionSettings.FilterSettings.Clone(); assemblyListTreeNode.FilterSettings = sessionSettings.FilterSettings.Clone();
assemblyListTreeNode.Select = SelectNode; assemblyListTreeNode.Select = SelectNode;
treeView.Root = assemblyListTreeNode; treeView.Root = assemblyListTreeNode;
if (assemblyList.ListName == AssemblyListManager.DefaultListName) if (assemblyList.ListName == AssemblyListManager.DefaultListName)
#if DEBUG #if DEBUG
this.Title = $"ILSpy {RevisionClass.FullVersion}"; this.Title = $"ILSpy {RevisionClass.FullVersion}";
@ -588,7 +591,7 @@ namespace ICSharpCode.ILSpy
if (CurrentAssemblyListChanged != null) if (CurrentAssemblyListChanged != null)
CurrentAssemblyListChanged(this, e); CurrentAssemblyListChanged(this, e);
} }
void LoadInitialAssemblies() void LoadInitialAssemblies()
{ {
// Called when loading an empty assembly list; so that // Called when loading an empty assembly list; so that
@ -606,7 +609,7 @@ namespace ICSharpCode.ILSpy
foreach (System.Reflection.Assembly asm in initialAssemblies) foreach (System.Reflection.Assembly asm in initialAssemblies)
assemblyList.OpenAssembly(asm.Location); assemblyList.OpenAssembly(asm.Location);
} }
void filterSettings_PropertyChanged(object sender, PropertyChangedEventArgs e) void filterSettings_PropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
RefreshTreeViewFilter(); RefreshTreeViewFilter();
@ -614,7 +617,7 @@ namespace ICSharpCode.ILSpy
DecompileSelectedNodes(recordHistory: false); DecompileSelectedNodes(recordHistory: false);
} }
} }
public void RefreshTreeViewFilter() public void RefreshTreeViewFilter()
{ {
// filterSettings is mutable; but the ILSpyTreeNode filtering assumes that filter settings are immutable. // filterSettings is mutable; but the ILSpyTreeNode filtering assumes that filter settings are immutable.
@ -623,11 +626,11 @@ namespace ICSharpCode.ILSpy
if (assemblyListTreeNode != null) if (assemblyListTreeNode != null)
assemblyListTreeNode.FilterSettings = sessionSettings.FilterSettings.Clone(); assemblyListTreeNode.FilterSettings = sessionSettings.FilterSettings.Clone();
} }
internal AssemblyListTreeNode AssemblyListTreeNode { internal AssemblyListTreeNode AssemblyListTreeNode {
get { return assemblyListTreeNode; } get { return assemblyListTreeNode; }
} }
#region Node Selection #region Node Selection
public void SelectNode(SharpTreeNode obj) public void SelectNode(SharpTreeNode obj)
@ -653,7 +656,7 @@ namespace ICSharpCode.ILSpy
treeView.SetSelectedNodes(nodes); treeView.SetSelectedNodes(nodes);
} }
} }
/// <summary> /// <summary>
/// Retrieves a node using the .ToString() representations of its ancestors. /// Retrieves a node using the .ToString() representations of its ancestors.
/// </summary> /// </summary>
@ -678,7 +681,7 @@ namespace ICSharpCode.ILSpy
else else
return node; return node;
} }
/// <summary> /// <summary>
/// Gets the .ToString() representation of the node's ancestors. /// Gets the .ToString() representation of the node's ancestors.
/// </summary> /// </summary>
@ -694,7 +697,7 @@ namespace ICSharpCode.ILSpy
path.Reverse(); path.Reverse();
return path.ToArray(); return path.ToArray();
} }
public ILSpyTreeNode FindTreeNode(object reference) public ILSpyTreeNode FindTreeNode(object reference)
{ {
switch (reference) { switch (reference) {
@ -716,12 +719,12 @@ namespace ICSharpCode.ILSpy
return null; return null;
} }
} }
public void JumpToReference(object reference) public void JumpToReference(object reference)
{ {
JumpToReferenceAsync(reference).HandleExceptions(); JumpToReferenceAsync(reference).HandleExceptions();
} }
/// <summary> /// <summary>
/// Jumps to the specified reference. /// Jumps to the specified reference.
/// </summary> /// </summary>
@ -792,7 +795,7 @@ namespace ICSharpCode.ILSpy
{ {
if (fileNames == null) if (fileNames == null)
throw new ArgumentNullException(nameof(fileNames)); throw new ArgumentNullException(nameof(fileNames));
if (focusNode) if (focusNode)
treeView.UnselectAll(); treeView.UnselectAll();
@ -805,24 +808,29 @@ namespace ICSharpCode.ILSpy
foreach (string file in fileNames) { foreach (string file in fileNames) {
switch (Path.GetExtension(file)) { switch (Path.GetExtension(file)) {
case ".nupkg": case ".nupkg":
LoadedNugetPackage package = new LoadedNugetPackage(file); this.handlingNugetPackageSelection = true;
var selectionDialog = new NugetPackageBrowserDialog(package); try {
selectionDialog.Owner = this; LoadedNugetPackage package = new LoadedNugetPackage(file);
if (selectionDialog.ShowDialog() != true) var selectionDialog = new NugetPackageBrowserDialog(package);
break; selectionDialog.Owner = this;
foreach (var entry in selectionDialog.SelectedItems) { if (selectionDialog.ShowDialog() != true)
var nugetAsm = assemblyList.OpenAssembly("nupkg://" + file + ";" + entry.Name, entry.Stream, true); break;
if (nugetAsm != null) { foreach (var entry in selectionDialog.SelectedItems) {
if (loadedAssemblies != null) var nugetAsm = assemblyList.OpenAssembly("nupkg://" + file + ";" + entry.Name, entry.Stream, true);
loadedAssemblies.Add(nugetAsm); if (nugetAsm != null) {
else { if (loadedAssemblies != null)
var node = assemblyListTreeNode.FindAssemblyNode(nugetAsm); loadedAssemblies.Add(nugetAsm);
if (node != null && focusNode) { else {
treeView.SelectedItems.Add(node); var node = assemblyListTreeNode.FindAssemblyNode(nugetAsm);
lastNode = node; if (node != null && focusNode) {
treeView.SelectedItems.Add(node);
lastNode = node;
}
} }
} }
} }
} finally {
this.handlingNugetPackageSelection = false;
} }
break; break;
default: default:
@ -845,7 +853,7 @@ namespace ICSharpCode.ILSpy
treeView.FocusNode(lastNode); treeView.FocusNode(lastNode);
} }
} }
void RefreshCommandExecuted(object sender, ExecutedRoutedEventArgs e) void RefreshCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{ {
try { try {
@ -857,13 +865,13 @@ namespace ICSharpCode.ILSpy
refreshInProgress = false; refreshInProgress = false;
} }
} }
void SearchCommandExecuted(object sender, ExecutedRoutedEventArgs e) void SearchCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{ {
SearchPane.Instance.Show(); SearchPane.Instance.Show();
} }
#endregion #endregion
#region Decompile (TreeView_SelectionChanged) #region Decompile (TreeView_SelectionChanged)
void TreeView_SelectionChanged(object sender, SelectionChangedEventArgs e) void TreeView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
@ -872,10 +880,10 @@ namespace ICSharpCode.ILSpy
if (SelectionChanged != null) if (SelectionChanged != null)
SelectionChanged(sender, e); SelectionChanged(sender, e);
} }
Task decompilationTask; Task decompilationTask;
bool ignoreDecompilationRequests; bool ignoreDecompilationRequests;
void DecompileSelectedNodes(DecompilerTextViewState state = null, bool recordHistory = true) void DecompileSelectedNodes(DecompilerTextViewState state = null, bool recordHistory = true)
{ {
if (ignoreDecompilationRequests) if (ignoreDecompilationRequests)
@ -883,14 +891,14 @@ namespace ICSharpCode.ILSpy
if (treeView.SelectedItems.Count == 0 && refreshInProgress) if (treeView.SelectedItems.Count == 0 && refreshInProgress)
return; return;
if (recordHistory) { if (recordHistory) {
var dtState = decompilerTextView.GetState(); var dtState = decompilerTextView.GetState();
if(dtState != null) if (dtState != null)
history.UpdateCurrent(new NavigationState(dtState)); history.UpdateCurrent(new NavigationState(dtState));
history.Record(new NavigationState(treeView.SelectedItems.OfType<SharpTreeNode>())); history.Record(new NavigationState(treeView.SelectedItems.OfType<SharpTreeNode>()));
} }
if (treeView.SelectedItems.Count == 1) { if (treeView.SelectedItems.Count == 1) {
ILSpyTreeNode node = treeView.SelectedItem as ILSpyTreeNode; ILSpyTreeNode node = treeView.SelectedItem as ILSpyTreeNode;
if (node != null && node.View(decompilerTextView)) if (node != null && node.View(decompilerTextView))
@ -919,7 +927,7 @@ namespace ICSharpCode.ILSpy
refreshInProgress = false; refreshInProgress = false;
} }
} }
public DecompilerTextView TextView { public DecompilerTextView TextView {
get { return decompilerTextView; } get { return decompilerTextView; }
} }
@ -942,7 +950,7 @@ namespace ICSharpCode.ILSpy
e.Handled = true; e.Handled = true;
e.CanExecute = history.CanNavigateBack; e.CanExecute = history.CanNavigateBack;
} }
void BackCommandExecuted(object sender, ExecutedRoutedEventArgs e) void BackCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{ {
if (history.CanNavigateBack) { if (history.CanNavigateBack) {
@ -950,13 +958,13 @@ namespace ICSharpCode.ILSpy
NavigateHistory(false); NavigateHistory(false);
} }
} }
void ForwardCommandCanExecute(object sender, CanExecuteRoutedEventArgs e) void ForwardCommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
{ {
e.Handled = true; e.Handled = true;
e.CanExecute = history.CanNavigateForward; e.CanExecute = history.CanNavigateForward;
} }
void ForwardCommandExecuted(object sender, ExecutedRoutedEventArgs e) void ForwardCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{ {
if (history.CanNavigateForward) { if (history.CanNavigateForward) {
@ -964,18 +972,17 @@ namespace ICSharpCode.ILSpy
NavigateHistory(true); NavigateHistory(true);
} }
} }
void NavigateHistory(bool forward) void NavigateHistory(bool forward)
{ {
var dtState = decompilerTextView.GetState(); var dtState = decompilerTextView.GetState();
if(dtState != null) if (dtState != null)
history.UpdateCurrent(new NavigationState(dtState)); history.UpdateCurrent(new NavigationState(dtState));
var newState = forward ? history.GoForward() : history.GoBack(); var newState = forward ? history.GoForward() : history.GoBack();
ignoreDecompilationRequests = true; ignoreDecompilationRequests = true;
treeView.SelectedItems.Clear(); treeView.SelectedItems.Clear();
foreach (var node in newState.TreeNodes) foreach (var node in newState.TreeNodes) {
{
treeView.SelectedItems.Add(node); treeView.SelectedItems.Add(node);
} }
if (newState.TreeNodes.Any()) if (newState.TreeNodes.Any())
@ -983,9 +990,9 @@ namespace ICSharpCode.ILSpy
ignoreDecompilationRequests = false; ignoreDecompilationRequests = false;
DecompileSelectedNodes(newState.ViewState, false); DecompileSelectedNodes(newState.ViewState, false);
} }
#endregion #endregion
protected override void OnStateChanged(EventArgs e) protected override void OnStateChanged(EventArgs e)
{ {
base.OnStateChanged(e); base.OnStateChanged(e);
@ -993,7 +1000,7 @@ namespace ICSharpCode.ILSpy
if (this.WindowState != System.Windows.WindowState.Minimized) if (this.WindowState != System.Windows.WindowState.Minimized)
sessionSettings.WindowState = this.WindowState; sessionSettings.WindowState = this.WindowState;
} }
protected override void OnClosing(CancelEventArgs e) protected override void OnClosing(CancelEventArgs e)
{ {
base.OnClosing(e); base.OnClosing(e);
@ -1024,7 +1031,7 @@ namespace ICSharpCode.ILSpy
return loadedAssy.FileName; return loadedAssy.FileName;
} }
#region Top/Bottom Pane management #region Top/Bottom Pane management
/// <summary> /// <summary>
@ -1038,14 +1045,12 @@ namespace ICSharpCode.ILSpy
var pane2Height = pane2Row.Height; var pane2Height = pane2Row.Height;
//only star height values are normalized. //only star height values are normalized.
if (!pane1Height.IsStar || !pane2Height.IsStar) if (!pane1Height.IsStar || !pane2Height.IsStar) {
{
return; return;
} }
var totalHeight = pane1Height.Value + pane2Height.Value; var totalHeight = pane1Height.Value + pane2Height.Value;
if (totalHeight == 0) if (totalHeight == 0) {
{
return; return;
} }
@ -1072,20 +1077,20 @@ namespace ICSharpCode.ILSpy
} }
topPane.Visibility = Visibility.Visible; topPane.Visibility = Visibility.Visible;
} }
void TopPane_CloseButtonClicked(object sender, EventArgs e) void TopPane_CloseButtonClicked(object sender, EventArgs e)
{ {
sessionSettings.TopPaneSplitterPosition = topPaneRow.Height.Value / (topPaneRow.Height.Value + textViewRow.Height.Value); sessionSettings.TopPaneSplitterPosition = topPaneRow.Height.Value / (topPaneRow.Height.Value + textViewRow.Height.Value);
topPaneRow.MinHeight = 0; topPaneRow.MinHeight = 0;
topPaneRow.Height = new GridLength(0); topPaneRow.Height = new GridLength(0);
topPane.Visibility = Visibility.Collapsed; topPane.Visibility = Visibility.Collapsed;
IPane pane = topPane.Content as IPane; IPane pane = topPane.Content as IPane;
topPane.Content = null; topPane.Content = null;
if (pane != null) if (pane != null)
pane.Closed(); pane.Closed();
} }
public void ShowInBottomPane(string title, object content) public void ShowInBottomPane(string title, object content)
{ {
bottomPaneRow.MinHeight = 100; bottomPaneRow.MinHeight = 100;
@ -1105,26 +1110,26 @@ namespace ICSharpCode.ILSpy
} }
bottomPane.Visibility = Visibility.Visible; bottomPane.Visibility = Visibility.Visible;
} }
void BottomPane_CloseButtonClicked(object sender, EventArgs e) void BottomPane_CloseButtonClicked(object sender, EventArgs e)
{ {
sessionSettings.BottomPaneSplitterPosition = bottomPaneRow.Height.Value / (bottomPaneRow.Height.Value + textViewRow.Height.Value); sessionSettings.BottomPaneSplitterPosition = bottomPaneRow.Height.Value / (bottomPaneRow.Height.Value + textViewRow.Height.Value);
bottomPaneRow.MinHeight = 0; bottomPaneRow.MinHeight = 0;
bottomPaneRow.Height = new GridLength(0); bottomPaneRow.Height = new GridLength(0);
bottomPane.Visibility = Visibility.Collapsed; bottomPane.Visibility = Visibility.Collapsed;
IPane pane = bottomPane.Content as IPane; IPane pane = bottomPane.Content as IPane;
bottomPane.Content = null; bottomPane.Content = null;
if (pane != null) if (pane != null)
pane.Closed(); pane.Closed();
} }
#endregion #endregion
public void UnselectAll() public void UnselectAll()
{ {
treeView.UnselectAll(); treeView.UnselectAll();
} }
public void SetStatus(string status, Brush foreground) public void SetStatus(string status, Brush foreground)
{ {
if (this.statusBar.Visibility == Visibility.Collapsed) if (this.statusBar.Visibility == Visibility.Collapsed)
@ -1132,12 +1137,12 @@ namespace ICSharpCode.ILSpy
this.StatusLabel.Foreground = foreground; this.StatusLabel.Foreground = foreground;
this.StatusLabel.Text = status; this.StatusLabel.Text = status;
} }
public ItemCollection GetMainMenuItems() public ItemCollection GetMainMenuItems()
{ {
return mainMenu.Items; return mainMenu.Items;
} }
public ItemCollection GetToolBarItems() public ItemCollection GetToolBarItems()
{ {
return toolBar.Items; return toolBar.Items;

Loading…
Cancel
Save