-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUEditorForm.pas
More file actions
6301 lines (5864 loc) · 168 KB
/
UEditorForm.pas
File metadata and controls
6301 lines (5864 loc) · 168 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
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 UEditorForm;
interface
uses
Windows,
Winapi.Messages,
Winapi.D2D1,
SynEditPrint,
SysUtils,
Classes,
Graphics,
Forms,
Controls,
StdCtrls,
Menus,
ComCtrls,
ExtCtrls,
System.ImageList,
Vcl.ToolWin,
Vcl.ImgList,
Vcl.BaseImageCollection,
Vcl.VirtualImageList,
Vcl.WinXCtrls,
SVGIconImageCollection,
TB2Item,
SpTBXItem,
SynEdit,
SynEditExport,
SynEditHighlighter,
SynEditMiscClasses,
USynEditEx,
UModel,
UBaseForm,
UJavaParser,
UParseThread;
// Application FFrameType:= 8
// JApplet FFrameType:= 7
// JDialog FFrameType:= 6
// JFrame FFrameType:= 5
// Applet FFrameType:= 4
// Dialog FFrameType:= 3
// Frame FFrameType:= 2
// Console FFrameType:= 1
const
CInsertBlink = 500;
EcWordLeft = 5; // Move cursor left one word
EcWordRight = 6; // Move cursor right one word
type
TLineInfo = (dlCurrentDebuggerLine, dlBreakpointLine, dlExecutableLine,
dlSearchLine);
TLineInfos = set of TLineInfo;
{ TFEditForm }
TFEditForm = class(TFForm)
PMain: TPanel;
TVFileStructure: TTreeView;
StatusBar: TStatusBar;
BottomPanel: TPanel;
DesignButton: TButton;
EditformToolbar: TToolBar;
TBClose: TToolButton;
TBExplorer: TToolButton;
TBBrowser: TToolButton;
TBDesignform: TToolButton;
TBStructure: TToolButton;
TBClassOpen: TToolButton;
TBMatchBracket: TToolButton;
TBSystemOutPrintln: TToolButton;
TBStructureIndent: TToolButton;
TBIfStatement: TToolButton;
TBIfElseStatement: TToolButton;
TBWhileStatement: TToolButton;
TBForStatement: TToolButton;
TBDoWhileStatement: TToolButton;
TBSwitchStatement: TToolButton;
TBTryStatement: TToolButton;
TBBlockStatement: TToolButton;
TBComment: TToolButton;
TBIndent: TToolButton;
TBUnindent: TToolButton;
TBWordWrap: TToolButton;
TBBreakpoint: TToolButton;
TBBreakpointsClear: TToolButton;
TBBookmark: TToolButton;
TBGotoBookmark: TToolButton;
TBParagraph: TToolButton;
TBNumbers: TToolButton;
TBZoomIn: TToolButton;
TBZoomOut: TToolButton;
TBValidate: TToolButton;
icEditor: TSVGIconImageCollection;
vilEditorToolbarLight: TVirtualImageList;
vilEditorToolbarDark: TVirtualImageList;
icContextMenu: TSVGIconImageCollection;
vilContextMenuLight: TVirtualImageList;
vilContextMenuDark: TVirtualImageList;
PopUpEditor: TSpTBXPopupMenu;
MISearchDeclaration: TSpTBXItem;
MIAPIHelp: TSpTBXItem;
MIClassOpen: TSpTBXItem;
MIClassEditor: TSpTBXItem;
MICreateStructogram: TSpTBXItem;
MILine0: TSpTBXSeparatorItem;
MIExecute: TSpTBXItem;
MIExecuteWithoutConsole: TSpTBXItem;
MIExecuteWithConsole: TSpTBXItem;
MILine5: TSpTBXSeparatorItem;
MIGit: TSpTBXSubmenuItem;
MIGitStatus: TSpTBXItem;
MIGitAdd: TSpTBXItem;
MIGitCommit: TSpTBXItem;
MIGitLog: TSpTBXItem;
MIGitLine1: TSpTBXSeparatorItem;
MIGitReset: TSpTBXItem;
MIGitCheckout: TSpTBXItem;
MIGitRemove: TSpTBXItem;
MIGitLine2: TSpTBXSeparatorItem;
MIGitRemote: TSpTBXItem;
MIGitFetch: TSpTBXItem;
MIGitPush: TSpTBXItem;
MIGitLine3: TSpTBXSeparatorItem;
MIGitGui: TSpTBXItem;
MIGitViewer: TSpTBXItem;
MIGitConsole: TSpTBXItem;
MIRenewImports: TSpTBXItem;
MICopyPath: TSpTBXItem;
MILine1: TSpTBXSeparatorItem;
MIUndo: TSpTBXItem;
MIRedo: TSpTBXItem;
MILine2: TSpTBXSeparatorItem;
MICut: TSpTBXItem;
MICopy: TSpTBXItem;
MIInsert: TSpTBXItem;
MILine3: TSpTBXSeparatorItem;
MIUnindent: TSpTBXItem;
MIIndent: TSpTBXItem;
MILine4: TSpTBXSeparatorItem;
MIFont: TSpTBXItem;
MIConfiguration: TSpTBXItem;
MIClose: TSpTBXItem;
vilBookmarksLight: TVirtualImageList;
vilBookmarksDark: TVirtualImageList;
MIAssistant: TSpTBXSubmenuItem;
mnAssistantCancel: TSpTBXItem;
mnAssistantOptimize: TSpTBXItem;
mnAssistantFixBugs: TSpTBXItem;
mnAssistantExplain: TSpTBXItem;
mnAssistanSuggest: TSpTBXItem;
SpTBXSeparatorItem1: TSpTBXSeparatorItem;
ActivityIndicator: TActivityIndicator;
icBookmarks: TSVGIconImageCollection;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormClose(Sender: TObject; var AAction: TCloseAction); override;
procedure EditorStatusChange(Sender: TObject; Changes: TSynStatusChanges);
procedure Enter(Sender: TObject); override;
procedure UpdateState; override;
procedure BreakpointGutterClick(Sender: TObject; Button: TMouseButton;
X, Y, Row, Line: Integer);
procedure MICutClick(Sender: TObject);
procedure MICopyClick(Sender: TObject);
procedure MIInsertClick(Sender: TObject);
procedure MIUnindentClick(Sender: TObject);
procedure MIIndentClick(Sender: TObject);
procedure MIUndoClick(Sender: TObject);
procedure MIRedoClick(Sender: TObject);
procedure EditorKeyPress(Sender: TObject; var Key: Char);
procedure EditorKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure MICloseClick(Sender: TObject);
procedure MIAPIHelpClick(Sender: TObject);
procedure EditorPaintTransient(Sender: TObject; ACanvas: TCanvas;
TransientType: TTransientType);
procedure SBParagraphClick(Sender: TObject);
procedure SBNumbersClick(Sender: TObject);
procedure SBMatchBracketClick(Sender: TObject);
procedure SBBookmarkClick(Sender: TObject);
procedure SBGotoBookmarkClick(Sender: TObject);
procedure SBStatementClick(Sender: TObject);
procedure SBIndentClick(Sender: TObject);
procedure SBUnindentClick(Sender: TObject);
procedure SBBreakpointClick(Sender: TObject);
procedure SBBreakpointsClearClick(Sender: TObject);
procedure SBCommentClick(Sender: TObject);
procedure SBDesignformClick(Sender: TObject);
procedure SBClassEditClick(Sender: TObject);
procedure SBClassOpenClick(Sender: TObject);
procedure SBBrowserClick(Sender: TObject);
procedure SBExplorerClick(Sender: TObject);
procedure SBCloseClick(Sender: TObject);
procedure SBStructureIndentClick(Sender: TObject);
procedure SBWordWrapClick(Sender: TObject);
procedure SBValidateClick(Sender: TObject);
procedure SBSystemOutPrintlnClick(Sender: TObject);
procedure SBZoomOutClick(Sender: TObject);
procedure SBZoomInClick(Sender: TObject);
procedure MIFontClick(Sender: TObject);
procedure WMNCButtonDBLClick(var Msg: TMessage); message WM_NCLBUTTONDBLCLK;
procedure MIExecuteClick(Sender: TObject);
procedure PopUpEditorPopup(Sender: TObject);
procedure MIExecuteWithoutConsoleClick(Sender: TObject);
procedure MIExecuteWithConsoleClick(Sender: TObject);
procedure MIRenewImportsClick(Sender: TObject);
procedure MICreateStructogramClick(Sender: TObject);
procedure MICopyPathClick(Sender: TObject);
procedure DoOnMouseOverToken(Sender: TObject; const Token: string;
TokenType: Integer; Caret, Posi: TPoint; Attri: TSynHighlighterAttributes;
var Highlight: Boolean);
procedure DoOnMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure DoOnBuildStructure(Sender: TObject);
procedure TVFileStructureChange(Sender: TObject; Node: TTreeNode);
procedure MIClassOpenClick(Sender: TObject);
procedure MIClassEditorClick(Sender: TObject);
procedure MISearchDeclarationClick(Sender: TObject);
procedure MIGitStatusClick(Sender: TObject);
procedure MIGitAddClick(Sender: TObject);
procedure MIGitCommitClick(Sender: TObject);
procedure MIGitGuiClick(Sender: TObject);
procedure MIGitRemoveClick(Sender: TObject);
procedure MIGitLogClick(Sender: TObject);
procedure MIGitResetClick(Sender: TObject);
procedure MIGitCheckoutClick(Sender: TObject);
procedure MIGitRemoteClick(Sender: TObject);
procedure MIGitFetchClick(Sender: TObject);
procedure MIGitPushClick(Sender: TObject);
procedure MIGitConsoleClick(Sender: TObject);
procedure MIGitViewerClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure MIConfigurationClick(Sender: TObject);
procedure DesignButtonClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure mnAssistanSuggestClick(Sender: TObject);
procedure mnAssistantExplainClick(Sender: TObject);
procedure mnAssistantFixBugsClick(Sender: TObject);
procedure mnAssistantOptimizeClick(Sender: TObject);
procedure mnAssistantCancelClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
FBookmark: Integer;
FBreakPointCount: Integer;
FMouseIsInBorderOfStructure: Boolean;
FMouseBorderOfStructure: Integer;
FMousePosition: TBufferCoord;
FModifiedStrs: array [Boolean] of string;
FInsertModeStrs: array [Boolean] of string;
FToolButtons: array [0 .. 29] of TToolButton;
FFrameType: Integer; // 1..8, look in UEditorForm
FCheckAgeEnabled: Boolean;
FDebuglineMark: TSynEditMark;
FEditor: TSynEditEx;
FEditorAge: TDateTime;
FEncoding: string;
FFileExtension: string;
FNeedsParsing: Boolean;
FNeedToSyncFileStructure: Boolean;
FIsJUnitTestClass: Boolean;
FLastToken: string;
FLineBreak: string;
FModel: TObjectModel;
FParameter: string;
FParser: TJavaParser;
FParseThread: TParseThread;
FStartOption: Integer;
FSynEditPrint: TSynEditPrint;
FHidden: Boolean;
procedure Translate;
procedure Statusline(Num: Integer; const Str: string);
procedure CalculateStatusline;
procedure SetNeedsParsing(Value: Boolean);
function GetJavaCodeAt(Caret: TPoint): string;
procedure CreateTooltip(Caret, Posi: TPoint; const Token: string);
function GetFrameType: Integer;
procedure SynEditDebugInfoPaintLines(RenderTarget: ID2D1RenderTarget;
ClipR: TRect; const FirstRow, LastRow: Integer;
var DoDefaultPainting: Boolean);
procedure SynEditGutterDebugInfoMouseCursor(Sender: TObject;
X, Y, Row, Line: Integer; var Cursor: TCursor);
procedure SynEditBookmarkPaintLines(RenderTarget: ID2D1RenderTarget;
ClipR: TRect; const FirstRow, LastRow: Integer;
var DoDefaultPainting: Boolean);
procedure BookmarkGutterClick(Sender: TObject; Button: TMouseButton;
X, Y, Row, Line: Integer);
procedure SynEditChange(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
procedure New(const FileName: string);
procedure Open(const FileName: string; State: string;
Hidden: Boolean = False);
procedure Save(WithBackup: Boolean); override;
procedure SaveIn(const Dir: string); override;
procedure SaveAs(const FileName: string);
function GetSaveAsName: string; override;
procedure SetHighlighter;
procedure SetToolButtons;
procedure PreparePrint;
procedure Print; override;
procedure PrintAll(AllPages: Boolean);
procedure Show;
procedure Hide;
procedure SetFont(AFont: TFont); override;
function GetFont: TFont; override;
procedure SetFontSize(Delta: Integer); override;
procedure SetOptions; override;
procedure SetDeleteBookmark(Xpos, YPos: Integer);
procedure Unindent;
procedure Indent;
procedure Search; override;
procedure SearchAgain; override;
procedure Replace; override;
procedure SystemOutPrintln;
procedure Matchbracket;
function GetIndent: string;
procedure PutText(Str: string; WithCursor: Boolean = True);
function CBSearchClassOrMethod(Stop: Boolean; Line: Integer): string;
function SourceContainsClass(const AClassname: string): Boolean;
procedure GotoLine(Line: Integer);
procedure CutToClipboard; override;
procedure CopyToClipboard; override;
procedure PasteFromClipboard; override;
procedure Undo; override;
procedure Redo; override;
procedure SetModified(AModified: Boolean); override;
function GetModified: Boolean; override;
procedure DoExport; override;
// Test-Menü
procedure ClearBreakpoints;
procedure SetBreakpoints;
function HasBreakpoints: Boolean;
function HasBreakpoint(Line: Integer): Boolean;
function IsExecutableLine(Line: Integer): Boolean;
procedure SetDebuglineMark(Line: Integer);
procedure DeleteDebuglineMark;
procedure DeleteBreakpoint(Str: string);
function GetBreakpointMark(Line: Integer): TSynEditMark;
function GetMarksBreakpoints: string;
procedure SetMarksBreakpoints(MarkBreakpoint: string);
procedure InsertBreakpointMark(Line: Integer);
procedure DeleteBreakpointAtLine(Line: Integer);
procedure InsertGotoCursorBreakpoint;
procedure InsertBreakpoint;
procedure HTMLforApplet(const AWidth, AHeight, CharSet, AClass: string);
function CurrentCol: Integer;
function CurrentRow: Integer;
procedure ExportToFile(const FileName: string;
Exporter: TSynCustomExporter);
procedure ExportToClipboard(AsHtml: Boolean; AsText: Boolean);
procedure ExportWithNumbers;
procedure ExportRTFNumbered;
procedure SynEditorReplaceText(Sender: TObject;
const ASearch, AReplace: string; Line, Column: Integer;
var AAction: TSynReplaceAction);
procedure SynEditorSpecialLineColors(Sender: TObject; Line: Integer;
var Special: Boolean; var Foreground, Background: TColor);
procedure SynEditGutterGetText(Sender: TObject; ALine: Integer;
var AText: string);
function GetLineInfos(ALine: Integer): TLineInfos;
procedure ParseSourcecodeWithThread(HasChanged: Boolean);
procedure ParseSourceCode(HasChanged: Boolean);
procedure CreateTVFileStructure;
procedure RunTests;
function GetWidthAndHeight: TPoint;
procedure ChangeWidthAndHeight(Width, Height: Integer);
procedure ReplaceWidthHeight(Width, Height: Integer);
function GetLNGStartAttributes: Integer;
function GetLNGEndAttributes: Integer;
function GetLNGStartComponents: Integer;
function GetLNGEndComponents: Integer;
function GetLNGStartEventMethods: Integer;
function GetLNGEndEventMethods: Integer;
function GetLNG(Num, ClassNumber: Integer): string;
procedure EnsureStartEnd(CorI: Integer = 1);
procedure InsertStartEnd;
function HasStartAndEnd(CorI: Integer): Boolean;
function GetLineNumberWith(const Str: string): Integer;
function GetLineNumberWithFrom(From: Integer; const Str: string): Integer;
function GetLineNumberWithFromTill(From, Till: Integer;
const Str: string): Integer;
function GetLineNumberWithWord(const Str: string): Integer;
function GetLineNumberWithWordFrom(From: Integer;
const Str: string): Integer;
function GetLineNumberWithStartsWordFrom(From: Integer;
const Str: string): Integer;
function GetSource(Lines, LineE: Integer): string;
function GetLine(Line: Integer): string;
function ContainsWord(const Key: string; Line: Integer): Boolean;
procedure ReplaceLine(const Str1, Str2: string);
procedure ReplaceLineWith(Line: Integer; const Str: string);
procedure ReplaceLineInLine(Line: Integer; const Old, ANew: string);
procedure ReplaceText(const Str1, Str2: string; All: Boolean);
procedure ReplaceTextWithRegex(const Reg, Str: string; All: Boolean;
From: Integer = -1; Till: Integer = -1);
procedure ReplaceWord(const Str1, Str2: string; All: Boolean);
procedure ReplaceComponentname(const Str1, Str2: string; Events: string);
procedure ReplaceAttributAt(const AtLine, Key, Str: string);
procedure ReplaceAttribute(const Key, Str: string);
procedure ReplaceMethod(var Method: TOperation; const New: string);
procedure SetAttributValue(const Container, Key, Str: string;
After: Integer);
procedure ChangeAttributValue(const Key, Str: string); overload; // Swing
procedure ChangeAttributValue(const Container, Key, Str: string); overload;
// IsFX
function HasComponent(const Key: string; Line: Integer): Boolean;
procedure InsertAttributValue(const Destination, Str: string;
After: Integer);
procedure InsertLinesAt(Line: Integer; Str: string); overload;
procedure InsertLinesAt(const AtLine, Str: string); overload;
procedure InsertAttributAfter(const AtLine, Attribute: string);
procedure InsertAttribute(ClassNumber: Integer; const Str: string);
overload;
procedure InsertAttribute(const Container, AIndent, Variable: string;
IsFX: Boolean); overload;
procedure InsertAttribute(const Container, Variable: string;
IsFX: Boolean); overload;
procedure InsertComponent(const Str: string);
procedure InsertProcedure(const AProcedure: string); overload;
procedure InsertProcedure(ClassNumber: Integer;
const AProcedure: string); overload;
procedure InsertListener(const Component, Listener: string);
procedure InsertConstructor(ClassNumber: Integer; const AProcedure: string);
procedure InsertImport(const Package: string);
procedure DeleteAttribute(const Str: string);
function DeleteAttributeValue(const Str: string): Boolean;
procedure DeleteComponentValue(const Str: string);
procedure DeleteAttributeValues(const Str: string);
procedure DeleteEmptyLines(Line: Integer);
procedure DeleteLine(Line: Integer);
procedure DeleteBlock(StartLine, EndLine: Integer);
procedure DeleteComponent(const Component: string);
procedure DeleteComponentDefault(Control: TControl);
procedure DeleteComponentTotal(ClassNumber: Integer;
const Component, Typ: string);
procedure DeleteMethod(const Method: string;
SourcecodeCheck: Boolean = True); overload;
procedure DeleteMethod(Method: TOperation); overload;
procedure DeleteEventMethod(Method: string);
procedure DeleteListener(const Listener: string);
procedure DeleteFXListener(Listener: string);
procedure DeleteLambdaListener(Listener: string);
procedure DeleteOldAddNewMethods(OldMethods, NewMethods: TStringList);
procedure DeleteFXOldAddNewMethods(OldMethods, NewMethods: TStringList);
procedure DeleteTryCatch(const Key: string);
procedure MoveBlock(From, Till, Dest, DestTill: Integer;
const Blanklines: string);
function GetBlock(From, Lines: Integer): string;
procedure ToForeground(Control: TControl);
procedure ToBackground(Control: TControl);
procedure Go_To(const Str: string);
function GetClassAttribut(const AClass, AAttribute: string): string;
function HasText(const Str: string): Boolean;
function HasWord(const Str: string): Boolean;
function HasEventProcedureInModel(const AMethodname: string): Boolean;
function HasMainInModel: Boolean;
function IsJava: Boolean;
function IsPascal: Boolean;
function IsHTML: Boolean;
function IsCSS: Boolean;
function IsHTMLApplet: Boolean;
function GetFormType: string; override;
function GetState: string; override;
procedure SetState(var Str: string); override;
function EncodingAsString(const AEncoding: string): string;
function LinebreakAsString: string;
function LinebreakAsCtrls(const Str: string): string;
function GetEncodingAsType: TEncoding;
procedure SetEncoding(AEncoding: string);
procedure AutomatedCompleteImports;
procedure SetNewActionEventFormat;
procedure CollectClasses(StringList: TStringList); override;
function GetPackage: string;
procedure CheckAge;
procedure AddShortcutsToHints;
function GetAllPathnames: TStringList; override;
function GetAllClassnames: TStringList; override;
function ClassnameDifferentFromAncestors(const AClassname: string): Boolean;
procedure InitShowCompileErrors;
procedure SetErrorMark(Line, Column: Integer);
procedure UnderlineCompileErrors;
procedure ClearCompilerErrorMarks;
procedure ClearMarks;
procedure TerminateThread(Sender: TObject);
procedure ChangeStyle; override;
procedure RemoveShortCutFromEditor(ShortCut: Integer);
procedure ReplaceShortCutFromEditor(ShortCut, ShortCut2: Integer);
procedure EditShortCuts;
procedure CollapseGUICreation;
procedure DoOnIdle;
procedure SyncFileStructure;
function MakeUpperEvents(Events: string): string;
procedure SetFXBackgroundAsString(const Container, AName, AColor: string);
procedure DPIChanged; override;
function CountClassOrInterface: Integer;
procedure SetActivityIndicator(TurnOn: Boolean; const Hint: string = '';
OnClick: TNotifyEvent = nil);
procedure ShowAssistantError(const Msg: string);
function IsApplet: Boolean;
function IsAWT: Boolean;
function FrameTypToString: string;
property CheckAgeEnabled: Boolean read FCheckAgeEnabled
write FCheckAgeEnabled;
property DebuglineMark: TSynEditMark read FDebuglineMark;
property Editor: TSynEditEx read FEditor;
property EditorAge: TDateTime read FEditorAge write FEditorAge;
property Encoding: string read FEncoding;
property FileExtension: string read FFileExtension;
property IsJUnitTestClass: Boolean read FIsJUnitTestClass;
property NeedsParsing: Boolean read FNeedsParsing write SetNeedsParsing;
property FrameType: Integer read GetFrameType write FFrameType;
property LastToken: string read FLastToken write FLastToken;
property LineBreak: string read FLineBreak;
property Model: TObjectModel read FModel;
property Parameter: string read FParameter write FParameter;
property Parser: TJavaParser read FParser write FParser;
property ParseThread: TParseThread read FParseThread;
property SynEditPrint: TSynEditPrint read FSynEditPrint;
end;
implementation
{$R *.dfm}
uses
Printers,
Dialogs,
IOUtils,
Types,
UITypes,
Clipbrd,
Math,
StrUtils,
RegularExpressions,
JvGnugettext,
SynExportRTF,
SynExportHTML,
SynEditPrintTypes,
SynEditTypes,
SynHighlighterJava,
SynDWrite,
UJava,
UGUIDesigner,
UJavaCommands,
UUtils,
UConfiguration,
UTree,
UModelEntity,
UFileProvider,
UMessages,
UGUIForm,
UCodeCompletion,
UDlgConfirmReplace,
UUMLForm,
UStringRessources,
UDebugger,
UFileStructure,
UFXComponents,
UGit,
UJUnitTest,
USequenceForm,
UJavaScanner,
UTooltip,
UObjectInspector,
UJEComponents,
UTemplates,
ULLMSupport;
const
EcMatchBracket = 250; // Go to matching bracket
EcBlockIndent = 610; // Indent selection
EcBlockUnindent = 611; // Unindent selection
NoBreakpointImageIndex = 14;
BreakpointImageIndex = 13;
ErrorMarkIndex = 10;
StopInAt = True;
var
LNGs: array [1 .. 6] of string;
{ --- TFEditForm --------------------------------------------------------------- }
{ Gutterparts
MarksPart
LineNumberPart
ChangesPart
SeparatorPart
CodeFoldPart
LineOverviewPart
Gutter.LeftOffset
}
constructor TFEditForm.Create(AOwner: TComponent);
begin
inherited;
FormTag := 1;
end;
procedure TFEditForm.FormCreate(Sender: TObject);
begin
TranslateComponent(Self);
FEditor := TSynEditEx.Create(Self);
with FEditor do
begin
MaxUndo := 300;
TabWidth := 2;
WantTabs := True;
PopupMenu := PopUpEditor;
BookMarkOptions.BookmarkImages := vilBookmarksLight;
Font.Assign(FConfiguration.EditFont);
Font.Quality:= fqClearTypeNatural;
if not FConfiguration.ShowControlFlowSymbols then
DisplayFlowControl.Enabled := False;
Options := [eoAutoIndent, eoSmartTabs, eoTabIndent,
eoTabsToSpaces, eoSmartTabDelete, eoGroupUndo, eoDropFiles, eoKeepCaretX,
eoBracketsHighlight, eoAccessibility, eoCompleteBrackets,
eoCompleteQuotes, eoEnhanceHomeKey];
if FConfiguration.ShowLigatures then
Options:= Options + [eoShowLigatures];
ScrollOptions := [eoDisableScrollArrows, eoScrollPastEol, eoShowScrollHint];
Gutter.AutoSize := True;
Gutter.BorderStyle := gbsNone;
Gutter.DigitCount := 1;
Gutter.Font.Assign(FConfiguration.Font);
Gutter.Font.Height := FEditor.Font.Height + 2;
Gutter.Font.Quality := fqClearTypeNatural;
Gutter.BorderStyle := gbsNone;
//Gutter.Gradient := True; // ToDo as option
//Gutter.GradientSteps := 30;
Gutter.ShowLineNumbers := FConfiguration.LineNumbering;
Gutter.TrackChanges.Width := 2;
Gutter.TrackChanges.Visible := True;
FJava.ThemeEditorGutter(Gutter);
var
Band := TSynGutterBand(Gutter.Bands.Insert(1));
Band.Kind := gbkCustom;
Band.Width := 17;
Band.OnPaintLines := SynEditDebugInfoPaintLines;
Band.OnClick := BreakpointGutterClick;
Band.OnMouseCursor := SynEditGutterDebugInfoMouseCursor;
Band := Gutter.Bands[0];
Band.Width := 16;
Band.OnPaintLines := SynEditBookmarkPaintLines;
Band.OnClick := BookmarkGutterClick;
Band.OnMouseCursor := SynEditGutterDebugInfoMouseCursor;
IndentGuides.Style := igsDotted;
SelectedColor.Background := clSkyBlue;
UseCodeFolding := True;
WantTabs := True;
WordWrapGlyph.Visible := True;
SearchEngine := FJava.SynEditSearch;
Indent := FConfiguration.Indent;
StructureColorIntensity := FConfiguration.StructureColorIntensity;
SetCaretBlinkTime(CInsertBlink);
ScrollbarAnnotations.SetDefaultAnnotations;
OnBuildStructure := DoOnBuildStructure;
OnGutterGetText := SynEditGutterGetText;
OnSpecialLineColors := SynEditorSpecialLineColors;
OnKeyUp := EditorKeyUp;
OnKeyPress := EditorKeyPress;
OnChange := SynEditChange;
OnStatusChange := EditorStatusChange;
OnReplaceText := SynEditorReplaceText;
OnMouseOverToken := DoOnMouseOverToken;
OnMouseDown := DoOnMouseDown;
OnDropFiles := FJava.DropFiles;
if FConfiguration.EightyColumnLine then
RightEdge := 80
else
RightEdge := 0;
end;
FEditor.Parent := PMain;
FEditor.Align := alClient;
ActivityIndicator.Parent := FEditor;
EditformToolbar.Visible := FConfiguration.VisToolbars[2];
FEncoding := FConfiguration.GetEncoding;
FCheckAgeEnabled := FConfiguration.CheckAge;
FNeedsParsing := False;
FBookmark := 0;
FBreakPointCount := 0;
FEditorAge := 0;
FModel := TObjectModel.Create;
Partner := nil;
FParser := nil;
FLineBreak := #13#10;
FFrameType := 0;
FHidden := False;
CalculateStatusline;
EditorStatusChange(Sender, [scAll]);
OnMouseActivate := FormMouseActivate;
SetOptions;
ToMainPanel;
FToolButtons[0] := TBClose;
FToolButtons[1] := TBExplorer;
FToolButtons[2] := TBBrowser;
FToolButtons[3] := TBDesignform;
FToolButtons[4] := TBStructure;
FToolButtons[5] := TBClassOpen;
FToolButtons[6] := TBMatchBracket;
FToolButtons[7] := TBSystemOutPrintln;
FToolButtons[8] := TBStructureIndent;
FToolButtons[9] := TBIfStatement;
FToolButtons[10] := TBIfElseStatement;
FToolButtons[11] := TBWhileStatement;
FToolButtons[12] := TBForStatement;
FToolButtons[13] := TBDoWhileStatement;
FToolButtons[14] := TBSwitchStatement;
FToolButtons[15] := TBTryStatement;
FToolButtons[16] := TBBlockStatement;
FToolButtons[17] := TBComment;
FToolButtons[18] := TBIndent;
FToolButtons[19] := TBUnindent;
FToolButtons[20] := TBWordWrap;
FToolButtons[21] := TBBreakpoint;
FToolButtons[22] := TBBreakpointsClear;
FToolButtons[23] := TBBookmark;
FToolButtons[24] := TBGotoBookmark;
FToolButtons[25] := TBParagraph;
FToolButtons[26] := TBNumbers;
FToolButtons[27] := TBZoomOut;
FToolButtons[28] := TBZoomIn;
FToolButtons[29] := TBValidate;
Translate;
end;
procedure TFEditForm.SynEditGutterGetText(Sender: TObject; ALine: Integer;
var AText: string);
begin
if ALine = TSynEdit(Sender).CaretY then
Exit;
if ALine mod 10 <> 0 then
if ALine mod 5 <> 0 then
AText := '·'
else
AText := '-';
end;
procedure TFEditForm.AddShortcutsToHints;
begin
var
Str := ShortCutToText(FJava.MIIndent.ShortCut);
if Pos(Str, TBIndent.Hint) = 0 then
TBIndent.Hint := TBIndent.Hint + ' - ' + Str;
Str := ShortCutToText(FJava.MIUnindent.ShortCut);
if Pos(Str, TBUnindent.Hint) = 0 then
TBUnindent.Hint := TBUnindent.Hint + ' - ' + Str;
Str := ShortCutToText(FJava.MIStructuredIndent.ShortCut);
if Pos(Str, TBStructureIndent.Hint) = 0 then
TBStructureIndent.Hint := TBStructureIndent.Hint + ' - ' + Str;
Str := ShortCutToText(FJava.MICommentOnOff.ShortCut);
if Pos(Str, TBComment.Hint) = 0 then
TBComment.Hint := TBComment.Hint + ' - ' + Str;
Str := ShortCutToText(FJava.MISystemOutPrintln.ShortCut);
if Pos(Str, TBSystemOutPrintln.Hint) = 0 then
TBSystemOutPrintln.Hint := TBSystemOutPrintln.Hint + ' - ' + Str;
if Pos(Str, TBBookmark.Hint) = 0 then
TBBookmark.Hint := TBBookmark.Hint + ' - ' + Str;
if Pos(Str, TBGotoBookmark.Hint) = 0 then
TBGotoBookmark.Hint := TBGotoBookmark.Hint + ' - ' + Str;
end;
procedure TFEditForm.Translate;
begin
TBIfStatement.Hint := 'if ' + _(LNGStatement);
TBIfElseStatement.Hint := 'if-else ' + _(LNGStatement);
TBWhileStatement.Hint := 'while ' + _(LNGStatement);
TBForStatement.Hint := 'for ' + _(LNGStatement);
TBDoWhileStatement.Hint := 'do-while ' + _(LNGStatement);
TBSwitchStatement.Hint := 'switch ' + _(LNGStatement);
TBTryStatement.Hint := 'try ' + _(LNGStatement);
TBBlockStatement.Hint := 'block ' + _(LNGStatement);
LNGs[1] := _(LNGStartGUIVariables);
LNGs[2] := _(LNGEndGUIVariables);
LNGs[3] := _(LNGStartComponents);
LNGs[4] := _(LNGEndComponents);
LNGs[5] := _(LNGStartEventMethods);
LNGs[6] := _(LNGEndEventMethods);
FModifiedStrs[False] := '';
FModifiedStrs[True] := _(LNGModified);
FInsertModeStrs[False] := _(LNGModusOverwrite);
FInsertModeStrs[True] := _(LNGModusInsert);
CalculateStatusline;
if UUtils.Left(MIExecuteWithoutConsole.Caption, 4) <> ' ' then
begin
MIExecuteWithoutConsole.Caption := ' ' + MIExecuteWithoutConsole.Caption;
MIExecuteWithConsole.Caption := ' ' + MIExecuteWithConsole.Caption;
end;
end;
procedure TFEditForm.New(const FileName: string);
begin
Caption := FileName;
Pathname := FileName;
FFileExtension := LowerCase(ExtractFileExt(FileName));
DesignButton.Visible := FileExists(ChangeFileExt(FileName, '.jfm'));
SetHighlighter;
SetToolButtons;
if not FHidden then
begin
FJava.AddToWindowMenuAndTabBar(Number, OpenWindow, Self);
FJava.TabModified(Number, Modified);
Enter(Self); // must stay!
if Visible and FEditor.CanFocus then
FEditor.SetFocus;
end;
end;
procedure TFEditForm.Open(const FileName: string; State: string;
Hidden: Boolean = False);
begin
FHidden := Hidden;
try
FEditor.LockUndo;
try
FEditor.Lines.LoadFromFile(FileName);
// set UTF8 as default FEncoding
if (FEditor.Lines.Encoding <> TEncoding.UTF8) and
not IsWriteProtected(FileName) then
begin
var
WriteTime := TFile.GetLastWriteTime(FileName);
FEditor.Lines.SaveToFile(FileName, TEncoding.UTF8);
TFile.SetLastWriteTime(FileName, WriteTime);
FEditor.Lines.LoadFromFile(FileName, TEncoding.UTF8);
end;
FEncoding := EncodingAsString(FEditor.Lines.Encoding.EncodingName);
FLineBreak := FEditor.Lines.LineBreak;
FEditor.ReplaceTabs(FConfiguration.TabWidth);
finally
FEditor.UnlockUndo;
end;
if FEditor.NeedsWordWrap then
SBWordWrapClick(Self);
FileAge(FileName, FEditorAge);
New(FileName);
FEditor.ReadOnly := (Pos(FConfiguration.JavaCache, FileName) = 1) or
IsWriteProtected(FileName);
if FEditor.ReadOnly then
Caption := Caption + ' (' + _(LNGWriteProtected) + ')';
CalculateStatusline;
if IsJava then begin
CollapseGUICreation;
ParseSourceCode(True);
end;
SetState(State);
// ensure vertical scrollbar is visible
FEditor.UpdateScrollBars;
except
on e: Exception do
begin
ErrorMsg(e.Message);
FConfiguration.Log('TFEditForm.Open: ' + FileName, e);
end;
end;
end;
procedure TFEditForm.CollapseGUICreation;
var
Line: Integer;
Str, Name: string;
begin
if FConfiguration.GUICodeFolding and (GetFrameType > 1) then
begin
Name := ChangeFileExt(ExtractFileName(Pathname), '');
case FFrameType of
8:
Str := 'public void start(Stage';
7, 4:
Str := 'public void init()';
6, 5, 3, 2:
Str := 'public ' + Name + '(';
end;
for var I := 0 to Min(FEditor.AllFoldRanges.Count - 1, 2) do
begin
Line := FEditor.AllFoldRanges[I].FromLine;
if Pos(Str, FEditor.Lines[Line - 1]) > 0 then
FEditor.Collapse(I);
end;
end;
end;
procedure TFEditForm.DoOnIdle;
begin
if not FNeedsParsing then
SyncFileStructure;
end;
procedure TFEditForm.SyncFileStructure;
begin
if FNeedToSyncFileStructure and IsJava then
begin
FFileStructure.ShowEditorCodeElement;
FNeedToSyncFileStructure := False;
end;
end;
procedure TFEditForm.EnsureStartEnd(CorI: Integer = 1);
begin
if Assigned(FEditor) and not FEditor.ReadOnly and not HasStartAndEnd(CorI)
then
InsertStartEnd;
end;
function PointToDisplay(Posi: TPoint): TDisplayCoord;
begin
Result.Column := Posi.X;
Result.Row := Posi.Y;
end;
procedure TFEditForm.SynEditorReplaceText(Sender: TObject;
const ASearch, AReplace: string; Line, Column: Integer;
var AAction: TSynReplaceAction);
var
APos: TDisplayCoord;
EditRect: TRect;
begin
if ASearch = AReplace then
AAction := raSkip
else
begin
APos := DisplayCoord(Column, Line);
APos := PointToDisplay
(FEditor.ClientToScreen(FEditor.RowColumnToPixels(APos)));
EditRect := ClientRect;
EditRect.TopLeft := ClientToScreen(EditRect.TopLeft);
EditRect.BottomRight := ClientToScreen(EditRect.BottomRight);
with TFConfirmReplace.Create(FJava) do
begin
PrepareShow(EditRect, APos.Column, APos.Row,
APos.Row + FEditor.LineHeight, ASearch);
case ShowModal of
mrYes:
AAction := raReplace;
mrYesToAll:
AAction := raReplaceAll;
mrNo:
AAction := raSkip;
else
AAction := raCancel;
end;
Free;
end;
end;
end;
procedure TFEditForm.SetHighlighter;
begin
if FConfiguration.NoSyntaxHighlighting then
FEditor.Highlighter := nil
else
FEditor.Highlighter := FConfiguration.GetHighlighter(FFileExtension);
if FEditor.Highlighter = nil then
FEditor.StructureColoring := False
else
begin
FEditor.StructureColoring := FConfiguration.StructureColoring;
FEditor.UseCodeFolding := True;
end;
if FEditor.StructureColoring and IsJava then
FNeedsParsing := True;
end;
procedure TFEditForm.SetToolButtons;
begin
for var I := 0 to 29 do
FToolButtons[I].Visible := True;