44
44
using ICSharpCode . Decompiler . Documentation ;
45
45
using ICSharpCode . Decompiler . TypeSystem . Implementation ;
46
46
using System . Reflection . Metadata ;
47
+ using System . Text ;
48
+ using System . Windows . Navigation ;
47
49
48
50
using ICSharpCode . ILSpy . AppEnv ;
49
51
using ICSharpCode . ILSpy . Search ;
50
52
using ICSharpCode . Decompiler ;
51
- using System . Text ;
52
53
53
54
using TomsToolbox . Essentials ;
54
55
using TomsToolbox . Wpf ;
55
- using System . Windows . Navigation ;
56
56
57
57
namespace ICSharpCode . ILSpy . AssemblyTree
58
58
{
@@ -67,6 +67,7 @@ public class AssemblyTreeModel : ToolPaneModel
67
67
AssemblyListTreeNode assemblyListTreeNode ;
68
68
69
69
readonly NavigationHistory < NavigationState > history = new ( ) ;
70
+ private bool isNavigatingHistory ;
70
71
71
72
public AssemblyTreeModel ( )
72
73
{
@@ -78,7 +79,7 @@ public AssemblyTreeModel()
78
79
MessageBus < NavigateToReferenceEventArgs > . Subscribers += JumpToReference ;
79
80
MessageBus < SettingsChangedEventArgs > . Subscribers += ( sender , e ) => Settings_PropertyChanged ( sender , e ) ;
80
81
81
- var selectionChangeThrottle = new DispatcherThrottle ( DispatcherPriority . Background , TreeView_SelectionChanged ) ;
82
+ var selectionChangeThrottle = new DispatcherThrottle ( DispatcherPriority . Input , TreeView_SelectionChanged ) ;
82
83
SelectedItems . CollectionChanged += ( _ , _ ) => selectionChangeThrottle . Tick ( ) ;
83
84
}
84
85
@@ -94,8 +95,7 @@ private void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e)
94
95
case nameof ( SessionSettings . Theme ) :
95
96
// update syntax highlighting and force reload (AvalonEdit does not automatically refresh on highlighting change)
96
97
DecompilerTextView . RegisterHighlighting ( ) ;
97
- DecompileSelectedNodes (
98
- DockWorkspace . Instance . ActiveTabPage . GetState ( ) as DecompilerTextViewState ) ;
98
+ DecompileSelectedNodes ( DockWorkspace . Instance . ActiveTabPage . GetState ( ) as DecompilerTextViewState ) ;
99
99
break ;
100
100
case nameof ( SessionSettings . CurrentCulture ) :
101
101
MessageBox . Show ( Properties . Resources . SettingsChangeRestartRequired , "ILSpy" ) ;
@@ -107,7 +107,7 @@ private void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e)
107
107
switch ( e . PropertyName )
108
108
{
109
109
case nameof ( LanguageSettings . Language ) or nameof ( LanguageSettings . LanguageVersion ) :
110
- DecompileSelectedNodes ( recordHistory : false ) ;
110
+ DecompileSelectedNodes ( ) ;
111
111
break ;
112
112
}
113
113
}
@@ -502,36 +502,26 @@ public void SelectNode(SharpTreeNode node, bool inNewTabPage = false)
502
502
}
503
503
}
504
504
505
- internal void SelectNodes ( IEnumerable < SharpTreeNode > nodes , bool ignoreCompilationRequests = false )
505
+ internal void SelectNodes ( IEnumerable < SharpTreeNode > nodes )
506
506
{
507
- this . ignoreDecompilationRequests = ignoreCompilationRequests ;
507
+ // Ensure nodes exist
508
+ var nodesList = nodes . Select ( n => FindNodeByPath ( GetPathForNode ( n ) , true ) )
509
+ . Where ( n => n != null )
510
+ . ToArray ( ) ;
508
511
509
- try
512
+ if ( ! nodesList . Any ( ) || nodesList . Any ( n => n . AncestorsAndSelf ( ) . Any ( a => a . IsHidden ) ) )
510
513
{
511
- // Ensure nodes exist
512
- var nodesList = nodes . Select ( n => FindNodeByPath ( GetPathForNode ( n ) , true ) )
513
- . Where ( n => n != null )
514
- . ToArray ( ) ;
515
-
516
- if ( ! nodesList . Any ( ) || nodesList . Any ( n => n . AncestorsAndSelf ( ) . Any ( a => a . IsHidden ) ) )
517
- {
518
- return ;
519
- }
520
-
521
- if ( SelectedItems . SequenceEqual ( nodesList ) )
522
- {
523
- Dispatcher . BeginInvoke ( RefreshDecompiledView ) ;
524
- return ;
525
- }
526
-
527
- SelectedItems . Clear ( ) ;
528
- SelectedItems . AddRange ( nodesList ) ;
514
+ return ;
529
515
}
530
- finally
516
+
517
+ if ( SelectedItems . SequenceEqual ( nodesList ) )
531
518
{
532
- this . ignoreDecompilationRequests = false ;
519
+ Dispatcher . BeginInvoke ( RefreshDecompiledView ) ;
520
+ return ;
533
521
}
534
522
523
+ SelectedItems . Clear ( ) ;
524
+ SelectedItems . AddRange ( nodesList ) ;
535
525
}
536
526
537
527
/// <summary>
@@ -700,15 +690,27 @@ public void LoadAssemblies(IEnumerable<string> fileNames, List<LoadedAssembly> l
700
690
701
691
void TreeView_SelectionChanged ( )
702
692
{
703
- var delayDecompilationRequestDueToContextMenu = Mouse . RightButton == MouseButtonState . Pressed ;
704
-
705
- if ( ! delayDecompilationRequestDueToContextMenu )
706
- {
707
- DecompileSelectedNodes ( ) ;
708
- }
709
- else
693
+ if ( SelectedItems . Count > 0 )
710
694
{
711
- ContextMenuProvider . ContextMenuClosed += ContextMenuClosed ;
695
+ if ( ! isNavigatingHistory )
696
+ {
697
+ var activeTabPage = DockWorkspace . Instance . ActiveTabPage ;
698
+ var currentState = activeTabPage . GetState ( ) ;
699
+ if ( currentState != null )
700
+ history . UpdateCurrent ( new NavigationState ( activeTabPage , currentState ) ) ;
701
+ history . Record ( new NavigationState ( activeTabPage , SelectedItems ) ) ;
702
+ }
703
+
704
+ var delayDecompilationRequestDueToContextMenu = Mouse . RightButton == MouseButtonState . Pressed ;
705
+
706
+ if ( ! delayDecompilationRequestDueToContextMenu )
707
+ {
708
+ DecompileSelectedNodes ( ) ;
709
+ }
710
+ else
711
+ {
712
+ ContextMenuProvider . ContextMenuClosed += ContextMenuClosed ;
713
+ }
712
714
}
713
715
714
716
MessageBus . Send ( this , new AssemblyTreeSelectionChangedEventArgs ( ) ) ;
@@ -728,23 +730,10 @@ void ContextMenuClosed(object sender, EventArgs e)
728
730
}
729
731
}
730
732
731
- private bool ignoreDecompilationRequests ;
732
-
733
- public void DecompileSelectedNodes ( DecompilerTextViewState newState = null , bool recordHistory = true )
733
+ private void DecompileSelectedNodes ( DecompilerTextViewState newState = null )
734
734
{
735
- if ( ignoreDecompilationRequests )
736
- return ;
737
-
738
735
var activeTabPage = DockWorkspace . Instance . ActiveTabPage ;
739
736
740
- if ( recordHistory )
741
- {
742
- var currentState = activeTabPage . GetState ( ) ;
743
- if ( currentState != null )
744
- history . UpdateCurrent ( new NavigationState ( activeTabPage , currentState ) ) ;
745
- history . Record ( new NavigationState ( activeTabPage , SelectedItems ) ) ;
746
- }
747
-
748
737
activeTabPage . SupportsLanguageSwitching = true ;
749
738
750
739
if ( SelectedItems . Count == 1 )
@@ -754,7 +743,7 @@ public void DecompileSelectedNodes(DecompilerTextViewState newState = null, bool
754
743
}
755
744
if ( newState ? . ViewedUri != null )
756
745
{
757
- MainWindow . Instance . AssemblyTreeModel . NavigateTo ( new ( newState . ViewedUri , null ) , recordHistory : false ) ;
746
+ NavigateTo ( new ( newState . ViewedUri , null ) , recordHistory : false ) ;
758
747
return ;
759
748
}
760
749
@@ -782,6 +771,9 @@ public IEnumerable<ILSpyTreeNode> SelectedNodes {
782
771
783
772
public void NavigateHistory ( bool forward )
784
773
{
774
+ isNavigatingHistory = true ;
775
+ this . Dispatcher . BeginInvoke ( DispatcherPriority . Background , ( ) => isNavigatingHistory = false ) ;
776
+
785
777
TabPageModel tabPage = DockWorkspace . Instance . ActiveTabPage ;
786
778
var state = tabPage . GetState ( ) ;
787
779
if ( state != null )
@@ -790,8 +782,7 @@ public void NavigateHistory(bool forward)
790
782
791
783
DockWorkspace . Instance . ActiveTabPage = newState . TabPage ;
792
784
793
- SelectNodes ( newState . TreeNodes , ignoreCompilationRequests : true ) ;
794
- DecompileSelectedNodes ( newState . ViewState as DecompilerTextViewState , false ) ;
785
+ SelectNodes ( newState . TreeNodes ) ;
795
786
}
796
787
797
788
public bool CanNavigateBack => history . CanNavigateBack ;
@@ -814,6 +805,7 @@ internal void NavigateTo(RequestNavigateEventArgs e, bool recordHistory = true,
814
805
e . Handled = true ;
815
806
return ;
816
807
}
808
+
817
809
AvalonEditTextOutput output = new AvalonEditTextOutput {
818
810
Address = e . Uri ,
819
811
Title = e . Uri . AbsolutePath ,
@@ -845,7 +837,7 @@ void RecordHistory()
845
837
if ( currentState != null )
846
838
history . UpdateCurrent ( new NavigationState ( tabPage , currentState ) ) ;
847
839
848
- UnselectAll ( ignoreCompilationRequests : true ) ;
840
+ UnselectAll ( ) ;
849
841
850
842
history . Record ( new NavigationState ( tabPage , new ViewState { ViewedUri = e . Uri } ) ) ;
851
843
}
@@ -861,11 +853,9 @@ public void Refresh()
861
853
}
862
854
}
863
855
864
- public void UnselectAll ( bool ignoreCompilationRequests = false )
856
+ private void UnselectAll ( )
865
857
{
866
- this . ignoreDecompilationRequests = ignoreCompilationRequests ;
867
858
SelectedItems . Clear ( ) ;
868
- this . ignoreDecompilationRequests = false ;
869
859
}
870
860
871
861
public IEnumerable < SharpTreeNode > GetTopLevelSelection ( )
0 commit comments