forked from integrated-application-development/pasfmt-rad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasfmt.SettingsFrame.pas
184 lines (148 loc) · 5.22 KB
/
Pasfmt.SettingsFrame.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
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
unit Pasfmt.SettingsFrame;
interface
uses
System.Classes,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
ToolsAPI,
Vcl.StdCtrls,
Vcl.ExtCtrls;
type
TPasfmtSettingsFrame = class(TFrame)
LogLevelCombo: TComboBox;
LogLevelLabel: TLabel;
ExeChooseDialog: TOpenDialog;
ExePathBrowseButton: TButton;
ExePathRadioGroup: TRadioGroup;
ExePathEdit: TEdit;
ExePathLabel: TLabel;
OnSaveCheckBox: TCheckBox;
UserSettingsLabel: TLabel;
TimeoutLabel: TLabel;
TimeoutEdit: TEdit;
FastModeThresholdEdit: TEdit;
FastModeThresholdLabel: TLabel;
procedure ExePathBrowseButtonClick(Sender: TObject);
procedure ExePathRadioGroupClick(Sender: TObject);
public
procedure UpdateExePathControls(ExePath: string);
procedure SyncExePathControls;
end;
TPasfmtAddInOptions = class(TInterfacedObject, INTAAddInOptions)
private
FFrame: TPasfmtSettingsFrame;
public
function GetArea: string;
function GetCaption: string;
function GetFrameClass: TCustomFrameClass;
procedure FrameCreated(AFrame: TCustomFrame);
procedure DialogClosed(Accepted: Boolean);
function ValidateContents: Boolean;
function GetHelpContext: Integer;
function IncludeInIDEInsight: Boolean;
end;
implementation
uses
System.IOUtils,
Pasfmt.Settings,
Pasfmt.Log,
System.StrUtils,
Pasfmt.OnSave,
System.SysUtils;
{$R *.dfm}
//______________________________________________________________________________________________________________________
procedure TPasfmtAddInOptions.FrameCreated(AFrame: TCustomFrame);
begin
FFrame := TPasfmtSettingsFrame(AFrame);
PasfmtSettings.Load;
FFrame.LogLevelCombo.ItemIndex := Ord(PasfmtSettings.LogLevel);
FFrame.UpdateExePathControls(PasfmtSettings.ExecutablePath);
FFrame.OnSaveCheckBox.Checked := PasfmtSettings.FormatOnSave;
FFrame.TimeoutEdit.Text := IntToStr(PasfmtSettings.FormatTimeout);
FFrame.FastModeThresholdEdit.Text := IntToStr(PasfmtSettings.MaxFileKiBWithUndoHistory);
end;
//______________________________________________________________________________________________________________________
procedure TPasfmtAddInOptions.DialogClosed(Accepted: Boolean);
var
LogLevelOrd: Integer;
NewTimeout: Integer;
NewThreshold: Integer;
begin
if Accepted then begin
PasfmtSettings.ExecutablePath := IfThen(FFrame.ExePathRadioGroup.ItemIndex = 1, Trim(FFrame.ExePathEdit.Text), '');
if TryStrToInt(FFrame.TimeoutEdit.Text, NewTimeout) then begin
PasfmtSettings.FormatTimeout := NewTimeout;
end;
LogLevelOrd := FFrame.LogLevelCombo.ItemIndex;
if (LogLevelOrd < 0) or (LogLevelOrd > Ord(High(TLogLevel))) then begin
LogLevelOrd := Ord(llDebug);
end;
PasfmtSettings.LogLevel := TLogLevel(LogLevelOrd);
Log.SetLogLevel(PasfmtSettings.LogLevel);
PasfmtSettings.FormatOnSave := FFrame.OnSaveCheckBox.Checked;
if not PasfmtSettings.FormatOnSave then begin
OnSaveInstaller.UninstallAll;
end;
if TryStrToInt(FFrame.FastModeThresholdEdit.Text, NewThreshold) then begin
PasfmtSettings.MaxFileKiBWithUndoHistory := NewThreshold;
end;
end;
FFrame := nil;
end;
//______________________________________________________________________________________________________________________
function TPasfmtAddInOptions.GetArea: string;
begin
Result := '';
end;
function TPasfmtAddInOptions.GetCaption: string;
begin
Result := 'Pasfmt';
end;
function TPasfmtAddInOptions.GetFrameClass: TCustomFrameClass;
begin
Result := TPasfmtSettingsFrame;
end;
function TPasfmtAddInOptions.GetHelpContext: Integer;
begin
Result := -1;
end;
function TPasfmtAddInOptions.IncludeInIDEInsight: Boolean;
begin
Result := True;
end;
function TPasfmtAddInOptions.ValidateContents: Boolean;
begin
Result := True;
end;
//______________________________________________________________________________________________________________________
procedure TPasfmtSettingsFrame.ExePathBrowseButtonClick(Sender: TObject);
begin
if TPath.HasValidPathChars(ExePathEdit.Text, False) and (ExePathEdit.Text <> '') then begin
ExeChooseDialog.FileName := TPath.GetFileName(ExePathEdit.Text);
ExeChooseDialog.InitialDir := TPath.GetDirectoryName(ExePathEdit.Text);
end;
if ExeChooseDialog.Execute then begin
ExePathEdit.Text := ExeChooseDialog.FileName;
end;
end;
//______________________________________________________________________________________________________________________
procedure TPasfmtSettingsFrame.ExePathRadioGroupClick(Sender: TObject);
begin
SyncExePathControls;
end;
//______________________________________________________________________________________________________________________
procedure TPasfmtSettingsFrame.SyncExePathControls;
begin
ExePathEdit.Visible := ExePathRadioGroup.ItemIndex = 1;
ExePathBrowseButton.Visible := ExePathEdit.Visible;
end;
//______________________________________________________________________________________________________________________
procedure TPasfmtSettingsFrame.UpdateExePathControls(ExePath: string);
begin
ExePathRadioGroup.ItemIndex := Integer(ExePath <> '');
ExePathEdit.Text := ExePath;
SyncExePathControls;
end;
//______________________________________________________________________________________________________________________
end.