-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPasfmt.Settings.pas
More file actions
237 lines (188 loc) · 6.5 KB
/
Pasfmt.Settings.pas
File metadata and controls
237 lines (188 loc) · 6.5 KB
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
unit Pasfmt.Settings;
interface
uses
Pasfmt.Log,
System.Win.Registry,
System.Classes,
System.SysUtils;
type
TPasfmtSettings = class(TObject)
private
const
CLogLevelName = 'Log Level';
CExecutablePathName = 'Executable Path';
CFormatOnSaveName = 'Format On Save';
CFormatTimeoutName = 'Format Timeout';
CMaxFileKiBWithUndoHistory = 'Max File Size With Undo History';
CFormatHotkey = 'Format Hotkey';
private
FRegistry: TRegistry;
FBaseKey: string;
FLogLevel: TLogLevel;
FExecutablePath: string;
FFormatOnSave: Boolean;
FFormatTimeout: Integer;
FMaxFileKiBWithUndoHistory: Integer;
FFormatHotkey: TShortCut;
FFormatHotkeyChanged: TProc;
procedure SetLogLevel(Value: TLogLevel);
procedure SetExecutablePath(Value: string);
procedure SetFormatOnSave(Value: Boolean);
procedure SetFormatTimeout(Value: Integer);
procedure SetMaxFileKiBWithUndoHistory(Value: Integer);
procedure SetFormatHotkey(Value: TShortCut);
public
constructor Create;
destructor Destroy; override;
procedure Load;
property LogLevel: TLogLevel read FLogLevel write SetLogLevel;
property ExecutablePath: string read FExecutablePath write SetExecutablePath;
property FormatOnSave: Boolean read FFormatOnSave write SetFormatOnSave;
property FormatTimeout: Integer read FFormatTimeout write SetFormatTimeout;
property MaxFileKiBWithUndoHistory: Integer read FMaxFileKiBWithUndoHistory write SetMaxFileKiBWithUndoHistory;
property FormatHotkey: TShortCut read FFormatHotkey write SetFormatHotkey;
property OnFormatHotkeyChanged: TProc write FFormatHotkeyChanged;
end;
function PasfmtSettings: TPasfmtSettings;
implementation
uses
ToolsAPI,
Winapi.Windows,
Vcl.Menus;
var
GSettings: TPasfmtSettings;
function PasfmtSettings: TPasfmtSettings;
begin
if not Assigned(GSettings) then begin
GSettings := TPasfmtSettings.Create;
GSettings.Load;
end;
Result := GSettings;
end;
//______________________________________________________________________________________________________________________
constructor TPasfmtSettings.Create;
begin
FBaseKey := (BorlandIDEServices as IOTAServices).GetBaseRegistryKey + '\Pasfmt';
FRegistry := TRegistry.Create(KEY_ALL_ACCESS);
FRegistry.RootKey := HKEY_CURRENT_USER;
FFormatHotkeyChanged := nil;
end;
//______________________________________________________________________________________________________________________
destructor TPasfmtSettings.Destroy;
begin
FreeAndNil(FRegistry);
inherited;
end;
//______________________________________________________________________________________________________________________
procedure TPasfmtSettings.SetExecutablePath(Value: string);
begin
FExecutablePath := Value;
FRegistry.OpenKey(FBaseKey, True);
try
FRegistry.WriteString(CExecutablePathName, Value);
finally
FRegistry.CloseKey;
end;
end;
procedure TPasfmtSettings.SetFormatHotkey(Value: TShortCut);
begin
if FFormatHotkey = Value then
exit;
FFormatHotkey := Value;
FRegistry.OpenKey(FBaseKey, True);
try
FRegistry.WriteString(CFormatHotkey, ShortCutToText(Value));
finally
FRegistry.CloseKey;
end;
if Assigned(FFormatHotkeyChanged) then
FFormatHotkeyChanged;
end;
//______________________________________________________________________________________________________________________
procedure TPasfmtSettings.SetFormatOnSave(Value: Boolean);
begin
FFormatOnSave := Value;
FRegistry.OpenKey(FBaseKey, True);
try
FRegistry.WriteBool(CFormatOnSaveName, Value);
finally
FRegistry.CloseKey;
end;
end;
//______________________________________________________________________________________________________________________
procedure TPasfmtSettings.SetFormatTimeout(Value: Integer);
begin
FFormatTimeout := Value;
FRegistry.OpenKey(FBaseKey, True);
try
FRegistry.WriteInteger(CFormatTimeoutName, Value);
finally
FRegistry.CloseKey;
end;
end;
//______________________________________________________________________________________________________________________
procedure TPasfmtSettings.SetMaxFileKiBWithUndoHistory(Value: Integer);
begin
FMaxFileKiBWithUndoHistory := Value;
FRegistry.OpenKey(FBaseKey, True);
try
FRegistry.WriteInteger(CMaxFileKiBWithUndoHistory, Value);
finally
FRegistry.CloseKey;
end;
end;
//______________________________________________________________________________________________________________________
procedure TPasfmtSettings.SetLogLevel(Value: TLogLevel);
begin
FLogLevel := Value;
FRegistry.OpenKey(FBaseKey, True);
try
FRegistry.WriteInteger(CLogLevelName, Ord(Value));
finally
FRegistry.CloseKey;
end;
end;
//______________________________________________________________________________________________________________________
procedure TPasfmtSettings.Load;
begin
FRegistry.OpenKey(FBaseKey, True);
try
FLogLevel := llWarn;
FExecutablePath := '';
FFormatOnSave := False;
FFormatTimeout := 500;
FMaxFileKiBWithUndoHistory := 1024;
FFormatHotkey := ShortCut(Ord('F'), [ssCtrl, ssAlt]);
if FRegistry.ValueExists(CLogLevelName) then
FLogLevel := TLogLevel(FRegistry.ReadInteger(CLogLevelName))
else
FRegistry.WriteInteger(CLogLevelName, Ord(FLogLevel));
if FRegistry.ValueExists(CExecutablePathName) then
FExecutablePath := FRegistry.ReadString(CExecutablePathName)
else
FRegistry.WriteString(CExecutablePathName, FExecutablePath);
if FRegistry.ValueExists(CFormatOnSaveName) then
FFormatOnSave := FRegistry.ReadBool(CFormatOnSaveName)
else
FRegistry.WriteBool(CFormatOnSaveName, FFormatOnSave);
if FRegistry.ValueExists(CFormatTimeoutName) then
FFormatTimeout := FRegistry.ReadInteger(CFormatTimeoutName)
else
FRegistry.WriteInteger(CFormatTimeoutName, FFormatTimeout);
if FRegistry.ValueExists(CMaxFileKiBWithUndoHistory) then
FMaxFileKiBWithUndoHistory := FRegistry.ReadInteger(CMaxFileKiBWithUndoHistory)
else
FRegistry.WriteInteger(CMaxFileKiBWithUndoHistory, FMaxFileKiBWithUndoHistory);
if FRegistry.ValueExists(CFormatHotkey) then
FFormatHotkey := TextToShortCut(FRegistry.ReadString(CFormatHotkey))
else
FRegistry.WriteString(CFormatHotkey, ShortCutToText(FFormatHotkey));
finally
FRegistry.CloseKey;
end;
end;
//______________________________________________________________________________________________________________________
initialization
finalization
FreeAndNil(GSettings);
end.