-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathamScript.Debugger.Frame.FileSystemStructure.pas
More file actions
283 lines (227 loc) · 8.26 KB
/
Copy pathamScript.Debugger.Frame.FileSystemStructure.pas
File metadata and controls
283 lines (227 loc) · 8.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
unit amScript.Debugger.Frame.FileSystemStructure;
(*
* Copyright © 2011 Brian Frost
* Copyright © 2019 Anders Melander
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*)
interface
uses
Generics.Collections,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, Menus, ActnList, ImgList,
System.UITypes,
cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxFilter, cxCustomData, cxStyles,
dxScrollbarAnnotations, cxTL, cxTextEdit, cxTLdxBarBuiltInMenu, cxInplaceContainer, cxTLData,
amScript.Debugger.API,
amScript.FileSystemStructure.API;
type
TFrame = TScriptDebuggerFrame;
TScriptDebuggerFileSystemStructureFrame = class(TFrame)
TreeListFileSystemStructure: TcxVirtualTreeList;
TreeListFileSystemStructureColumnName: TcxTreeListColumn;
procedure TreeListFileSystemStructureGetChildCount(Sender: TcxCustomTreeList; AParentNode: TcxTreeListNode;
var ACount: Integer);
procedure TreeListFileSystemStructureGetNodeValue(Sender: TcxCustomTreeList; ANode: TcxTreeListNode; AColumn: TcxTreeListColumn;
var AValue: Variant);
procedure TreeListFileSystemStructureGetNodeImageIndex(Sender: TcxCustomTreeList; ANode: TcxTreeListNode;
AIndexType: TcxTreeListImageIndexType; var AIndex: TImageIndex);
procedure TreeListFileSystemStructureSelectionChanged(Sender: TObject);
procedure TreeListFileSystemStructureDblClick(Sender: TObject);
strict private
procedure Finalize;
strict private
FFolder: IScriptFileSystemFolder;
FRootFolders: TList<IScriptFileSystemFolder>;
function LinkNode(Node: TcxTreeListNode): IScriptFileSystemObject;
procedure SetFolder(const Value: IScriptFileSystemFolder);
// property Folder: IScriptFileSystemFolder read FFolder write SetFolder;
strict protected
// IScriptDebuggerWindow
procedure Initialize(const ADebugger: IScriptDebugger; AImageList, AImageListSymbols: TCustomImageList); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
implementation
{$R *.dfm}
uses
amScript.FileSystemStructure,
amScript.IDE.Data;
{ TDwsIdeCallStackFrame }
constructor TScriptDebuggerFileSystemStructureFrame.Create(AOwner: TComponent);
begin
inherited;
FRootFolders := TList<IScriptFileSystemFolder>.Create;
end;
destructor TScriptDebuggerFileSystemStructureFrame.Destroy;
begin
Finalize;
FRootFolders.Free;
inherited;
end;
procedure TScriptDebuggerFileSystemStructureFrame.Initialize(const ADebugger: IScriptDebugger; AImageList, AImageListSymbols: TCustomImageList);
begin
inherited Initialize(ADebugger, AImageList, AImageListSymbols);
TreeListFileSystemStructure.Images := AImageList;
// Get list of root folders
for var Folder in ScriptFileSystemStructure do
FRootFolders.Add(Folder);
// Default to first root folder
if (FRootFolders.Count > 0) then
SetFolder(FRootFolders[0]);
TreeListFileSystemStructure.FullRefresh;
if (TreeListFileSystemStructure.Root.HasChildren) then
begin
var Node := TreeListFileSystemStructure.Root.GetFirstChild;
Node.MakeVisible;
Node.Expand(False);
end;
end;
procedure TScriptDebuggerFileSystemStructureFrame.Finalize;
begin
FRootFolders.Clear;
end;
function TScriptDebuggerFileSystemStructureFrame.LinkNode(Node: TcxTreeListNode): IScriptFileSystemObject;
var
ParentFolder: IScriptFileSystemFolder;
begin
Result := nil;
if (Node.Data <> nil) then
begin
Result := IScriptFileSystemObject(Node.Data);
exit;
end;
// If we haven't set the node reference yet, set it now
if (Node.Parent.Parent <> nil) then
begin
// Parent is a file or a folder
// Only folders have children
if (Supports(IInterface(Node.Parent.Data), IScriptFileSystemFolder, ParentFolder)) then
begin
var FileSystemObject: IScriptFileSystemObject;
var Index := Node.Index;
if (Index <= High(ParentFolder.GetFolders)) then
Result := ParentFolder.GetFolders[Index]
else
begin
Dec(Index, Length(ParentFolder.GetFolders));
if (Index < Length(ParentFolder.GetFiles)) then
Result := ParentFolder.GetFiles[Index];
// else error!
end;
end;
end else
// Parent is a root folder
Result := FRootFolders[Node.Index];
Node.Data := pointer(Result);
end;
procedure TScriptDebuggerFileSystemStructureFrame.SetFolder(const Value: IScriptFileSystemFolder);
function FocusFolder(ParentNode: TcxTreeListNode): boolean;
begin
// First try all immediate child nodes
var Node := ParentNode.getFirstChild;
while (Node <> nil) do
begin
if (IScriptFileSystemFolder(Node.Data) = FFolder) then
begin
Node.MakeVisible;
Node.Focused := True;
Exit(True);
end;
Node := Node.getNextSibling;
end;
// Then recurse and try their children
Node := ParentNode.getFirstChild;
while (Node <> nil) do
begin
if (FocusFolder(Node)) then
Exit(True);
Node := Node.getNextSibling;
end;
Result := False;
end;
begin
if (FFolder = Value) then
exit;
FFolder := Value;
if (TreeListFileSystemStructure.FocusedNode <> nil) and (IScriptFileSystemFolder(TreeListFileSystemStructure.FocusedNode.Data) = FFolder) then
// Folder is already focused - Nothing to do
exit;
// Search for folder node
FocusFolder(TreeListFileSystemStructure.Root);
end;
procedure TScriptDebuggerFileSystemStructureFrame.TreeListFileSystemStructureDblClick(Sender: TObject);
begin
if (TreeListFileSystemStructure.FocusedNode = nil) or (TreeListFileSystemStructure.FocusedNode.Data = nil) then
exit;
var FileSystemObject := IScriptFileSystemObject(TreeListFileSystemStructure.FocusedNode.Data);
var FileSystemFile: IScriptFileSystemFile;
if (not Supports(FileSystemObject, IScriptFileSystemFile, FileSystemFile)) then
exit;
var ScriptProvider := FileSystemFile.CreateScriptProvider;
Debugger.CreateEditor(ScriptProvider);
end;
procedure TScriptDebuggerFileSystemStructureFrame.TreeListFileSystemStructureGetChildCount(Sender: TcxCustomTreeList;
AParentNode: TcxTreeListNode; var ACount: Integer);
var
ParentFolder: IScriptFileSystemFolder;
begin
if (FRootFolders = nil) then
exit;
if (AParentNode.Parent = nil) then
begin
// Root node; Each child is a structure root.
ACount := FRootFolders.Count
end else
begin
// Child node; Children are either files or folders
var FileSystemObject := LinkNode(AParentNode);
if (Supports(FileSystemObject, IScriptFileSystemFolder, ParentFolder)) then
ACount := Length(ParentFolder.GetFolders) + Length(ParentFolder.GetFiles)
else
ACount := 0;
end;
end;
procedure TScriptDebuggerFileSystemStructureFrame.TreeListFileSystemStructureGetNodeImageIndex(Sender: TcxCustomTreeList;
ANode: TcxTreeListNode; AIndexType: TcxTreeListImageIndexType; var AIndex: TImageIndex);
begin
AIndex := -1;
if (not (AIndexType in [tlitImageIndex, tlitSelectedIndex])) then
exit;
var FileSystemObject := LinkNode(ANode);
if (FileSystemObject <> nil) then
begin
if (Supports(FileSystemObject, IScriptFileSystemFolder)) then
begin
if (ANode.Expanded) then
AIndex := ImageIndexFileTypeFolderOpen
else
AIndex := ImageIndexFileTypeFolder;
end else
if (Supports(FileSystemObject, IScriptFileSystemFile)) then
AIndex := ImageIndexFileTypeScript;
end;
end;
procedure TScriptDebuggerFileSystemStructureFrame.TreeListFileSystemStructureGetNodeValue(Sender: TcxCustomTreeList;
ANode: TcxTreeListNode; AColumn: TcxTreeListColumn; var AValue: Variant);
begin
if (ANode.Parent = nil) then
exit;
var FileSystemObject := LinkNode(ANode);
if (FileSystemObject <> nil) then
AValue := FileSystemObject.Name;
end;
procedure TScriptDebuggerFileSystemStructureFrame.TreeListFileSystemStructureSelectionChanged(Sender: TObject);
begin
if (TreeListFileSystemStructure.FocusedNode <> nil) then
SetFolder(IScriptFileSystemFolder(TreeListFileSystemStructure.FocusedNode.Data))
else
SetFolder(nil);
end;
initialization
RegisterClass(TScriptDebuggerFileSystemStructureFrame);
finalization
end.