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

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