-
Notifications
You must be signed in to change notification settings - Fork 2
/
PyJediOptions.pas
75 lines (65 loc) · 1.26 KB
/
PyJediOptions.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
unit PyJediOptions;
interface
type
TPJOptions = record
DropRestOfWord: Boolean;
ImagesSize: integer;
CallTipAutoTimeout: Integer;
procedure LoadFromFile(const fn: string);
procedure SaveToFile(const fn: string);
end;
const
__defaultOptions: TPJOptions = (
DropRestOfWord: true;
ImagesSize: 16;
CallTipAutoTimeout: 500;
);
var
PJOptions: TPJOptions;
implementation
uses
superobject, System.Classes, System.SysUtils;
{ TPJOptions }
procedure TPJOptions.LoadFromFile(const fn: string);
var
json: ISuperObject;
ctx: TSuperRttiContext;
begin
if not FileExists(fn) then
Exit;
with TStringStream.Create do
try
LoadFromFile(fn);
json := SO(DataString);
finally
Free;
end;
ctx := TSuperRttiContext.Create;
try
Self := ctx.AsType<TPJOptions>(json);
finally
ctx.Free;
end;
end;
procedure TPJOptions.SaveToFile(const fn: string);
var
json: ISuperObject;
ctx: TSuperRttiContext;
begin
ForceDirectories(ExtractFilePath(fn));
ctx := TSuperRttiContext.Create;
try
json := ctx.AsJson<TPJOptions>(Self);
finally
ctx.Free;
end;
with TStringStream.Create(json.AsJSon(true)) do
try
SaveToFile(fn);
finally
Free;
end;
end;
initialization
PJOptions := __defaultOptions;
end.