-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathEditorUnit.pas
2806 lines (2549 loc) · 76.5 KB
/
EditorUnit.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
{$MINSTACKSIZE $00400000}
{$MAXSTACKSIZE $00400000}
unit EditorUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls, Printers,
Menus, Dialogs, ComCtrls, Math, AppEvnts;
const
FormatPC = 0;
FormatLinux = 1;
FormatMac = 2;
MinFontSize = 1;
MaxFontSize = 72;
ClickTime = 500;
cObjOn = True; // Compile flags
cObjOff = False;
cListOn = True;
cListOff = False;
cDocOn = True;
cDocOff = False;
type
TEditorForm = class(TForm)
MainMenu: TMainMenu;
FileMenu: TMenuItem;
FileNewItem: TMenuItem;
FileOpenItem: TMenuItem;
FileSaveItem: TMenuItem;
FileSaveAsItem: TMenuItem;
FileN1: TMenuItem;
FileSelectTopIFiletem: TMenuItem;
FileN2: TMenuItem;
FileListToggleItem: TMenuItem;
FileListToggleDebugItem: TMenuItem;
FileDocToggleItem: TMenuItem;
FileN3: TMenuItem;
FilePrintItem: TMenuItem;
FileN4: TMenuItem;
FileExitItem: TMenuItem;
EditMenu: TMenuItem;
EditCutItem: TMenuItem;
EditCopyItem: TMenuItem;
EditPasteItem: TMenuItem;
EditSelectAllItem: TMenuItem;
EditN1: TMenuItem;
EditFindReplaceItem: TMenuItem;
EditFindItem: TMenuItem;
EditReplaceItem: TMenuItem;
EditN2: TMenuItem;
EditTextBiggerItem: TMenuItem;
EditTextSmallerItem: TMenuItem;
RunMenu: TMenuItem;
RunCompileItem: TMenuItem;
RunCompileDebugItem: TMenuItem;
RunCompileLoadItem: TMenuItem;
RunCompileLoadDebugItem: TMenuItem;
RunCompileProgramItem: TMenuItem;
RunCompileProgramDebugItem: TMenuItem;
RunDebugToggleItem: TMenuItem;
RunN1: TMenuItem;
RunAutoSaveItem: TMenuItem;
RunGenerateBinaryItem: TMenuItem;
RunN2: TMenuItem;
RunGetHardwareItem: TMenuItem;
RunChangePortItem: TMenuItem;
RunN3: TMenuItem;
RunComposeRomItem: TMenuItem;
HelpMenu: TMenuItem;
HelpAboutItem: TMenuItem;
OpenDialog: TOpenDialog;
SaveDialog: TSaveDialog;
StatusBar: TStatusBar;
CursorTimer: TTimer;
SelectTimer: TTimer;
DebugTimer: TTimer;
procedure WMGetDlgCode(var Msg: TWMGetDlgCode); message WM_GETDLGCODE;
procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormPaint(Sender: TObject);
procedure ShowHint(Sender: TObject);
procedure CursorTimerTick(Sender: TObject);
procedure FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: boolean);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure SelectTimerTick(Sender: TObject);
procedure FileNew(Sender: TObject);
procedure FileOpenItemClick(Sender: TObject);
procedure FileSave(Sender: TObject);
procedure FileSaveAs(Sender: TObject);
procedure FileSelectTopIFiletemClick(Sender: TObject);
procedure FileListToggle(Sender: TObject);
procedure FileListToggleDebug(Sender: TObject);
procedure FileDocToggle(Sender: TObject);
procedure FilePrint(Sender: TObject);
procedure FileExit(Sender: TObject);
procedure EditCut(Sender: TObject);
procedure EditCopy(Sender: TObject);
procedure EditPaste(Sender: TObject);
procedure EditSelectAll(Sender: TObject);
procedure EditFindReplace(Sender: TObject);
procedure EditFind(Sender: TObject);
procedure EditReplace(Sender: TObject);
procedure EditTextBigger(Sender: TObject);
procedure EditTextSmaller(Sender: TObject);
procedure RunMenuClick(Sender: TObject);
procedure RunCompile(Sender: TObject);
procedure RunCompileDebug(Sender: TObject);
procedure RunCompileLoad(Sender: TObject);
procedure RunCompileLoadDebug(Sender: TObject);
procedure RunCompileProgram(Sender: TObject);
procedure RunCompileProgramDebug(Sender: TObject);
procedure RunDebugToggle(Sender: TObject);
procedure RunAutoSave(Sender: TObject);
procedure RunGenerateBinary(Sender: TObject);
procedure RunGetHardware(Sender: TObject);
procedure RunChangePort(Sender: TObject);
procedure RunComposeRom(Sender: TObject);
procedure HelpAbout(Sender: TObject);
function GoLeft: boolean;
function GoRight: boolean;
procedure GoUp;
procedure GoDown;
procedure GoHome;
procedure GoEnd;
procedure SetMark;
function IsWord: boolean;
function EditRead: byte;
procedure EditDelete(Start, Finish: integer);
function GetColumn: integer;
procedure MatchColumn;
procedure DecFlags;
procedure EditInsert(b: byte);
procedure EditInsertString(s: string);
procedure EditSlice;
procedure MakeDisplayLine(var Position: integer);
function DisplayLineChanged(Line: integer): boolean;
procedure MakeTextRect(Line: integer; var Column: integer; var Style: byte; var Rectangle: TRect; var Left: integer; var Top: integer);
procedure ResetColumn;
procedure ResizeDisplay;
procedure ShowCursor;
procedure HideCursor;
procedure ToggleCursor;
function DeleteSelection: boolean;
function GetSelection(var Start, Finish: integer): boolean;
function IsSelection: boolean;
function MouseInColumns(X: integer; var Column: integer): boolean;
function MouseInRows(Y: integer; var Row: integer): boolean;
procedure NewFile;
procedure LoadEditorFile(const Filename: string);
procedure SaveEditorFile(const Filename: string);
procedure AdjustInputFileCRLF;
procedure AdjustOutputFileCRLF;
procedure SetFilename(const NewFilename: string);
procedure SetExtFileMode(Ext: string; EditBuffer: pointer; Limit, Length: integer);
procedure CancelExtFileMode;
function CheckFileSave: boolean;
function GetErrorLine: integer;
procedure WriteErrorFile(s: string);
procedure DoPrint;
function PrintPage(Finish: integer): boolean;
procedure CutToClipBoard;
procedure CopyToClipBoard;
procedure PasteFromClipBoard;
function Find: boolean;
function Replace: boolean;
procedure SetDirectories;
procedure Compile(cObj, cList, cDoc: boolean);
procedure CompileRecursively(Filename: string; Level: integer; cObj, cList, cDoc: boolean);
procedure CompilerError(ErrorMsg: string);
procedure LoadCompilerFile(Filename: string);
procedure SaveFile(Filename: string; Start: Pointer; Bytes: integer);
procedure ComposeRAM(SaveFlash, ProgramFlash, DownloadToRAM: boolean);
procedure ComposeROM;
procedure LoadObj(Filename: string);
procedure LoadBin(Filename: string);
function NeedToStopDebugFirst: boolean;
procedure DebugTimerTick(Sender: TObject);
end;
var
EditorForm: TEditorForm;
FileFormat: integer;
CurrentFilename: string;
TopFilename: string;
TopDir: string;
CurrentDir: string;
LibraryDir: string;
ExtFileMode: boolean;
Edit: PByteArray;
EditLimit: integer;
EditPos: integer;
EditLength: integer;
EditSplit: integer;
EditMark: integer;
EditMarkFlag: byte;
EditTop: integer;
EditPan: integer;
ActiveColumns: integer;
ActiveRows: integer;
DrawnColumns: integer;
DrawnRows: integer;
EditColumn: integer;
EditColumnFlag: byte;
CursorColumn: integer;
CursorRow: integer;
CursorState: byte;
CursorEnabled: boolean;
EditFlag: boolean;
DrawnData: PByteArray;
DrawnDataSize: integer;
EditorRect: TRect;
ChrWidth: integer;
ChrHeight: integer;
ColumnIndent: integer;
RowIndent: integer;
SelectColumns: integer;
SelectRows: integer;
MouseIsDown: boolean;
Click1: cardinal;
Click2: cardinal;
Click3: cardinal;
UpdateAll: boolean;
UpdateEditor: boolean;
SourceLength: integer;
SourceSplit: integer;
SourceFilename: string;
SourceEditPos: integer;
SourceEditTop: integer;
SourceEditPan: integer;
DebugPostActive: boolean;
DebugPost: procedure(Sender: TObject) of object;
implementation
uses ShellAPI, GlobalUnit, PrintUnit, PrintStatusUnit, FindReplaceUnit,
AboutUnit, ProgressUnit, SerialUnit, ComUnit, DebugUnit, InfoUnit;
{$R *.DFM}
procedure TEditorForm.WMGetDlgCode(var Msg: TWMGetDlgCode);
begin
inherited;
Msg.Result := Msg.Result or DLGC_WANTTAB;
end;
procedure TEditorForm.WMDropFiles(var Msg: TWMDropFiles);
var
Filename: array[0..MAX_PATH] of Char;
begin
try
if DragQueryFile(Msg.Drop, 0, Filename, MAX_PATH) > 0 then
begin
CheckFileSave;
LoadEditorFile(Filename);
Msg.Result := 0;
end;
finally
DragFinish(Msg.Drop);
end;
end;
procedure TEditorForm.FormCreate(Sender: TObject);
begin
DrawnData := nil;
P2 := P2InitStruct;
P2.List := @ListBuffer;
P2.ListLimit := ListLimit;
P2.Doc := @DocBuffer;
P2.DocLimit := DocLimit;
P2.PreSymbols := 0;
Edit := @SourceBuffer;
EditLimit := SourceLimit;
FileFormat := FormatPC;
UpdateEditor := True;
ExtFileMode := False;
CommOpen := False;
CommPort := 1;
BeginTimeBase;
Application.OnHint := ShowHint;
end;
procedure TEditorForm.FormDestroy(Sender: TObject);
begin
EndTimeBase;
end;
procedure TEditorForm.FormShow(Sender: TObject);
var
cmd: boolean;
i: integer;
c, p: byte;
s: string;
begin
BatchMode := False;
ExitCode := 0;
Click1 := ClickTime * 0;
Click2 := ClickTime * 1;
Click3 := ClickTime * 2;
PrintForm.FontSize := 9;
FontName := 'Consolas';
if FontName <> 'Consolas' then FontName := 'Courier New';
FontSize := 10;
SetBounds(0, 0, Screen.Width * 3 div 4, Screen.Height * 3 div 4);
ResizeDisplay;
DragAcceptFiles(Handle, True);
if (ParamCount = 1) and (ParamStr(1) = '-rom') then
begin
RunN3.Visible := True;
RunComposeRomItem.Visible := True;
end
else if (ParamCount = 2) and (FileExists(ParamStr(1) + '.bin') or FileExists(ParamStr(1))) and
((ParamStr(2) = '-b') or (ParamStr(2) = '-bd')) then
begin
if FileExists(ParamStr(1) + '.bin') then
LoadBin(ExpandFilename(ParamStr(1) + '.bin'))
else
LoadBin(ExpandFilename(ParamStr(1)));
P2.DebugMode := (ParamStr(2) = '-bd'); // establish debug settings
P2.DebugBaud := P2.DownloadBaud;
P2.DebugLeft := 0;
P2.DebugTop := 0;
P2.DebugWidth := Screen.Width;
P2.DebugHeight := 200;
P2.DebugDisplayLeft := 0;
P2.DebugDisplayTop := 210;
P2.DebugLogSize := 0;
try
LoadHardware;
except
WriteErrorFile('serial_error');
ExitCode := 1;
Close;
Exit;
end;
WriteErrorFile('okay');
Close;
Exit;
end
else if (ParamCount >= 1) and (FileExists(ParamStr(1) + '.spin2') or FileExists(ParamStr(1))) then
begin
if FileExists(ParamStr(1) + '.spin2') then
TopFilename := ExpandFilename(ParamStr(1) + '.spin2')
else
TopFilename := ExpandFilename(ParamStr(1));
LoadEditorFile(TopFilename);
//
// check for -D preprocessor symbols
//
// if ParamCount >= 2 and even then -xx command (filename -xx {-D symbol})
// if ParamCount >= 1 and odd then no command (filename {-D symbol})
//
cmd := (ParamCount >= 2) and
((ParamStr(2) = '-c' ) or
(ParamStr(2) = '-cd') or
(ParamStr(2) = '-cf') or
(ParamStr(2) = '-cb') or
(ParamStr(2) = '-ci') or
(ParamStr(2) = '-r' ) or
(ParamStr(2) = '-rd') or
(ParamStr(2) = '-f' ) or
(ParamStr(2) = '-fd'));
if (cmd and (ParamCount > 2)) or (not cmd and (ParamCount > 1)) then
begin
if cmd and (ParamCount > 2) then i := 3 else i := 2;
repeat
if ParamStr(i) = '-D' then
begin
if P2.PreSymbols = 16 then
begin
WriteErrorFile('too_many_preprocessor_symbols');
ExitCode := 1;
Close;
Exit;
end;
if i + 1 > ParamCount then
begin
WriteErrorFile('preprocessor_symbol_missing');
ExitCode := 1;
Close;
Exit;
end;
s := UpperCase(ParamStr(i + 1));
p := Length(s);
if p > 31 then
begin
WriteErrorFile('preprocessor_symbol_too_long');
ExitCode := 1;
Close;
Exit;
end;
if not (s[1] in ['A'..'Z', '_']) then
begin
WriteErrorFile('preprocessor_symbol_starts_with_illegal_chr');
ExitCode := 1;
Close;
Exit;
end;
for c := 1 to p do
begin
if not (s[c] in ['0'..'9', 'A'..'Z', '_']) then
begin
WriteErrorFile('preprocessor_symbol_contains_illegal_chr');
ExitCode := 1;
Close;
Exit;
end;
p2.PreSymbolNames[P2.PreSymbols * 32 + c - 1] := Byte(s[c]);
end;
P2.PreSymbolNames[P2.PreSymbols * 32 + p] := 0;
Inc(P2.PreSymbols);
Inc(i, 2);
end
else
begin
WriteErrorFile('expected_D_or_U');
ExitCode := 1;
Close;
Exit;
end;
until i > ParamCount;
end;
if cmd then
begin
BatchMode := True;
try
P2.DebugMode := (ParamStr(2) = '-cd') or
(ParamStr(2) = '-cb') or
(ParamStr(2) = '-rd') or
(ParamStr(2) = '-fd');
Compile(cObjOn, cListOn, cDocOff); // aborts if error
except
WriteErrorFile(CurrentFilename + ':' + IntToStr(GetErrorLine) + ':error:' + P2.ErrorMsg);
ExitCode := 1;
Close;
Exit;
end;
try
RunGenerateBinaryItem.Checked := True;
ComposeRAM(
(ParamStr(2) = '-ci'),
(ParamStr(2) = '-cf') or (ParamStr(2) = '-cb') or (ParamStr(2) = '-f') or (ParamStr(2) = '-fd'),
(ParamStr(2) = '-r') or (ParamStr(2) = '-rd') or (ParamStr(2) = '-f') or (ParamStr(2) = '-fd'));
except
WriteErrorFile('serial_error');
ExitCode := 1;
Close;
Exit;
end;
WriteErrorFile('okay');
Close;
Exit;
end
else
WriteErrorFile('okay');
end
else if (ParamCount >= 1) and (ParamStr(1) = '-debug') then
begin
BatchMode := True;
if (ParamCount >= 2) then // get CommPort?
CommPort := StrToInt(ParamStr(2));
P2.DownloadBaud := DefaultBaud; // get DebugBaud?
if (ParamCount >= 3) then
P2.DownloadBaud := StrToInt(ParamStr(3));
P2.DebugBaud := P2.DownloadBaud; // establish other debug settings
P2.DebugLeft := 0;
P2.DebugTop := 0;
P2.DebugWidth := Screen.Width;
P2.DebugHeight := 200;
P2.DebugDisplayLeft := 0;
P2.DebugDisplayTop := 210;
P2.DebugLogSize := 0;
try
StartDebug;
except
WriteErrorFile('serial_error');
ExitCode := 1;
Close;
Exit;
end;
WriteErrorFile('okay');
Close;
Exit;
end
else
begin
WriteErrorFile('okay');
TopFilename := '';
FileNew(Sender);
end;
end;
procedure TEditorForm.FormResize(Sender: TObject);
begin
if ComponentState <> [csDestroying] then ResizeDisplay
else if DrawnData <> nil then FreeMem(DrawnData);
end;
procedure TEditorForm.FormPaint(Sender: TObject);
begin
UpdateAll := True;
ShowCursor;
end;
procedure TEditorForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
DebugActive := False; // end debug thread
CancelExtFileMode; // file need saving?
try
CheckFileSave;
except
CanClose := False;
end;
end;
procedure TEditorForm.ShowHint(Sender: TObject);
begin
if Length(Application.Hint) > 0 then
StatusBar.SimpleText := Application.Hint
else StatusBar.SimpleText := '';
end;
procedure TEditorForm.FormKeyPress(Sender: TObject; var Key: Char);
var
k: byte;
begin
// if mouse select in progress, exit
if MouseIsDown then Exit;
k := Byte(Key);
if (k in [kTab, kEnter, kSpace..$7E, $80..$FF]) then
begin
DeleteSelection;
EditInsert(k);
DecFlags;
HideCursor;
ShowCursor;
end;
end;
procedure TEditorForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var
i, j: integer;
sNone, sCtrl, sShift, sCtrlShift: boolean;
begin
// if mouse select in progress, exit
if MouseIsDown then Exit;
// Make shift-state booleans
sNone := not(ssShift in Shift) and not(ssCtrl in Shift);
sCtrl := not(ssShift in Shift) and (ssCtrl in Shift);
sShift := (ssShift in Shift) and not(ssCtrl in Shift);
sCtrlShift := (ssShift in Shift) and (ssCtrl in Shift);
// Process editor key
case Key of
// BackSpace key
kBackSpace:
begin
// Delete marked text?
if not DeleteSelection then
begin
// BackSpace?
if sNone then if GoLeft then EditDelete(EditPos, EditPos + 1);
// Delete to line start?
if sShift then
begin
//i := EditPos;
//GoHome;
//if EditPos <> i then EditDelete(EditPos, i);
end;
// Delete line?
if sCtrl then
begin
//GoHome;
//i := EditPos;
//GoEnd;
//GoRight;
//if EditPos <> i then EditDelete(i, EditPos);
end;
// Delete to file start?
//if sCtrlShift then if GoLeft then EditDelete(0, EditPos + 1);
end;
end;
// Delete key
kDelete:
begin
// Delete marked text?
if not DeleteSelection then
begin
// Delete?
if sNone and (EditPos <> EditLength) then EditDelete(EditPos, EditPos + 1);
// Delete to line end?
if sShift then
begin
//i := EditPos;
//GoEnd;
//if EditPos <> i then EditDelete(i, EditPos);
end;
// Delete line?
if sCtrl then
begin
//GoHome;
//i := EditPos;
//GoEnd;
//GoRight;
//if EditPos <> i then EditDelete(i, EditPos);
end;
// Delete to file end?
//if sCtrlShift then if EditPos <> EditLength then EditDelete(EditPos, EditLength);
end;
end;
// Left key
kLeft:
begin
// Mark?
if sShift or sCtrlShift then SetMark;
// Left?
if sNone or sShift then GoLeft
// Left word
else
begin
i := EditPos;
repeat
if IsWord then
begin
j := EditPos;
EditPos := EditMark;
EditMark := j;
if EditPos <> i then Break;
end;
if not GoLeft then
begin
EditMarkFlag := 0;
Break;
end;
until False;
end;
end;
// Right key
kRight:
begin
// Mark?
if sShift or sCtrlShift then SetMark;
// Right?
if sNone or sShift then GoRight
// right word
else
begin
i := EditPos;
repeat
if IsWord then if EditPos <> i then Break;
if not GoRight then
begin
EditMarkFlag := 0;
Break;
end;
until False;
end;
end;
// Up key
kUp:
begin
// Mark?
if sShift then SetMark;
// Up?
if sNone or sShift then
begin
if EditColumnFlag = 0 then EditColumn := GetColumn;
EditColumnFlag := 2;
GoUp;
MatchColumn;
end;
// Invalid?
if sCtrl or sCtrlShift then Exit;
end;
// Down key
kDown:
begin
// Mark?
if sShift then SetMark;
// Down?
if sNone or sShift then
begin
if EditColumnFlag = 0 then EditColumn := GetColumn;
EditColumnFlag := 2;
GoDown;
MatchColumn;
end;
// Invalid?
if sCtrl or sCtrlShift then Exit;
end;
// Home key
kHome:
begin
// Mark?
if sShift or sCtrlShift then SetMark;
// Home?
if sNone or sShift then GoHome
// File start
else EditPos := 0;
end;
// End key
kEnd:
begin
// Mark?
if sShift or sCtrlShift then SetMark;
// End?
if sNone or sShift then GoEnd
// File end
else EditPos := EditLength;
end;
// PageUp key
kPageUp:
begin
// Mark?
if sShift or sCtrlShift then SetMark;
// PageUp?
if sNone or sShift then
begin
if EditPos <> EditTop then EditPos := EditTop
else for i := 1 to ActiveRows do GoUp;
end
// File start
else EditPos := 0;
end;
// PageDown key
kPageDown:
begin
// Mark?
if sShift or sCtrlShift then SetMark;
// PageDown?
if sNone or sShift then
begin
i := EditPos;
EditPos := EditTop;
for j := 1 to ActiveRows - 1 do GoDown;
if EditPos <= i then for j := 1 to ActiveRows do GoDown;
end
// File end
else EditPos := EditLength;
end
// if none of the above, exit
else Exit;
end;
// else, update display
DecFlags;
HideCursor;
ShowCursor;
end;
//////////////////////
// Menu Responses //
//////////////////////
procedure TEditorForm.FileNew(Sender: TObject);
begin
CancelExtFileMode;
CheckFileSave;
NewFile;
SetFilename(IncludeTrailingPathDelimiter(GetCurrentDir) + 'Untitled.spin2');
end;
procedure TEditorForm.FileOpenItemClick(Sender: TObject);
begin
CancelExtFileMode;
CheckFileSave;
OpenDialog.Title := 'Open File';
if OpenDialog.Execute then LoadEditorFile(OpenDialog.Filename);
end;
procedure TEditorForm.FileSave(Sender: TObject);
begin
if CurrentFilename = 'Untitled.spin2' then FileSaveAs(Sender)
else SaveEditorFile(CurrentFilename);
end;
procedure TEditorForm.FileSaveAs(Sender: TObject);
begin
if not SaveDialog.Execute then Exit;
if FileExists(SaveDialog.Filename) then
if MessageDlg('OK to overwrite ' + SaveDialog.Filename, mtConfirmation, mbYesNoCancel, 0) <> idYes then Exit;
SaveEditorFile(SaveDialog.Filename);
SetFilename(SaveDialog.Filename);
end;
procedure TEditorForm.FileSelectTopIFiletemClick(Sender: TObject);
begin
OpenDialog.Title := 'Select Top File';
if OpenDialog.Execute then TopFilename := OpenDialog.Filename;
SetFilename(CurrentFilename);
end;
procedure TEditorForm.FileListToggle(Sender: TObject);
begin
if ExtFileMode then CancelExtFileMode
else
begin
P2.DebugMode := False;
Compile(cObjOff, cListOn, cDocOff); // aborts if error
SetExtFileMode('lst', @ListBuffer, ListLimit, P2.ListLength);
FileListToggleItem.Checked := True;
Hint := 'List Mode - Type Ctrl+L to return to source';
end;
end;
procedure TEditorForm.FileListToggleDebug(Sender: TObject);
begin
if ExtFileMode then CancelExtFileMode
else
begin
P2.DebugMode := True;
Compile(cObjOff, cListOn, cDocOff); // aborts if error
SetExtFileMode('lst', @ListBuffer, ListLimit, P2.ListLength);
FileListToggleDebugItem.Checked := True;
Hint := 'List Mode - Type Ctrl+L to return to source';
end;
end;
procedure TEditorForm.FileDocToggle(Sender: TObject);
begin
if ExtFileMode then CancelExtFileMode
else
begin
P2.DebugMode := False;
Compile(cObjOff, cListOff, cDocOn); // aborts if error
SetExtFileMode('txt', @DocBuffer, DocLimit, P2.DocLength);
FileDocToggleItem.Checked := True;
Hint := 'Documentation Mode - Type Ctrl+D to return to source';
end;
end;
procedure TEditorForm.FilePrint(Sender: TObject);
begin
DoPrint;
end;
procedure TEditorForm.FileExit(Sender: TObject);
begin
Close;
end;
procedure TEditorForm.EditCut(Sender: TObject);
begin
HideCursor;
CutToClipBoard;
ShowCursor;
end;
procedure TEditorForm.EditCopy(Sender: TObject);
begin
HideCursor;
CopyToClipBoard;
ShowCursor;
end;
procedure TEditorForm.EditPaste(Sender: TObject);
begin
HideCursor;
PasteFromClipBoard;
ShowCursor;
end;
procedure TEditorForm.EditSelectAll(Sender: TObject);
begin
EditPos := 0;
EditMark := EditLength;
EditMarkFlag := 1;
HideCursor;
ShowCursor;
end;
procedure TEditorForm.EditFindReplace(Sender: TObject);
begin
FindReplaceForm.ReplaceButton.Enabled := IsSelection;
case FindReplaceForm.ShowModal of
mrOk:
begin
if FindReplaceForm.StartCheckBox.Checked then EditPos := 0;
EditFind(Sender);
end;
mrRetry: EditReplace(Sender);
mrAll:
begin
HideCursor;
if FindReplaceForm.StartCheckBox.Checked then EditPos := 0;
if Find then
begin
repeat
Replace;
until not Find;
ResetColumn;
end
else MessageDlg('Nothing Found', mtInformation, [mbOK], 0);
ShowCursor;
end;
mrCancel: {nothing};
end;
end;
procedure TEditorForm.EditFind(Sender: TObject);
begin
HideCursor;
if Length(FindReplaceForm.FindMemo.Text) = 0 then MessageDlg('Nothing to Find', mtInformation, [mbOK], 0)
else if Find then ResetColumn else MessageDlg('Nothing Found', mtInformation, [mbOK], 0);
ShowCursor;
end;
procedure TEditorForm.EditReplace(Sender: TObject);
begin
HideCursor;
if Replace then ResetColumn else MessageDlg('Nothing Selected', mtInformation, [mbOK], 0);
ShowCursor;
end;
procedure TEditorForm.EditTextBigger(Sender: TObject);
begin
Inc(FontSize);
MaxLimit(FontSize, MaxFontSize);
ResizeDisplay;