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

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