forked from andersmelander/DWScriptStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamScript.FileSystemStructure.API.pas
More file actions
161 lines (131 loc) · 5.19 KB
/
amScript.FileSystemStructure.API.pas
File metadata and controls
161 lines (131 loc) · 5.19 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
unit amScript.FileSystemStructure.API;
(*
* Copyright © 2023 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,
Classes,
amScript.FileSystem.API,
amScript.Provider.API;
type
IScriptFileSystemFile = interface;
IScriptFileSystemFolder = interface;
// -----------------------------------------------------------------------------
//
// IScriptFileSystemObject
//
// -----------------------------------------------------------------------------
// A file system object; Either a file or a folder.
// -----------------------------------------------------------------------------
IScriptFileSystemObject = interface
['{1B7397C4-E1DB-4655-BCAF-8EF22D7041DA}']
function GetParent: IScriptFileSystemFolder;
property Parent: IScriptFileSystemFolder read GetParent;
function GetName: string;
property Name: string read GetName;
function GetPath: string;
property Path: string read GetPath;
end;
// -----------------------------------------------------------------------------
//
// IScriptFileSystemFolder
//
// -----------------------------------------------------------------------------
// A folder represents a collection of files and folders.
// -----------------------------------------------------------------------------
IScriptFileSystemFolder = interface(IScriptFileSystemObject)
['{A7A1A654-3570-4403-A37D-3AD1F52F0758}']
function GetFolders: TArray<IScriptFileSystemFolder>;
function GetFiles: TArray<IScriptFileSystemFile>;
end;
// -----------------------------------------------------------------------------
//
// IScriptFileSystemFile
//
// -----------------------------------------------------------------------------
// A file represents a single script unit.
// -----------------------------------------------------------------------------
IScriptFileSystemFile = interface(IScriptFileSystemObject)
['{67DF62F2-1139-43C8-8F59-81795E2AD742}']
function CreateScriptProvider: IScriptProvider;
end;
// -----------------------------------------------------------------------------
//
// IScriptFileSystemStructure
//
// -----------------------------------------------------------------------------
// A collection of file system structures
// -----------------------------------------------------------------------------
// A host file system can optionally register a root folder through this
// interface if it supports a hierarchical directory-like structure.
//
// The registered folders can be used by the IDE to browse "files".
// The interface is not used by the compiler/debugger.
// -----------------------------------------------------------------------------
type
IScriptFileSystemStructure = interface
['{DC7F5D93-86F7-4551-96E6-C9DBA1AC0B32}']
procedure RegisterFileSystemFolder(const AFolder: IScriptFileSystemFolder);
procedure UnregisterFileSystemFolder(const AFolder: IScriptFileSystemFolder);
function GetEnumerator: TEnumerator<IScriptFileSystemFolder>;
end;
function ScriptFileSystemStructure: IScriptFileSystemStructure;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
implementation
type
TScriptFileSystemStructure = class(TInterfacedObject, IScriptFileSystemStructure)
strict private
FItems: TList<IScriptFileSystemFolder>;
private
// IScriptFileSystemStructure
procedure RegisterFileSystemFolder(const AFolder: IScriptFileSystemFolder);
procedure UnregisterFileSystemFolder(const AFolder: IScriptFileSystemFolder);
function GetEnumerator: TEnumerator<IScriptFileSystemFolder>;
public
constructor Create;
destructor Destroy; override;
end;
constructor TScriptFileSystemStructure.Create;
begin
inherited Create;
FItems := TList<IScriptFileSystemFolder>.Create;
end;
destructor TScriptFileSystemStructure.Destroy;
begin
FItems.Free;
inherited;
end;
function TScriptFileSystemStructure.GetEnumerator: TEnumerator<IScriptFileSystemFolder>;
begin
Result := FItems.GetEnumerator;
end;
procedure TScriptFileSystemStructure.RegisterFileSystemFolder(const AFolder: IScriptFileSystemFolder);
begin
FItems.Add(AFolder);
end;
procedure TScriptFileSystemStructure.UnregisterFileSystemFolder(const AFolder: IScriptFileSystemFolder);
begin
FItems.Remove(AFolder);
end;
var
FScriptFileSystemStructure: IScriptFileSystemStructure;
function ScriptFileSystemStructure: IScriptFileSystemStructure;
begin
if (FScriptFileSystemStructure = nil) then
FScriptFileSystemStructure := TScriptFileSystemStructure.Create;
Result := FScriptFileSystemStructure;
end;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
initialization
finalization
FScriptFileSystemStructure := nil;
end.