1 unit fppkg_packagefileoptionsfrm;
2
3 {$mode objfpc}{$H+}
4
5 interface
6
7 uses
8 Classes,
9 SysUtils,
10 TypInfo,
11 fpmkunit,
12 Laz2_XMLCfg,
13 LazFileUtils,
14 Forms,
15 Controls,
16 StdCtrls,
17 ExtCtrls,
18 CheckLst,
19 PackageIntf,
20 IDEOptEditorIntf,
21 IDEOptionsIntf,
22 fppkg_const;
23
24 type
25
26 { TFppkgPackageFileIDEOptions }
27
28 TFppkgPackageFileIDEOptions = class(TAbstractPackageFileIDEOptions)
29 private
30 FIsParsed: Boolean;
31 FPackageFile: TLazPackageFile;
32 FLazPackage: TIDEPackage;
33 FAvailableOnAllTargetCPUs: Boolean;
34 FAvailableOnAllTargetOSes: Boolean;
35 FAvailableOnTargetOSes: TOSes;
36 FAvailableOnTargetCPUs: TCPUS;
37 protected
GetPackageFilenull38 function GetPackageFile: TLazPackageFile; override;
GetPackagenull39 function GetPackage: TIDEPackage; override;
40 public
41 constructor Create(APackage: TIDEPackage; APackageFile: TLazPackageFile); override;
GetInstancenull42 class function GetInstance(APackage: TIDEPackage; AFile: TLazPackageFile): TAbstractIDEOptions; overload; override;
GetGroupCaptionnull43 class function GetGroupCaption: string; override;
44
45 // Parse the options from the CustomOptions of the package-file
46 procedure ParseOptions;
47
48 // These are called when the options are read/written to the GUI for the package-options
49 procedure DoBeforeRead; override;
50 procedure DoAfterWrite(Restore: boolean); override;
51
52 property AvailableOnAllTargetCPUs: Boolean read FAvailableOnAllTargetCPUs write FAvailableOnAllTargetCPUs;
53 property AvailableOnAllTargetOSes: Boolean read FAvailableOnAllTargetOSes write FAvailableOnAllTargetOSes;
54 property AvailableOnTargetOSes: TOSes read FAvailableOnTargetOSes write FAvailableOnTargetOSes;
55 property AvailableOnTargetCPUs: TCPUS read FAvailableOnTargetCPUs write FAvailableOnTargetCPUs;
56 end;
57
58
59 { TFppkgPackageFileOptionsFrm }
60
61 TFppkgPackageFileOptionsFrm = class(TAbstractIDEOptionsEditor)
62 FileTargetOSPanel: TPanel;
63 FileTargetOSCheckList: TCheckListBox;
64 FileTargetOSComboBox: TComboBox;
65 FileTargetCPUPanel: TPanel;
66 FileTargetCPUCheckList: TCheckListBox;
67 FileTargetCPUComboBox: TComboBox;
68 procedure FileTargetOSCheckListClickCheck(Sender: TObject);
69 procedure FileTargetCPUCheckListClickCheck(Sender: TObject);
70 procedure FileTargetOSComboBoxChange(Sender: TObject);
71 procedure FileTargetCPUComboBoxChange(Sender: TObject);
72 public
73 procedure Setup(ADialog: TAbstractOptionsEditorDialog); override;
74 procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
75 procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
76
SupportedOptionsClassnull77 class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
GetTitlenull78 function GetTitle: String; override;
79 end;
80
81 implementation
82
83 {$R *.lfm}
84
85 { TFppkgPackageFileIDEOptions }
86
87 constructor TFppkgPackageFileIDEOptions.Create(APackage: TIDEPackage; APackageFile: TLazPackageFile);
88 begin
89 FLazPackage := APackage as TIDEPackage;
90 FPackageFile := APackageFile;
91 end;
92
TFppkgPackageFileIDEOptions.GetGroupCaptionnull93 class function TFppkgPackageFileIDEOptions.GetGroupCaption: string;
94 begin
95 Result := rsPackageFileOptionsTitle;
96 end;
97
TFppkgPackageFileIDEOptions.GetInstancenull98 class function TFppkgPackageFileIDEOptions.GetInstance(APackage: TIDEPackage; AFile: TLazPackageFile): TAbstractIDEOptions;
99 begin
100 Result := AFile.GetOptionsInstanceOf(TFppkgPackageFileIDEOptions);
101 end;
102
GetPackagenull103 function TFppkgPackageFileIDEOptions.GetPackage: TIDEPackage;
104 begin
105 Result := FLazPackage;
106 end;
107
GetPackageFilenull108 function TFppkgPackageFileIDEOptions.GetPackageFile: TLazPackageFile;
109 begin
110 Result := FPackageFile;
111 end;
112
113 Const
114 SetDelim = ['[',']',',',' '];
115
GetNextElementnull116 Function GetNextElement(Var S : String) : String;
117 Var
118 J : Integer;
119 begin
120 J:=1;
121 Result:='';
122 If Length(S)>0 then
123 begin
124 While (J<=Length(S)) and Not (S[j] in SetDelim) do
125 Inc(j);
126 Result:=Copy(S,1,j-1);
127 Delete(S,1,j);
128 end;
129 end;
130
StringToOSesnull131 Function StringToOSes(S : String) : TOSes;
132 Var
133 T : String;
134 I : Integer;
135 PTI : PTypeInfo;
136
137 begin
138 Result:=[];
139 PTI:=TypeInfo(TOS);
140 I:=1;
141 If Length(S)>0 then
142 begin
143 While (I<=Length(S)) and (S[i] in SetDelim) do
144 Inc(I);
145 Delete(S,1,i-1);
146 end;
147 While (S<>'') do
148 begin
149 T:=GetNextElement(S);
150 if T<>'' then
151 begin
152 I:=GetEnumValue(PTI,T);
153 if (I>-1) then
154 Result:=Result + [TOS(I)];
155 end;
156 end;
157 end;
158
159 procedure TFppkgPackageFileIDEOptions.DoBeforeRead;
160 begin
161 ParseOptions;
162 inherited DoBeforeRead;
163 end;
164
165 procedure TFppkgPackageFileIDEOptions.DoAfterWrite(Restore: boolean);
166 begin
167 inherited DoAfterWrite(Restore);
168 PackageFile.CustomOptions.SetDeleteValue('FPMake/AllOSes', AvailableOnAllTargetOSes, True);
169 PackageFile.CustomOptions.SetDeleteValue('FPMake/AllCPUs', AvailableOnAllTargetCPUs, True);
170 PackageFile.CustomOptions.SetDeleteValue('FPMake/TargetOSes', OSesToString(AvailableOnTargetOSes), '');
171 PackageFile.CustomOptions.SetDeleteValue('FPMake/TargetCPUs', CPUSToString(AvailableOnTargetCPUs), '');
172 end;
173
174 procedure TFppkgPackageFileIDEOptions.ParseOptions;
175 begin
176 if not FIsParsed then
177 begin
178 AvailableOnAllTargetOSes := PackageFile.CustomOptions.GetValue('FPMake/AllOSes', True);
179 AvailableOnAllTargetCPUs := PackageFile.CustomOptions.GetValue('FPMake/AllCPUs', True);
180 AvailableOnTargetOSes := StringToOSes(PackageFile.CustomOptions.GetValue('FPMake/TargetOSes', ''));
181 AvailableOnTargetCPUs := StringToCPUS(PackageFile.CustomOptions.GetValue('FPMake/TargetCPUs', ''));
182 FIsParsed := True;
183 end;
184 end;
185
186 { TFppkgPackageFileOptionsFrm }
187
TFppkgPackageFileOptionsFrm.SupportedOptionsClassnull188 class function TFppkgPackageFileOptionsFrm.SupportedOptionsClass: TAbstractIDEOptionsClass;
189 begin
190 result := TFppkgPackageFileIDEOptions;
191 end;
192
TFppkgPackageFileOptionsFrm.GetTitlenull193 function TFppkgPackageFileOptionsFrm.GetTitle: String;
194 begin
195 Result := rsPackageFileOptionsTitle;
196 end;
197
198 procedure TFppkgPackageFileOptionsFrm.Setup(ADialog: TAbstractOptionsEditorDialog);
199 var
200 OS: TOS;
201 CPU: TCpu;
202 begin
203 FileTargetOSCheckList.Items.Clear;
204 for OS := Succ(Low(OS)) to High(OS) do begin
205 FileTargetOSCheckList.Items.add(OSToString(OS));
206 end;
207 FileTargetCPUCheckList.Items.Clear;
208 for CPU := Succ(Low(CPU)) to High(CPU) do begin
209 FileTargetCPUCheckList.Items.add(CPUToString(CPU));
210 end;
211 end;
212
213 procedure TFppkgPackageFileOptionsFrm.ReadSettings(AOptions: TAbstractIDEOptions);
214 var
215 FileSettings: TFppkgPackageFileIDEOptions;
216 OS: TOS;
217 CPU: TCpu;
218 begin
219 if not Assigned(AOptions) then
220 Exit;
221 FileSettings := AOptions as TFppkgPackageFileIDEOptions;
222 // Supported FPMake CPU's and OS'es
223 if FileSettings.AvailableOnAllTargetOSes then
224 FileTargetOSComboBox.ItemIndex := 0
225 else
226 FileTargetOSComboBox.ItemIndex := 1;
227
228 if FileSettings.AvailableOnAllTargetCPUs then
229 FileTargetCPUComboBox.ItemIndex := 0
230 else
231 FileTargetCPUComboBox.ItemIndex := 1;
232
233 for OS := Succ(Low(OS)) to High(OS) do
234 FileTargetOSCheckList.Checked[Ord(OS) -1] := (OS in FileSettings.AvailableOnTargetOSes);
235 for CPU := Succ(Low(CPU)) to High(CPU) do
236 FileTargetCPUCheckList.Checked[Ord(CPU) -1] := (CPU in FileSettings.AvailableOnTargetCPUs);
237 end;
238
239 procedure TFppkgPackageFileOptionsFrm.WriteSettings(AOptions: TAbstractIDEOptions);
240 var
241 OS: TOS;
242 CPU: TCPU;
243 FileSettings: TFppkgPackageFileIDEOptions;
244 begin
245 if not Assigned(AOptions) then
246 Exit;
247 FileSettings := AOptions as TFppkgPackageFileIDEOptions;
248 FileSettings.AvailableOnTargetOSes := [];
249 for OS := Succ(Low(OS)) to High(OS) do
250 if FileTargetOSCheckList.Checked[Ord(OS) -1] then
251 FileSettings.AvailableOnTargetOSes := FileSettings.AvailableOnTargetOSes + [OS];
252
253 FileSettings.AvailableOnTargetCPUs := [];
254 for CPU := Succ(Low(CPU)) to High(CPU) do
255 if FileTargetCPUCheckList.Checked[Ord(CPU) -1] then
256 FileSettings.AvailableOnTargetCPUs := FileSettings.AvailableOnTargetCPUs + [CPU];
257
258 FileSettings.AvailableOnAllTargetCPUs := (FileTargetCPUComboBox.ItemIndex=0);
259 FileSettings.AvailableOnAllTargetOSes := (FileTargetOSComboBox.ItemIndex=0);
260 end;
261
262 procedure TFppkgPackageFileOptionsFrm.FileTargetOSCheckListClickCheck(Sender: TObject);
263 begin
264 DoOnChange;
265 end;
266
267 procedure TFppkgPackageFileOptionsFrm.FileTargetCPUCheckListClickCheck(Sender: TObject);
268 begin
269 DoOnChange;
270 end;
271
272 procedure TFppkgPackageFileOptionsFrm.FileTargetOSComboBoxChange(Sender: TObject);
273 begin
274 DoOnChange;
275 end;
276
277 procedure TFppkgPackageFileOptionsFrm.FileTargetCPUComboBoxChange(Sender: TObject);
278 begin
279 DoOnChange;
280 end;
281
282 var
283 OptionsGroup: Integer;
284
285 initialization
286 OptionsGroup := GetFreeIDEOptionsGroupIndex(GroupPackageFile);
287 RegisterIDEOptionsGroup(OptionsGroup, TFppkgPackageFileIDEOptions);
288 RegisterIDEOptionsEditor(OptionsGroup, TFppkgPackageFileOptionsFrm, 1);
289 end.
290
291