-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOptionsForm.pas
411 lines (363 loc) · 9.92 KB
/
OptionsForm.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
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
{ Ïðè èñïîëüçîâàíèè äàííûõ èñõîäíèêîâ èëè èõ ôðàãìåíòîâ, ññûëêà íà èñòî÷íèê
îáÿçàòåëüíà.
http://irchat.ru
Ôîðìà íàñòðîåê.
Ñîäåðæèò ïðåäîïðåäåëåííóþ óíèâåðñàëüíóþ ñòðàíèöó îòîáðàæåíèÿ è
ðåäàêòèðîâàíèÿ ñïèñêà íàñòðîåê, êîòîðàÿ èñïîëüçóåòñÿ, åñëè ïàíåëü
ñòðàíèöû íàñòðîåê íå íàçíà÷åíà.
 êà÷åñòâå îñíîâíîãî êîíôèãà èñïîëüçóåòñÿ ãëîáàëüíûé conf.
}
unit OptionsForm;
interface
uses
SysUtils, Classes, Controls, Forms,
StdCtrls, ExtCtrls, ComCtrls, Configs, Buttons;
type
TfrmOptions = class(TForm)
tvConfTree: TTreeView;
panOptionsPanel: TPanel;
btOk: TButton;
btnApply: TButton;
btnCancel: TButton;
panValuesList: TPanel;
lvItemsList: TListView;
panelModValue: TPanel;
lbValueName: TLabel;
cbValue: TCheckBox;
edValueString: TEdit;
btnSetValue: TButton;
memoValue: TMemo;
bbtnFold: TBitBtn;
bbtnUnfold: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure lvItemsListSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure btnSetValueClick(Sender: TObject);
procedure tvConfTreeChange(Sender: TObject; Node: TTreeNode);
procedure FormDestroy(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
procedure btnApplyClick(Sender: TObject);
procedure btOkClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure bbtnFoldClick(Sender: TObject);
procedure bbtnUnfoldClick(Sender: TObject);
private
{ Private declarations }
CurConfItem: TConfItem;
CurConfItems: TConfItems;
CurConfNode: TConfNode;
public
{ Public declarations }
procedure RefreshConfTree();
procedure RefreshAllOptions();
procedure RefreshItemsList(SaveSelected: boolean = false);
procedure SaveOptions();
procedure LoadOptions();
procedure ChangeLanguage();
procedure SelectItemByOwner(AOwner: TObject);
end;
type
TConfListItem = class(TListItem)
public
ConfItem: TConfItem;
end;
TConfTreeNode = class(TTreeNode)
public
ConfNode: TConfNode;
end;
var
frmOptions: TfrmOptions;
VisualConf: TConf;
implementation
uses IRC_Options, MainOptions, Core, Plugins;
{$R *.dfm}
procedure TfrmOptions.RefreshConfTree();
var
i: integer;
NewTreeNode: TConfTreeNode;
procedure FillTreeNode(TreeNode: TConfTreeNode; ConfNode: TConfNode);
var
i: integer;
NewTreeNode: TConfTreeNode;
begin
TreeNode.Text:=ConfNode.FullName;
TreeNode.ConfNode:=ConfNode;
if ConfNode.ChildCount = 0 then Exit;
for i:=0 to ConfNode.ChildCount-1 do
begin
NewTreeNode:=TConfTreeNode.Create(TreeNode.Owner);
TreeNode.Owner.AddNode(NewTreeNode, TreeNode, '', nil, naAddChild);
FillTreeNode(NewTreeNode, ConfNode.ChildNodes[i]);
end;
end;
begin
tvConfTree.Items.BeginUpdate();
tvConfTree.Items.Clear();
NewTreeNode:=TConfTreeNode.Create(tvConfTree.Items);
FillTreeNode(NewTreeNode, VisualConf.RootNode);
tvConfTree.Items.EndUpdate();
if tvConfTree.Items.Count <= 20 then tvConfTree.FullExpand();
end;
procedure TfrmOptions.tvConfTreeChange(Sender: TObject; Node: TTreeNode);
var
stdListVisible: boolean;
begin
if Assigned(CurConfNode) and Assigned(CurConfNode.Panel) then
begin
CurConfNode.Panel.Visible:=false;
end;
CurConfNode:=TConfTreeNode(Node).ConfNode;
CurConfItems:=CurConfNode.ConfItems;
stdListVisible:=true;
if Assigned(CurConfNode.Panel) then
begin
CurConfNode.Panel.Parent:=panOptionsPanel;
CurConfNode.Panel.Visible:=true;
stdListVisible:=false;
end;
panValuesList.Visible:=stdListVisible;
//lvItemsList.Visible:=stdListVisible;
//panelModValue.Visible:=stdListVisible;
RefreshItemsList();
end;
//================================
// Items list
//================================
procedure TfrmOptions.RefreshItemsList(SaveSelected: boolean = false);
var
i: integer;
NewItem: TConfListItem;
SelIndex: integer;
begin
SelIndex:=0;
if SaveSelected then
begin
SelIndex:=lvItemsList.ItemIndex;
end;
lvItemsList.Clear();
if Assigned(CurConfItems) then
begin
for i:=0 to CurConfItems.Count-1 do
begin
NewItem:=TConfListItem.Create(lvItemsList.Items);
NewItem.ConfItem:=CurConfItems.Items[i];
//NewItem.Caption:=IntToStr(NewItem.ConfItem.ID);
NewItem.SubItems.Add(NewItem.ConfItem.Name);
NewItem.SubItems.Add(NewItem.ConfItem.FullName);
NewItem.SubItems.Add(NewItem.ConfItem.ValueString);
lvItemsList.Items.AddItem(NewItem);
NewItem.Caption:=IntToStr(NewItem.ConfItem.ID);
end;
end;
if SaveSelected then
begin
lvItemsList.ItemIndex:=SelIndex;
Exit;
end;
CurConfItem:=nil;
edValueString.Text:='';
end;
procedure TfrmOptions.lvItemsListSelectItem(Sender: TObject;
Item: TListItem; Selected: Boolean);
begin
edValueString.Visible := false;
lbValueName.Visible := false;
cbValue.Visible := false;
memoValue.Visible := false;
if not Assigned(Item) then
begin
CurConfItem:=nil;
Exit;
end;
CurConfItem:=TConfListItem(Item).ConfItem;
if CurConfItem.ValueType = 'B' then
begin
cbValue.Visible := true;
cbValue.Caption := CurConfItem.FullName;
if CurConfItem.ValueString = '1' then
cbValue.Checked:=true
else
cbValue.Checked:=false;
end
else if CurConfItem.ValueType = 'T' then
begin
lbValueName.Visible := true;
lbValueName.Caption := CurConfItem.FullName;
memoValue.Visible := true;
memoValue.Text:=CurConfItem.ValueString;
end
else
begin
lbValueName.Visible := true;
lbValueName.Caption := CurConfItem.FullName;
edValueString.Visible := true;
edValueString.Text:=CurConfItem.ValueString;
end;
end;
procedure TfrmOptions.btnSetValueClick(Sender: TObject);
begin
if not Assigned(CurConfItem) then Exit;
if CurCOnfItem.ValueType = 'S' then
begin
CurConfItem.ValueString:=edValueString.Text;
end
else if CurCOnfItem.ValueType = 'T' then
begin
CurConfItem.ValueString:=memoValue.Text;
end
else if CurCOnfItem.ValueType = 'B' then
begin
if cbValue.Checked then
CurConfItem.ValueString:='1'
else
CurConfItem.ValueString:='0';
end
else
begin
CurConfItem.ValueString:=edValueString.Text;
end;
RefreshItemsList(true);
end;
procedure TfrmOptions.SaveOptions();
var
i: integer;
Conf: TConf;
begin
// Apply main conf
MainConf.ApplySettings();
MainConf.Save();
// Apply clients conf
if not Assigned(ClientsManager) then Exit;
for i:=0 to Core.ClientsManager.ClientsCount-1 do
begin
Conf:=Core.ClientsManager.GetClient(i).GetConf();
if Assigned(Conf) then
begin
Conf.ApplySettings();
Conf.Save();
end;
end;
// Apply plugins conf
if Assigned(PluginsManager) then
begin
for i:=0 to PluginsManager.Count-1 do
begin
Conf:=TPlugin(PluginsManager[i]).Conf;
if Assigned(Conf) then
begin
Conf.ApplySettings();
//Conf.Save();
end;
end;
PluginsManager.BroadcastMsg('OPTIONS_CHANGED');
end;
end;
procedure TfrmOptions.LoadOptions();
var
i: integer;
Conf: TConf;
begin
MainConf.Load();
MainConf.RefreshItemsList();
if not Assigned(ClientsManager) then Exit;
for i:=0 to Core.ClientsManager.ClientsCount-1 do
begin
Conf:=Core.ClientsManager.GetClient(i).GetConf();
if Assigned(Conf) then
begin
Conf.Load();
Conf.RefreshItemsList();
end;
end;
end;
procedure TfrmOptions.RefreshAllOptions();
var
i: integer;
Conf: TConf;
begin
MainConf.RefreshItemsList();
if not Assigned(ClientsManager) then Exit;
for i:=0 to Core.ClientsManager.ClientsCount-1 do
begin
Conf:=Core.ClientsManager.GetClient(i).GetConf();
if Assigned(Conf) then
begin
Conf.RefreshItemsList();
end;
end;
end;
procedure TfrmOptions.FormCreate(Sender: TObject);
begin
VisualConf:=TConf.Create();
//Conf.FileName:=ExtractFilePath(ParamStr(0))+'\test.ini';
// Root node
VisualConf.RootNode:=TConfNode.Create(nil);
VisualConf.RootNode.Name:='Root';
VisualConf.RootNode.FullName:='Root node';
end;
procedure TfrmOptions.FormDestroy(Sender: TObject);
begin
FreeAndNil(VisualConf);
end;
procedure TfrmOptions.SelectItemByOwner(AOwner: TObject);
var
i: Integer;
TreeNode: TConfTreeNode;
begin
for i:=0 to tvConfTree.Items.Count-1 do
begin
TreeNode:=(tvConfTree.Items[i] as TConfTreeNode);
if TreeNode.ConfNode.Owner=AOwner then
begin
tvConfTree.Selected:=TreeNode;
TreeNode.Expand(true);
Exit;
end;
end;
end;
procedure TfrmOptions.btnCancelClick(Sender: TObject);
begin
Close();
end;
procedure TfrmOptions.btnApplyClick(Sender: TObject);
begin
SaveOptions();
end;
procedure TfrmOptions.btOkClick(Sender: TObject);
begin
SaveOptions();
Close();
end;
procedure TfrmOptions.FormShow(Sender: TObject);
begin
//LoadOptions();
RefreshAllOptions();
RefreshConfTree();
end;
procedure TfrmOptions.bbtnFoldClick(Sender: TObject);
begin
tvConfTree.FullCollapse();
end;
procedure TfrmOptions.bbtnUnfoldClick(Sender: TObject);
begin
tvConfTree.FullExpand();
end;
procedure TfrmOptions.ChangeLanguage();
function GetStr(Name: string; s: string): string;
begin
result:=Core.LangIni.ReadString('MainOptions', Name, s);
end;
begin
if not Assigned(Core.LangIni) then Exit;
try
btnApply.Caption:=GetStr('btnApply.Caption', btnApply.Caption);
btnCancel.Caption:=GetStr('btnCancel.Caption', btnCancel.Caption);
btOk.Caption:=GetStr('btOk.Caption', btOk.Caption);
bbtnFold.Hint:=GetStr('bbtnFold.Hint', bbtnFold.Hint);
bbtnUnfold.Hint:=GetStr('bbtnUnfold.Hint', bbtnUnfold.Hint);
//.Caption:=GetStr('.Caption', .Caption);
//:=GetStr('', );
finally
end;
end;
end.