-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathFrmEditorAdvancedSettings.pas
More file actions
219 lines (190 loc) · 6.72 KB
/
FrmEditorAdvancedSettings.pas
File metadata and controls
219 lines (190 loc) · 6.72 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
unit FrmEditorAdvancedSettings;
interface
uses
System.Classes,
Vcl.Controls,
Vcl.StdCtrls,
Vcl.ExtCtrls,
Vcl.Forms,
Vcl.Dialogs,
PluginSettings;
type
TFrmEditorAdvancedSettings = class(TForm)
lblCommand: TLabel;
edCommand: TEdit;
btnBrowse: TButton;
pnlBottom: TPanel;
btnResetToDefault: TButton;
btnOK: TButton;
btnCancel: TButton;
GroupBox1: TGroupBox;
lblWindowClassName: TLabel;
edWindowClassName: TEdit;
lblWindowTitleSuffix: TLabel;
edWindowTitleSuffix: TEdit;
GroupBox2: TGroupBox;
lblReuseOpenArgs: TLabel;
edReuseOpenArgs: TEdit;
lblReuseGotoArgs: TLabel;
edReuseGotoArgs: TEdit;
lblNewOpenArgs: TLabel;
edNewOpenArgs: TEdit;
lblNewGotoArgs: TLabel;
edNewGotoArgs: TEdit;
lblDelphiLspArgs: TLabel;
edDelphiLspArgs: TEdit;
lblArgsHint: TLabel;
procedure btnBrowseClick(Sender: TObject);
procedure btnResetToDefaultClick(Sender: TObject);
strict private
FEditorId: string;
function CreateDefaultSettingsCopy: TEditorSettings;
function HasAllRequiredFields: Boolean;
procedure InputChanged(Sender: TObject);
procedure LoadFromEditorSettings(EditorSettings: TEditorSettings);
procedure SaveToEditorSettings(EditorSettings: TEditorSettings);
procedure UpdateOkButtonState;
public
class function EditEditorSettings(EditorSettings: TEditorSettings): Boolean;
end;
implementation
{$R *.dfm}
uses
System.SysUtils;
function TFrmEditorAdvancedSettings.CreateDefaultSettingsCopy: TEditorSettings;
begin
Result := TPluginSettings.CreateDefaultBuiltInEditorCopy(FEditorId);
end;
function TFrmEditorAdvancedSettings.HasAllRequiredFields: Boolean;
begin
if Trim(edCommand.Text) = '' then
Exit(False);
if Trim(edWindowClassName.Text) = '' then
Exit(False);
if Trim(edWindowTitleSuffix.Text) = '' then
Exit(False);
if Trim(edReuseOpenArgs.Text) = '' then
Exit(False);
if Trim(edReuseGotoArgs.Text) = '' then
Exit(False);
if Trim(edNewOpenArgs.Text) = '' then
Exit(False);
if Trim(edNewGotoArgs.Text) = '' then
Exit(False);
if Trim(edDelphiLspArgs.Text) = '' then
Exit(False);
Result := True;
end;
procedure TFrmEditorAdvancedSettings.InputChanged(Sender: TObject);
begin
UpdateOkButtonState;
end;
procedure TFrmEditorAdvancedSettings.btnBrowseClick(Sender: TObject);
begin
var Dialog := TOpenDialog.Create(nil);
try
Dialog.Title := 'Select editor executable';
Dialog.Filter := 'Scripts and executables|*.cmd;*.exe;*.bat|All files|*.*';
Dialog.FileName := edCommand.Text;
if Dialog.Execute(Handle) then begin
edCommand.Text := Dialog.FileName;
UpdateOkButtonState;
end;
finally
Dialog.Free;
end;
end;
procedure TFrmEditorAdvancedSettings.btnResetToDefaultClick(Sender: TObject);
begin
var DefaultSettings := CreateDefaultSettingsCopy;
try
if DefaultSettings = nil then begin
ShowMessage('This editor does not have built-in defaults.');
Exit;
end;
LoadFromEditorSettings(DefaultSettings);
finally
DefaultSettings.Free;
end;
end;
class function TFrmEditorAdvancedSettings.EditEditorSettings(EditorSettings: TEditorSettings): Boolean;
begin
var Dialog := TFrmEditorAdvancedSettings.Create(nil);
try
Dialog.FEditorId := EditorSettings.Id;
Dialog.edCommand.OnChange := Dialog.InputChanged;
Dialog.edWindowClassName.OnChange := Dialog.InputChanged;
Dialog.edWindowTitleSuffix.OnChange := Dialog.InputChanged;
Dialog.edReuseOpenArgs.OnChange := Dialog.InputChanged;
Dialog.edReuseGotoArgs.OnChange := Dialog.InputChanged;
Dialog.edNewOpenArgs.OnChange := Dialog.InputChanged;
Dialog.edNewGotoArgs.OnChange := Dialog.InputChanged;
Dialog.edDelphiLspArgs.OnChange := Dialog.InputChanged;
Dialog.LoadFromEditorSettings(EditorSettings);
Result := Dialog.ShowModal = mrOK;
if Result then
Dialog.SaveToEditorSettings(EditorSettings);
finally
Dialog.Free;
end;
end;
procedure TFrmEditorAdvancedSettings.LoadFromEditorSettings(EditorSettings: TEditorSettings);
begin
if EditorSettings = nil then
Exit;
Caption := 'Advanced Settings - ' + EditorSettings.DisplayName;
edCommand.Text := EditorSettings.Command;
edWindowClassName.Text := EditorSettings.WindowClassName;
edWindowTitleSuffix.Text := EditorSettings.WindowTitleSuffix;
edReuseOpenArgs.Text := EditorSettings.ReuseOpenArgs;
edReuseGotoArgs.Text := EditorSettings.ReuseGotoArgs;
edNewOpenArgs.Text := EditorSettings.NewOpenArgs;
edNewGotoArgs.Text := EditorSettings.NewGotoArgs;
edDelphiLspArgs.Text := EditorSettings.DelphiLspArgs;
var DefaultSettings := CreateDefaultSettingsCopy;
try
btnResetToDefault.Enabled := DefaultSettings <> nil;
finally
DefaultSettings.Free;
end;
UpdateOkButtonState;
end;
procedure TFrmEditorAdvancedSettings.SaveToEditorSettings(EditorSettings: TEditorSettings);
begin
if EditorSettings = nil then
Exit;
var DefaultSettings := CreateDefaultSettingsCopy;
try
EditorSettings.Command := Trim(edCommand.Text);
if (EditorSettings.Command = '') and (DefaultSettings <> nil) then
EditorSettings.Command := DefaultSettings.Command;
EditorSettings.WindowClassName := Trim(edWindowClassName.Text);
if (EditorSettings.WindowClassName = '') and (DefaultSettings <> nil) then
EditorSettings.WindowClassName := DefaultSettings.WindowClassName;
EditorSettings.WindowTitleSuffix := Trim(edWindowTitleSuffix.Text);
if (EditorSettings.WindowTitleSuffix = '') and (DefaultSettings <> nil) then
EditorSettings.WindowTitleSuffix := DefaultSettings.WindowTitleSuffix;
EditorSettings.ReuseOpenArgs := Trim(edReuseOpenArgs.Text);
if (EditorSettings.ReuseOpenArgs = '') and (DefaultSettings <> nil) then
EditorSettings.ReuseOpenArgs := DefaultSettings.ReuseOpenArgs;
EditorSettings.ReuseGotoArgs := Trim(edReuseGotoArgs.Text);
if (EditorSettings.ReuseGotoArgs = '') and (DefaultSettings <> nil) then
EditorSettings.ReuseGotoArgs := DefaultSettings.ReuseGotoArgs;
EditorSettings.NewOpenArgs := Trim(edNewOpenArgs.Text);
if (EditorSettings.NewOpenArgs = '') and (DefaultSettings <> nil) then
EditorSettings.NewOpenArgs := DefaultSettings.NewOpenArgs;
EditorSettings.NewGotoArgs := Trim(edNewGotoArgs.Text);
if (EditorSettings.NewGotoArgs = '') and (DefaultSettings <> nil) then
EditorSettings.NewGotoArgs := DefaultSettings.NewGotoArgs;
EditorSettings.DelphiLspArgs := Trim(edDelphiLspArgs.Text);
if (EditorSettings.DelphiLspArgs = '') and (DefaultSettings <> nil) then
EditorSettings.DelphiLspArgs := DefaultSettings.DelphiLspArgs;
finally
DefaultSettings.Free;
end;
end;
procedure TFrmEditorAdvancedSettings.UpdateOkButtonState;
begin
btnOK.Enabled := HasAllRequiredFields;
end;
end.