-
Notifications
You must be signed in to change notification settings - Fork 63
/
DN.EnvironmentOptions.pas
196 lines (167 loc) · 4.98 KB
/
DN.EnvironmentOptions.pas
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
unit DN.EnvironmentOptions;
interface
uses
Classes,
Generics.Collections,
DN.Types,
DN.EnvironmentOptions.Intf;
type
TDNEnvironmentOptions = class(TInterfacedObject, IDNEnvironmentOptions)
private
FPlatform: TDNCompilerPlatform;
FUpdateLevel: Integer;
FOnChanged: TNotifyEvent;
function GetPlatform: TDNCompilerPlatform;
function GetBPLOutput: string;
function GetBrowsingPath: string;
function GetDCPOutput: string;
function GetSearchPath: string;
procedure SetBPLOutput(const Value: string);
procedure SetBrowsingPath(const Value: string);
procedure SetDCPOutput(const Value: string);
procedure SetSearchPath(const Value: string);
protected
FBrowsingPathName: string;
FSearchPathName: string;
FBPLOutputName: string;
FDCPOutputName: string;
function ReadString(const AName: string): string; virtual; abstract;
procedure WriteString(const AName, AValue: string); virtual; abstract;
procedure Changed(); virtual;
function IsUpdating: Boolean;
public
constructor Create(APlatform: TDNCompilerPlatform);
procedure BeginUpdate();
procedure EndUpdate();
property Platform: TDNCompilerPlatform read GetPlatform;
property BrowingPath: string read GetBrowsingPath write SetBrowsingPath;
property SearchPath: string read GetSearchPath write SetSearchPath;
property BPLOutput: string read GetBPLOutput write SetBPLOutput;
property DCPOutput: string read GetDCPOutput write SetDCPOutput;
property OnChanged: TNotifyEvent read FOnChanged write FOnChanged;
end;
TDNEnvironmentOptionsService = class(TInterfacedObject, IDNEnvironmentOptionsService)
private
FSupportedPlatforms: TDNCompilerPlatforms;
FOptions: TDictionary<TDNCompilerPlatform, IDNEnvironmentOptions>;
FUpdateLevel: Integer;
FChanges: Integer;
function GetOptions(
const APlatform: TDNCompilerPlatform): IDNEnvironmentOptions;
function GetSupportedPlatforms: TDNCompilerPlatforms;
protected
procedure AddOption(const AOption: IDNEnvironmentOptions);
public
constructor Create;
destructor Destroy(); override;
procedure BeginUpdate(); virtual;
procedure EndUpdate(); virtual;
property Options[const APlatform: TDNCompilerPlatform]: IDNEnvironmentOptions read GetOptions;
property SupportedPlatforms: TDNCompilerPlatforms read GetSupportedPlatforms;
end;
implementation
{ TDNEnvironmentOptions }
procedure TDNEnvironmentOptions.BeginUpdate;
begin
Inc(FUpdateLevel);
end;
procedure TDNEnvironmentOptions.Changed;
begin
if Assigned(FOnChanged) then
FOnChanged(Self);
end;
constructor TDNEnvironmentOptions.Create(APlatform: TDNCompilerPlatform);
begin
inherited Create();
FPlatform := APlatform;
end;
procedure TDNEnvironmentOptions.EndUpdate;
begin
if FUpdateLevel > 0 then
begin
Dec(FUpdateLevel);
if FUpdateLevel = 0 then
Changed();
end;
end;
function TDNEnvironmentOptions.GetBPLOutput: string;
begin
Result := ReadString(FBPLOutputName);
end;
function TDNEnvironmentOptions.GetBrowsingPath: string;
begin
Result := ReadString(FBrowsingPathName);
end;
function TDNEnvironmentOptions.GetDCPOutput: string;
begin
Result := ReadString(FDCPOutputName);
end;
function TDNEnvironmentOptions.GetPlatform: TDNCompilerPlatform;
begin
Result := FPlatform;
end;
function TDNEnvironmentOptions.GetSearchPath: string;
begin
Result := ReadString(FSearchPathName);
end;
function TDNEnvironmentOptions.IsUpdating: Boolean;
begin
Result := FUpdateLevel > 0;
end;
procedure TDNEnvironmentOptions.SetBPLOutput(const Value: string);
begin
WriteString(FBPLOutputName, Value);
end;
procedure TDNEnvironmentOptions.SetBrowsingPath(const Value: string);
begin
WriteString(FBrowsingPathName, Value);
end;
procedure TDNEnvironmentOptions.SetDCPOutput(const Value: string);
begin
WriteString(FDCPOutputName, Value);
end;
procedure TDNEnvironmentOptions.SetSearchPath(const Value: string);
begin
WriteString(FSearchPathName, Value);
end;
{ TDNEnvironmentOptionsService }
procedure TDNEnvironmentOptionsService.AddOption(const AOption: IDNEnvironmentOptions);
begin
FOptions.Add(AOption.Platform, AOption);
Include(FSupportedPlatforms, AOption.Platform);
end;
procedure TDNEnvironmentOptionsService.BeginUpdate;
begin
Inc(FUpdateLevel);
end;
constructor TDNEnvironmentOptionsService.Create;
begin
inherited;
FOptions := TDictionary<TDNCompilerPlatform, IDNEnvironmentOptions>.Create();
end;
destructor TDNEnvironmentOptionsService.Destroy;
begin
FOptions.Free;
inherited;
end;
procedure TDNEnvironmentOptionsService.EndUpdate;
begin
if FUpdateLevel > 0 then
begin
Dec(FUpdateLevel);
if (FUpdateLevel = 0) and (FChanges > 0) then
begin
FChanges := 0;
end;
end;
end;
function TDNEnvironmentOptionsService.GetOptions(
const APlatform: TDNCompilerPlatform): IDNEnvironmentOptions;
begin
Result := FOptions[APlatform];
end;
function TDNEnvironmentOptionsService.GetSupportedPlatforms: TDNCompilerPlatforms;
begin
Result := FSupportedPlatforms;
end;
end.