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

Last change on this file since 837 was 244, checked in by alloc, 17 years ago
File size: 4.2 KB
RevLine 
[228]1unit _Extensions;
2
3interface
4
[231]5uses
[233]6 _FileTypes, _TreeElement;
[231]7
[228]8type
[233]9 TExtension = class(TTreeElement)
[241]10 protected
[233]11 function GetChildCount: Integer; override;
12 function GetChild(ID: Integer): TTreeElement; override;
13 function GetCaption: String; override;
[241]14 function GetType: String; override;
[228]15 private
[229]16 FExt: String;
[228]17 FFiles: array of Integer;
18 public
19 constructor Create(ConnectionID: Integer; Ext: String); virtual;
20 procedure InitList;
[237]21 property Ext: String read FExt;
[228]22 end;
23
[233]24 TExtensions = class(TTreeElement)
25 function GetChildCount: Integer; override;
26 function GetChild(ID: Integer): TTreeElement; override;
27 function GetCaption: String; override;
[244]28 function GetType: String; override;
[233]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;
[228]36
[229]37
[233]38
[228]39implementation
40
41uses
[233]42 Classes, StrUtils, SysUtils, ConnectionManager, TypeDefs, DataAccess, _MetaManager;
[228]43
44{ TExtension }
45
46constructor TExtension.Create(ConnectionID: Integer; Ext: String);
[229]47begin
48 FConnectionID := ConnectionID;
49 FExt := Ext;
50end;
51
[233]52function TExtension.GetCaption: String;
[229]53begin
[237]54 Result := FExt + '[' + IntToStr(GetChildCount) + ']';
[229]55end;
56
[233]57function TExtension.GetChild(ID: Integer): TTreeElement;
58var
59 Meta: TMetaManager;
[229]60begin
[233]61 Meta := ConManager.Connection[FConnectionID].MetaData;
62 Meta.InitFile(FFiles[ID]);
63 Result := Meta.FileById[FFiles[ID]];
64end;
65
66function TExtension.GetChildCount: Integer;
67begin
[229]68 Result := Length(FFiles);
69end;
70
[241]71function TExtension.GetType: String;
72begin
73 Result := '';
74end;
75
[229]76procedure TExtension.InitList;
[228]77var
78 files: TStrings;
79 i: Integer;
80 fid: Integer;
81 finfo: TFileInfo;
82begin
83 files := TStringList.Create;
[233]84 files := ConManager.Connection[FConnectionID].GetFilesList(FExt, '', False, ST_NameAsc);
[228]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
[233]101
102{ TExtensions }
103
104function TExtensions.GetCaption: String;
105begin
[244]106 Result := 'Extensions';
[233]107end;
108
109function TExtensions.GetChild(ID: Integer): TTreeElement;
110begin
[237]111 FExtensions[ID].InitList;
[233]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
[237]153 if FExtensions[i].Ext = Ext then
[233]154 begin
155 Result := FExtensions[i];
156 Break;
157 end;
158end;
159
[244]160function TExtensions.GetType: String;
161begin
162 Result := '';
163end;
164
[233]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
[228]186end.
Note: See TracBrowser for help on using the repository browser.