Skip to content

Commit 19a9d91

Browse files
Add: Outline/Label Explorer now properly storing states per ASM File info
1 parent 2f42804 commit 19a9d91

File tree

7 files changed

+179
-41
lines changed

7 files changed

+179
-41
lines changed

C64Studio/Documents/LabelExplorer.cs

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using RetroDevStudio;
2+
using RetroDevStudio.Types;
23
using System;
34
using System.Collections.Generic;
45
using System.ComponentModel;
@@ -16,7 +17,12 @@ public partial class LabelExplorer : BaseDocument
1617
public System.Windows.Forms.TreeNode NodeRoot = null;
1718
private Project LabelExplorerProject = null;
1819
private GR.Collections.MultiMap<string,SymbolInfo> LabelExplorerTokens = new GR.Collections.MultiMap<string, SymbolInfo>();
19-
private GR.Collections.Map<string,bool> _ExpandedNodes = new GR.Collections.Map<string, bool>();
20+
21+
private DocumentInfo ActiveDocumentInfo = null;
22+
private Types.ASM.FileInfo ActiveASMFileInfo = null;
23+
24+
private Dictionary<Types.ASM.FileInfo,GR.Collections.Map<string, bool>> _ExpandedNodesPerProject = new Dictionary<Types.ASM.FileInfo, GR.Collections.Map<string, bool>>();
25+
private Dictionary<string,Types.ASM.FileInfo> _FileInfoPerFileCache = new Dictionary<string, Types.ASM.FileInfo>();
2026

2127

2228

@@ -67,28 +73,63 @@ private void treeProject_NodeMouseClick( object sender, System.Windows.Forms.Tre
6773

6874

6975

70-
private void StoreOpenNodes()
76+
public override void OnApplicationEvent( ApplicationEvent Event )
7177
{
72-
_ExpandedNodes.Clear();
78+
switch ( Event.EventType )
79+
{
80+
case ApplicationEvent.Type.PROJECT_OPENED:
81+
break;
82+
case ApplicationEvent.Type.DOCUMENT_CLOSED:
83+
if ( _ExpandedNodesPerProject.ContainsKey( Event.Doc.ASMFileInfo ) )
84+
{
85+
_ExpandedNodesPerProject.Remove( Event.Doc.ASMFileInfo );
86+
}
87+
if ( ActiveDocumentInfo == Event.Doc )
88+
{
89+
ActiveDocumentInfo = null;
90+
NodeRoot.Nodes.Clear();
91+
}
92+
break;
93+
case ApplicationEvent.Type.PROJECT_CLOSED:
94+
95+
break;
96+
}
97+
}
98+
7399

74-
foreach ( TreeNode node in NodeRoot.Nodes )
100+
101+
private void StoreOpenNodes()
102+
{
103+
if ( ActiveDocumentInfo != null )
75104
{
76-
_ExpandedNodes[node.Text] = node.IsExpanded;
105+
if ( !_ExpandedNodesPerProject.ContainsKey( ActiveDocumentInfo.ASMFileInfo ) )
106+
{
107+
_ExpandedNodesPerProject.Add( ActiveDocumentInfo.ASMFileInfo, new GR.Collections.Map<string, bool>() );
108+
}
109+
var expandedNodesEntry = _ExpandedNodesPerProject[ActiveDocumentInfo.ASMFileInfo];
110+
expandedNodesEntry.Clear();
111+
foreach ( TreeNode node in NodeRoot.Nodes )
112+
{
113+
expandedNodesEntry[node.Text] = node.IsExpanded;
114+
}
77115
}
78116
}
79117

80118

81119

82120
public void RefreshFromDocument( BaseDocument Doc )
83121
{
84-
if ( Doc == null )
122+
if ( ( Doc == null )
123+
|| ( Doc.DocumentInfo.FullPath == null ) )
85124
{
86125
return;
87126
}
88-
if ( ( LabelExplorerProject == Doc.DocumentInfo.Project )
89-
&& ( LabelExplorerTokens == Doc.DocumentInfo.KnownTokens ) )
127+
128+
if ( ActiveASMFileInfo == Doc.DocumentInfo.ASMFileInfo )
90129
{
91130
// nothing to do
131+
ActiveDocumentInfo = Doc.DocumentInfo;
132+
LabelExplorerProject = Doc.DocumentInfo.Project;
92133
return;
93134
}
94135

@@ -98,10 +139,30 @@ public void RefreshFromDocument( BaseDocument Doc )
98139
return;
99140
}
100141

101-
LabelExplorerProject = Doc.DocumentInfo.Project;
102-
LabelExplorerTokens = Doc.DocumentInfo.KnownTokens;
142+
if ( _FileInfoPerFileCache.TryGetValue( Doc.DocumentInfo.FullPath, out Types.ASM.FileInfo cachedASMFileInfo ) )
143+
{
144+
if ( cachedASMFileInfo != Doc.DocumentInfo.ASMFileInfo )
145+
{
146+
_ExpandedNodesPerProject.Remove( cachedASMFileInfo );
147+
}
148+
_FileInfoPerFileCache.Remove( Doc.DocumentInfo.FullPath );
149+
}
150+
_FileInfoPerFileCache.Add( Doc.DocumentInfo.FullPath, Doc.DocumentInfo.ASMFileInfo );
151+
152+
if ( InvokeRequired )
153+
{
154+
Invoke( new MainForm.DocCallback( RefreshFromDocument ), new object[] { Doc } );
155+
return;
156+
}
103157

104158
StoreOpenNodes();
159+
160+
ActiveDocumentInfo = Doc.DocumentInfo;
161+
LabelExplorerProject = Doc.DocumentInfo.Project;
162+
163+
ActiveASMFileInfo = Doc.DocumentInfo.ASMFileInfo;
164+
LabelExplorerTokens = Doc.DocumentInfo.KnownTokens;
165+
105166
RefreshNodes();
106167
}
107168

@@ -112,6 +173,12 @@ private void RefreshNodes()
112173
treeProject.BeginUpdate();
113174
NodeRoot.Nodes.Clear();
114175

176+
if ( !_ExpandedNodesPerProject.ContainsKey( ActiveASMFileInfo ) )
177+
{
178+
_ExpandedNodesPerProject.Add( ActiveASMFileInfo, new GR.Collections.Map<string, bool>() );
179+
}
180+
var expandedNodes = _ExpandedNodesPerProject[ActiveASMFileInfo];
181+
115182
IList<SymbolInfo> sortedTokens = null;
116183

117184
// sort by line number
@@ -286,8 +353,8 @@ private void RefreshNodes()
286353
|| ( addToGlobalNode ) )
287354
{
288355
globalZone.Nodes.Add( node );
289-
if ( ( _ExpandedNodes.ContainsKey( globalZone.Text ) )
290-
&& ( _ExpandedNodes[globalZone.Text] ) )
356+
if ( ( expandedNodes.ContainsKey( globalZone.Text ) )
357+
&& ( expandedNodes[globalZone.Text] ) )
291358
{
292359
globalZone.Expand();
293360
}
@@ -314,8 +381,8 @@ private void RefreshNodes()
314381
}
315382
parentZoneNode.Nodes.Add( node );
316383

317-
if ( ( _ExpandedNodes.ContainsKey( nodeParentText ) )
318-
&& ( _ExpandedNodes[nodeParentText] ) )
384+
if ( ( expandedNodes.ContainsKey( nodeParentText ) )
385+
&& ( expandedNodes[nodeParentText] ) )
319386
{
320387
parentZoneNode.Expand();
321388
}

C64Studio/Documents/Outline.cs

Lines changed: 77 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using RetroDevStudio;
2+
using RetroDevStudio.Types;
23
using System;
34
using System.Collections.Generic;
45
using System.ComponentModel;
56
using System.Diagnostics;
7+
using System.Linq;
68
using System.Text;
79
using System.Windows.Forms;
810
using 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
}

C64Studio/Documents/SolutionExplorer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ private void treeProject_NodeMouseClick( object sender, System.Windows.Forms.Tre
179179

180180
if ( isProject )
181181
{
182-
183182
if ( Core.Navigating.Solution.ActiveProject == project.Settings.Name )
184183
{
185184
var itemUnmark = new System.Windows.Forms.ToolStripMenuItem( "Unmark as active project" );

0 commit comments

Comments
 (0)