-
Notifications
You must be signed in to change notification settings - Fork 51
/
uSourceViewFrame.pas
105 lines (82 loc) · 2.27 KB
/
uSourceViewFrame.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
unit uSourceViewFrame;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls,
SynEdit, SynMemo, Vcl.StdCtrls;
type
TSourceViewFrame = class(TFrame)
synmSourceView: TSynMemo;
eSrcFileName: TEdit;
private
FSourceFileName: String;
procedure SetSourceFileName(const Value: String);
public
constructor Create(AOwner: TComponent); override;
procedure BeginUpdate;
procedure EndUpdate;
procedure Clear;
procedure GotoLine(const LineNo: Integer; const Alignment: TVerticalAlignment);
procedure SelectLine(const LineNo: Integer);
property SourceFileName: String read FSourceFileName write SetSourceFileName;
end;
implementation
uses
SynEditTypes;
{$R *.dfm}
{ TSourceViewFrame }
procedure TSourceViewFrame.BeginUpdate;
begin
synmSourceView.BeginUpdate;
end;
procedure TSourceViewFrame.Clear;
begin
FSourceFileName := '';
synmSourceView.Clear;
eSrcFileName.Text := '';
end;
constructor TSourceViewFrame.Create(AOwner: TComponent);
begin
inherited;
FSourceFileName := '';
end;
procedure TSourceViewFrame.EndUpdate;
begin
synmSourceView.EndUpdate;
end;
procedure TSourceViewFrame.GotoLine(const LineNo: Integer; const Alignment: TVerticalAlignment);
begin
if (LineNo > 0) and (LineNo < synmSourceView.Lines.Count) then
begin
case Alignment of
taVerticalCenter:
synmSourceView.GotoLineAndCenter(LineNo);
else
synmSourceView.TopLine := LineNo;
end;
end;
end;
procedure TSourceViewFrame.SelectLine(const LineNo: Integer);
begin
if (LineNo > 0) and (LineNo < synmSourceView.Lines.Count) then
begin
synmSourceView.SetCaretAndSelection(
BufferCoord(1, LineNo),
BufferCoord(1, LineNo),
BufferCoord(1, LineNo + 1)
);
end;
end;
procedure TSourceViewFrame.SetSourceFileName(const Value: String);
begin
if FSourceFileName <> Value then
begin
FSourceFileName := Value;
eSrcFileName.Text := FSourceFileName;
if FileExists(FSourceFileName) then
synmSourceView.Lines.LoadFromFile(FSourceFileName)
else
synmSourceView.Clear;
end;
end;
end.