source: oup/current/FileClasses/_Extensions.pas@ 243

Last change on this file since 243 was 241, checked in by alloc, 17 years ago
File size: 4.1 KB
Line 
1unit _Extensions;
2
3interface
4
5uses
6 _FileTypes, _TreeElement;
7
8type
9 TExtension = class(TTreeElement)
10 protected
11 function GetChildCount: Integer; override;
12 function GetChild(ID: Integer): TTreeElement; override;
13 function GetCaption: String; override;
14 function GetType: String; override;
15 private
16 FExt: String;
17 FFiles: array of Integer;
18 public
19 constructor Create(ConnectionID: Integer; Ext: String); virtual;
20 procedure InitList;
21 property Ext: String read FExt;
22 end;
23
24 TExtensions = class(TTreeElement)
25 function GetChildCount: Integer; override;
26 function GetChild(ID: Integer): TTreeElement; override;
27 function GetCaption: String; override;
28 private
29 FExtensions: array of TExtension;
30 public
31 constructor Create(DataAccess: TObject; ConnectionID: Integer);
32 function GetExt(Ext: String): TExtension;
33 procedure AddExt(Ext: String);
34 end;
35
36
37
38implementation
39
40uses
41 Classes, StrUtils, SysUtils, ConnectionManager, TypeDefs, DataAccess, _MetaManager;
42
43{ TExtension }
44
45constructor TExtension.Create(ConnectionID: Integer; Ext: String);
46begin
47 FConnectionID := ConnectionID;
48 FExt := Ext;
49end;
50
51function TExtension.GetCaption: String;
52begin
53 Result := FExt + '[' + IntToStr(GetChildCount) + ']';
54end;
55
56function TExtension.GetChild(ID: Integer): TTreeElement;
57var
58 Meta: TMetaManager;
59begin
60 Meta := ConManager.Connection[FConnectionID].MetaData;
61 Meta.InitFile(FFiles[ID]);
62 Result := Meta.FileById[FFiles[ID]];
63end;
64
65function TExtension.GetChildCount: Integer;
66begin
67 Result := Length(FFiles);
68end;
69
70function TExtension.GetType: String;
71begin
72 Result := '';
73end;
74
75procedure TExtension.InitList;
76var
77 files: TStrings;
78 i: Integer;
79 fid: Integer;
80 finfo: TFileInfo;
81begin
82 files := TStringList.Create;
83 files := ConManager.Connection[FConnectionID].GetFilesList(FExt, '', False, ST_NameAsc);
84 if files.Count > 0 then
85 begin
86 for i := 0 to files.Count - 1 do
87 begin
88 fid := StrToInt(MidStr(files.Strings[i], 1, 5));
89 finfo := ConManager.Connection[FConnectionID].GetFileInfo(fid);
90 if Length(finfo.Name) > 0 then
91 begin
92 SetLength(FFiles, Length(FFiles) + 1);
93 FFiles[High(FFiles)] := fid;
94 end;
95 end;
96 end;
97 files.Free;
98end;
99
100
101{ TExtensions }
102
103function TExtensions.GetCaption: String;
104begin
105 Result := '';
106end;
107
108function TExtensions.GetChild(ID: Integer): TTreeElement;
109begin
110 FExtensions[ID].InitList;
111 Result := FExtensions[ID];
112end;
113
114function TExtensions.GetChildCount: Integer;
115begin
116 Result := Length(FExtensions);
117end;
118
119constructor TExtensions.Create(DataAccess: TObject; ConnectionID: Integer);
120var
121 files: TStrings;
122 i: Integer;
123 fid: Integer;
124 finfo: TFileInfo;
125begin
126 FConnectionID := ConnectionID;
127 files := TStringList.Create;
128 files := TDataAccess(DataAccess).GetFilesList('', '', False, ST_IDAsc);
129 SetLength(FExtensions, 0);
130 if files.Count > 0 then
131 begin
132 for i := 0 to files.Count - 1 do
133 begin
134 fid := StrToInt(MidStr(files.Strings[i], 1, 5));
135 finfo := TDataAccess(DataAccess).GetFileInfo(fid);
136 if Length(finfo.Name) > 0 then
137 if not Assigned(GetExt(finfo.Extension)) then
138 AddExt(finfo.Extension);
139 end;
140 end;
141 files.Free;
142end;
143
144
145function TExtensions.GetExt(Ext: String): TExtension;
146var
147 i: Integer;
148begin
149 Result := nil;
150 if Length(FExtensions) > 0 then
151 for i := 0 to High(FExtensions) do
152 if FExtensions[i].Ext = Ext then
153 begin
154 Result := FExtensions[i];
155 Break;
156 end;
157end;
158
159procedure TExtensions.AddExt(Ext: String);
160var
161 i: Integer;
162begin
163 SetLength(FExtensions, Length(FExtensions) + 1);
164 for i := High(FExtensions) downto 1 do
165 begin
166 if FExtensions[i-1].GetCaption < Ext then
167 begin
168 FExtensions[i] := TExtension.Create(FConnectionID, Ext);
169 Break;
170 end
171 else
172 FExtensions[i] := FExtensions[i-1];
173 end;
174 if i = 0 then
175 FExtensions[0] := TExtension.Create(FConnectionID, Ext);
176end;
177
178
179
180end.
Note: See TracBrowser for help on using the repository browser.