1 | unit FormSourceCode;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
|
---|
7 | SynEdit, SynHighlighterPas, Project;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TFormSourceCode }
|
---|
12 |
|
---|
13 | TFormSourceCode = class(TForm)
|
---|
14 | SynEditSource: TSynEdit;
|
---|
15 | SynPasSyn1: TSynPasSyn;
|
---|
16 | procedure SynEditSourceChange(Sender: TObject);
|
---|
17 | private
|
---|
18 | FProjectFile: TProjectFile;
|
---|
19 | procedure SetProjectFile(const AValue: TProjectFile);
|
---|
20 | public
|
---|
21 | property ProjectFile: TProjectFile read FProjectFile write SetProjectFile;
|
---|
22 | procedure Save;
|
---|
23 | procedure UpdateInterface;
|
---|
24 | procedure SelectFile(FileName: string; Position: TPoint);
|
---|
25 | end;
|
---|
26 |
|
---|
27 |
|
---|
28 | implementation
|
---|
29 |
|
---|
30 | uses
|
---|
31 | FormMain, Core;
|
---|
32 |
|
---|
33 | {$R *.lfm}
|
---|
34 |
|
---|
35 | { TFormSourceCode }
|
---|
36 |
|
---|
37 | procedure TFormSourceCode.SynEditSourceChange(Sender: TObject);
|
---|
38 | begin
|
---|
39 | Save;
|
---|
40 | if Assigned(Core.Core.Project) and Assigned(ProjectFile) then
|
---|
41 | ProjectFile.Modified := True;
|
---|
42 | end;
|
---|
43 |
|
---|
44 | procedure TFormSourceCode.SetProjectFile(const AValue: TProjectFile);
|
---|
45 | begin
|
---|
46 | if FProjectFile = AValue then Exit;
|
---|
47 | FProjectFile := AValue;
|
---|
48 | if Assigned(AValue) then
|
---|
49 | SynEditSource.Lines.Assign(FProjectFile.Source)
|
---|
50 | else SynEditSource.ClearAll;
|
---|
51 | end;
|
---|
52 |
|
---|
53 | procedure TFormSourceCode.Save;
|
---|
54 | begin
|
---|
55 | if Assigned(ProjectFile) then
|
---|
56 | ProjectFile.Source.Assign(SynEditSource.Lines);
|
---|
57 | end;
|
---|
58 |
|
---|
59 | procedure TFormSourceCode.UpdateInterface;
|
---|
60 | begin
|
---|
61 | SynEditSource.Enabled := Assigned(Core.Core.Project);
|
---|
62 | if not Assigned(Core.Core.Project) then SynEditSource.ClearAll;
|
---|
63 | end;
|
---|
64 |
|
---|
65 | procedure TFormSourceCode.SelectFile(FileName: string; Position: TPoint);
|
---|
66 | var
|
---|
67 | ProjectFile: TProjectFile;
|
---|
68 | begin
|
---|
69 | with Core.Core do begin
|
---|
70 | ProjectFile := Project.Files.SearchFile(FileName);
|
---|
71 | if Assigned(ProjectFile) then
|
---|
72 | SynEditSource.Lines.Assign(ProjectFile.Source)
|
---|
73 | else if FileExists(FileName) then
|
---|
74 | SynEditSource.Lines.LoadFromFile(FileName);
|
---|
75 | SynEditSource.CaretXY := Position;
|
---|
76 | TForm(SynEditSource.Owner).Show;
|
---|
77 | SynEditSource.SetFocus;
|
---|
78 | end;
|
---|
79 | end;
|
---|
80 |
|
---|
81 | end.
|
---|
82 |
|
---|