forked from yavfast/dbg-spider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuProjectOptions.pas
360 lines (305 loc) · 10.3 KB
/
uProjectOptions.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
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
unit uProjectOptions;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, PlatformDefaultStyleActnCtrls, ActnList, ActnMan,
ComCtrls, ActnCtrls, ToolWin, StdCtrls, Buttons, ImgList,
RibbonSilverStyleActnCtrls, System.Actions;
type
TOpenType = (otNew, otEdit, otSaveAs);
TfmProjectOptions = class(TForm)
alProjectOpt: TActionList;
acSave: TAction;
acCancel: TAction;
acOpenApplication: TAction;
acSaveProjectName: TAction;
acSaveProjectStorage: TAction;
odApplication: TFileOpenDialog;
sdProjectName: TFileSaveDialog;
acDelphiSource: TAction;
acProjectSource: TAction;
pcProjectOpt: TPageControl;
tsProject: TTabSheet;
lbeApplication: TLabeledEdit;
lbeProjectName: TLabeledEdit;
lbeProjectStorage: TLabeledEdit;
btnOpenApplication: TBitBtn;
btnSaveProjectName: TBitBtn;
btnSaveProjectStorage: TBitBtn;
tsSources: TTabSheet;
lbeProjectSource: TLabeledEdit;
btnProjectSource: TBitBtn;
lbeDelphiSource: TLabeledEdit;
btnDelphiSource: TBitBtn;
pActions: TPanel;
btnOk: TBitBtn;
btnCancel: TBitBtn;
tsRunParams: TTabSheet;
lbeParameters: TLabeledEdit;
lbeWorkDir: TLabeledEdit;
btnSelWorkDir: TBitBtn;
acSelWorkDir: TAction;
odSelectWorkDir: TFileOpenDialog;
procedure acSaveExecute(Sender: TObject);
procedure acCancelExecute(Sender: TObject);
procedure acOpenApplicationExecute(Sender: TObject);
procedure acSaveProjectNameExecute(Sender: TObject);
procedure acSaveProjectStorageExecute(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure acDelphiSourceExecute(Sender: TObject);
procedure acProjectSourceExecute(Sender: TObject);
procedure acSelWorkDirExecute(Sender: TObject);
private
FOpenType: TOpenType;
function GetApplicationName: String;
function GetProjectName: String;
function GetProjectStorage: String;
function GetDelphiSource: String;
function GetProjectSource: String;
function GetRunParams: String;
function GetWorkingDirectory: String;
procedure SetApplicationName(const Value: String);
procedure SetDelphiSource(const Value: String);
procedure SetProjectName(const Value: String);
procedure SetProjectSource(const Value: String);
procedure SetProjectStorage(const Value: String);
procedure SetRunParams(const Value: String);
procedure SetWorkingDirectory(const Value: String);
public
property OpenType: TOpenType read FOpenType write FOpenType;
property ApplicationName: String read GetApplicationName write SetApplicationName;
property ProjectName: String read GetProjectName write SetProjectName;
property ProjectStorage: String read GetProjectStorage write SetProjectStorage;
property ProjectSource: String read GetProjectSource write SetProjectSource;
property DelphiSource: String read GetDelphiSource write SetDelphiSource;
property RunParams: String read GetRunParams write SetRunParams;
property WorkingDirectory: String read GetWorkingDirectory write SetWorkingDirectory;
end;
function OpenProjectOptions(const OpenType: TOpenType): Integer;
var
fmProjectOptions: TfmProjectOptions;
implementation
uses
IOUtils, uShareData, uSelectSource, uActionController;
{$R *.dfm}
function OpenProjectOptions(const OpenType: TOpenType): Integer;
var
F: TfmProjectOptions;
begin
Application.CreateForm(TfmProjectOptions, F);
try
F.OpenType := OpenType;
if OpenType in [otEdit, otSaveAs] then
begin
F.ProjectName := gvProjectOptions.ProjectName;
F.ApplicationName := gvProjectOptions.ApplicationName;
F.ProjectStorage := gvProjectOptions.ProjectStorage;
F.ProjectSource := gvProjectOptions.ProjectSource;
F.DelphiSource := gvProjectOptions.DelphiSource;
F.RunParams := gvProjectOptions.RunParams;
F.WorkingDirectory := gvProjectOptions.WorkingDirectory;
end;
if OpenType = otSaveAs then
F.ProjectName := Format('%s_copy%s', [
ChangeFileExt(gvProjectOptions.ProjectName, ''),
ExtractFileExt(gvProjectOptions.ProjectName)
]);
Result := F.ShowModal;
if Result = mrOk then
begin
ChangeFileExt(F.ProjectName, '.spider');
gvProjectOptions.Open(F.ProjectName);
gvProjectOptions.BeginUpdate;
try
gvProjectOptions.ApplicationName := F.ApplicationName;
gvProjectOptions.ProjectStorage := F.ProjectStorage;
gvProjectOptions.ProjectSource := F.ProjectSource;
gvProjectOptions.DelphiSource := F.DelphiSource;
gvProjectOptions.RunParams := F.RunParams;
gvProjectOptions.WorkingDirectory := F.WorkingDirectory;
finally
gvProjectOptions.EndUpdate;
end;
if OpenType in [otNew, otSaveAs] then
begin
gvProjectOptions.Clear;
_AC.DoAction(acSetProjectName, [F.ProjectName, OpenType]);
end;
if OpenType = otEdit then
_AC.DoAction(acChangeProjectSettings, []);
end;
finally
F.Release;
end;
end;
procedure TfmProjectOptions.acCancelExecute(Sender: TObject);
begin
ModalResult := mrCancel;
end;
procedure TfmProjectOptions.acDelphiSourceExecute(Sender: TObject);
begin
lbeDelphiSource.Text := SelectSource(lbeDelphiSource.Text);
end;
procedure TfmProjectOptions.acOpenApplicationExecute(Sender: TObject);
begin
if lbeApplication.Text <> '' then
odApplication.FileName := lbeApplication.Text;
if odApplication.Execute then
begin
// Project settings
lbeApplication.Text := odApplication.FileName;
if lbeProjectName.Text = '' then
lbeProjectName.Text := ChangeFileExt(lbeApplication.Text, '.spider');
if lbeProjectStorage.Text = '' then
lbeProjectStorage.Text := ExtractFilePath(lbeProjectName.Text) + '_spider_storage';
// Source settings
if lbeProjectSource.Text = '' then
lbeProjectSource.Text := TProjectOptions.GetDefProjectSource(odApplication.FileName);
if lbeDelphiSource.Text = '' then
lbeDelphiSource.Text := TProjectOptions.GetDefDelphiSource;
// Run parameters
if lbeWorkDir.Text = '' then
lbeWorkDir.Text := ExtractFilePath(lbeProjectName.Text);
end;
end;
procedure TfmProjectOptions.acProjectSourceExecute(Sender: TObject);
begin
lbeProjectSource.Text := SelectSource(lbeProjectSource.Text);
end;
procedure TfmProjectOptions.acSaveExecute(Sender: TObject);
begin
if not FileExists(ApplicationName) then
begin
pcProjectOpt.ActivePage := tsProject;
ActiveControl := lbeApplication;
ShowMessageFmt('Application "%s" not found', [ApplicationName]);
Exit;
end;
if not TFile.Exists(ProjectName) then
begin
try
TFile.Create(ProjectName).Free;
TFile.Delete(ProjectName);
except
on E: Exception do
begin
pcProjectOpt.ActivePage := tsProject;
ActiveControl := lbeProjectName;
ShowMessageFmt('%s', [E.Message]);
Exit;
end;
end;
end;
if not TDirectory.Exists(ProjectStorage) then
begin
try
TDirectory.CreateDirectory(ProjectStorage);
TDirectory.Delete(ProjectStorage);
except
on E: Exception do
begin
pcProjectOpt.ActivePage := tsProject;
ActiveControl := lbeProjectName;
ShowMessageFmt('%s', [E.Message]);
Exit;
end;
end;
end;
if (WorkingDirectory <> '') and not TDirectory.Exists(WorkingDirectory) then
begin
pcProjectOpt.ActivePage := tsRunParams;
ActiveControl := lbeWorkDir;
ShowMessageFmt('Working directory "%s" not exists', [WorkingDirectory]);
Exit;
end;
ModalResult := mrOk;
end;
procedure TfmProjectOptions.acSaveProjectNameExecute(Sender: TObject);
begin
if lbeProjectName.Text <> '' then
sdProjectName.FileName := lbeProjectName.Text;
if sdProjectName.Execute then
begin
lbeProjectName.Text := sdProjectName.FileName;
lbeProjectStorage.Text := ExtractFilePath(lbeProjectName.Text) + '_spider_storage';
end;
end;
procedure TfmProjectOptions.acSaveProjectStorageExecute(Sender: TObject);
begin
//
end;
procedure TfmProjectOptions.acSelWorkDirExecute(Sender: TObject);
begin
odSelectWorkDir.FileName := lbeWorkDir.Text;
if odSelectWorkDir.Execute then
lbeWorkDir.Text := ExcludeTrailingPathDelimiter(Trim(odSelectWorkDir.FileName));
end;
procedure TfmProjectOptions.FormCreate(Sender: TObject);
begin
FOpenType := otNew;
pcProjectOpt.ActivePage := tsProject;
ActiveControl := lbeApplication;
end;
procedure TfmProjectOptions.FormShow(Sender: TObject);
begin
if FOpenType = otNew then
acOpenApplication.Execute;
end;
function TfmProjectOptions.GetApplicationName: String;
begin
Result := lbeApplication.Text;
end;
function TfmProjectOptions.GetDelphiSource: String;
begin
Result := lbeDelphiSource.Text;
end;
function TfmProjectOptions.GetProjectName: String;
begin
Result := lbeProjectName.Text;
end;
function TfmProjectOptions.GetProjectSource: String;
begin
Result := lbeProjectSource.Text;
end;
function TfmProjectOptions.GetProjectStorage: String;
begin
Result := lbeProjectStorage.Text;
end;
function TfmProjectOptions.GetRunParams: String;
begin
Result := lbeParameters.Text;
end;
function TfmProjectOptions.GetWorkingDirectory: String;
begin
Result := ExcludeTrailingPathDelimiter(Trim(lbeWorkDir.Text));
end;
procedure TfmProjectOptions.SetApplicationName(const Value: String);
begin
lbeApplication.Text := Value;
end;
procedure TfmProjectOptions.SetDelphiSource(const Value: String);
begin
lbeDelphiSource.Text := Value;
end;
procedure TfmProjectOptions.SetProjectName(const Value: String);
begin
lbeProjectName.Text := Value;
end;
procedure TfmProjectOptions.SetProjectSource(const Value: String);
begin
lbeProjectSource.Text := Value;
end;
procedure TfmProjectOptions.SetProjectStorage(const Value: String);
begin
lbeProjectStorage.Text := Value;
end;
procedure TfmProjectOptions.SetRunParams(const Value: String);
begin
lbeParameters.Text := Value;
end;
procedure TfmProjectOptions.SetWorkingDirectory(const Value: String);
begin
lbeWorkDir.Text := Value;
end;
end.