11
11
interface
12
12
13
13
uses
14
- classes, sysutils, inifiles, lazmethodlist, variants, fgl, controls, graphics;
15
-
16
- const
17
- SETTINGS_VERSION = 2 ; // Increase if settings become incompatible
14
+ Classes, SysUtils, IniFiles, LazMethodList, Variants, Controls,
15
+ simba.containers;
18
16
19
17
type
20
18
TSimbaSettings = class ;
@@ -79,11 +77,10 @@ TSimbaSetting_Integer = class(TSimbaSetting)
79
77
TSimbaSettings = class
80
78
protected
81
79
type
82
- TSettingList = specialize TFPGObjectList <TSimbaSetting>;
80
+ TSettingList = specialize TSimbaObjectList <TSimbaSetting>;
83
81
protected
84
82
FList: TSettingList;
85
83
FFirstLaunch: Boolean;
86
- FIsLoading: Boolean;
87
84
public
88
85
General: record
89
86
TrayIconVisible: TSimbaSetting;
@@ -173,7 +170,6 @@ TSimbaSettings = class
173
170
end ;
174
171
175
172
property FirstLaunch: Boolean read FFirstLaunch;
176
- property IsLoading: Boolean read FIsLoading;
177
173
178
174
class function GetINIFile : TINIFile;
179
175
class procedure SetSimpleSetting (AName, Value : String);
@@ -226,7 +222,7 @@ procedure TSimbaSetting_Integer.CheckValue(AValue: Variant);
226
222
227
223
procedure TSimbaSetting_Integer.ReadValue (INI: TINIFile);
228
224
begin
229
- Value := INI.ReadInt64(FSection, FName, Value );
225
+ FValue := INI.ReadInt64(FSection, FName, Value );
230
226
end ;
231
227
232
228
procedure TSimbaSetting_Integer.WriteValue (INI: TINIFile);
@@ -242,7 +238,7 @@ procedure TSimbaSetting_BinaryString.CheckValue(AValue: Variant);
242
238
243
239
procedure TSimbaSetting_BinaryString.ReadValue (INI: TINIFile);
244
240
begin
245
- Value := BaseDecode(EBaseEncoding.b64, INI.ReadString(FSection, FName, Value ));
241
+ FValue := BaseDecode(EBaseEncoding.b64, INI.ReadString(FSection, FName, Value ));
246
242
end ;
247
243
248
244
procedure TSimbaSetting_BinaryString.WriteValue (INI: TINIFile);
@@ -258,7 +254,7 @@ procedure TSimbaSetting_String.CheckValue(AValue: Variant);
258
254
259
255
procedure TSimbaSetting_String.ReadValue (INI: TINIFile);
260
256
begin
261
- Value := INI.ReadString(FSection, FName, Value );
257
+ FValue := INI.ReadString(FSection, FName, Value );
262
258
end ;
263
259
264
260
procedure TSimbaSetting_String.WriteValue (INI: TINIFile);
@@ -274,7 +270,7 @@ procedure TSimbaSetting_Boolean.CheckValue(AValue: Variant);
274
270
275
271
procedure TSimbaSetting_Boolean.ReadValue (INI: TINIFile);
276
272
begin
277
- Value := INI.ReadBool(FSection, FName, Value );
273
+ FValue := INI.ReadBool(FSection, FName, Value );
278
274
end ;
279
275
280
276
procedure TSimbaSetting_Boolean.WriteValue (INI: TINIFile);
@@ -325,11 +321,6 @@ procedure TSimbaSetting.Changed;
325
321
var
326
322
I: Integer;
327
323
begin
328
- if FSettings.IsLoading then
329
- Exit;
330
-
331
- // DebugLn('[TSimbaSettings] Setting changed: ' + FName);
332
-
333
324
I := FChangeEventList.Count;
334
325
while FChangeEventList.NextDownIndex(I) do
335
326
TSimbaSettingChangedEvent(FChangeEventList.Items[I])(Self);
@@ -390,34 +381,21 @@ procedure TSimbaSettings.Load;
390
381
INI: TIniFile;
391
382
Setting: TSimbaSetting;
392
383
begin
393
- FIsLoading := True;
394
-
395
384
INI := GetINIFile();
396
385
try
397
- if (INI.ReadInteger(' Settings' , ' Version' , 0 ) <> SETTINGS_VERSION) then
398
- begin
399
- DeleteFile(INI.FileName + ' .old' );
400
- RenameFile(INI.FileName, INI.FileName + ' .old' );
401
-
402
- Exit;
403
- end ;
404
-
405
386
if FileExists(SimbaSettingFileName) then
406
387
begin
407
388
FFirstLaunch := False;
408
389
409
- for Setting in FList do
410
- begin
411
- if not INI.ValueExists(Setting.FSection, Setting.FName) then
412
- Continue;
413
-
414
- Setting.ReadValue(INI);
415
- end ;
390
+ for Setting in FList.ToArray() do
391
+ if INI.ValueExists(Setting.FSection, Setting.FName) then
392
+ Setting.ReadValue(INI);
416
393
end ;
417
- finally
418
- INI.Free();
419
- FIsLoading := False ;
394
+ except
395
+ on E: Exception do
396
+ DebugLn( ' TSimbaSettings.Load: %s ' , [E.Message]) ;
420
397
end ;
398
+ INI.Free();
421
399
end ;
422
400
423
401
procedure TSimbaSettings.Save ;
@@ -426,16 +404,13 @@ procedure TSimbaSettings.Save;
426
404
Setting: TSimbaSetting;
427
405
begin
428
406
INI := GetINIFile();
429
- INI.WriteInteger(' Settings' , ' Version' , SETTINGS_VERSION);
430
-
431
- for Setting in FList do
407
+ for Setting in FList.ToArray() do
432
408
Setting.WriteValue(INI);
433
409
434
410
try
435
411
INI.UpdateFile();
436
412
except
437
413
end ;
438
-
439
414
INI.Free();
440
415
end ;
441
416
@@ -484,7 +459,7 @@ constructor TSimbaSettings.Create;
484
459
SynDefaultFontSize := SynDefaultFontSize + 1 ;
485
460
486
461
FFirstLaunch := True;
487
- FList := TSettingList.Create();
462
+ FList := TSettingList.Create(True );
488
463
489
464
// General
490
465
General.TrayIconVisible := TSimbaSetting_Boolean.Create(Self, ' General' , ' TrayIconVisible' , True);
@@ -573,14 +548,9 @@ destructor TSimbaSettings.Destroy;
573
548
inherited Destroy();
574
549
end ;
575
550
576
- procedure CreateSimbaSettings ;
577
- begin
551
+ initialization
578
552
SimbaSettingsInstance := TSimbaSettings.Create();
579
553
SimbaSettingsInstance.Load();
580
- end ;
581
-
582
- initialization
583
- SimbaIDEInitialization_AddBeforeCreate(@CreateSimbaSettings, ' Create SimbaSettings' );
584
554
585
555
finalization
586
556
if (SimbaSettingsInstance <> nil ) then
0 commit comments