-
Notifications
You must be signed in to change notification settings - Fork 1
/
u_ViewIconsSettings.pas
136 lines (114 loc) · 3.54 KB
/
u_ViewIconsSettings.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
unit u_ViewIconsSettings;
interface
// super simple configuration settings file.
uses
vcl.Graphics,
system.Classes,
svgViewer.Types;
type
TSettings = class(TInterfacedObject,ISVGIconConfig)
private
fSettings : tStringlist;
protected
function GetOptionStr(Name:String):String;
function GetOptionInt(Name:STring):Integer;
function GetOptionColor(Name:STring):TColor;
function GetOptionBool(Name:String):Boolean;
procedure SetOptionStr(Name,value:String);
procedure SetOptionInt(Name:String;value:Integer);
procedure SetOptionColor(Name:STring;value:TColor);
procedure SetOptionBool(Name:String;value:Boolean);
public
constructor Create;
destructor Destroy; override;
function GetOptionStrDefault(Name,Default:String):String;
function GetOptionIntDefault(Name:STring;Default:Integer):Integer;
function GetOptionColorDefault(Name:STring;Default:TColor):TColor;
function GetOptionBooleanDefault(Name:STring;Default:Boolean):Boolean;
property OptionStr[Name:String]:String read GetOptionStr write SetOptionStr;
property OptionInt[Name:String]:Integer read GetOptionInt write SetOptionInt;
property OptionColor[Name:String]:TColor read GetOptionColor write SetOptionColor;
property OptionBoolean[Name:String]:Boolean read GetOptionBool write SetOptionBool;
end;
implementation
uses
System.SysUtils,
system.IOUtils,
System.StrUtils,
vcl.GraphUtil;
{ TSettings }
constructor TSettings.Create;
begin
inherited;
fSettings := tStringlist.create;
if tFile.Exists(TPath.GetHomePath+'\svgViewer.config') then
fSettings.LoadFromFile(TPath.GetHomePath+'\svgViewer.config');
end;
destructor TSettings.Destroy;
begin
fSettings.SaveToFile(TPath.GetHomePath+'\svgViewer.config');
fSettings.free;
inherited;
end;
function TSettings.GetOptionBool(Name: String): Boolean;
begin
Result := StrToBool(fSettings.values[name]);
end;
function TSettings.GetOptionBooleanDefault(Name: STring;
Default: Boolean): Boolean;
begin
Result := StrToBoolDef(fSettings.values[name],Default);
end;
function TSettings.GetOptionColor(Name: STring): TColor;
begin
if not MatchText(fSettings.Values[name],['(none)','']) then
Result := WebColorStrToColor(fSettings.Values[name])
else
Result := clNone;
end;
function TSettings.GetOptionColorDefault(Name: STring; Default: TColor): TColor;
begin
if fSettings.Values[name] <> '' then
Result := GetOptionColor(Name)
else
Result := Default;
end;
function TSettings.GetOptionInt(Name: STring): Integer;
begin
Result := StrToIntDef(fSettings.Values[name],0);
end;
function TSettings.GetOptionIntDefault(Name: STring; Default: Integer): Integer;
begin
Result := StrToIntDef(fSettings.Values[name],Default);
end;
function TSettings.GetOptionStr(Name: String): String;
begin
Result := fSettings.Values[name];
end;
function TSettings.GetOptionStrDefault(Name, Default: String): String;
begin
if fSettings.Values[name] <> '' then
Result := fSettings.Values[name]
else
Result := Default;
end;
procedure TSettings.SetOptionBool(Name: String; value: Boolean);
begin
fSettings.Values[name] := BoolToStr(value,true);
end;
procedure TSettings.SetOptionColor(Name: STring; value: TColor);
begin
if Value = clNone then
fSettings.Values[name] := '(none)'
else
fSettings.Values[name] := ColorToWebColorStr(value);
end;
procedure TSettings.SetOptionInt(Name: String; value: Integer);
begin
fSettings.Values[name] := IntToSTr(Value);
end;
procedure TSettings.SetOptionStr(Name, value: String);
begin
fSettings.Values[name] := Value;
end;
end.