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
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;
[237]19 property Ext: String read FExt;
[228]20 end;
21
[233]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;
[228]33
[229]34
[233]35
[228]36implementation
37
38uses
[233]39 Classes, StrUtils, SysUtils, ConnectionManager, TypeDefs, DataAccess, _MetaManager;
[228]40
41{ TExtension }
42
43constructor TExtension.Create(ConnectionID: Integer; Ext: String);
[229]44begin
45 FConnectionID := ConnectionID;
46 FExt := Ext;
47end;
48
[233]49function TExtension.GetCaption: String;
[229]50begin
[237]51 Result := FExt + '[' + IntToStr(GetChildCount) + ']';
[229]52end;
53
[233]54function TExtension.GetChild(ID: Integer): TTreeElement;
55var
56 Meta: TMetaManager;
[229]57begin
[233]58 Meta := ConManager.Connection[FConnectionID].MetaData;
59 Meta.InitFile(FFiles[ID]);
60 Result := Meta.FileById[FFiles[ID]];
61end;
62
63function TExtension.GetChildCount: Integer;
64begin
[229]65 Result := Length(FFiles);
66end;
67
68procedure TExtension.InitList;
[228]69var
70 files: TStrings;
71 i: Integer;
72 fid: Integer;
73 finfo: TFileInfo;
74begin
75 files := TStringList.Create;
[233]76 files := ConManager.Connection[FConnectionID].GetFilesList(FExt, '', False, ST_NameAsc);
[228]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
[233]93
94{ TExtensions }
95
96function TExtensions.GetCaption: String;
97begin
98 Result := '';
99end;
100
101function TExtensions.GetChild(ID: Integer): TTreeElement;
102begin
[237]103 FExtensions[ID].InitList;
[233]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
[237]145 if FExtensions[i].Ext = Ext then
[233]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
[228]173end.
Note: See TracBrowser for help on using the repository browser.