/
frmEditor.pas
3238 lines (2964 loc) · 95.6 KB
/
frmEditor.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 Name: frmEditor
Author: Kiriakos Vlahos
Date: 23-Feb-2005
Purpose:
History: Origianlly Based on SynEdit Demo
----------------------------------------------------------------------------- }
unit frmEditor;
interface
uses
WinApi.Windows,
WinApi.Messages,
System.Types,
System.UITypes,
System.SysUtils,
System.Classes,
System.Contnrs,
System.ImageList,
System.Threading,
Vcl.Graphics,
Vcl.Controls,
Vcl.Menus,
Vcl.Forms,
Vcl.StdCtrls,
Vcl.ExtCtrls,
Vcl.ImgList,
Vcl.Dialogs,
Vcl.VirtualImageList,
TB2Item,
SpTBXItem,
SpTBXSkins,
SpTBXDkPanels,
SpTBXTabs,
SpTBXControls,
JclStrings,
SynEdit,
SynEditTypes,
SynEditHighlighter,
SynEditMiscClasses,
SynEditKeyCmds,
SynCompletionProposal,
VirtualResources,
uCommonFunctions,
frmCodeExplorer,
uEditAppIntfs,
cPyControl,
cPythonSourceScanner,
cCodeCompletion,
cPyBaseDebugger,
cPySupportTypes;
type
TEditor = class;
THotIdentInfo = record
SynEdit: TSynEdit;
[weak] Editor : TEditor;
HaveHotIdent: boolean;
IdentArea: TRect;
Ident: string;
DottedIdent: string;
StartCoord: TBufferCoord;
SynToken: string;
SynAttri: TSynHighlighterAttributes;
end;
TEditorForm = class(TForm)
pmnuEditor: TSpTBXPopupMenu;
pmnuViewsTab: TSpTBXPopupMenu;
mnCloseTab: TSpTBXItem;
SynEdit: TSynEdit;
SynEdit2: TSynEdit;
EditorSplitter: TSpTBXSplitter;
mnUpdateView: TSpTBXItem;
ViewsTabControl: TSpTBXTabControl;
tabSource: TSpTBXTabItem;
tbshSource: TSpTBXTabSheet;
SpTBXRightAlignSpacerItem1: TSpTBXRightAlignSpacerItem;
tbiUpdateView: TSpTBXItem;
tbiCloseTab: TSpTBXItem;
mnEditUndo: TSpTBXItem;
mnEditRedo: TSpTBXItem;
N5: TSpTBXSeparatorItem;
mnEditCut: TSpTBXItem;
mnEditCopy: TSpTBXItem;
mnEditPaste: TSpTBXItem;
mnEditDelete: TSpTBXItem;
mnEditSelectAll: TSpTBXItem;
TBXSeparatorItem9: TSpTBXSeparatorItem;
mnSourceCode: TSpTBXSubmenuItem;
SpTBXSeparatorItem1: TSpTBXSeparatorItem;
mnSearch: TSpTBXSubmenuItem;
SpTBXSeparatorItem2: TSpTBXSeparatorItem;
mnMaximizeEditor2: TSpTBXItem;
mnRestoreEditor2: TSpTBXItem;
N12: TSpTBXSeparatorItem;
mnEditorOptions: TSpTBXItem;
BGPanel: TPanel;
mnFoldVisible: TSpTBXItem;
SpTBXSeparatorItem4: TSpTBXSeparatorItem;
mnFold: TSpTBXSubmenuItem;
mnUnfold: TSpTBXSubmenuItem;
mnFoldAll: TSpTBXItem;
mnUnfoldAll: TSpTBXItem;
mnFoldNearest: TSpTBXItem;
mnUnfoldNearest: TSpTBXItem;
mnFoldRegions: TSpTBXItem;
SpTBXSeparatorItem3: TSpTBXSeparatorItem;
mnFoldLevel1: TSpTBXItem;
mnUnfoldRegions: TSpTBXItem;
SpTBXSeparatorItem5: TSpTBXSeparatorItem;
mnUnfoldLevel1: TSpTBXItem;
mnFoldLevel2: TSpTBXItem;
mnFoldLevel3: TSpTBXItem;
mnUnfoldLevel2: TSpTBXItem;
mnUnfoldLevel3: TSpTBXItem;
SpTBXSeparatorItem6: TSpTBXSeparatorItem;
mnFoldFunctions: TSpTBXItem;
mnFoldClasses: TSpTBXItem;
SpTBXSeparatorItem7: TSpTBXSeparatorItem;
mnUnfoldFunctions: TSpTBXItem;
mnUnfoldClasses: TSpTBXItem;
vilGutterGlyphs: TVirtualImageList;
vilCodeImages: TVirtualImageList;
procedure SynEditMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
procedure SynParamCompletionExecute(Kind: SynCompletionType;
Sender: TObject; var CurrentInput: string; var X, Y: Integer;
var CanExecute: boolean);
procedure FormDestroy(Sender: TObject);
procedure SynEditChange(Sender: TObject);
procedure SynEditEnter(Sender: TObject);
procedure SynEditExit(Sender: TObject);
procedure SynEditStatusChange(Sender: TObject; Changes: TSynStatusChanges);
procedure FormCreate(Sender: TObject);
procedure SynEditGutterClick(Sender: TObject; Button: TMouseButton;
X, Y, Line: Integer; Mark: TSynEditMark);
procedure SynEditSpecialLineColors(Sender: TObject; Line: Integer;
var Special: boolean; var FG, BG: TColor);
procedure SynEditPaintTransient(Sender: TObject; Canvas: TCanvas;
TransientType: TTransientType);
procedure SynEditKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure SynEditMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FGPanelEnter(Sender: TObject);
procedure FGPanelExit(Sender: TObject);
procedure mnCloseTabClick(Sender: TObject);
procedure SynEditMouseCursor(Sender: TObject;
const aLineCharPos: TBufferCoord; var aCursor: TCursor);
procedure SynEditKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure SynCodeCompletionExecute(Kind: SynCompletionType;
Sender: TObject; var CurrentInput: string; var X, Y: Integer;
var CanExecute: boolean);
procedure SynEditMouseWheelDown(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: boolean);
procedure SynEditMouseWheelUp(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: boolean);
procedure SynCodeCompletionClose(Sender: TObject);
procedure SynWebCompletionExecute(Kind: SynCompletionType; Sender: TObject;
var CurrentInput: string; var X, Y: Integer; var CanExecute: boolean);
procedure SynWebCompletionAfterCodeCompletion(Sender: TObject;
const Value: string; Shift: TShiftState; Index: Integer;
EndToken: WideChar);
procedure mnUpdateViewClick(Sender: TObject);
procedure ViewsTabControlContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: boolean);
procedure ViewsTabControlActiveTabChange(Sender: TObject;
TabIndex: Integer);
procedure SynEditDblClick(Sender: TObject);
procedure SynCodeCompletionAfterCodeCompletion(Sender: TObject;
const Value: string; Shift: TShiftState; Index: Integer; EndToken: Char);
procedure SynEditGutterGetText(Sender: TObject; aLine: Integer;
var aText: string);
private
fEditor: TEditor;
fActiveSynEdit: TSynEdit;
fAutoCompleteActive: boolean;
fHotIdentInfo: THotIdentInfo;
fNeedToCheckSyntax: boolean;
fNeedToParseModule: boolean;
fNeedToSyncCodeExplorer: boolean;
fSyntaxErrorPos: TEditorPos;
fCloseBracketChar: WideChar;
fOldCaretY : Integer;
fSyntaxTask: ITask;
procedure HandlePythonVersionChange(Sender: TObject);
function DoAskSaveChanges: boolean;
procedure DoAssignInterfacePointer(AActive: boolean);
function DoSave: boolean;
function DoSaveFile: boolean;
function DoSaveAs: boolean;
function DoSaveAsRemote: boolean;
procedure DoUpdateCaption;
procedure DoUpdateHighlighter(HighlighterName: string = '');
procedure AutoCompleteBeforeExecute(Sender: TObject);
procedure AutoCompleteAfterExecute(Sender: TObject);
procedure WMFolderChangeNotify(var Msg: TMessage); message WM_FOLDERCHANGENOTIFY;
procedure SynCodeCompletionCodeItemInfo(Sender: TObject;
AIndex: Integer; var Info : string);
procedure DoCodeCompletion(Editor: TSynEdit; Caret: TBufferCoord);
class var fOldEditorForm: TEditorForm;
class var fHintIdentInfo: THotIdentInfo;
class procedure CodeHintEventHandler(Sender: TObject; AArea: TRect;
var CodeHint: string);
class procedure CodeHintLinkHandler(Sender: TObject; LinkName: string);
class procedure SetUpCodeHints;
protected
procedure Retranslate;
procedure WMSpSkinChange(var Message: TMessage); message WM_SPSKINCHANGE;
procedure EditorZoom(theZoom: Integer);
procedure EditorMouseWheel(theDirection: Integer; Shift: TShiftState);
public
BreakPoints: TObjectList;
FoundSearchItems: TObjectList;
HasFocus: boolean;
FileTime: TDateTime;
DefaultExtension: string;
ParentTabItem: TSpTBXTabItem;
ParentTabControl: TSpTBXCustomTabControl;
[Align(8)]
SourceScanner: IAsyncSourceScanner;
procedure ClearSearchItems;
procedure DoActivate;
procedure DoActivateEditor(Primary: boolean = True);
function DoActivateView(ViewFactory: IEditorViewFactory): IEditorView;
function GetEditor: IEditor;
procedure EditorCommandHandler(Sender: TObject; AfterProcessing: boolean;
var Handled: boolean; var Command: TSynEditorCommand;
var AChar: WideChar; Data: Pointer; HandlerData: Pointer);
procedure PaintGutterGlyphs(ACanvas: TCanvas; AClip: TRect;
FirstLine, LastLine: Integer);
procedure DoOnIdle;
function ReparseIfNeeded: boolean;
procedure SyncCodeExplorer;
procedure AddWatchAtCursor;
function HasSyntaxError: boolean;
procedure GoToSyntaxError;
end;
TEditor = class(TInterfacedObject, IUnknown, IEditor, IEditCommands,
IFileCommands, ISearchCommands)
private
// IEditor implementation
procedure Activate(Primary: boolean = True);
function ActivateView(ViewFactory: IEditorViewFactory): IEditorView;
function AskSaveChanges: boolean;
procedure Close;
function GetCaretPos: TPoint;
function GetSynEdit: TSynEdit;
function GetSynEdit2: TSynEdit;
function GetActiveSynEdit: TSynEdit;
function GetBreakPoints: TObjectList;
function GetEditorState: string;
function GetFileName: string;
function GetFileTitle: string;
function GetFileNameOrTitle: string;
function GetModified: boolean;
function GetFileEncoding: TFileSaveFormat;
procedure SetFileEncoding(FileEncoding: TFileSaveFormat);
function GetEncodedText: AnsiString;
procedure OpenFile(const AFileName: string; HighlighterName: string = '');
procedure OpenRemoteFile(const FileName, ServerName: string);
function SaveToRemoteFile(const FileName, ServerName: string) : boolean;
function HasPythonFile: boolean;
function GetReadOnly : Boolean;
procedure SetReadOnly(Value : Boolean);
procedure ExecuteSelection;
procedure SplitEditorHorizontally;
procedure SplitEditorVertrically;
procedure Retranslate;
function GetForm: TForm;
function GetSourceScanner: IInterface;
function GetCodeExplorerData: IInterface;
function GetTabControlIndex: Integer;
function GetRemoteFileName: string;
function GetSSHServer: string;
// IEditCommands implementation
function CanCopy: boolean;
function CanCut: boolean;
function IEditCommands.CanDelete = CanCut;
function CanPaste: boolean;
function CanRedo: boolean;
function CanSelectAll: boolean;
function CanUndo: boolean;
procedure ExecCopy;
procedure ExecCut;
procedure ExecDelete;
procedure ExecPaste;
procedure ExecRedo;
procedure ExecSelectAll;
procedure ExecUndo;
// IFileCommands implementation
function CanClose: boolean;
function CanPrint: boolean;
function CanSave: boolean;
function CanSaveAs: boolean;
function CanReload: boolean;
procedure ExecClose;
procedure ExecPrint;
procedure ExecPrintPreview;
procedure ExecSave;
procedure ExecSaveAs;
procedure ExecSaveAsRemote;
procedure ExecReload(Quiet: boolean = False);
// ISearchCommands implementation
function CanFind: boolean;
function CanFindNext: boolean;
function ISearchCommands.CanFindPrev = CanFindNext;
function ISearchCommands.GetSearchTarget = GetActiveSynEdit;
function CanReplace: boolean;
procedure ExecFind;
procedure ExecFindNext;
procedure ExecFindPrev;
procedure ExecReplace;
private
fFileName: string;
fRemoteFileName : string;
fSSHServer : string;
fForm: TEditorForm;
fHasSelection: boolean;
fUntitledNumber: Integer;
fCodeExplorerData: ICodeExplorerData;
function IsEmpty: boolean;
constructor Create(AForm: TEditorForm);
procedure DoSetFileName(AFileName: string);
function GetEncodedTextEx(var EncodedText: AnsiString;
InformationLossWarning: boolean): boolean;
end;
implementation
{$R *.DFM}
uses
System.Math,
VirtualShellNotifier,
PythonEngine,
VarPyth,
Vcl.Themes,
JclFileUtils,
SynUnicode,
SynEditTextBuffer,
SynHighlighterWebMisc,
SynHighlighterWeb,
SynHighlighterPython,
JvDockControlForm,
JvGnugettext,
StringResources,
dmCommands,
dlgSynPrintPreview,
dlgPickList,
frmPyIDEMain,
frmBreakPoints,
frmPythonII,
frmWatches,
frmIDEDockWin,
uSearchHighlighter,
cInternalPython,
cPyDebugger,
cRefactoring,
cCodeHint,
cPyScripterSettings,
cSSHSupport,
dlgRemoteFile;
const
WM_DELETETHIS = WM_USER + 42;
{ TGutterMarkDrawPlugin }
type
TDebugSupportPlugin = class(TSynEditPlugin)
protected
fForm: TEditorForm;
procedure AfterPaint(ACanvas: TCanvas; const AClip: TRect;
FirstLine, LastLine: Integer); override;
procedure LinesInserted(FirstLine, Count: Integer); override;
procedure LinesDeleted(FirstLine, Count: Integer); override;
public
constructor Create(AForm: TEditorForm);
end;
constructor TDebugSupportPlugin.Create(AForm: TEditorForm);
begin
inherited Create(AForm.SynEdit);
fForm := AForm;
end;
Type
TUnderlineStyle = (usCorelWordPerfect, usMicrosoftWord);
procedure TDebugSupportPlugin.AfterPaint(ACanvas: TCanvas; const AClip: TRect;
FirstLine, LastLine: Integer);
Var
TP: TPoint;
MaxX, LH: Integer;
procedure PaintUnderLine;
Const
UnderlineStyle: TUnderlineStyle = usMicrosoftWord;
var
NewPoint, NewY: Integer;
procedure DrawPoint;
begin
// Do not draw on gutter.
// This happens when a word is underlined and part of it is "hidden" under
// the gutter.
if TP.X <= Editor.Gutter.RealGutterWidth(Editor.CharWidth) then
Exit;
with ACanvas do
begin
if NewY = TP.Y - 1 then
Pen.Color := fForm.SynEdit.Color
else
Pen.Color := clRed;
Pixels[TP.X, NewY] := Pen.Color;
end;
end;
const
// Microsoft Word style
// MW_POINTS: array[0..6] of ShortInt = (1, 2, 2, 1, 0, 0, 0);
MW_POINTS: array [0 .. 3] of ShortInt = (0, 1, 2, 1);
// Corel Word Perfect style
// WP_POINTS: array[0..4] of ShortInt = (3, 2, 1, -1, -1);
WP_POINTS: array [0 .. 3] of ShortInt = (2, 1, 0, -1);
begin
Inc(TP.Y, LH - 3);
NewPoint := 0;
if UnderlineStyle = usMicrosoftWord then
NewY := TP.Y + MW_POINTS[NewPoint]
else
NewY := TP.Y + WP_POINTS[NewPoint];
DrawPoint;
while TP.X <= MaxX do
begin
DrawPoint;
Inc(NewPoint);
if UnderlineStyle = usMicrosoftWord then
begin
if NewPoint > High(MW_POINTS) then
NewPoint := 0
end
else
begin
if NewPoint > High(WP_POINTS) then
NewPoint := 0;
end;
DrawPoint;
Inc(TP.X);
if UnderlineStyle = usMicrosoftWord then
NewY := TP.Y + MW_POINTS[NewPoint]
else
NewY := TP.Y + WP_POINTS[NewPoint];
end;
end;
begin
if fForm.HasSyntaxError then
with fForm.fSyntaxErrorPos do
if System.Math.InRange(Line, fForm.SynEdit.RowToLine(FirstLine),
fForm.SynEdit.RowToLine(LastLine)) and not (fForm.SynEdit.UseCodeFolding and
fForm.SynEdit.AllFoldRanges.FoldHidesLine(Line)) then
begin
LH := fForm.SynEdit.LineHeight;
TP := fForm.SynEdit.RowColumnToPixels
(fForm.SynEdit.BufferToDisplayPos(BufferCoord(1, Line)));
if TP.X <= ACanvas.ClipRect.Right - ACanvas.ClipRect.Left then
begin
MaxX := fForm.SynEdit.RowColumnToPixels
(fForm.SynEdit.BufferToDisplayPos(BufferCoord(Char, Line))).X;
PaintUnderLine;
end;
end;
if fForm.SynEdit.Highlighter = CommandsDataModule.SynPythonSyn then
fForm.PaintGutterGlyphs(ACanvas, AClip, FirstLine, LastLine);
end;
procedure TDebugSupportPlugin.LinesInserted(FirstLine, Count: Integer);
var
i: Integer;
begin
with fForm do
begin
for i := 0 to BreakPoints.Count - 1 do
if TBreakPoint(BreakPoints[i]).LineNo >= FirstLine then
begin
TBreakPoint(BreakPoints[i]).LineNo := TBreakPoint(BreakPoints[i])
.LineNo + Count;
PyControl.BreakPointsChanged := True;
BreakPointsWindow.UpdateWindow;
end;
end;
end;
procedure TDebugSupportPlugin.LinesDeleted(FirstLine, Count: Integer);
var
i: Integer;
begin
with fForm do
begin
for i := BreakPoints.Count - 1 downto 0 do
if TBreakPoint(BreakPoints[i]).LineNo >= FirstLine + Count then
begin
TBreakPoint(BreakPoints[i]).LineNo := TBreakPoint(BreakPoints[i])
.LineNo - Count;
PyControl.BreakPointsChanged := True;
BreakPointsWindow.UpdateWindow;
end
else if TBreakPoint(BreakPoints[i]).LineNo >= FirstLine then
begin
BreakPoints.Delete(i);
PyControl.BreakPointsChanged := True;
BreakPointsWindow.UpdateWindow;
end;
end;
end;
{ TEditor }
constructor TEditor.Create(AForm: TEditorForm);
begin
Assert(AForm <> nil);
inherited Create;
fForm := AForm;
fUntitledNumber := -1;
fCodeExplorerData := TCodeExplorerData.Create;
SetFileEncoding(PyIDEOptions.NewFileEncoding);
end;
procedure TEditor.Activate(Primary: boolean = True);
begin
if fForm <> nil then
fForm.DoActivateEditor(Primary);
end;
function TEditor.ActivateView(ViewFactory: IEditorViewFactory): IEditorView;
begin
if fForm <> nil then
Result := fForm.DoActivateView(ViewFactory);
end;
function TEditor.AskSaveChanges: boolean;
begin
if fForm <> nil then
Result := fForm.DoAskSaveChanges
else
Result := True;
end;
procedure TEditor.Close;
// Closes without asking
Var
TabSheet: TSpTBXTabSheet;
TabControl: TSpTBXCustomTabControl;
begin
if (fForm <> nil) then
begin
CodeExplorerWindow.UpdateWindow(ceuExit);
GI_PyIDEServices.MRUAddEditor(Self);
if fUntitledNumber <> -1 then
CommandsDataModule.ReleaseUntitledNumber(fUntitledNumber);
if fForm.BreakPoints.Count > 0 then
begin
PyControl.BreakPointsChanged := True;
BreakPointsWindow.UpdateWindow;
end;
TabSheet := (fForm.Parent as TSpTBXTabSheet);
TabControl := TabSheet.TabControl;
TabControl.View.BeginUpdate;
try
(fForm.ParentTabControl as TSpTBXTabControl).zOrder.Remove(TabSheet.Item);
fForm.DoAssignInterfacePointer(False);
// fForm.Close;
TabSheet.Free;
if Assigned(TabControl) then
TabControl.Toolbar.MakeVisible(TabControl.ActiveTab);
finally
TabControl.View.EndUpdate;
end;
end;
end;
procedure TEditor.DoSetFileName(AFileName: string);
begin
if AFileName <> fFileName then
begin
fFileName := AFileName;
fRemoteFileName := '';
fSSHServer := '';
if fUntitledNumber <> -1 then
begin
CommandsDataModule.ReleaseUntitledNumber(fUntitledNumber);
fUntitledNumber := -1;
end;
// Kernel change notification
if (fFileName <> '') and FileExists(fFileName) then
ChangeNotifier.NotifyWatchFolder(fForm, ExtractFileDir(fFileName))
else
ChangeNotifier.NotifyWatchFolder(fForm, '');
end;
fForm.fNeedToParseModule := True;
end;
function TEditor.GetSynEdit: TSynEdit;
begin
Result := fForm.SynEdit;
end;
function TEditor.GetSynEdit2: TSynEdit;
begin
Result := fForm.SynEdit2;
end;
function TEditor.GetTabControlIndex: Integer;
begin
Result := PyIDEMainForm.TabControlIndex(fForm.ParentTabControl);
end;
function TEditor.GetActiveSynEdit: TSynEdit;
begin
if fForm.SynEdit2.Visible and (fForm.fActiveSynEdit = fForm.SynEdit2) then
Result := fForm.SynEdit2
else
Result := fForm.SynEdit;
end;
function TEditor.GetBreakPoints: TObjectList;
begin
Result := fForm.BreakPoints;
end;
function TEditor.GetCaretPos: TPoint;
begin
if fForm <> nil then
begin
Result := TPoint(GetActiveSynEdit.CaretXY);
end
else
Result := Point(-1, -1);
end;
function TEditor.GetCodeExplorerData: IInterface;
begin
Result := fCodeExplorerData;
end;
function TEditor.GetEditorState: string;
begin
if fForm <> nil then
begin
if fForm.SynEdit.ReadOnly then
Result := _(SReadOnly)
else if fForm.SynEdit.InsertMode then
Result := _(SInsert)
else
Result := _(SOverwrite);
end
else
Result := '';
end;
function TEditor.GetEncodedText: AnsiString;
begin
GetEncodedTextEx(Result, False);
end;
function TEditor.GetEncodedTextEx(var EncodedText: AnsiString;
InformationLossWarning: boolean): boolean;
begin
Result := WideStringsToEncodedText(GetFileNameOrTitle, fForm.SynEdit.Lines,
EncodedText, InformationLossWarning, HasPythonFile);
end;
function TEditor.GetFileName: string;
begin
Result := fFileName;
end;
function TEditor.GetFileTitle: string;
begin
if fFileName <> '' then
begin
if PyIDEOptions.DisplayPackageNames and
FileIsPythonPackage(fFileName)
then
Result := FileNameToModuleName(fFileName)
else
Result := ExtractFileName(fFileName);
end
else if fSSHServer <> '' then
Result := TSSHFileName.Format(fSSHServer, fRemoteFileName)
else
begin
if fUntitledNumber = -1 then
fUntitledNumber := CommandsDataModule.GetUntitledNumber;
if fForm.SynEdit.Highlighter = CommandsDataModule.SynPythonSyn then
Result := _(SNonamePythonFileTitle) + IntToStr(fUntitledNumber)
else
Result := _(SNonameFileTitle) + IntToStr(fUntitledNumber);
end;
end;
function TEditor.GetFileNameOrTitle: string;
begin
if fFileName <> '' then
Result := fFileName
else
Result := GetFileTitle;
end;
function TEditor.GetModified: boolean;
begin
if fForm <> nil then
Result := fForm.SynEdit.Modified
else
Result := False;
end;
function TEditor.GetReadOnly: Boolean;
begin
Result := GetSynEdit.ReadOnly;
end;
function TEditor.GetRemoteFileName: string;
begin
Result := fRemoteFileName;
end;
function TEditor.GetSourceScanner: IInterface;
begin
fForm.ReparseIfNeeded;
Result := fForm.SourceScanner;
end;
function TEditor.GetSSHServer: string;
begin
Result := fSSHServer;
end;
function TEditor.GetFileEncoding: TFileSaveFormat;
begin
with fForm.SynEdit.Lines do
begin
if Encoding = nil then Exit(sf_Ansi);
if Encoding = TEncoding.UTF8 then
begin
if WriteBOM then
Result := sf_UTF8
else
Result := sf_UTF8_NoBOM;
end else if Encoding = TEncoding.Unicode then
Result := sf_UTF16LE
else if Encoding = TEncoding.BigEndianUnicode then
Result := sf_UTF16BE
else
Result := sf_Ansi;
end;
end;
procedure TEditor.SetFileEncoding(FileEncoding: TFileSaveFormat);
begin
with TSynEditStringList(fForm.SynEdit.Lines) do
begin
case FileEncoding of
sf_Ansi: SetEncoding(Encoding.ANSI);
sf_UTF8,
sf_UTF8_NoBOM: SetEncoding(TEncoding.UTF8);
sf_UTF16LE: SetEncoding(TEncoding.Unicode);
sf_UTF16BE: SetEncoding(TEncoding.BigEndianUnicode);
end;
if FileEncoding = sf_UTF8_NoBOM then
WriteBOM := False
else
WriteBom := True;
end;
end;
procedure TEditor.SetReadOnly(Value: Boolean);
begin
GetSynEdit.ReadOnly := Value;
GetSynEdit2.ReadOnly := Value;
end;
procedure TEditor.SplitEditorHorizontally;
begin
with fForm do
begin
EditorSplitter.Visible := False;
SynEdit2.Visible := False;
SynEdit2.Align := alBottom;
SynEdit2.Height := (ClientHeight - 5) div 2;
EditorSplitter.Align := alBottom;
SynEdit2.Visible := True;
EditorSplitter.Visible := True;
end;
end;
procedure TEditor.SplitEditorVertrically;
begin
with fForm do
begin
EditorSplitter.Visible := False;
SynEdit2.Visible := False;
SynEdit2.Align := alRight;
SynEdit2.Width := (ClientWidth - 5) div 2;
EditorSplitter.Align := alRight;
SynEdit2.Visible := True;
EditorSplitter.Visible := True;
end;
end;
procedure TEditor.OpenFile(const AFileName: string;
HighlighterName: string = '');
begin
DoSetFileName(AFileName);
if fForm <> nil then
begin
if (AFileName <> '') and FileExists(AFileName) then
begin
if LoadFileIntoWideStrings(AFileName, fForm.SynEdit.Lines) then
begin
if not FileAge(AFileName, fForm.FileTime) then
fForm.FileTime := 0;
end
else
Abort;
end
else
begin
fForm.SynEdit.Lines.Clear;
if AFileName = '' then
begin
// Default settings for new files
if PyIDEOptions.NewFileLineBreaks <> sffUnicode then
(fForm.SynEdit.Lines as TSynEditStringList).FileFormat :=
PyIDEOptions.NewFileLineBreaks;
end;
end;
fForm.SynEdit.Modified := False;
fForm.DoUpdateHighlighter(HighlighterName);
fForm.DoUpdateCaption;
fForm.fOldEditorForm := fForm;
fForm.Synedit.UseCodeFolding := PyIDEOptions.CodeFoldingEnabled;
fForm.Synedit2.UseCodeFolding := fForm.Synedit.UseCodeFolding;
end;
end;
procedure TEditor.OpenRemoteFile(const FileName, ServerName: string);
Var
TempFileName : string;
ErrorMsg : string;
begin
if (fForm = nil) or (FileName = '') or (ServerName = '') then Abort;
DoSetFileName('');
TempFileName := ChangeFileExt(FileGetTempName('PyScripter'), ExtractFileExt(FileName));
if not ScpDownload(ServerName, FileName, TempFileName, ErrorMsg) then begin
StyledMessageDlg(Format(_(SFileOpenError), [FileName, ErrorMsg]), mtError, [mbOK], 0);
Abort;
end else begin
if not LoadFileIntoWideStrings(TempFileName, fForm.SynEdit.Lines) then
Abort
else
DeleteFile(TempFileName);
end;
fRemoteFileName := FileName;
fSSHServer := ServerName;
fForm.SynEdit.Modified := False;
fForm.DoUpdateHighlighter('');
fForm.DoUpdateCaption;
fForm.fOldEditorForm := fForm;
fForm.Synedit.UseCodeFolding := PyIDEOptions.CodeFoldingEnabled;
fForm.Synedit2.UseCodeFolding := fForm.Synedit.UseCodeFolding;
end;
function TEditor.SaveToRemoteFile(const FileName, ServerName: string): boolean;
Var
TempFileName : string;
ErrorMsg : string;
begin
if (fForm = nil) or (FileName = '') or (ServerName = '') then Abort;
TempFileName := FileGetTempName('PyScripter');
Result := SaveWideStringsToFile(TempFileName, fForm.SynEdit.Lines, False);
if Result then begin
Result := ScpUpload(ServerName, TempFileName, FileName, ErrorMsg);
DeleteFile(TempFileName);
if not Result then
StyledMessageDlg(Format(_(SFileSaveError), [FileName, ErrorMsg]), mtError, [mbOK], 0);
end;
end;
procedure TEditor.Retranslate;
begin
fForm.Retranslate;
end;
function TEditor.HasPythonFile: boolean;
begin
Result := GetSynEdit.Highlighter is TSynPythonSyn;
end;
function TEditor.GetForm: TForm;
begin
Result := fForm;
end;
// IEditCommands implementation
function TEditor.CanCopy: boolean;
begin
Result := (fForm <> nil);
end;
function TEditor.CanCut: boolean;
begin
Result := (fForm <> nil) and not GetReadOnly;
end;
function TEditor.CanPaste: boolean;
begin
Result := (fForm <> nil) and GetActiveSynEdit.CanPaste;
end;
function TEditor.CanRedo: boolean;
begin
Result := (fForm <> nil) and fForm.SynEdit.CanRedo;
end;
function TEditor.CanReload: boolean;
begin
Result := fFileName <> '';
end;
function TEditor.CanSelectAll: boolean;
begin
Result := fForm <> nil;
end;
function TEditor.CanUndo: boolean;
begin
Result := (fForm <> nil) and fForm.SynEdit.CanUndo;
end;
procedure TEditor.ExecCopy;
begin
if fForm <> nil then
GetActiveSynEdit.CopyToClipboard;
end;
procedure TEditor.ExecCut;
begin
if fForm <> nil then
GetActiveSynEdit.CutToClipboard;
end;
procedure TEditor.ExecDelete;
begin
if fForm <> nil then
GetActiveSynEdit.SelText := '';
end;
procedure TEditor.ExecPaste;
begin
if fForm <> nil then
GetActiveSynEdit.PasteFromClipboard;
end;
procedure TEditor.ExecRedo;
begin
if fForm <> nil then
fForm.SynEdit.Redo;
end;
procedure TEditor.ExecReload(Quiet: boolean = False);
Var
P: TBufferCoord;
begin
if Quiet or not GetModified or (StyledMessageDlg(_(SFileReloadingWarning),
mtWarning, [mbYes, mbNo], 0) = mrYes) then
begin
P := GetSynEdit.CaretXY;