1 | unit _TemplateFile;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
7 | Dialogs, _BaseTemplate, StdCtrls, ExtCtrls,
|
---|
8 | TypeDefs;
|
---|
9 |
|
---|
10 | type
|
---|
11 | TNewFileSelectedEvent = procedure(FileInfo: TFileInfo) of object;
|
---|
12 |
|
---|
13 | TForm_TemplateFile = class(TForm_BaseTemplate)
|
---|
14 | protected
|
---|
15 | FOnNewFileSelected: TNewFileSelectedEvent;
|
---|
16 | FSelectedFile: TFileInfo;
|
---|
17 | public
|
---|
18 | constructor Create(AOwner: TComponent); override;
|
---|
19 | procedure SelectFileID(ConnectionID, FileID: Integer);
|
---|
20 | published
|
---|
21 | property OnNewFileSelected: TNewFileSelectedEvent read FOnNewFileSelected write FOnNewFileSelected;
|
---|
22 | property SelectedFile: TFileInfo read FSelectedFile;
|
---|
23 | end;
|
---|
24 |
|
---|
25 | var
|
---|
26 | ToolList: TToolList;
|
---|
27 | procedure AddToolListEntry(context, name, exts: String);
|
---|
28 |
|
---|
29 | implementation
|
---|
30 | {$R *.dfm}
|
---|
31 | uses ConnectionManager;
|
---|
32 |
|
---|
33 |
|
---|
34 | constructor TForm_TemplateFile.Create(AOwner: TComponent);
|
---|
35 | begin
|
---|
36 | inherited;
|
---|
37 | FOnNewFileSelected := nil;
|
---|
38 | FSelectedFile.ID := -1;
|
---|
39 | end;
|
---|
40 |
|
---|
41 |
|
---|
42 | procedure TForm_TemplateFile.SelectFileID(ConnectionID, FileID: Integer);
|
---|
43 | begin
|
---|
44 | if FConnectionID <> ConnectionID then
|
---|
45 | SelectConnection(ConnectionID);
|
---|
46 |
|
---|
47 | if FileID < ConManager.Connection[FConnectionID].GetFileCount then
|
---|
48 | FSelectedFile := ConManager.Connection[FConnectionID].GetFileInfo(FileID)
|
---|
49 | else
|
---|
50 | FSelectedFile.ID := -1;
|
---|
51 | if Assigned(FOnNewFileSelected) then
|
---|
52 | FOnNewFileSelected(FSelectedFile);
|
---|
53 | end;
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 | procedure AddToolListEntryExt(context, ext: String);
|
---|
58 | var
|
---|
59 | i: Integer;
|
---|
60 | begin
|
---|
61 | for i := 0 to High(ToolList) do
|
---|
62 | if ToolList[i].context = context then
|
---|
63 | begin
|
---|
64 | if Pos(ext, ToolList[i].exts) = 0 then
|
---|
65 | begin
|
---|
66 | if Length(ToolList[i].exts) = 0 then
|
---|
67 | ToolList[i].exts := ext
|
---|
68 | else
|
---|
69 | ToolList[i].exts := ToolList[i].exts + ',' + ext;
|
---|
70 | end;
|
---|
71 | Exit;
|
---|
72 | end;
|
---|
73 | end;
|
---|
74 |
|
---|
75 | procedure AddToolListEntry(context, name, exts: String);
|
---|
76 | var
|
---|
77 | i: Integer;
|
---|
78 | begin
|
---|
79 | if Length(ToolList) > 0 then
|
---|
80 | begin
|
---|
81 | for i := 0 to High(ToolList) do
|
---|
82 | if ToolList[i].context = context then
|
---|
83 | begin
|
---|
84 | if (Length(ToolList[i].name) = 0) and (Length(name) > 0) then
|
---|
85 | ToolList[i].name := name;
|
---|
86 | if Length(exts) > 0 then
|
---|
87 | AddToolListEntryExt(context, exts);
|
---|
88 | Exit;
|
---|
89 | end;
|
---|
90 | end;
|
---|
91 | SetLength(ToolList, Length(ToolList) + 1);
|
---|
92 | for i := High(ToolList) downto 1 do
|
---|
93 | if ToolList[i - 1].name > name then
|
---|
94 | ToolList[i] := ToolList[i - 1]
|
---|
95 | else
|
---|
96 | Break;
|
---|
97 | ToolList[i].context := context;
|
---|
98 | ToolList[i].name := name;
|
---|
99 | ToolList[i].exts := exts;
|
---|
100 | end;
|
---|
101 |
|
---|
102 | end.
|
---|