Ignore:
Timestamp:
Jun 29, 2007, 2:38:24 PM (17 years ago)
Author:
alloc
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • oup/current/FileClasses/_Extensions.pas

    r231 r233  
    44
    55uses
    6   _FileTypes;
     6  _FileTypes, _TreeElement;
    77
    88type
    9   TExtension = class
     9  TExtension = class(TTreeElement)
     10      function GetChildCount: Integer; override;
     11      function GetChild(ID: Integer): TTreeElement; override;
     12      function GetCaption: String; override;
    1013    private
    11       FConnectionID: Integer;
    1214      FExt: String;
    1315      FFiles: array of Integer;
    14       function GetFile(ID: Integer): Integer;
    15       function GetFileCount: Integer;
    1616    public
    1717      constructor Create(ConnectionID: Integer; Ext: String); virtual;
    1818      procedure InitList;
    19       property Ext: String read FExt;
    20       property Files[ID: Integer]: Integer read GetFile;
    21       property FileCount: Integer read GetFileCount;
    2219  end;
    2320
    24   TExtensions = array of TExtension;
    25                      
     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;
     32
    2633
    2734
     
    2936
    3037uses
    31   Classes, StrUtils, SysUtils, ConnectionManager, TypeDefs;
     38  Classes, StrUtils, SysUtils, ConnectionManager, TypeDefs, DataAccess, _MetaManager;
    3239
    3340{ TExtension }
     
    3946end;
    4047
    41 function TExtension.GetFile(ID: Integer): Integer;
     48function TExtension.GetCaption: String;
    4249begin
    43   Result := FFiles[ID];
     50  Result := FExt;
    4451end;
    4552
    46 function TExtension.GetFileCount: Integer;
     53function TExtension.GetChild(ID: Integer): TTreeElement;
     54var
     55  Meta: TMetaManager;
     56begin
     57  Meta := ConManager.Connection[FConnectionID].MetaData;
     58  Meta.InitFile(FFiles[ID]);
     59  Result := Meta.FileById[FFiles[ID]];
     60end;
     61
     62function TExtension.GetChildCount: Integer;
    4763begin
    4864  Result := Length(FFiles);
     
    5773begin
    5874  files := TStringList.Create;
    59   files := ConManager.Connection[FConnectionID].GetFilesList(Ext, '', False, ST_NameAsc);
     75  files := ConManager.Connection[FConnectionID].GetFilesList(FExt, '', False, ST_NameAsc);
    6076  if files.Count > 0 then
    6177  begin
     
    7490end;
    7591
     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
    76171end.
Note: See TracChangeset for help on using the changeset viewer.