Browse Source

Fix navigation history

pull/3283/head
tom-englert 8 months ago
parent
commit
5b8e7ce6eb
  1. 38
      ILSpy/AssemblyTree/AssemblyTreeModel.cs
  2. 1
      ILSpy/MainWindow.xaml

38
ILSpy/AssemblyTree/AssemblyTreeModel.cs

@ -44,15 +44,15 @@ using System.Windows;
using ICSharpCode.Decompiler.Documentation; using ICSharpCode.Decompiler.Documentation;
using ICSharpCode.Decompiler.TypeSystem.Implementation; using ICSharpCode.Decompiler.TypeSystem.Implementation;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using System.Text;
using System.Windows.Navigation;
using ICSharpCode.ILSpy.AppEnv; using ICSharpCode.ILSpy.AppEnv;
using ICSharpCode.ILSpy.Search; using ICSharpCode.ILSpy.Search;
using ICSharpCode.Decompiler; using ICSharpCode.Decompiler;
using System.Text;
using TomsToolbox.Essentials; using TomsToolbox.Essentials;
using TomsToolbox.Wpf; using TomsToolbox.Wpf;
using System.Windows.Navigation;
namespace ICSharpCode.ILSpy.AssemblyTree namespace ICSharpCode.ILSpy.AssemblyTree
{ {
@ -67,6 +67,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree
AssemblyListTreeNode assemblyListTreeNode; AssemblyListTreeNode assemblyListTreeNode;
readonly NavigationHistory<NavigationState> history = new(); readonly NavigationHistory<NavigationState> history = new();
private bool isNavigatingHistory;
public AssemblyTreeModel() public AssemblyTreeModel()
{ {
@ -78,7 +79,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree
MessageBus<NavigateToReferenceEventArgs>.Subscribers += JumpToReference; MessageBus<NavigateToReferenceEventArgs>.Subscribers += JumpToReference;
MessageBus<SettingsChangedEventArgs>.Subscribers += (sender, e) => Settings_PropertyChanged(sender, e); MessageBus<SettingsChangedEventArgs>.Subscribers += (sender, e) => Settings_PropertyChanged(sender, e);
var selectionChangeThrottle = new DispatcherThrottle(DispatcherPriority.Background, TreeView_SelectionChanged); var selectionChangeThrottle = new DispatcherThrottle(DispatcherPriority.Input, TreeView_SelectionChanged);
SelectedItems.CollectionChanged += (_, _) => selectionChangeThrottle.Tick(); SelectedItems.CollectionChanged += (_, _) => selectionChangeThrottle.Tick();
} }
@ -94,8 +95,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree
case nameof(SessionSettings.Theme): case nameof(SessionSettings.Theme):
// update syntax highlighting and force reload (AvalonEdit does not automatically refresh on highlighting change) // update syntax highlighting and force reload (AvalonEdit does not automatically refresh on highlighting change)
DecompilerTextView.RegisterHighlighting(); DecompilerTextView.RegisterHighlighting();
DecompileSelectedNodes( DecompileSelectedNodes(DockWorkspace.Instance.ActiveTabPage.GetState() as DecompilerTextViewState);
DockWorkspace.Instance.ActiveTabPage.GetState() as DecompilerTextViewState);
break; break;
case nameof(SessionSettings.CurrentCulture): case nameof(SessionSettings.CurrentCulture):
MessageBox.Show(Properties.Resources.SettingsChangeRestartRequired, "ILSpy"); MessageBox.Show(Properties.Resources.SettingsChangeRestartRequired, "ILSpy");
@ -107,7 +107,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree
switch (e.PropertyName) switch (e.PropertyName)
{ {
case nameof(LanguageSettings.Language) or nameof(LanguageSettings.LanguageVersion): case nameof(LanguageSettings.Language) or nameof(LanguageSettings.LanguageVersion):
DecompileSelectedNodes(recordHistory: false); DecompileSelectedNodes();
break; break;
} }
} }
@ -692,6 +692,15 @@ namespace ICSharpCode.ILSpy.AssemblyTree
{ {
if (SelectedItems.Count > 0) if (SelectedItems.Count > 0)
{ {
if (!isNavigatingHistory)
{
var activeTabPage = DockWorkspace.Instance.ActiveTabPage;
var currentState = activeTabPage.GetState();
if (currentState != null)
history.UpdateCurrent(new NavigationState(activeTabPage, currentState));
history.Record(new NavigationState(activeTabPage, SelectedItems));
}
var delayDecompilationRequestDueToContextMenu = Mouse.RightButton == MouseButtonState.Pressed; var delayDecompilationRequestDueToContextMenu = Mouse.RightButton == MouseButtonState.Pressed;
if (!delayDecompilationRequestDueToContextMenu) if (!delayDecompilationRequestDueToContextMenu)
@ -721,18 +730,10 @@ namespace ICSharpCode.ILSpy.AssemblyTree
} }
} }
public void DecompileSelectedNodes(DecompilerTextViewState newState = null, bool recordHistory = true) private void DecompileSelectedNodes(DecompilerTextViewState newState = null)
{ {
var activeTabPage = DockWorkspace.Instance.ActiveTabPage; var activeTabPage = DockWorkspace.Instance.ActiveTabPage;
if (recordHistory)
{
var currentState = activeTabPage.GetState();
if (currentState != null)
history.UpdateCurrent(new NavigationState(activeTabPage, currentState));
history.Record(new NavigationState(activeTabPage, SelectedItems));
}
activeTabPage.SupportsLanguageSwitching = true; activeTabPage.SupportsLanguageSwitching = true;
if (SelectedItems.Count == 1) if (SelectedItems.Count == 1)
@ -742,7 +743,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree
} }
if (newState?.ViewedUri != null) if (newState?.ViewedUri != null)
{ {
MainWindow.Instance.AssemblyTreeModel.NavigateTo(new(newState.ViewedUri, null), recordHistory: false); NavigateTo(new(newState.ViewedUri, null), recordHistory: false);
return; return;
} }
@ -770,6 +771,9 @@ namespace ICSharpCode.ILSpy.AssemblyTree
public void NavigateHistory(bool forward) public void NavigateHistory(bool forward)
{ {
isNavigatingHistory = true;
this.Dispatcher.BeginInvoke(DispatcherPriority.Background, () => isNavigatingHistory = false);
TabPageModel tabPage = DockWorkspace.Instance.ActiveTabPage; TabPageModel tabPage = DockWorkspace.Instance.ActiveTabPage;
var state = tabPage.GetState(); var state = tabPage.GetState();
if (state != null) if (state != null)
@ -779,7 +783,6 @@ namespace ICSharpCode.ILSpy.AssemblyTree
DockWorkspace.Instance.ActiveTabPage = newState.TabPage; DockWorkspace.Instance.ActiveTabPage = newState.TabPage;
SelectNodes(newState.TreeNodes); SelectNodes(newState.TreeNodes);
DecompileSelectedNodes(newState.ViewState as DecompilerTextViewState, false);
} }
public bool CanNavigateBack => history.CanNavigateBack; public bool CanNavigateBack => history.CanNavigateBack;
@ -802,6 +805,7 @@ namespace ICSharpCode.ILSpy.AssemblyTree
e.Handled = true; e.Handled = true;
return; return;
} }
AvalonEditTextOutput output = new AvalonEditTextOutput { AvalonEditTextOutput output = new AvalonEditTextOutput {
Address = e.Uri, Address = e.Uri,
Title = e.Uri.AbsolutePath, Title = e.Uri.AbsolutePath,

1
ILSpy/MainWindow.xaml

@ -37,6 +37,7 @@
<Window.InputBindings> <Window.InputBindings>
<KeyBinding Key="R" Modifiers="Control" Command="{x:Static local:ILSpyCommands.Analyze}" /> <KeyBinding Key="R" Modifiers="Control" Command="{x:Static local:ILSpyCommands.Analyze}" />
<KeyBinding Key="Z" Modifiers="Control" Command="{x:Static NavigationCommands.BrowseBack}" />
</Window.InputBindings> </Window.InputBindings>
<Window.TaskbarItemInfo> <Window.TaskbarItemInfo>

Loading…
Cancel
Save