-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmphpsettings.pas
516 lines (452 loc) · 14.3 KB
/
frmphpsettings.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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
unit frmphpsettings;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.ComCtrls, Vcl.Grids,
Vcl.ValEdit, SynEditHighlighter, SynHighlighterIni, SynEdit,
VirtualTrees, Vcl.StdCtrls, VirtualTrees.BaseAncestorVCL,
VirtualTrees.BaseTree, VirtualTrees.AncestorVCL;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
tbsVisual: TTabSheet;
tbsSourceCode: TTabSheet;
Panel1: TPanel;
SynMemo1: TSynEdit;
SynIniSyn1: TSynIniSyn;
vstPHP: TVirtualStringTree;
btnSave: TButton;
btnCancel: TButton;
btnEditMode: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure vstPHPFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vstPHPGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
procedure btnCancelClick(Sender: TObject);
procedure vstPHPNodeDblClick(Sender: TBaseVirtualTree;
const HitInfo: THitInfo);
procedure vstPHPInitNode(Sender: TBaseVirtualTree; ParentNode,
Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
procedure vstPHPBeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
procedure vstPHPInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode;
var ChildCount: Cardinal);
procedure vstPHPChecked(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vstPHPEditing(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; var Allowed: Boolean);
procedure vstPHPNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; NewText: string);
procedure btnEditModeClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure SynMemo1Change(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
private
{ Private declarations }
PHPIniText: TStrings;
PHPIniBuf : String;
PHPEditedFile: string;
procedure ParsePHPIni(text: String);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses main, locales;
type
Pinidata = ^Tinidata;
Tinidata = record
key: string;
value: string;
savedvalue: string;
enabled: Boolean;
sectionchanges: String; //used to count changes inside
line: Integer;
OtherNode: PVirtualNode;
end;
{$R *.dfm}
procedure TForm1.btnCancelClick(Sender: TObject);
begin
Close;
end;
procedure TForm1.btnEditModeClick(Sender: TObject);
begin
if btnEditMode.Caption = R_phpini_text then
begin
SynMemo1.ReadOnly := False;
vstPHP.Enabled := False;
btnEditMode.Caption := R_phpini_visual;
PageControl1.ActivePage := tbsSourceCode;
PHPIniBuf := SynMemo1.Text;
end
else
begin
SynMemo1.ReadOnly := True;
vstPHP.Enabled := True;
btnEditMode.Caption := R_phpini_text;
PageControl1.ActivePage := tbsVisual;
PHPIniBuf := SynMemo1.Text;
ParsePHPIni('');
end;
end;
procedure TForm1.btnSaveClick(Sender: TObject);
begin
SynMemo1.Lines.SaveToFile(PHPEditedFile);
PHPIniBuf := SynMemo1.Text;
SynMemo1Change(SynMemo1);
ParsePHPIni('');
//TODO: if visual mode, just update all nodes statuses so refreshing won't be needed
//pHPINIBUF might be wrong working, just a test was its purpose
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
NotModal := True;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
EnableImmersiveDarkMode(True);
PHPIniText := TStringList.Create;
vstPHP.NodeDataSize := SizeOf(Tinidata);
btnEditMode.Caption := R_phpini_text;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
PHPIniText.Free;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
if main.frmAMP.cbPHPversion.Text = 'PHP 8' then
PHPEditedFile := ExtractFilePath(ParamStr(0))+'content\php8\php.ini'
else if main.frmAMP.cbPHPversion.Text = 'PHP 7' then
PHPEditedFile := ExtractFilePath(ParamStr(0))+'content\php7\php.ini'
else
PHPEditedFile := ExtractFilePath(ParamStr(0))+'content\php5\php.ini';
if FileExists(PHPEditedFile) then
begin
PHPIniText.LoadFromFile(PHPEditedFile);
SynMemo1.Text := PHPIniText.Text;
ParsePHPIni('');
end
else
raise Exception.Create('No PHP.INI file found!');
end;
// This will populate php settings in the virtual string tree
procedure TForm1.ParsePHPIni(text: String);
var
lines: TStrings;
i : Integer;
node,subnode,extnode, _node: PVirtualNode;
data: Pinidata;
parser: TStringList;
begin
lines := TStringList.Create;
try
lines.Text := SynMemo1.Text;
vstPHP.DeleteChildren(vstPHP.RootNode);
// First section will be the extensions'
extnode := vstPHP.AddChild(nil);
data := vstPHP.GetNodeData(extnode);
data^.key := 'Extensions';
data^.line := 0;
data^.sectionchanges := '';
for i := 0 to lines.Count - 1 do
begin
if Pos('[',Trim(lines[i])) = 1 then
begin
node := vstPHP.AddChild(nil);
data := vstPHP.GetNodeData(node);
data^.key := Trim(lines[i]);
data^.line := i;
data^.sectionchanges := ''; //defaults to no changes
end
// comments out
else
if Pos(';',Trim(lines[i])) = 1 then
begin
// find out if is a valid commented/disabled value
parser := TStringList.Create;
try
parser.Text := StringReplace(lines[i], '=',#13#10'#'#13#10,[]);
if Pos(' ', Trim(parser[0]))> 0 then
begin
// is not a valid key value
end
else if parser.Count > 1 then
begin
if Assigned(node) then
begin
_node := nil;
if (LowerCase(Trim(Copy(parser[0],2))) = 'extension')
or (LowerCase(Trim(Copy(parser[0],2))) = 'extension_dir')
then
begin
_node := node;
node := extnode;
end;
subnode := vstPHP.AddChild(node);
data := vstPHP.GetNodeData(subnode);
data^.key := Copy(parser[0],2);
if parser.Count > 2 then
begin
data^.value := parser[2];
data^.savedvalue := parser[2];
end;
data^.line := i;
data^.enabled := False;
subnode.CheckState := csUncheckedNormal;
if _node <> nil then node := _node;
end;
end;
finally
parser.Free;
end;
end
else if Trim(lines[i]) = '' then
begin
//empty line
end
else
begin
parser := TStringList.Create;
try
parser.Text := StringReplace(lines[i], '=',#13#10'#'#13#10,[]);
if Pos(' ', Trim(parser[0]))> 0 then
begin
// is not a valid key value
end
else if parser.Count > 1 then
begin
if Assigned(node) then
begin
_node := nil;
if (LowerCase(Trim(parser[0])) = 'extension')
or (LowerCase(Trim(parser[0])) = 'extension_dir')
then
begin
_node := node;
node := extnode;
end;
subnode := vstPHP.AddChild(node);
data := vstPHP.GetNodeData(subnode);
data^.key := parser[0];
if parser.Count > 2 then
begin
data^.value := parser[2];
data^.savedvalue := parser[2];
end;
data^.line := i;
data^.enabled := True;
subnode.CheckState := csCheckedNormal;
if _node <> nil then node := _node;
end;
end;
finally
parser.Free;
end;
end;
end;
finally
lines.Free;
end;
end;
procedure TForm1.SynMemo1Change(Sender: TObject);
begin
if PHPIniBuf <> SynMemo1.Text then
btnSave.Enabled := True
else
btnSave.Enabled := False;
end;
procedure TForm1.vstPHPBeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
var
Level: Integer;
Data: Pinidata;
begin
Level := Sender.GetNodeLevel(Node);
case Level of
0:
begin
TargetCanvas.Brush.Color := $1f1f1f; //fondo
TargetCanvas.FillRect(CellRect);
Data := Sender.GetNodeData(Node);
if Trim(Data^.sectionchanges) <> '' then
begin
TargetCanvas.Brush.Color := $76BFFB;
TargetCanvas.FillRect(CellRect);
end;
end;
1:
begin
Data := Sender.GetNodeData(Node);
if (Node.Index and 1) = 1 then
begin
TargetCanvas.Brush.Color := $1f1f1f;
TargetCanvas.FillRect(CellRect);
end;
if Node.CheckState = csCheckedNormal then
begin
if not Data^.enabled then // to highlight if changed from original state
begin
TargetCanvas.Brush.Color := $76BFFB;
TargetCanvas.FillRect(CellRect);
end
else
TargetCanvas.Brush.Color := $6b5e4f;//$A3D491;
TargetCanvas.FillRect(CellRect);
end
else if Node.CheckState = csUncheckedNormal then
begin
if Data^.enabled then // to highlight if changed from original state
begin
TargetCanvas.Brush.Color := $76BFFB;
TargetCanvas.FillRect(CellRect);
end;
end;
if Data^.savedvalue <> Data^.value then
begin
TargetCanvas.Brush.Color := $12ddea;
TargetCanvas.FillRect(CellRect);
end;
end;
end;
end;
procedure TForm1.vstPHPChecked(Sender: TBaseVirtualTree; Node: PVirtualNode);
var
Level: Integer;
Data: Pinidata;
ParentData: Pinidata;
Nodo: PVirtualNode;
I: Integer;
begin
// Node := Sender.FocusedNode;
Level := Sender.GetNodeLevel(Node);
if Level > 0 then // just to act if subnode is clicked specially for changes on checkbox
begin
ParentData := Sender.GetNodeData(Node.Parent);
Nodo := Sender.GetFirstChild(Node.Parent);
ParentData^.sectionchanges := '';
I := 0;
while Assigned(Nodo) do
begin
Data := Sender.GetNodeData(Nodo);
if Nodo.CheckState = csCheckedNormal then
begin
if not Data^.enabled then Inc(I);
end
else if Nodo.CheckState = csUncheckedNormal then
begin
if Data^.enabled then Inc(I);
end;
if Data^.savedvalue <> Data^.value then
Inc(I);
if I > 0 then
ParentData^.sectionchanges:= I.ToString;
Nodo := Sender.GetNextSibling(Nodo);
end;
vstPHP.RepaintNode(Node.Parent);
// Let's update the line in its source code
Data := Sender.GetNodeData(Node);
if Node.CheckState = csCheckedNormal then
SynMemo1.Lines[Data^.line] := Data^.key + ' = ' + Data^.value
else if Node.CheckState = csUnCheckedNormal then
SynMemo1.Lines[Data^.line] := ';'+Data^.key + ' = ' + Data^.value;
SynMemo1Change(SynMemo1);
end;
end;
procedure TForm1.vstPHPEditing(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; var Allowed: Boolean);
begin
// Allowed := True;
end;
procedure TForm1.vstPHPFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
var
data: Pinidata;
begin
data := vstPHP.GetNodeData(Node);
if Assigned(data) then
begin
data^.key := '';
data^.value := '';
data^.savedvalue := '';
data^.sectionchanges := '';
end;
end;
procedure TForm1.vstPHPGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
var
Level: Integer;
Data: Pinidata;
begin
Data := Sender.GetNodeData(Node);
Level := Sender.GetNodeLevel(Node);
case Column of
0: CellText := Data.key;
1:
begin
if Level = 0 then
begin
if Trim(Data.sectionchanges) <> '' then
CellText := 'Changes : '+Data.sectionchanges
else
CellText := '';
end
else
CellText := Data.value;
end;
2: CellText := Data.value;
end;
end;
procedure TForm1.vstPHPInitChildren(Sender: TBaseVirtualTree;
Node: PVirtualNode; var ChildCount: Cardinal);
begin
ChildCount := Sender.GetNodeLevel(Node) + 2;
end;
procedure TForm1.vstPHPInitNode(Sender: TBaseVirtualTree; ParentNode,
Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
var
Level: Integer;
begin
Level := Sender.GetNodeLevel(Node);
// Include(InitialStates, ivsHasChildren);
if Level = 0 then
Node.CheckType := ctNone;
if Level = 1 then
Node.CheckType := ctCheckBox;
end;
procedure TForm1.vstPHPNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; NewText: string);
var
Level: Integer;
Data: Pinidata;
begin
Level := Sender.GetNodeLevel(Node);
if Level = 0 then Exit;
if Column = 1 then
begin
Data := Sender.GetNodeData(Node);
Data^.value := NewText;
vstPHPChecked(Sender, Node);
end;
end;
procedure TForm1.vstPHPNodeDblClick(Sender: TBaseVirtualTree;
const HitInfo: THitInfo);
var
Data: Pinidata;
Node: PVirtualNode;
begin
Node := Sender.FocusedNode;
Data := Sender.GetNodeData(Node);
if Assigned(Node) then
begin
if (Data^.line+1 >=1) and (Data^.line+1 < SynMemo1.Lines.Count) then
begin
SynMemo1.GotoLineAndCenter(Data^.line+1);
PageControl1.SelectNextPage(True);
end;
end;
end;
end.