-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEditor.pas
2470 lines (2338 loc) · 69.7 KB
/
Editor.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
(*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Initial Developer of this code is Mark Overmars.
* Portions created by John Hansen are Copyright (C) 2009-2013 John Hansen.
* All Rights Reserved.
*
*)
{$B-}
unit Editor;
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
interface
uses
{$IFDEF FPC}
LResources,
LMessages,
LCLType,
LCLIntf,
LCLProc,
SynEditMarks,
{$ENDIF}
Messages, Classes, Graphics, Controls, Forms,
StdCtrls, ComCtrls, Menus, ImgList, SynEdit, ExtCtrls, BricxccSynEdit,
SynEditHighlighter, SynEditRegexSearch, SynEditMiscClasses, SynEditSearch,
SynEditEx, SynEditKeyCmds, uOfficeComp;
type
TEditorForm = class(TForm)
TheErrors: TListBox;
ilBookmarkImages: TImageList;
splErrors: TSplitter;
procedure TheErrorsClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure TheErrorsMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
fFileName : string;
fHighlighter: TSynCustomHighlighter;
procedure UpdateModeOnStatusBar;
procedure UpdateModifiedOnStatusBar;
procedure UpdateStatusBar;
// procedure InsertOptionInfo;
procedure WMMDIActivate(var Message: TWMMDIActivate); message WM_MDIACTIVATE;
procedure SetFilename(const Value: string);
procedure OpenFileAtCursor;
procedure SwapIntfAndImpl;
procedure FindDeclaration(const aIdent : string);
procedure CreatePopupMenu;
procedure CreateTheEditor;
function GetPosition: integer;
function GetSource: string;
procedure SetPosition(const Value: integer);
protected
function MDI : Boolean;
procedure CreateParams(var Params: TCreateParams); override;
procedure HookCompProp;
procedure SetActiveHelpFile;
procedure SetCaption(const fname : string);
public
// menu and synedit components
TheEditor: TBricxccSynEdit;
pmnuEditor: TOfficePopupMenu;
mniFindDeclaration: TOfficeMenuItem;
N5: TOfficeMenuItem;
mniClosePage: TOfficeMenuItem;
mniOpenFileAtCursor: TOfficeMenuItem;
mnTopicSearch: TOfficeMenuItem;
N3: TOfficeMenuItem;
lmiEditUndo: TOfficeMenuItem;
lmiEditRedo: TOfficeMenuItem;
N2: TOfficeMenuItem;
lmiEditCut: TOfficeMenuItem;
lmiEditCopy: TOfficeMenuItem;
lmiEditPaste: TOfficeMenuItem;
lmiEditDelete: TOfficeMenuItem;
N1: TOfficeMenuItem;
lmiEditSelectAll: TOfficeMenuItem;
lmiCopySpecial: TOfficeMenuItem;
lmiCopyHTML: TOfficeMenuItem;
lmiCopyRTF: TOfficeMenuItem;
N4: TOfficeMenuItem;
mniToggleBookmarks: TOfficeMenuItem;
mniTBookmark0: TOfficeMenuItem;
mniTBookmark1: TOfficeMenuItem;
mniTBookmark2: TOfficeMenuItem;
mniTBookmark3: TOfficeMenuItem;
mniTBookmark4: TOfficeMenuItem;
mniTBookmark5: TOfficeMenuItem;
mniTBookmark6: TOfficeMenuItem;
mniTBookmark7: TOfficeMenuItem;
mniTBookmark8: TOfficeMenuItem;
mniTBookmark9: TOfficeMenuItem;
mniGotoBookmarks: TOfficeMenuItem;
mniGBookmark0: TOfficeMenuItem;
mniGBookmark1: TOfficeMenuItem;
mniGBookmark2: TOfficeMenuItem;
mniGBookmark3: TOfficeMenuItem;
mniGBookmark4: TOfficeMenuItem;
mniGBookmark5: TOfficeMenuItem;
mniGBookmark6: TOfficeMenuItem;
mniGBookmark7: TOfficeMenuItem;
mniGBookmark8: TOfficeMenuItem;
mniGBookmark9: TOfficeMenuItem;
N6: TOfficeMenuItem;
mniViewExplorer: TOfficeMenuItem;
mniToggleBreakpoint: TOfficeMenuItem;
public
// event handlers
procedure pmnuEditorPopup(Sender: TObject);
procedure lmiEditUndoClick(Sender: TObject);
procedure lmiEditRedoClick(Sender: TObject);
procedure lmiEditCutClick(Sender: TObject);
procedure lmiEditCopyClick(Sender: TObject);
procedure lmiEditDeleteClick(Sender: TObject);
procedure lmiEditSelectAllClick(Sender: TObject);
procedure lmiEditPasteClick(Sender: TObject);
procedure DoCopyRTF(Sender: TObject);
procedure DoCopyHTML(Sender: TObject);
procedure mniOpenFileAtCursorClick(Sender: TObject);
procedure mniClosePageClick(Sender: TObject);
procedure mniViewExplorerClick(Sender: TObject);
procedure mniFindDeclarationClick(Sender: TObject);
procedure mnTopicSearchClick(Sender: TObject);
procedure ToggleBookmark(Sender: TObject);
procedure GotoBookmark(Sender: TObject);
procedure mniToggleBreakpointClick(Sender: TObject);
procedure TheEditorKeyPress(Sender: TObject; var Key: Char);
procedure TheEditorKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure TheEditorReplaceText(Sender: TObject; const ASearch,
AReplace: String; Line, Column: Integer;
var Action: TSynReplaceAction);
procedure TheEditorStatusChange(Sender: TObject;
Changes: TSynStatusChanges);
procedure TheEditorGutterClick(Sender: TObject; X, Y, Line: Integer;
mark: TSynEditMark);
procedure TheEditorPlaceBookmark(Sender: TObject;
var Mark: TSynEditMark);
procedure TheEditorClearBookmark(Sender: TObject;
var Mark: TSynEditMark);
procedure TheEditorChange(Sender: TObject);
procedure TheEditorMouseOverToken(Sender: TObject; const Token: String;
TokenType: Integer; Attri: TSynHighlighterAttributes;
var Highlight: Boolean);
procedure TheEditorProcessCommand(Sender: TObject;
var Command: TSynEditorCommand; var AChar: Char; Data: Pointer);
procedure TheEditorDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure TheEditorDragDrop(Sender, Source: TObject; X, Y: Integer);
procedure TheEditorMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure TheEditorSpecialLineColors(Sender: TObject; Line: Integer;
var Special: Boolean; var FG, BG: TColor);
procedure TheEditorProcessUserCommand(Sender: TObject;
var Command: TSynEditorCommand; var AChar: Char; Data: Pointer);
procedure TheEditorPaintTransient(Sender: TObject; Canvas: TCanvas;
TransientType: TTransientType);
public
{File handling}
IsNew:boolean; // Whether it is a new file
procedure NewFile(fname:string); // Create a new file in the editor
procedure OpenFile(fname:string; lineNo : integer = -1; linePos : integer = -1); // Open an existing file
procedure SaveFile; // Saves the file
procedure SaveFileAs(fname:string);// Saves the file as fname
procedure InsertFile(fname:string);// Insert file at cursor
function OpenFileOnPath(const fname : string) : boolean;
{Editing}
function CanUndo: boolean; // Whether you can undo something
function CanRedo: boolean; // Whether you can redo something
function Selected: boolean; // Whether something is selected
function CanFind : boolean;
function CanFindNext : boolean;
function CanReplace : boolean;
function CanCut: Boolean;
function CanPaste: Boolean;
function CanFindDeclaration : Boolean;
procedure Undo;
procedure Redo;
procedure CutSel;
procedure CopySel;
procedure Paste;
procedure DeleteSel;
procedure SelectAll;
procedure GotoLine;
procedure ProcedureList;
procedure NextField;
procedure AddConstructString(constr:string; x : integer = -1; y :integer = -1);
// procedure AddConstruct(const aLang, numb : integer; x : integer = -1; y :integer = -1);
procedure SetSyntaxHighlighter;
procedure SetValuesFromPreferences;
procedure ExecFind;
procedure ExecFindNext;
procedure ExecFindPrev;
procedure ExecReplace;
procedure AddErrorMessage(const errMsg : string);
procedure ShowTheErrors;
procedure SelectLine(lineNo : integer; linePos : integer = -1);
function IsMaximized : Boolean;
procedure UpdatePositionOnStatusBar;
property Filename : string read fFilename write SetFilename;
property Highlighter : TSynCustomHighlighter read fHighlighter write fHighlighter;
property Source : string read GetSource;
property Position : integer read GetPosition write SetPosition;
end;
var
EditorForm: TEditorForm;
function HelpALink(keyword: string; bNQC : Boolean = True): Boolean;
implementation
{$IFNDEF FPC}
{$R *.DFM}
{$ENDIF}
uses
{$IFNDEF FPC}
Windows,
MainUnit,
{$ENDIF}
SysUtils, Dialogs, ClipBrd,
Preferences, GotoLine, ConstructUnit, dlgSearchText,
dlgReplaceText, dlgConfirmReplace, DTestPrintPreview, Translate,
CodeUnit, ExecProgram, brick_common, FakeSpirit, uCodeExplorer, uMacroForm,
GX_ProcedureList, SynEditTypes, uLegoSDKUtils, uParseCommon, uRICComp,
uMiscDefines, uNXTClasses, uNBCInterface, ParamUtils, uNXTConstants,
uPSDisassembly, uLocalizedStrings, uNBCCommon, rcx_constants, uEditorUtils,
uEditorExperts, uProgram, uNXTExplorer, uCompStatus, uGlobals, uBasicPrefs,
uHTMLHelp, uNXCHTMLTopics, uNQCHTMLTopics, uNBCHTMLTopics, uSPCHTMLTopics,
uPSComponent, uPSDebugger, uROPS, uCompTokens, uCompCommon;
function HelpALink(keyword: string; bNQC : Boolean): Boolean;
var
MacroStr: array[0..255] of Char;
const
MACRO_ARRAY : array[Boolean] of PChar =
(
'IE( KL('#96'%0:s'#39', 4), '#96'KL('#96'%0:s'#39', 1)'#39', '#96'IE( AL('#96'%0:s'#39', 4), '#96'AL('#96'%0:s'#39', 1)'#39', '#96'JK("", '#96'%0:s'#39')'#39' )'#39' )',
'IE( AL('#96'%0:s'#39', 4), '#96'AL('#96'%0:s'#39', 1)'#39', '#96'IE( KL('#96'%0:s'#39', 4), '#96'KL('#96'%0:s'#39', 1)'#39', '#96'JK("", '#96'%0:s'#39')'#39' )'#39' )'
);
begin
{$IFNDEF FPC}
if UseHTMLHelp then
begin
keyword := LookupHTMLTopic(keyword);
Result := Application.HelpCommand(HELP_COMMAND, Integer(PChar(keyword)));
end
else
begin
if FileIsMindScriptOrLASM then
begin
Result := Application.HelpCommand(HELP_KEY, Integer(PChar(keyword)));
end
else
begin
StrLFmt(MacroStr, SizeOf(MacroStr) - 1, MACRO_ARRAY[bNQC], [keyword]);
Result := Application.HelpCommand(HELP_COMMAND, Longint(@MacroStr));
end;
end;
{$ENDIF}
end;
{File Handling routines}
procedure TEditorForm.NewFile(fname:string);
begin
IsNew := True;
Filename := fname;
SetCaption(ExtractFileName(fname));
TheEditor.Modified := False;
if TheEditor.CanFocus then
TheEditor.SetFocus;
MainForm.actFileSave.Enabled := False;
SetSyntaxHighlighter;
UpdateStatusBar;
HookCompProp;
frmCodeExplorer.RefreshEntireTree;
end;
procedure TEditorForm.OpenFile(fname:string; lineNo : integer; linePos : integer);
var
ext : string;
D : TRXEDumper;
begin
if FileExists(fname) then
begin
ext := Lowercase(ExtractFileExt(fname));
if (ext = '.rxe') or (ext = '.sys') or (ext = '.rtm') then
begin
IsNew := False;
Filename := ChangeFileExt(fname, '.nbc');
SetCaption(ExtractFileName(Filename));
Application.ProcessMessages;
Screen.Cursor := crHourGlass;
try
D := TRXEDumper.Create;
try
if NXT2Firmware then
D.FirmwareVersion := MIN_FW_VER2X;
D.LoadFromFile(fname);
D.DumpRXE(TheEditor.Lines);
TheEditor.Modified := True;
finally
D.Free;
end;
finally
Screen.Cursor := crDefault;
end;
fname := Filename;
end
else if (ext = '.ric') then
begin
IsNew := False;
if RICDecompAsData then
Filename := ChangeFileExt(fname, '.h')
else
Filename := ChangeFileExt(fname, '.rs');
SetCaption(ExtractFileName(Filename));
Application.ProcessMessages;
Screen.Cursor := crHourGlass;
try
if RICDecompAsData then
TheEditor.Lines.Text := TRICComp.RICToDataArray(fname, RICDecompNameFormat, lnNXCHeader)
else
TheEditor.Lines.Text := TRICComp.RICToText(fname);
TheEditor.Modified := True;
finally
Screen.Cursor := crDefault;
end;
fname := Filename;
end
else
begin
IsNew := False;
Filename := fname;
SetCaption(ExtractFileName(fname));
TheEditor.Lines.LoadFromFile(fname);
TheEditor.ReadOnly := FileIsReadOnly(fname);
TheEditor.Modified := False;
MainForm.actFileSave.Enabled := False;
end;
if TheEditor.CanFocus then
TheEditor.SetFocus;
MainForm.LoadDesktop(fname);
SetSyntaxHighlighter;
UpdateStatusBar;
HookCompProp;
frmCodeExplorer.ProcessFile(fname, TheEditor.Lines.Text);
frmCodeExplorer.RefreshEntireTree;
if FileIsROPS(Highlighter) then
ce.Script.Assign(TheEditor.Lines);
SelectLine(lineNo, linePos);
end;
end;
procedure TEditorForm.SaveFile;
begin
SaveFileAs(Filename);
end;
procedure TEditorForm.SaveFileAs(fname:string);
var
backfname : string;
begin
Filename := fname;
IsNew := false;
SetCaption(ExtractFileName(fname));
if SaveBackup and FileExists(fname) then
begin
backfname := ChangeFileExt(fname,'.bak');
DeleteFile(backfname);
RenameFile(fname,backfname);
end;
TheEditor.Lines.SaveToFile(fname);
TheEditor.Modified := False;
MainForm.actFileSave.Enabled := False;
if AutoSaveDesktop then
MainForm.SaveDesktop(Filename);
SetSyntaxHighlighter;
HookCompProp;
end;
procedure TEditorForm.InsertFile(fname:string);
var
tmpSL : TStringlist;
begin
tmpSL := TStringList.Create;
try
tmpSL.LoadFromFile(fname);
TheEditor.SelText := tmpSL.Text;
finally
tmpSL.Free;
end;
end;
{Edit routines}
function TEditorForm.CanUndo : Boolean;
begin
Result := TheEditor.CanUndo;
end;
function TEditorForm.CanCut : Boolean;
begin
Result := not TheEditor.ReadOnly and Selected;
end;
function TEditorForm.CanPaste : Boolean;
begin
Result := TheEditor.CanPaste;
end;
function TEditorForm.Selected : Boolean;
begin
Result := TheEditor.SelAvail;
end;
procedure TEditorForm.Undo;
begin
TheEditor.Undo;
end;
procedure TEditorForm.Redo;
begin
TheEditor.Redo;
end;
procedure TEditorForm.CutSel;
begin
TheEditor.CutToClipboard;
end;
procedure TEditorForm.CopySel;
begin
if MultiFormatCopy then
begin
Clipboard.Open;
try
// put on the clipboard as plain text
Clipboard.AsText := TheEditor.SelText;
// put on the clipboard as HTML
MainForm.expHTML.ExportAsText := False;
MainForm.expHTML.ExportRange(TheEditor.Lines, TheEditor.BlockBegin, TheEditor.BlockEnd);
MainForm.expHTML.CopyToClipboard;
// put on the clipboard as RTF
MainForm.expRTF.ExportAsText := False;
MainForm.expRTF.ExportRange(TheEditor.Lines, TheEditor.BlockBegin, TheEditor.BlockEnd);
MainForm.expRTF.CopyToClipboard;
finally
Clipboard.Close;
end;
end
else
TheEditor.CopyToClipboard;
end;
procedure TEditorForm.Paste;
begin
TheEditor.PasteFromClipboard;
end;
procedure TEditorForm.DeleteSel;
begin
TheEditor.ClearSelection;
end;
procedure TEditorForm.SelectAll;
begin
TheEditor.SelectAll;
end;
procedure TEditorForm.GotoLine;
var
G : TGotoForm;
begin
G := TGotoForm.Create(nil);
try
G.MaxLine := GetLineNumber(TheEditor.Lines.Count);
G.TheLine := GetLineNumber(TheEditor.CaretY);
if G.ShowModal = mrOK then
begin
with TheEditor do begin
SetFocus;
CaretXY := Point(0, G.TheLine);
BlockBegin := CaretXY;
BlockEnd := BlockBegin;
EnsureCursorPosVisible;
end;
end;
finally
G.Free;
end;
end;
procedure TEditorForm.NextField;
begin
TheEditor.SelectDelimited;
end;
procedure TEditorForm.AddConstructString(constr:string; x, y : integer);
var
str:string;
i,j,tt,curposy,curposx:integer;
escaped,fieldexists:boolean;
p : TPoint;
begin
if TheEditor.ReadOnly then Exit;
if (x <> -1) and (y <> -1) then
begin
// drag and drop
p := TheEditor.PixelsToRowColumn(Point(X, Y));
// p.X := 0;
TheEditor.SetCaretAndSelection(p, p, p);
end;
if TheEditor.SelAvail then
tt := TheEditor.BlockBegin.x - 1
else
tt := TheEditor.CaretXY.x - 1; // make it a zero-based column number
fieldexists:=false;
escaped:=false;
str:='';
for i:=1 to Length(constr) do
begin
if escaped then
begin
if constr[i] = '\' then str := str + '\';
if constr[i] = '<' then tt := tt - TheEditor.TabWidth;
if constr[i] = '>' then tt := tt + TheEditor.TabWidth;
if constr[i] in ['=','<','>'] then
begin
str := str + #13#10;
for j:= 1 to tt do str := str + ' ';
end;
escaped := false;
end else begin
if constr[i] = '"' then fieldexists := true;
if constr[i] = '\' then
escaped := true
else
str:=str+constr[i];
end;
end;
MainForm.SetFocus;
TheEditor.SetFocus;
curposy := TheEditor.CaretXY.Y;
curposx := tt;
TheEditor.SelText := str;
if fieldexists then
begin
TheEditor.CaretXY := Point(curposx, curposy);
// TheEditor.CaretXY := Point(TheEditor.CaretXY.X, curposy);
NextField;
end;
end;
(*
procedure TEditorForm.AddConstruct(const aLang, numb : integer; x, y:integer);
begin
AddConstructString(templates[aLang][numb-1], x, y);
end;
*)
{Event Handlers}
procedure TEditorForm.TheErrorsClick(Sender: TObject);
var
i, p, q, lnumb, lpos, c : integer;
str, tmp : string;
bThisFile : boolean;
begin
if TheErrors.ItemIndex <> -1 then
TheErrors.Hint := TheErrors.Items[TheErrors.ItemIndex];
lnumb := -1;
lpos := -1;
for i := TheErrors.ItemIndex downto 0 do
begin
str := TheErrors.Items[i];
p := Pos('line ',str);
if p > 0 then
begin
p := p + 4;
q := Pos(', position ', str);
if q > 0 then
tmp := Copy(str, p, q-p)
else
tmp := Copy(str, p, 6); // up to 6 digit line numbers
Val(tmp, lnumb, c);
if q > 0 then
begin
tmp := str;
System.Delete(tmp, 1, q+10);
p := Pos(':', tmp);
if p > 0 then
System.Delete(tmp, p, MaxInt);
p := Pos(',', tmp);
if p > 0 then
System.Delete(tmp, p, MaxInt);
Val(tmp, lpos, c);
end;
break;
end;
if UseNBCCompiler(Highlighter) then
break;
end;
bThisFile := True;
if lnumb >= 0 then
begin
if ZeroStart and ShowLineNumbers then
inc(lnumb);
// if there is a filename on this line and it does not match
// the current filename then open that file in a new editor window at the
// specified line
i := Pos('file "', str);
if i > 0 then
begin
str := Copy(str, i+6, MaxInt);
i := Pos('":', str);
Delete(str, i, MaxInt);
bThisFile := AnsiUpperCase(str) = AnsiUpperCase(Filename);
end;
if bThisFile then
begin
SelectLine(lnumb, lpos);
end
else
begin
MainForm.OpenFile(str, lnumb);
end;
end;
if bThisFile then
TheEditor.SetFocus;
end;
procedure TEditorForm.TheEditorKeyPress(Sender: TObject; var Key: Char);
begin
{Ignore <Ctr><Alt> combinations when a macro was added}
if Key = Chr(27) then
GlobalAbort := True;
end;
procedure TEditorForm.TheEditorKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
ctrldown,altdown,shiftdown : boolean;
ch : char;
i : integer;
str,constr : string;
begin
ctrldown := (ssCtrl in Shift);
altdown := (ssAlt in Shift);
shiftdown := (ssShift in Shift);
{Handle <Ctr><Alt> Combinations as macro's}
{$IFNDEF FPC}
ch:=Char(MapVirtualKey(Key,2));
{$ELSE}
ch := #0;
{$ENDIF}
if MacrosOn and ctrldown and altdown and
(((ch>='A') and (ch<='Z')) or ((ch>='0') and (ch<='9'))) then
begin
str:='';
if ctrldown then str:=str+'<Ctrl>';
if altdown then str:=str+'<Alt>';
if shiftdown then str:=str+'<Shift>';
str:=str+ch;
for i:=1 to macronumb do
begin
if Pos(str,Macros[i]) = 1 then
begin
constr:=Copy(Macros[i],Length(str)+2,1000);
AddConstructString(constr);
Key:=0;
break;
end;
end;
end
else if ctrldown and (Key = $0D) then begin
OpenFileAtCursor;
end
else if ctrldown and shiftdown and (Key in [VK_UP, VK_DOWN]) then
begin
if FileIsPascal then
begin
SwapIntfAndImpl;
end;
end;
end;
procedure TEditorForm.FormActivate(Sender: TObject);
begin
UpdateStatusBar;
if TheErrors.Visible then
MainForm.barStatus.Panels[1].Text := sErrors
else
MainForm.barStatus.Panels[1].Text := '';
MainForm.ChangeActiveEditor;
end;
procedure TEditorForm.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
// 9/13/2001 JCH added id_No case to fix problems when closing main form
// while files are modified. Added check for assigned(MainForm) to protect
// against access violations
if TheEditor.Modified then
begin
BringToFront;
case MessageDlg(Format(S_FileChanged, [Caption]),
mtConfirmation, [mbYes, mbNo, mbCancel], 0) of
id_Yes: if Assigned(MainForm) then MainForm.DoSave(Self);
id_No: TheEditor.Modified := False;
id_Cancel: CanClose:=false;
end;
end;
if AppIsClosing and not CanClose then
AppIsClosing := False;
end;
procedure TEditorForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Assigned(MainForm) then
begin
MainForm.barStatus.Panels[0].Text := '';
MainForm.barStatus.Panels[4].Text := '';
MainForm.barStatus.Panels[5].Text := '';
end;
Action := caFree;
end;
procedure TEditorForm.FormShow(Sender: TObject);
begin
// PopupMenu := ConstructForm.ConstructMenu;
TheEditor.Font.Name := FontName;
TheEditor.Font.Size := FontSize;
end;
procedure TEditorForm.FormCreate(Sender: TObject);
begin
CreatePopupMenu;
CreateTheEditor;
SetValuesFromPreferences;
SetSyntaxHighlighter;
MainForm.SynAutoComp.AddEditor(TheEditor);
MainForm.SynMacroRec.AddEditor(TheEditor);
end;
procedure TEditorForm.SetSyntaxHighlighter;
begin
if IsNew then
begin
if LocalFirmwareType = ftStandard then
begin
if PreferredLanguage = 0 then
begin
if LocalBrickType = SU_NXT then
Self.Highlighter := MainForm.SynNXCSyn
else
Self.Highlighter := MainForm.SynNQCSyn;
end
else if PreferredLanguage = 1 then
Self.Highlighter := MainForm.SynMindScriptSyn
else if PreferredLanguage = 2 then
Self.Highlighter := MainForm.SynLASMSyn
else if PreferredLanguage = 3 then
Self.Highlighter := MainForm.SynNBCSyn
else if PreferredLanguage = 5 then
Self.Highlighter := MainForm.SynSPCSyn
else
Self.Highlighter := MainForm.SynNXCSyn;
end
else if LocalFirmwareType = ftBrickOS then
Self.Highlighter := MainForm.SynCppSyn
else if LocalFirmwareType = ftPBForth then
Self.Highlighter := MainForm.SynForthSyn
else if LocalFirmwareType = ftLeJOS then
Self.Highlighter := MainForm.SynJavaSyn
else if LocalFirmwareType = ftLinux then
begin
Self.Highlighter := MainForm.SynCppSyn;
end;
end
else
Self.Highlighter := GetHighlighterForFile(Filename);
if ColorCoding then
begin
TheEditor.Highlighter := Self.Highlighter;
end
else
TheEditor.Highlighter := nil;
MainForm.expHTML.Highlighter := Self.Highlighter;
MainForm.expRTF.Highlighter := Self.Highlighter;
SetActiveHelpFile;
end;
procedure TEditorForm.ExecFind;
begin
ShowSearchReplaceDialog(TheEditor, FALSE);
end;
procedure TEditorForm.ExecFindNext;
begin
DoSearchReplaceText(TheEditor, FALSE, FALSE);
End;
procedure TEditorForm.ExecFindPrev;
begin
DoSearchReplaceText(TheEditor, FALSE, TRUE);
end;
procedure TEditorForm.ExecReplace;
begin
ShowSearchReplaceDialog(TheEditor, TRUE);
end;
procedure TEditorForm.TheEditorReplaceText(Sender: TObject; const ASearch,
AReplace: String; Line, Column: Integer; var Action: TSynReplaceAction);
var
APos: TPoint;
EditRect: TRect;
begin
if ASearch = AReplace then
Action := raSkip
else begin
APos := Point(Column, Line);
APos := TheEditor.ClientToScreen(TheEditor.RowColumnToPixels(APos));
EditRect := ClientRect;
EditRect.TopLeft := ClientToScreen(EditRect.TopLeft);
EditRect.BottomRight := ClientToScreen(EditRect.BottomRight);
if ConfirmReplaceDialog = nil then
ConfirmReplaceDialog := TConfirmReplaceDialog.Create(Application);
ConfirmReplaceDialog.PrepareShow(EditRect, APos.X, APos.Y,
APos.Y + TheEditor.LineHeight, ASearch);
case ConfirmReplaceDialog.ShowModal of
mrYes: Action := raReplace;
mrYesToAll: Action := raReplaceAll;
mrNo: Action := raSkip;
else Action := raCancel;
end;
end;
end;
procedure TEditorForm.TheEditorStatusChange(Sender: TObject;
Changes: TSynStatusChanges);
begin
// Note: scAll for new file loaded
// caret position has changed
if Changes * [scAll, scCaretX, scCaretY] <> [] then begin
UpdatePositionOnStatusBar;
end;
// InsertMode property has changed
if Changes * [scAll, scInsertMode, scReadOnly] <> [] then begin
UpdateModeOnStatusBar;
end;
// Modified property has changed
if Changes * [scAll, scModified] <> [] then
UpdateModifiedOnStatusBar;
end;
procedure TEditorForm.UpdateStatusBar;
begin
UpdatePositionOnStatusBar;
UpdateModeOnStatusBar;
UpdateModifiedOnStatusBar;
end;
procedure TEditorForm.UpdatePositionOnStatusBar;
var
p: TPoint;
begin
p := TheEditor.CaretXY;
MainForm.barStatus.Panels[0].Text := Format('%6d:%3d', [GetLineNumber(p.Y), p.X]);
end;
procedure TEditorForm.UpdateModeOnStatusBar;
const
InsertModeStrs: array[boolean] of string = (S_Overwrite, S_Insert);
begin
if TheEditor.ReadOnly then
MainForm.barStatus.Panels[4].Text := S_ReadOnly
else
MainForm.barStatus.Panels[4].Text := InsertModeStrs[TheEditor.InsertMode];
end;
procedure TEditorForm.UpdateModifiedOnStatusBar;
const
ModifiedStrs: array[boolean] of string = ('', S_Modified);
begin
MainForm.barStatus.Panels[5].Text := ModifiedStrs[TheEditor.Modified];
end;
function TEditorForm.CanRedo: boolean;
begin
Result := TheEditor.CanRedo;
end;
function TEditorForm.CanFind: boolean;
begin
Result := TheEditor.Lines.Count > 0;
end;
function TEditorForm.CanFindNext: boolean;
begin
Result := CanFind and (gsSearchText <> '');
end;
function TEditorForm.CanReplace: boolean;
begin
Result := CanFind and not TheEditor.ReadOnly;
end;
procedure TEditorForm.SetValuesFromPreferences;
begin
with TheEditor do
begin
if ShowTemplatePopup then
PopupMenu := ConstructForm.ConstructMenu
else
PopupMenu := pmnuEditor;
Font.Name := FontName;
Font.Size := FontSize;
if AltSetsSelMode then
Options := Options + [eoAltSetsColumnMode]
else
Options := Options - [eoAltSetsColumnMode];
if AutoIndentCode then
Options := Options + [eoAutoIndent]
else
Options := Options - [eoAutoIndent];
{$IFNDEF FPC}
if AutoMaxLeft then
Options := Options + [eoAutoSizeMaxLeftChar]
else
Options := Options - [eoAutoSizeMaxLeftChar];
if HighlightCurLine then
Options := Options + [eoHighlightCurrentLine]
else
Options := Options - [eoHighlightCurrentLine];
{$ENDIF}
// disable scroll arrows
if DragAndDropEditing then
Options := Options + [eoDragDropEditing]
else
Options := Options - [eoDragDropEditing];
// drop files
if EnhanceHomeKey then
Options := Options + [eoEnhanceHomeKey]
else
Options := Options - [eoEnhanceHomeKey];
if GroupUndo then
Options := Options + [eoGroupUndo]
else
Options := Options - [eoGroupUndo];
if HalfPageScroll then
Options := Options + [eoHalfPageScroll]
else
Options := Options - [eoHalfPageScroll];
// hide/show scrollbars
if KeepCaretX then
Options := Options + [eoKeepCaretX]
else
Options := Options - [eoKeepCaretX];
// no caret
// no selection
if MoveCursorRight then
Options := Options + [eoRightMouseMovesCursor]
else
Options := Options - [eoRightMouseMovesCursor];
// scroll by one less
// scroll hint follows
// scroll past EOF
if ScrollPastEOL then
Options := Options + [eoScrollPastEol]
else
Options := Options - [eoScrollPastEol];
// show scroll hint
if ShowSpecialChars then
Options := Options + [eoShowSpecialChars]