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

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