@@ -18,6 +18,7 @@ interface
1818
1919uses
2020 // Delphu
21+ Generics.Collections,
2122 ComCtrls,
2223 // Project
2324 DB.USnippet, UGroups, UView, UViewItemTreeNode;
@@ -32,13 +33,23 @@ interface
3233 TOverviewTreeBuilder = class abstract (TObject)
3334 strict private
3435 var
35- fTreeView: TTreeView; // Value of TreeView property
36- fSnippetList: TSnippetList; // Value of SnippetList property
36+ // Property values
37+ fTreeView: TTreeView;
38+ fSnippetList: TSnippetList;
39+ fViewStore: TList<IView>;
3740 strict protected
3841 property TreeView: TTreeView read fTreeView;
3942 { Reference to treeview populated by class}
4043 property SnippetList: TSnippetList read fSnippetList;
4144 { List of snippets to be displayed in treeview}
45+ // / <summary>List of <c>IView</c> instances referenced by treeview nodes.
46+ // / </summary>
47+ // / <remarks>This list is required to maintain reference counting of
48+ // / <c>IView</c>s because the tree nodes only store weak references.
49+ // / </remarks>
50+ property ViewStore : TList<IView> read fViewStore;
51+ { List of IView instances referenced (weakly) by treeview nodes. This list
52+ maintains maintains reference counting}
4253 function AddViewItemNode (const ParentNode: TViewItemTreeNode;
4354 ViewItem: IView): TViewItemTreeNode;
4455 { Adds a new node to the tree view that represents a view item.
@@ -57,12 +68,16 @@ TOverviewTreeBuilder = class abstract(TObject)
5768 @return Required view item object.
5869 }
5970 public
60- constructor Create(const TV: TTreeView; const SnippetList: TSnippetList);
61- { Class constructor. Sets up object to populate a treeview with a list of
62- snippets.
63- @param TV [in] Treeview control to be populated.
64- @param SnippetList [in] List of snippets to be added to TV.
65- }
71+ // / <summary>Constructs an object to populate a tree view with a list of
72+ // / snippets.</summary>
73+ // / <param name="TV"><c>TTreeView</c> [in] Treeview control to be
74+ // / populated.</param>
75+ // / <param name="SnippetList"><c>TSnippetList</c> [in] List of snippets to
76+ // / be added to the treeview.</param>
77+ // / <param name="ViewStore"><c>TList<IView></c> [in] Receives a list
78+ // / of view items, one per tree node.</param>
79+ constructor Create(const TV: TTreeView; const SnippetList: TSnippetList;
80+ const ViewStore: TList<IView>);
6681 procedure Build ;
6782 { Populates the treeview.
6883 }
@@ -177,7 +192,9 @@ procedure TOverviewTreeBuilder.Build;
177192 ParentNode: TViewItemTreeNode; // each section node in tree
178193 Grouping: TGrouping; // groups snippets
179194 Group: TGroupItem; // each group of snippets
195+ View : IView;
180196begin
197+ ViewStore.Clear;
181198 // Create required grouping of snippets
182199 Grouping := CreateGrouping;
183200 try
@@ -186,11 +203,17 @@ procedure TOverviewTreeBuilder.Build;
186203 begin
187204 if not Group.IsEmpty or Preferences.ShowEmptySections then
188205 begin
189- ParentNode := AddViewItemNode(nil , CreateViewItemForGroup(Group));
206+ View := CreateViewItemForGroup(Group);
207+ ParentNode := AddViewItemNode(nil , View );
208+ ViewStore.Add(View );
190209 for Snippet in Group.SnippetList do
210+ begin
211+ View := TViewFactory.CreateSnippetView(Snippet);
191212 AddViewItemNode(
192- ParentNode, TViewFactory.CreateSnippetView(Snippet)
213+ ParentNode, View
193214 );
215+ ViewStore.Add(View );
216+ end ;
194217 end ;
195218 end ;
196219 finally
@@ -199,16 +222,12 @@ procedure TOverviewTreeBuilder.Build;
199222end ;
200223
201224constructor TOverviewTreeBuilder.Create(const TV: TTreeView;
202- const SnippetList: TSnippetList);
203- { Class constructor. Sets up object to populate a treeview with a list of
204- snippets.
205- @param TV [in] Treeview control to be populated.
206- @param SnippetList [in] List of snippets to be added to TV.
207- }
225+ const SnippetList: TSnippetList; const ViewStore: TList<IView>);
208226begin
209227 inherited Create;
210228 fTreeView := TV;
211229 fSnippetList := SnippetList;
230+ fViewStore := ViewStore;
212231end ;
213232
214233{ TOverviewCategorisedTreeBuilder }
0 commit comments