-
Notifications
You must be signed in to change notification settings - Fork 2
/
Edit.pas
1376 lines (1077 loc) · 38.2 KB
/
Edit.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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit Edit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, SynEditHighlighter, SynHighlighterPerl,
SynEdit, ComCtrls, SearchReplace, SynEditKeyCmds, NewType, NewAction, FormLine, Registry, UnitSettings, ShellApi,
SynCompletionProposal, Config, StrUtils, SynHighlighterPHP, SuperObject, ActiveX, ComObj, shdocvw, mshtml;
type
TEditForm = class(TForm)
Panel1: TPanel;
ListBoxTypes: TListBox;
Panel2: TPanel;
Panel3: TPanel;
ListBoxRoles: TListBox;
Panel4: TPanel;
Panel5: TPanel;
Panel6: TPanel;
Splitter1: TSplitter;
Splitter2: TSplitter;
RadioButtonSelect: TRadioButton;
RadioButtonGetItem: TRadioButton;
RadioButtonDrawItem: TRadioButton;
RadioButtonDraw: TRadioButton;
SynEdit: TSynEdit;
SynPerlSyn: TSynPerlSyn;
ListBoxActions: TListBox;
Panel7: TPanel;
Splitter3: TSplitter;
RadioButtonDo: TRadioButton;
RadioButtonValidate: TRadioButton;
Splitter4: TSplitter;
ListBoxSubs: TListBox;
Panel8: TPanel;
SynCompletionProposal: TSynCompletionProposal;
SynPHPSyn: TSynPHPSyn;
EditFilter: TEdit;
procedure ListBoxTypesDblClick(Sender: TObject);
procedure ListBoxTypesKeyPress(Sender: TObject; var Key: Char);
procedure ListBoxRolesDblClick(Sender: TObject);
procedure ListBoxRolesKeyPress(Sender: TObject; var Key: Char);
procedure RadioButtonSelectClick(Sender: TObject);
procedure RadioButtonGetItemClick(Sender: TObject);
procedure RadioButtonDrawClick(Sender: TObject);
procedure RadioButtonDrawItemClick(Sender: TObject);
procedure SynEditChange(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure ListBoxActionsClick(Sender: TObject);
procedure SynEditKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure SynEditCommandProcessed(Sender: TObject;
var Command: TSynEditorCommand; var AChar: Char; Data: Pointer);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ListBoxSubsKeyPress(Sender: TObject; var Key: Char);
procedure ListBoxSubsDblClick(Sender: TObject);
procedure SynCompletionProposalExecute(Kind: SynCompletionType;
Sender: TObject; var AString: String; var x, y: Integer;
var CanExecute: Boolean);
procedure EditFilterChange(Sender: TObject);
private
ScmName: string;
LastLoadedText: string;
path, appname, tpl_path, ext, sub, brc: string;
CurrentFile: string;
TortoiseSVNPath: string;
LastLoadTime: TDateTime;
dirty: boolean;
StatusLine: TStatusBar;
SynSearchOptions: TSynSearchOptions;
SearchReplaceForm: TSearchReplaceForm;
LastSubName: string;
SavedPositionsSubs: TStringList;
SavedPositionsX: TStringList;
SavedPositionsY: TStringList;
function GetTypeName: string;
function GetRoleName: string;
function GetSubName: string;
function GetSubTemplate: string;
function FillTemplate (name: string): string;
function GetFileName: string;
function GetActionName: string;
procedure RefreshTypes;
procedure RefreshRoles;
procedure RefreshRowCol;
procedure RefreshActions;
procedure SetDirty (b: boolean);
procedure LoadCurrentSub (UseSavedPos: boolean = true);
procedure GoToAction (action: string; validate:boolean = false);
procedure ReadSettings;
public
ConfigForm: TConfigForm;
procedure Init (_path: string; _StatusLine: TStatusBar; is_php: boolean);
procedure SaveFile;
end;
var
EditForm: TEditForm;
implementation
uses Help;
{$R *.dfm}
function yes (title, text: string): boolean;
begin
if pos ('<none>', text) > 0
then Result := false
else Result := idyes = Application.MessageBox (PChar (text), PChar (title), mb_yesno + mb_iconquestion);
end;
{
function FillTemplate (name: string): string;
begin
end;
}
function TEditForm.FillTemplate (name: string): string;
var
f: textfile;
t, l: string;
begin
t := GetTypeName;
Result := '';
assignfile (f, tpl_path + name + '.tpl');
reset (f);
while not eof(f) do begin
readln (f, l);
Result := Result + ANSIReplacestr(l, '__TYPE__', t) + #13;
end;
closefile (f);
end;
function TEditForm.GetSubTemplate: string;
begin
Result := '';
if RadioButtonSelect.Checked then Result := FillTemplate (sub + '_select');
if RadioButtonGetItem.Checked then Result := FillTemplate (sub + '_get_item');
if RadioButtonDo.Checked then Result := FillTemplate (sub + '_do');
if RadioButtonDo.Checked and (GetActionName = 'create') then Result := FillTemplate (sub + '_do_create');
if RadioButtonDo.Checked and (GetActionName = 'add') then Result := FillTemplate (sub + '_do_add');
if RadioButtonDo.Checked and (GetActionName = 'update') then Result := FillTemplate (sub + '_do_update');
if RadioButtonDo.Checked and (GetActionName = 'download') then Result := FillTemplate (sub + '_do_download');
if RadioButtonDo.Checked and (GetActionName = 'delete') then Result := FillTemplate (sub + '_do_delete');
if RadioButtonDo.Checked and (GetActionName = 'print') then Result := FillTemplate (sub + '_do_print');
if RadioButtonDraw.Checked then Result := FillTemplate (sub + '_draw');
if RadioButtonDrawItem.Checked then Result := FillTemplate (sub + '_draw_item');
if RadioButtonValidate.Checked then Result := FillTemplate (sub + '_validate');
end;
procedure TEditForm.RefreshRowCol;
begin
StatusLine.Panels [0].Text := 'Row: ' + inttostr (SynEdit.CaretY);
StatusLine.Panels [1].Text := 'Ñol: ' + inttostr (SynEdit.CaretX);
end;
procedure TEditForm.RefreshActions;
var
f: textfile;
s, last_action: string;
p1, p2: integer;
begin
last_action := '';
if ListBoxActions.itemIndex > -1 then last_action := ListBoxActions.Items [ListBoxActions.itemIndex];
ListBoxActions.Items.Clear;
ListBoxActions.Items.Add ('<none>');
ListBoxActions.ItemIndex := 0;
Assignfile (f, path + '\Content\' + GetTypeName + '.' + ext);
reset (f);
while not EOF (f) do begin
readln (f, s);
p1 := pos (sub +' do_', s);
if p1 = 0 then continue;
inc (p1, 4 + length (sub));
p2 := pos ('_' + GetTypeName, s);
s := copy (s, p1, p2 - p1);
if ListBoxActions.Items.IndexOf (s) < 0 then ListBoxActions.Items.Add (s);
end;
closefile (f);
{
i := ListBoxActions.Items.IndexOf (last_action);
if i > -1 then ListBoxActions.Items.Add (last_action);
ListBoxActions.ItemIndex := ListBoxActions.Items.IndexOf (last_action);
}
end;
procedure TEditForm.SetDirty (b: boolean);
begin
dirty := b;
Caption := CurrentFile;
if b then Caption := '* ' + Caption;
end;
procedure TEditForm.SaveFile;
var
sl: TStringList;
s: string;
begin
if not dirty then exit;
if LastLoadTime < FileDateToDateTime (FileAge (currentFile)) then begin
sl := TStringList.Create;
sl.LoadFromFile (currentFile);
s := sl.DelimitedText;
sl.Free;
if s <> LastLoadedText then begin
if Application.MessageBox ('Attention! Someone changed the file on the disk since your last read. Load the changed file?', 'Conflict', mb_iconexclamation + mb_yesno) = idyes
then begin
if Application.MessageBox ('Are you sure to reload the file? (ALL YOUR CHANGES WILL BE LOST!!!)', 'Conflict', mb_iconexclamation + mb_yesno) = idyes then begin
LoadCurrentSub;
LastLoadedText := SynEdit.Lines.DelimitedText;
Exit;
end;
end
else begin
Exit;
end;
end;
end;
SynEdit.Lines.SaveToFile (currentFile);
LastLoadedText := SynEdit.Lines.DelimitedText;
LastLoadTime := FileDateToDateTime (FileAge (currentFile));
SetDirty (false);
self.ConfigForm.scp (currentFile);
StatusLine.Panels [2].Text := currentFile + ' saved.';
end;
procedure TEditForm.LoadCurrentSub;
var
token: string;
i: integer;
f: textfile;
found: boolean;
SavedPosition: integer;
begin
if ListBoxTypes.ItemIndex < 0 then Exit;
if LastSubName <> '' then begin
SavedPosition := SavedPositionsSubs.IndexOf (LastSubName);
if (SavedPosition < 0)
then begin
SavedPositionsSubs.Add (LastSubName);
SavedPositionsX.Add (inttostr (SynEdit.CaretX));
SavedPositionsY.Add (inttostr (SynEdit.CaretY));
end
else begin
SavedPositionsX [SavedPosition] := inttostr (SynEdit.CaretX);
SavedPositionsY [SavedPosition] := inttostr (SynEdit.CaretY);
end
end;
if currentFile <> GetFileName then begin
if dirty and yes ('Save changes', 'File ' + currentFile + ' is changed. Save it?') then SaveFile;
if not FileExists (GetFileName) then begin
if not yes ('File not found', 'File ' + GetFileName + ' doesn''t exist. Create it?') then begin
SynEdit.Lines.Clear;
exit;
end;
Assignfile (f, GetFileName);
rewrite (f);
if ext = 'php' then begin
writeln (f, '<?php');
writeln (f);
writeln (f, '?>');
end
else begin
writeln (f);
writeln (f, '1;');
end;
closefile (f);
end;
SynEdit.Lines.LoadFromFile (GetFileName);
LastLoadedText := SynEdit.Lines.DelimitedText;
currentFile := GetFileName;
SetDirty (false);
RefreshActions;
StatusLine.Panels [2].Text := currentFile + ' loaded';
end
else StatusLine.Panels [2].Text := '';
token := sub + ' ' + GetSubName;
found := false;
for i := 1 to SynEdit.Lines.Count do begin
if pos (token, SynEdit.Lines [i - 1]) = 0 then Continue;
SynEdit.CaretY := i;
SynEdit.EnsureCursorPosVisibleEx (true);
found := true;
Break;
end;
if found and UseSavedPos then begin
SavedPosition := SavedPositionsSubs.IndexOf (GetSubName);
if SavedPosition >= 0 then begin
SynEdit.CaretX := strtoint (SavedPositionsX [SavedPosition]);
SynEdit.CaretY := strtoint (SavedPositionsY [SavedPosition]);
end
end;
if not found and yes ('Sub not found', 'Sub ' + GetSubName + ' doesn''t exist. Create it?') then begin
SynEdit.CaretX := 0;
SynEdit.CaretY := 0;
SynEdit.SelStart := 0;
SynEdit.SelEnd := length (SynEdit.Lines [0]) + 1;
SynEdit.SelText := SynEdit.Lines [0] + #13 + #13 +
'################################################################################'
+ #13
+ #13
+ sub + ' ' + GetSubName + brc + ' { # È ÷òî ýòî çà ïðîöåäóðà?'
+ #13
+ #13
+ GetSubTemplate
+ #13
+ '}'
+ #13
+ #13
;
SynEdit.CaretY := 4;
StatusLine.Panels [2].Text := 'Sub ' + GetSubName + ' created.';
end;
ActiveControl := SynEdit;
LastLoadTime := FileDateToDateTime (FileAge (currentFile));
LastSubName := GetSubName;
if (ListBoxSubs.Items.IndexOf (LastSubName) < 0) and (pos('<none>', LastSubName) = 0) then begin
ListBoxSubs.Items.Add (LastSubName);
ListBoxSubs.ItemIndex := ListBoxSubs.Items.IndexOf (LastSubName);
end;
end;
function TEditForm.GetTypeName: string;
begin
Result := ListBoxTypes.Items [ListBoxTypes.ItemIndex];
end;
function TEditForm.GetRoleName: string;
begin
Result := ListBoxRoles.Items [ListBoxRoles.ItemIndex];
end;
function TEditForm.GetActionName: string;
begin
Result := ListBoxActions.Items [ListBoxActions.ItemIndex];
end;
function TEditForm.GetSubName: string;
begin
if RadioButtonSelect.Checked then Result := 'select';
if RadioButtonGetItem.Checked then Result := 'get_item_of';
if RadioButtonDo.Checked then Result := 'do_' + GetActionName;
if RadioButtonValidate.Checked then Result := 'validate_' + GetActionName;
if RadioButtonDraw.Checked then Result := 'draw';
if RadioButtonDrawItem.Checked then Result := 'draw_item_of';
Result := Result + '_' + GetTypeName;
if ListBoxRoles.ItemIndex > 0 then Result := Result + '_for_' + GetRoleName;
end;
function TEditForm.GetFileName: string;
begin
Result := path + '\';
if RadioButtonDraw.Checked or RadioButtonDrawItem.Checked
then Result := Result + 'Presentation'
else Result := Result + 'Content';
Result := Result + '\' + GetTypeName + '.' + ext;
end;
procedure TEditForm.RefreshRoles;
var
F: TextFile;
s: string;
i, j: integer;
begin
ListBoxRoles.Items.Clear;
ListBoxRoles.Items.Add ('<everybody>');
ListBoxRoles.ItemIndex := 0;
AssignFile (F, path + '\Content\menu.' + ext);
Reset (F);
while not EOF (F) do begin
Readln (F, s);
i := pos ('_menu_for_', s);
if i = 0 then Continue;
inc (i, 10);
j := i;
while (j < length (s)) and (s [j] in ['a'..'z', '0'..'9', '_']) do Inc (j);
ListBoxRoles.Items.Add (copy (s, i, j - i));
end;
CloseFile (F);
end;
procedure TEditForm.RefreshTypes;
var
sr: TSearchRec;
s: string;
begin
ListBoxTypes.Items.Clear;
if FindFirst(path + '\Content\*.' + ext, 0, sr) = 0 then begin
repeat
s := copy (sr.Name, 1, pos ('.' + ext, sr.Name) - 1);
if (length(EditFilter.Text) > 0) and (pos(EditFilter.Text, s) = 0) then continue;
ListBoxTypes.Items.Add (s)
until FindNext (sr) <> 0;
FindClose (sr);
end;
end;
procedure TEditForm.Init;
var
i: integer;
lib_path: string;
begin
if is_php then ext := 'php' else ext := 'pm';
if is_php then sub := 'function' else sub := 'sub';
if is_php then brc := ' ($data)' else brc := '';
if is_php then synedit.Highlighter := SynPHPSyn;
path := _path;
StatusLine := _StatusLine;
currentFile := '';
SetDirty (false);
RefreshTypes;
RefreshRoles;
WindowState := wsMaximized;
Application.CreateForm (TSearchReplaceForm, SearchReplaceForm);
SynSearchOptions := [];
i := pos ('\lib\_', path);
if i > 0 then appname := copy (path, i + 6, 255)
else begin
appname := path;
i := pos ('\lib', appname);
appname := copy (appname, 1, i - 1);
i := length (appname);
while (i > 0) and (appname [i] <> '\') do dec (i);
delete (appname, 1, i);
end;
appname := UpperCase (appname);
// if appname [1] = '_' then delete (appname, 1, 1);
Application.MainForm.Caption := appname;
Application.Title := appname;
ScmName := '';
i := pos ('\lib', path);
lib_path := copy (path, 0, i - 1);
if DirectoryExists (lib_path + '\.svn') then ScmName := 'TortoiseSVN';
if DirectoryExists (lib_path + '\.git') then ScmName := 'TortoiseGit';
ReadSettings;
end;
procedure TEditForm.ListBoxTypesDblClick(Sender: TObject);
begin
RadioButtonDo.Enabled := false;
RadioButtonValidate.Enabled := false;
RadioButtonSelect.Enabled := true;
RadioButtonGetItem.Enabled := true;
if RadioButtonDo.Checked then RadioButtonSelect.Checked := true;
if RadioButtonValidate.Checked then RadioButtonGetItem.Checked := true;
LoadCurrentSub;
end;
procedure TEditForm.ListBoxTypesKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then LoadCurrentSub;
end;
procedure TEditForm.ListBoxRolesDblClick(Sender: TObject);
begin
LoadCurrentSub;
end;
procedure TEditForm.ListBoxRolesKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then LoadCurrentSub;
end;
procedure TEditForm.RadioButtonSelectClick(Sender: TObject);
begin
LoadCurrentSub;
end;
procedure TEditForm.RadioButtonGetItemClick(Sender: TObject);
begin
LoadCurrentSub;
end;
procedure TEditForm.RadioButtonDrawClick(Sender: TObject);
begin
LoadCurrentSub;
end;
procedure TEditForm.RadioButtonDrawItemClick(Sender: TObject);
begin
LoadCurrentSub;
end;
procedure TEditForm.SynEditChange(Sender: TObject);
begin
SetDirty (true);
StatusLine.Panels [2].Text := '';
end;
procedure TEditForm.FormClose (Sender: TObject; var Action: TCloseAction);
begin
if dirty and yes ('Save changes', 'File ' + currentFile + ' is changed. Save it?') then SaveFile;
Action := caFree;
end;
procedure TEditForm.GoToAction (action: string; validate:boolean = false);
begin
RadioButtonDo.Enabled := true;
RadioButtonValidate.Enabled := true;
RadioButtonSelect.Enabled := false;
RadioButtonGetItem.Enabled := false;
if validate then RadioButtonValidate.Checked := true else RadioButtonDo.Checked := true;
if ListBoxActions.Items.IndexOf (action) < 0 then ListBoxActions.Items.Add (action);
ListBoxActions.ItemIndex := ListBoxActions.Items.IndexOf (action);
LoadCurrentSub;
end;
function DigitToHex(Digit: Integer): Char;
begin
case Digit of
0..9: Result := Chr(Digit + Ord('0'));
10..15: Result := Chr(Digit - 10 + Ord('A'));
else
Result := '0';
end;
end; // DigitToHex
function URLEncode(const S: string): string;
var
i, idx, len: Integer;
begin
len := 0;
for i := 1 to Length(S) do
if ((S[i] >= '0') and (S[i] <= '9')) or
((S[i] >= 'A') and (S[i] <= 'Z')) or
((S[i] >= 'a') and (S[i] <= 'z')) or (S[i] = ' ') or
(S[i] = '_') or (S[i] = '*') or (S[i] = '-') or (S[i] = '.') then
len := len + 1
else
len := len + 3;
SetLength(Result, len);
idx := 1;
for i := 1 to Length(S) do
if S[i] = ' ' then
begin
Result[idx] := '+';
idx := idx + 1;
end
else if ((S[i] >= '0') and (S[i] <= '9')) or
((S[i] >= 'A') and (S[i] <= 'Z')) or
((S[i] >= 'a') and (S[i] <= 'z')) or
(S[i] = '_') or (S[i] = '*') or (S[i] = '-') or (S[i] = '.') then
begin
Result[idx] := S[i];
idx := idx + 1;
end
else
begin
Result[idx] := '%';
Result[idx + 1] := DigitToHex(Ord(S[i]) div 16);
Result[idx + 2] := DigitToHex(Ord(S[i]) mod 16);
idx := idx + 3;
end;
end; // URLEncode
function URLDecode(const S: string): string;
var
i, idx, len, n_coded: Integer;
function WebHexToInt(HexChar: Char): Integer;
begin
if HexChar < '0' then
Result := Ord(HexChar) + 256 - Ord('0')
else if HexChar <= Chr(Ord('A') - 1) then
Result := Ord(HexChar) - Ord('0')
else if HexChar <= Chr(Ord('a') - 1) then
Result := Ord(HexChar) - Ord('A') + 10
else
Result := Ord(HexChar) - Ord('a') + 10;
end;
begin
len := 0;
n_coded := 0;
for i := 1 to Length(S) do
if n_coded >= 1 then
begin
n_coded := n_coded + 1;
if n_coded >= 3 then
n_coded := 0;
end
else
begin
len := len + 1;
if S[i] = '%' then
n_coded := 1;
end;
SetLength(Result, len);
idx := 0;
n_coded := 0;
for i := 1 to Length(S) do
if n_coded >= 1 then
begin
n_coded := n_coded + 1;
if n_coded >= 3 then
begin
Result[idx] := Chr((WebHexToInt(S[i - 1]) * 16 +
WebHexToInt(S[i])) mod 256);
n_coded := 0;
end;
end
else
begin
idx := idx + 1;
if S[i] = '%' then
n_coded := 1;
if S[i] = '+' then
Result[idx] := ' '
else
Result[idx] := S[i];
end;
end; // URLDecode
procedure TEditForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var
s: string;
app_path, params: string;
i: integer;
// ie: variant;
frame_name: olevariant;
Winds: IShellWindows;
IEWB: IWebBrowser2;
Doc: IHtmlDocument2;
frames: IHTMLFramesCollection2;
window: IHTMLWindow2;
// Location: IHTMLLocation;
url: string;
frame_dispatch: IDispatch;
_type: string;
_id: string;
begin
if Shift = [ssCtrl, ssAlt, ssShift] then begin
if ConfigForm.ssh_address <> '' then begin
case Key of
ord ('C'), ord ('M'), ord ('S'), ord ('B'): begin
params := '-load ' + copy (ConfigForm.ssh_address, 1, pos(':', ConfigForm.ssh_address) - 1);
ShellExecute (self.Handle, 'open', 'c:\program files\putty\putty.exe', pchar (params), '', SW_SHOWNORMAL);
end;
else exit;
end;
exit;
end;
if ScmName = '' then begin
Application.MessageBox ('Version control tool not detected, sorry', 'Error', mb_ok);
exit;
end;
if TortoiseSVNPath = '' then begin
Application.MessageBox (PChar(ScmName + ' is not installed, sorry'), 'Error', mb_ok);
exit;
end;
app_path := self.path + '\';
i := pos ('\lib\', app_path);
app_path := copy (app_path, 1, i - 1);
case Key of
ord ('C'): params := '/command:commit /path:"' + app_path + '" /notempfile';
ord ('M'): params := '/command:merge /path:"' + app_path + '" /notempfile';
ord ('S'): params := '/command:switch /path:"' + app_path + '" /notempfile';
ord ('B'):
if ScmName = 'TortoiseGit' then begin
params := '/command:branch /path:"' + app_path + '" /notempfile';
end
else begin
params := '/command:copy /path:"' + app_path + '" /notempfile';
end;
ord ('U'):
if ScmName = 'TortoiseGit' then begin
params := '/command:pull /path:"' + app_path + '" /notempfile';
end
else begin
params := '/command:update /path:"' + app_path + '" /notempfile /closeonend:3';
end;
else exit;
end;
ShellExecute (self.Handle, 'open', pchar (TortoiseSVNPath), pchar (params), pchar (app_path), SW_SHOWNORMAL);
end;
if (Key = ord ('S')) and (Shift = [ssCtrl]) then SaveFile;
if Shift = [] then case Key of
VK_F2: begin
try
Winds:=CoShellWindows.Create;
for i:=0 to Winds.Count-1 do
if (Winds.Item(i) as IWEbBrowser2).Document <> nil then
begin
IEWB:=Winds.Item (i) as IWEbBrowser2;
if IEWB.Document.QueryInterface(IhtmlDocument2, Doc)= S_OK
then begin
frames := Doc.frames;
frame_name := '_body_iframe';
frame_dispatch := frames.Item (frame_name);
window := frame_dispatch as IHTMLWindow2;
doc := window.document;
url := Doc.url;
_type := copy (url, pos ('&type=', url) + 6, length (url) - pos ('&type=', url) - 6);
_type := copy (_type, 1, pos ('&', _type) - 1);
_id := '';
if pos ('&id=', url) > 0 then begin
_id := copy (url, pos ('&id=', url) + 4, length (url) - pos ('&id=', url) - 4);
_id := copy (_id, 1, pos ('&', _id) - 1);
end;
ListBoxTypes.ItemIndex := ListBoxTypes.Items.IndexOf (_type);
if length (_id) > 0
then begin RadioButtonGetItem.Checked := true end
else begin RadioButtonSelect.Checked := true end;
LoadCurrentSub;
end;
end;
except
Application.MessageBox ('Can''t find the right IE window, sorry', 'Error', mb_ok + mb_iconerror);
end;
end;
VK_F1: begin
s := SynEdit.SelText;
if s = '' then s := 'StEludio';
ShellExecute (self.Handle, 'open', pchar ('http://eludia.ru/wiki/index.php/' + URLEncode(s)), nil, nil, SW_SHOWNORMAL);
end;
VK_F6: Application.MainForm.Next;
VK_F8: ActiveControl := ListBoxTypes;
VK_F9: ActiveControl := ListBoxRoles;
VK_F11: ActiveControl := ListBoxActions;
VK_F12: ActiveControl := ListBoxSubs;
VK_F5: begin
if Application.MainForm.WindowState = wsMaximized
then begin
Application.MainForm.WindowState := wsNormal;
Panel3.Width := 100;
end
else begin
Application.MainForm.WindowState := wsMaximized;
Panel3.Width := 1;
end;
StatusLine.Panels [2].Text := '';
end;
end;
if Shift = [ssAlt] then case Key of
ord ('S'): begin // select_...
ListBoxActions.ItemIndex := 0;
RadioButtonSelect.Checked := true;
LoadCurrentSub;
end;
ord ('G'): begin // get_item_of_...
ListBoxActions.ItemIndex := 0;
RadioButtonGetItem.Checked := true;
LoadCurrentSub;
end;
ord ('W'): begin // draw_...
ListBoxActions.ItemIndex := 0;
RadioButtonDraw.Checked := true;
LoadCurrentSub;
end;
ord ('M'): begin // draw_item_...
ListBoxActions.ItemIndex := 0;
RadioButtonDrawItem.Checked := true;
LoadCurrentSub;
end;
ord ('C'): GoToAction ('create'); // do_create_...
ord ('U'): GoToAction ('update'); // do_update_...
ord ('D'): GoToAction ('delete'); // do_delete_...
ord ('A'): GoToAction ('add'); // do_add_...
ord ('P'): GoToAction ('print'); // do_print_...
end;
if Shift = [ssCtrl, ssAlt] then case Key of
ord ('C'): GoToAction ('create', true); // validate_create_...
ord ('U'): GoToAction ('update', true); // validate_update_...
ord ('D'): GoToAction ('delete', true); // validate_delete_...
ord ('A'): GoToAction ('add', true); // validate_add_...
ord ('S'): begin
FormSettings.LabeledEditFontSize.Text := inttostr (SynEdit.Font.Size);
FormSettings.LabeledEditTabSize.Text := inttostr (SynEdit.TabWidth);
FormSettings.CheckBoxBold.Checked := fsBold in SynEdit.Font.Style;
if FormSettings.ShowModal <> mrok then Exit;
ReadSettings;
end;
ord ('R'): begin
if ext = 'php' then begin
s := SynEdit.SelText;
s := StringReplace (s, '{', 'array (', [rfReplaceAll]);
s := StringReplace (s, '[', 'array (', [rfReplaceAll]);
s := StringReplace (s, '}', ')', [rfReplaceAll]);
s := StringReplace (s, ']', ')', [rfReplaceAll]);
SynEdit.SelText := s;
end;
end;
end;
if Shift = [ssCtrl] then case Key of
VK_F8: ActiveControl := EditFilter;
219, 221: begin
SynEdit.FindMatchingBracket;
end;
190: begin // comment selected
s := '#' + StringReplace (SynEdit.SelText, #13#10, #13#10'#', [rfReplaceAll]);
delete (s, length(s), 1);
SynEdit.SelText := s;
end;
188: begin // uncomment selected
s := StringReplace (SynEdit.SelText, #13#10'#', #13#10, [rfReplaceAll]);
delete (s, 1, 1);
SynEdit.SelText := s;
end;
ord ('I'): begin
if Formln.ShowModal = idok then begin
SynEdit.CaretY := strtoint(Formln.LabeledEdit1.Text);
SynEdit.EnsureCursorPosVisibleEx (true);
StatusLine.Panels [0].Text := 'Row: ' + inttostr (SynEdit.CaretY);
end;
end;
ord ('B'): if NewActionForm.ShowModal = mrok then begin
if ListBoxActions.Items.IndexOf (NewActionForm.Edit.Text) > -1
then begin
Application.MessageBox ('Duplicate action name!', 'Error', mb_ok + mb_iconerror);
Exit;
end
else begin
ListBoxActions.Items.Add (NewActionForm.Edit.Text);
ListBoxActions.ItemIndex := ListBoxActions.Items.IndexOf (NewActionForm.Edit.Text);
ListBoxActions.OnClick (nil);
ListBoxActions.OnDblClick (nil);
end;
end;
ord ('N'): if NewTypeForm.ShowModal = mrok then begin
if ListBoxTypes.Items.IndexOf (NewTypeForm.Edit.Text) > -1
then begin
Application.MessageBox ('Duplicate type name!', 'Error', mb_ok + mb_iconerror);
Exit;
end
else begin
ListBoxTypes.Items.Add (NewTypeForm.Edit.Text);
ListBoxTypes.ItemIndex := ListBoxTypes.Items.IndexOf (NewTypeForm.Edit.Text);
ListBoxActions.OnClick (nil);
ListBoxTypes.OnDblClick (nil);
end;
end;
ord ('F'): begin
SearchReplaceForm.CheckBoxReplace.Checked := false;
if length (SynEdit.SelText) > 0 then SearchReplaceForm.EditSearch.Text := SynEdit.SelText;