source: oup/current/Tools/_TemplateFile.pas@ 1095

Last change on this file since 1095 was 217, checked in by alloc, 17 years ago
File size: 2.6 KB
Line 
1unit _TemplateFile;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, _BaseTemplate, StdCtrls, ExtCtrls,
8 TypeDefs;
9
10type
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
25var
26 ToolList: TToolList;
27procedure AddToolListEntry(context, name, exts: String);
28
29implementation
30{$R *.dfm}
31uses ConnectionManager;
32
33
34constructor TForm_TemplateFile.Create(AOwner: TComponent);
35begin
36 inherited;
37 FOnNewFileSelected := nil;
38 FSelectedFile.ID := -1;
39end;
40
41
42procedure TForm_TemplateFile.SelectFileID(ConnectionID, FileID: Integer);
43begin
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);
53end;
54
55
56
57procedure AddToolListEntryExt(context, ext: String);
58var
59 i: Integer;
60begin
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;
73end;
74
75procedure AddToolListEntry(context, name, exts: String);
76var
77 i: Integer;
78begin
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;
100end;
101
102end.
Note: See TracBrowser for help on using the repository browser.