-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathres2gooptions.pas
487 lines (417 loc) · 15.9 KB
/
res2gooptions.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
//----------------------------------------
//
// Copyright © ying32. All Rights Reserved.
//
// Licensed under Lazarus.modifiedLGPL
//
//----------------------------------------
unit res2goOptions;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, StdCtrls, ExtCtrls, EditBtn, ActnList,
StrUtils, IDEOptionsIntf, IDEOptEditorIntf, LazIDEIntf, ProjectIntf,
ProjectResourcesIntf, res2goresources, Laz2_XMLCfg, DividerBevel, uSupports;
type
{ TProjectRes2goRes }
TProjectRes2goRes = class(TAbstractProjectResource)
private const
DefaultCGOValue = {$ifdef windows}False{$else}True{$endif};
private
FEnabled: Boolean;
FGoBuildMode: string;
FGoEnabledCGO: Boolean;
FGoEnabledFinalizerOn: Boolean;
FGoRoot: string;
FGoTags: string;
FGoUseEmbed: Boolean;
FGoUseTempdll: Boolean;
FOutLang: TOutLang;
FOutputPath: string;
FPakcageName: string;
FSaveGfmFile: Boolean;
FUseDefaultWinAppRes: Boolean;
FUseOriginalFileName: Boolean;
procedure Changed;
procedure SetEnabled(AValue: Boolean);
procedure SetGoBuildMode(AValue: string);
procedure SetGoEnabledCGO(AValue: Boolean);
procedure SetGoEnabledFinalizerOn(AValue: Boolean);
procedure SetGoRoot(AValue: string);
procedure SetGoTags(AValue: string);
procedure SetGoUseEmbed(AValue: Boolean);
procedure SetGoUseTempdll(AValue: Boolean);
procedure SetOutLang(AValue: TOutLang);
procedure SetOutputPath(AValue: string);
procedure SetPackageName(AValue: string);
procedure SetSaveGfmFile(AValue: Boolean);
procedure SetUseDefaultWinAppRes(AValue: Boolean);
procedure SetUseOriginalFileName(AValue: Boolean);
public
function UpdateResources(AResources: TAbstractProjectResources; const {%H-}MainFilename: string): Boolean; override;
procedure WriteToProjectFile(AConfig: TObject; const Path: String); override;
procedure ReadFromProjectFile(AConfig: TObject; const Path: String); override;
public
property Enabled: Boolean read FEnabled write SetEnabled;
property OutputPath: string read FOutputPath write SetOutputPath;
property UseOriginalFileName: Boolean read FUseOriginalFileName write SetUseOriginalFileName;
property SaveGfmFile: Boolean read FSaveGfmFile write SetSaveGfmFile;
property OutLang: TOutLang read FOutLang write SetOutLang;
property PackageName: string read FPakcageName write SetPackageName;
property UseDefaultWinAppRes: Boolean read FUseDefaultWinAppRes write SetUseDefaultWinAppRes;
property GoUseTempdll: Boolean read FGoUseTempdll write SetGoUseTempdll;
property GoEnabledFinalizerOn: Boolean read FGoEnabledFinalizerOn write SetGoEnabledFinalizerOn;
property GoTags: string read FGoTags write SetGoTags;
property GoEnabledCGO: Boolean read FGoEnabledCGO write SetGoEnabledCGO;
property GoBuildMode: string read FGoBuildMode write SetGoBuildMode;
property GoRoot: string read FGoRoot write SetGoRoot;
property GoUseEmbed: Boolean read FGoUseEmbed write SetGoUseEmbed;
end;
{ TRes2goOptionsFrame }
TRes2goOptionsFrame = class(TAbstractIDEOptionsEditor)
actSaveGfm: TAction;
ActionList1: TActionList;
cbbLangs: TComboBox;
chkGoEnabledCGO: TCheckBox;
chkGoUseEmbed: TCheckBox;
chkGoUseTempdll: TCheckBox;
chkGoEnabledFinalizerOn: TCheckBox;
chkEanbledConvert: TCheckBox;
chkSaveGfmFile: TCheckBox;
chkUseDefaultWinAppRes: TCheckBox;
chkUseOriginalFileName: TCheckBox;
cbbGoBuildModes: TComboBox;
edtGoRoot: TDirectoryEdit;
DividerBevel1: TDividerBevel;
DividerBevel2: TDividerBevel;
DividerBevel3: TDividerBevel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
lblBuildModeHint: TLabel;
lblOutLang: TLabel;
lblOutputPath: TLabeledEdit;
lblGoTags: TLabeledEdit;
lblPkgName: TLabeledEdit;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
procedure actSaveGfmExecute(Sender: TObject);
procedure actSaveGfmUpdate(Sender: TObject);
procedure FrameClick(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function GetTitle: string; override;
procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
end;
implementation
{$R *.lfm}
uses
res2gomain;
const
ProjectOptionsRes2go = ProjectOptionsMisc + 500;
{ TProjectRes2goRes }
procedure TProjectRes2goRes.Changed;
begin
Self.Modified:= True;
end;
procedure TProjectRes2goRes.SetEnabled(AValue: Boolean);
begin
if FEnabled=AValue then Exit;
FEnabled:=AValue;
Changed;
end;
procedure TProjectRes2goRes.SetGoBuildMode(AValue: string);
begin
if FGoBuildMode=AValue then Exit;
FGoBuildMode:=AValue;
Changed;
end;
procedure TProjectRes2goRes.SetGoEnabledCGO(AValue: Boolean);
begin
if FGoEnabledCGO=AValue then Exit;
FGoEnabledCGO:=AValue;
Changed;
end;
procedure TProjectRes2goRes.SetGoEnabledFinalizerOn(AValue: Boolean);
begin
if FGoEnabledFinalizerOn=AValue then Exit;
FGoEnabledFinalizerOn:=AValue;
Changed;
end;
procedure TProjectRes2goRes.SetGoRoot(AValue: string);
begin
if FGoRoot=AValue then Exit;
FGoRoot:=AValue;
Changed;
end;
procedure TProjectRes2goRes.SetGoTags(AValue: string);
begin
if FGoTags=AValue then Exit;
FGoTags:=AValue;
Changed;
end;
procedure TProjectRes2goRes.SetGoUseEmbed(AValue: Boolean);
begin
if FGoUseEmbed=AValue then Exit;
FGoUseEmbed:=AValue;
Changed;
end;
procedure TProjectRes2goRes.SetGoUseTempdll(AValue: Boolean);
begin
if FGoUseTempdll=AValue then Exit;
FGoUseTempdll:=AValue;
Changed;
end;
procedure TProjectRes2goRes.SetOutLang(AValue: TOutLang);
begin
if FOutLang=AValue then Exit;
FOutLang:=AValue;
Changed;
end;
procedure TProjectRes2goRes.SetOutputPath(AValue: string);
begin
if FOutputPath=AValue then Exit;
FOutputPath:=AValue;
Changed;
end;
procedure TProjectRes2goRes.SetPackageName(AValue: string);
begin
if FPakcageName=AValue then Exit;
FPakcageName:=AValue;
Changed;
end;
procedure TProjectRes2goRes.SetSaveGfmFile(AValue: Boolean);
begin
if FSaveGfmFile=AValue then Exit;
FSaveGfmFile:=AValue;
Changed;
end;
procedure TProjectRes2goRes.SetUseDefaultWinAppRes(AValue: Boolean);
begin
if FUseDefaultWinAppRes=AValue then Exit;
FUseDefaultWinAppRes:=AValue;
Changed;
end;
procedure TProjectRes2goRes.SetUseOriginalFileName(AValue: Boolean);
begin
if FUseOriginalFileName=AValue then Exit;
FUseOriginalFileName:=AValue;
Changed;
end;
function TProjectRes2goRes.UpdateResources(
AResources: TAbstractProjectResources; const MainFilename: string): Boolean;
begin
Result := True;
if Assigned(MyIDEIntf) then
MyIDEIntf.ReConvertRes:= True;
end;
procedure TProjectRes2goRes.WriteToProjectFile(AConfig: TObject;
const Path: String);
begin
with TXMLConfig(AConfig) do
begin
SetDeleteValue(Path+'Res2go/Enabled/Value', Enabled, False);
SetDeleteValue(Path+'Res2go/OutputPath/Value', OutputPath, '');
SetDeleteValue(Path+'Res2go/UseOriginalFileName/Value', UseOriginalFileName, False);
SetDeleteValue(Path+'Res2go/SaveGfmFile/Value', SaveGfmFile, False);
SetDeleteValue(Path+'Res2go/OutLang/Value', Integer(OutLang), 0);
SetDeleteValue(Path+'Res2go/PackageName/Value', PackageName, 'main');
SetDeleteValue(Path+'Res2go/UseDefaultWinAppRes/Value', UseDefaultWinAppRes, False);
SetDeleteValue(Path+'Res2go/GoUseTempdll/Value', GoUseTempdll, False);
SetDeleteValue(Path+'Res2go/GoEnabledFinalizerOn/Value', GoEnabledFinalizerOn, False);
SetDeleteValue(Path+'Res2go/GoTags/Value', GoTags, '');
SetDeleteValue(Path+'Res2go/GoEnabledCGO/Value', GoEnabledCGO, DefaultCGOValue);
SetDeleteValue(Path+'Res2go/GoBuildMode/Value', GoBuildMode, '');
SetDeleteValue(Path+'Res2go/GoRoot/Value', GoRoot, '');
SetDeleteValue(Path+'Res2go/GoUseEmbed/Value', GoUseEmbed, False);
end;
end;
procedure TProjectRes2goRes.ReadFromProjectFile(AConfig: TObject;
const Path: String);
begin
with TXMLConfig(AConfig) do
begin
Enabled := GetValue(Path+'Res2go/Enabled/Value', False);
OutputPath := GetValue(Path+'Res2go/OutputPath/Value', '');
UseOriginalFileName := GetValue(Path+'Res2go/UseOriginalFileName/Value', False);
SaveGfmFile := GetValue(Path+'Res2go/SaveGfmFile/Value', False);
OutLang := TOutLang(GetValue(Path+'Res2go/SaveGfmFile/Value', 0));
PackageName := GetValue(Path+'Res2go/PackageName/Value', 'main');
UseDefaultWinAppRes := GetValue(Path+'Res2go/UseDefaultWinAppRes/Value', False);
GoUseTempdll := GetValue(Path+'Res2go/GoUseTempdll/Value', False);
GoEnabledFinalizerOn := GetValue(Path+'Res2go/GoEnabledFinalizerOn/Value', False);
GoTags := GetValue(Path+'Res2go/GoTags/Value', '');
GoEnabledCGO := {$ifndef windows}True{$else}GetValue(Path+'Res2go/GoEnabledCGO/Value', False){$endif};
GoBuildMode := GetValue(Path+'Res2go/GoBuildMode/Value', '');
GoRoot := Trim(GetValue(Path+'Res2go/GoRoot/Value', GetEnvironmentVariable('GOROOT')));
GoUseEmbed := GetValue(Path+'Res2go/GoUseEmbed/Value', False);
end;
if Assigned(MyIDEIntf) then
begin
MyIDEIntf.EnabledConvert := Enabled;
MyIDEIntf.OutputPath := OutputPath;
MyIDEIntf.UseOriginalFileName := UseOriginalFileName;
MyIDEIntf.SaveGfmFile := SaveGfmFile;
MyIDEIntf.OutLang := OutLang;
MyIDEIntf.PackageName := PackageName;
MyIDEIntf.UseDefaultWinAppRes := UseDefaultWinAppRes;
MyIDEIntf.GoUseTempdll := GoUseTempdll;
MyIDEIntf.GoEnabledFinalizerOn := GoEnabledFinalizerOn;
MyIDEIntf.GoTags := GoTags;
MyIDEIntf.GoEnabledCGO := GoEnabledCGO;
MyIDEIntf.GoBuildMode := GoBuildMode;
MyIDEIntf.GoRoot := GoRoot;
MyIDEIntf.GoUseEmbed := GoUseEmbed;
end;
end;
{ TRes2goOptionsFrame }
procedure TRes2goOptionsFrame.FrameClick(Sender: TObject);
begin
end;
procedure TRes2goOptionsFrame.actSaveGfmExecute(Sender: TObject);
begin
//
end;
procedure TRes2goOptionsFrame.actSaveGfmUpdate(Sender: TObject);
begin
TAction(Sender).Enabled:=not chkGoUseEmbed.Checked;
end;
constructor TRes2goOptionsFrame.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
destructor TRes2goOptionsFrame.Destroy;
begin
inherited Destroy;
end;
function TRes2goOptionsFrame.GetTitle: string;
begin
Result := 'res2go';
end;
procedure TRes2goOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
begin
chkEanbledConvert.Caption:=rsEnabledConvert;
chkUseOriginalFileName.Caption:=rsUseOriginalFileName;
//chkSaveGfmFile.Caption := rsSaveGfmFile;
actSaveGfm.Caption:=rsSaveGfmFile;
lblOutputPath.EditLabel.Caption:=rsOutputPath;
Label1.Caption:=rsOutputPathEg;
lblOutLang.Caption:=rsOutputLang;
lblPkgName.EditLabel.Caption:=rsPackageName;
chkUseDefaultWinAppRes.Caption:=rsUseDefaultWinAppRes;
chkGoUseTempdll.Caption := rsGoUseTempdll;
chkGoUseTempdll.Hint:=rsGoUseTempdllHint;
chkGoEnabledFinalizerOn.Caption := rsGoEnabledFinalizerOn;
chkGoEnabledFinalizerOn.Hint:=rsGoEnabledFinalizerOnHint;
lblGoTags.EditLabel.Caption := rsGoTags;
DividerBevel1.Caption := rsDividerBevel1;
chkGoEnabledCGO.Caption:=rsGoEnabledCGO;
Label2.Caption := rsBuildMode;
lblBuildModeHint.Caption := rsBuildModeHint;
chkGoUseEmbed.Caption:=rsGoEnabledEmbed;
{$ifndef windows}
chkGoEnabledCGO.Enabled := False;
chkGoEnabledCGO.Checked := True;
{$endif}
end;
procedure TRes2goOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
var
LRes: TProjectRes2goRes;
begin
if Assigned(MyIDEIntf) and Assigned(LazarusIDE) and Assigned(LazarusIDE.ActiveProject) and Assigned(LazarusIDE.ActiveProject.Resources) then
begin
LRes := TProjectRes2goRes(TAbstractProjectResources(LazarusIDE.ActiveProject.Resources).Resource[TProjectRes2goRes]);
if Assigned(LRes) then
begin
MyIDEIntf.EnabledConvert := LRes.Enabled;
MyIDEIntf.OutputPath := LRes.OutputPath;
MyIDEIntf.UseOriginalFileName := LRes.UseOriginalFileName;
MyIDEIntf.SaveGfmFile := LRes.SaveGfmFile;
MyIDEIntf.OutLang := LRes.OutLang;
MyIDEIntf.PackageName :=LRes.PackageName;
MyIDEIntf.UseDefaultWinAppRes := LRes.UseDefaultWinAppRes;
MyIDEIntf.GoUseTempdll := LRes.GoUseTempdll;
MyIDEIntf.GoEnabledFinalizerOn :=LRes.GoEnabledFinalizerOn;
MyIDEIntf.GoTags := LRes.GoTags;
MyIDEIntf.GoEnabledCGO :=LRes.GoEnabledCGO;
MyIDEIntf.GoBuildMode := LRes.GoBuildMode;
MyIDEIntf.GoRoot := LRes.GoRoot;
MyIDEIntf.GoUseEmbed:=LRes.GoUseEmbed;
chkEanbledConvert.Checked := MyIDEIntf.EnabledConvert;
lblOutputPath.Text := MyIDEIntf.OutputPath;
ChkUseOriginalFileName.Checked:= MyIDEIntf.UseOriginalFileName;
ChkSaveGfmFile.Checked := MyIDEIntf.SaveGfmFile;
cbbLangs.ItemIndex:=Integer(MyIDEIntf.OutLang);
lblPkgName.Text:=MyIDEIntf.PackageName;
chkUseDefaultWinAppRes.Checked:=MyIDEIntf.UseDefaultWinAppRes;
chkGoUseTempdll.Checked:=LRes.GoUseTempdll;
chkGoEnabledFinalizerOn.Checked:=LRes.GoEnabledFinalizerOn;
lblGoTags.Text := LRes.GoTags;
chkGoEnabledCGO.Checked:=LRes.GoEnabledCGO;
cbbGoBuildModes.ItemIndex:=cbbGoBuildModes.Items.IndexOf(LRes.GoBuildMode);
edtGoRoot.Text := Trim(LRes.GoRoot);
chkGoUseEmbed.Checked:=LRes.GoUseEmbed;
end;
end;
end;
procedure TRes2goOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
var
LRes: TProjectRes2goRes;
begin
if Assigned(MyIDEIntf) and Assigned(LazarusIDE) and Assigned(LazarusIDE.ActiveProject) and Assigned(LazarusIDE.ActiveProject.Resources) then
begin
LRes := TProjectRes2goRes(TAbstractProjectResources(LazarusIDE.ActiveProject.Resources).Resource[TProjectRes2goRes]);
if Assigned(LRes) then
begin
MyIDEIntf.EnabledConvert := chkEanbledConvert.Checked;
MyIDEIntf.OutputPath:= lblOutputPath.Text;
MyIDEIntf.UseOriginalFileName:=chkUseOriginalFileName.Checked;
MyIDEIntf.SaveGfmFile := chkSaveGfmFile.Checked;
MyIDEIntf.OutLang:=TOutLang(cbbLangs.ItemIndex);
MyIDEIntf.PackageName:=Trim(lblPkgName.Text);
if (not MyIDEIntf.UseDefaultWinAppRes) and chkUseDefaultWinAppRes.Checked then
MyIDEIntf.ReConvertRes:= True;
MyIDEIntf.UseDefaultWinAppRes := chkUseDefaultWinAppRes.Checked;
MyIDEIntf.GoUseTempdll := chkGoUseTempdll.Checked;
MyIDEIntf.GoEnabledFinalizerOn := chkGoEnabledFinalizerOn.Checked;
MyIDEIntf.GoTags := lblGoTags.Text;
MyIDEIntf.GoEnabledCGO:=chkGoEnabledCGO.Checked;
if cbbGoBuildModes.ItemIndex >= 0 then
MyIDEIntf.GoBuildMode := cbbGoBuildModes.Items[cbbGoBuildModes.ItemIndex]
else
MyIDEIntf.GoBuildMode := '';
MyIDEIntf.GoRoot := Trim(edtGoRoot.Text);
MyIDEIntf.GoUseEmbed:=chkGoUseEmbed.Checked;
// MyIDEIntf.GoBuildMode:= IfThen(cbbGoBuildModes.ItemIndex >= 0, cbbGoBuildModes.Items[cbbGoBuildModes.ItemIndex], ''); ???????
LRes.OutputPath := MyIDEIntf.OutputPath;
LRes.Enabled := MyIDEIntf.EnabledConvert;
LRes.UseOriginalFileName := MyIDEIntf.UseOriginalFileName;
LRes.SaveGfmFile := MyIDEIntf.SaveGfmFile;
LRes.OutLang:=MyIDEIntf.OutLang;
LRes.PackageName:=MyIDEIntf.PackageName;
LRes.UseDefaultWinAppRes := MyIDEIntf.UseDefaultWinAppRes;
LRes.GoUseTempdll:=MyIDEIntf.GoUseTempdll;
LRes.GoEnabledFinalizerOn:=MyIDEIntf.GoEnabledFinalizerOn;
LRes.GoTags := MyIDEIntf.GoTags;
LRes.GoEnabledCGO:=MyIDEIntf.GoEnabledCGO;
LRes.GoBuildMode:=MyIDEIntf.GoBuildMode;
LRes.GoRoot:= MyIDEIntf.GoRoot;
LRes.GoUseEmbed:=MyIDEIntf.GoUseEmbed;
end;
end;
end;
class function TRes2goOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
begin
Result := nil;//TProjectIDEOptions;
end;
initialization
//RegisterIDEOptionsGroup(GroupProject, TRes2goIDEOptions);
RegisterProjectResource(TProjectRes2goRes);
RegisterIDEOptionsEditor(GroupProject, TRes2goOptionsFrame, ProjectOptionsRes2go);
end.