11using RetroDevStudio ;
2+ using RetroDevStudio . Types ;
23using System ;
34using System . Collections . Generic ;
45using System . ComponentModel ;
56using System . Diagnostics ;
7+ using System . Linq ;
68using System . Text ;
79using System . Windows . Forms ;
810using WeifenLuo . WinFormsUI . Docking ;
@@ -14,9 +16,14 @@ namespace RetroDevStudio.Documents
1416 public partial class Outline : BaseDocument
1517 {
1618 public System . Windows . Forms . TreeNode NodeRoot = null ;
19+
1720 private Project OutlineProject = null ;
1821 private GR . Collections . MultiMap < string , SymbolInfo > OutlineTokens = new GR . Collections . MultiMap < string , SymbolInfo > ( ) ;
19- private GR . Collections . Map < string , bool > _ExpandedNodes = new GR . Collections . Map < string , bool > ( ) ;
22+ private DocumentInfo ActiveDocumentInfo = null ;
23+ private Types . ASM . FileInfo ActiveASMFileInfo = null ;
24+
25+ private Dictionary < Types . ASM . FileInfo , GR . Collections . Map < string , bool > > _ExpandedNodesPerProject = new Dictionary < Types . ASM . FileInfo , GR . Collections . Map < string , bool > > ( ) ;
26+ private Dictionary < string , Types . ASM . FileInfo > _FileInfoPerFileCache = new Dictionary < string , Types . ASM . FileInfo > ( ) ;
2027
2128
2229
@@ -67,42 +74,90 @@ private void treeProject_NodeMouseClick( object sender, System.Windows.Forms.Tre
6774
6875
6976
70- private void StoreOpenNodes ( )
77+ public override void OnApplicationEvent ( ApplicationEvent Event )
7178 {
72- _ExpandedNodes . Clear ( ) ;
79+ switch ( Event . EventType )
80+ {
81+ case ApplicationEvent . Type . PROJECT_OPENED :
82+ break ;
83+ case ApplicationEvent . Type . DOCUMENT_CLOSED :
84+ if ( _ExpandedNodesPerProject . ContainsKey ( Event . Doc . ASMFileInfo ) )
85+ {
86+ _ExpandedNodesPerProject . Remove ( Event . Doc . ASMFileInfo ) ;
87+ }
88+ if ( ActiveDocumentInfo == Event . Doc )
89+ {
90+ ActiveDocumentInfo = null ;
91+ NodeRoot . Nodes . Clear ( ) ;
92+ }
93+ break ;
94+ case ApplicationEvent . Type . PROJECT_CLOSED :
95+
96+ break ;
97+ }
98+ }
99+
73100
74- foreach ( TreeNode node in NodeRoot . Nodes )
101+
102+ private void StoreOpenNodes ( )
103+ {
104+ if ( ActiveDocumentInfo != null )
75105 {
76- _ExpandedNodes [ node . Text ] = node . IsExpanded ;
106+ if ( ! _ExpandedNodesPerProject . ContainsKey ( ActiveDocumentInfo . ASMFileInfo ) )
107+ {
108+ _ExpandedNodesPerProject . Add ( ActiveDocumentInfo . ASMFileInfo , new GR . Collections . Map < string , bool > ( ) ) ;
109+ }
110+ var expandedNodesEntry = _ExpandedNodesPerProject [ ActiveDocumentInfo . ASMFileInfo ] ;
111+ expandedNodesEntry . Clear ( ) ;
112+ foreach ( TreeNode node in NodeRoot . Nodes )
113+ {
114+ expandedNodesEntry [ node . Text ] = node . IsExpanded ;
115+ }
77116 }
78117 }
79118
80119
81120
82121 public void RefreshFromDocument ( BaseDocument Doc )
83122 {
84- if ( Doc == null )
123+ if ( ( Doc == null )
124+ || ( Doc . DocumentInfo . FullPath == null ) )
85125 {
86126 return ;
87127 }
88- if ( ( OutlineProject == Doc . DocumentInfo . Project )
89- && ( OutlineTokens == Doc . DocumentInfo . KnownTokens ) )
128+
129+ if ( ActiveASMFileInfo == Doc . DocumentInfo . ASMFileInfo )
90130 {
91131 // nothing to do
132+ ActiveDocumentInfo = Doc . DocumentInfo ;
133+ OutlineProject = Doc . DocumentInfo . Project ;
92134 return ;
93135 }
94136
137+ if ( _FileInfoPerFileCache . TryGetValue ( Doc . DocumentInfo . FullPath , out Types . ASM . FileInfo cachedASMFileInfo ) )
138+ {
139+ if ( cachedASMFileInfo != Doc . DocumentInfo . ASMFileInfo )
140+ {
141+ _ExpandedNodesPerProject . Remove ( cachedASMFileInfo ) ;
142+ }
143+ _FileInfoPerFileCache . Remove ( Doc . DocumentInfo . FullPath ) ;
144+ }
145+ _FileInfoPerFileCache . Add ( Doc . DocumentInfo . FullPath , Doc . DocumentInfo . ASMFileInfo ) ;
146+
95147 if ( InvokeRequired )
96148 {
97149 Invoke ( new MainForm . DocCallback ( RefreshFromDocument ) , new object [ ] { Doc } ) ;
98150 return ;
99151 }
100152
101- OutlineProject = Doc . DocumentInfo . Project ;
102- OutlineTokens = Doc . DocumentInfo . KnownTokens ;
103- //Debug.Log( "Set to " + OutlineTokens.Count + " tokens from doc " + Doc.DocumentInfo.DocumentFilename );
104-
105153 StoreOpenNodes ( ) ;
154+
155+ ActiveDocumentInfo = Doc . DocumentInfo ;
156+ OutlineProject = Doc . DocumentInfo . Project ;
157+
158+ ActiveASMFileInfo = Doc . DocumentInfo . ASMFileInfo ;
159+ OutlineTokens = Doc . DocumentInfo . KnownTokens ;
160+
106161 RefreshNodes ( ) ;
107162 }
108163
@@ -113,6 +168,12 @@ private void RefreshNodes()
113168 treeProject . BeginUpdate ( ) ;
114169 NodeRoot . Nodes . Clear ( ) ;
115170
171+ if ( ! _ExpandedNodesPerProject . ContainsKey ( ActiveASMFileInfo ) )
172+ {
173+ _ExpandedNodesPerProject . Add ( ActiveASMFileInfo , new GR . Collections . Map < string , bool > ( ) ) ;
174+ }
175+ var expandedNodes = _ExpandedNodesPerProject [ ActiveASMFileInfo ] ;
176+
116177 IList < SymbolInfo > sortedTokens = null ;
117178
118179 // sort by line number
@@ -279,8 +340,8 @@ private void RefreshNodes()
279340 || ( addToGlobalNode ) )
280341 {
281342 globalZone . Nodes . Add ( node ) ;
282- if ( ( _ExpandedNodes . ContainsKey ( globalZone . Text ) )
283- && ( _ExpandedNodes [ globalZone . Text ] ) )
343+ if ( ( expandedNodes . ContainsKey ( globalZone . Text ) )
344+ && ( expandedNodes [ globalZone . Text ] ) )
284345 {
285346 globalZone . Expand ( ) ;
286347 }
@@ -297,8 +358,8 @@ private void RefreshNodes()
297358 }
298359 parentZoneNode . Nodes . Add ( node ) ;
299360
300- if ( ( _ExpandedNodes . ContainsKey ( nodeParentText ) )
301- && ( _ExpandedNodes [ nodeParentText ] ) )
361+ if ( ( expandedNodes . ContainsKey ( nodeParentText ) )
362+ && ( expandedNodes [ nodeParentText ] ) )
302363 {
303364 parentZoneNode . Expand ( ) ;
304365 }
0 commit comments