ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/_old_/Tools/Template.pas
(Generate patch)

Comparing oup/current/Tools/Template.pas (file contents):
Revision 83 by alloc, Sun Jan 14 01:30:12 2007 UTC vs.
Revision 86 by alloc, Sun Jan 14 20:19:08 2007 UTC

# Line 9 | Line 9 | uses
9  
10   type
11    TNewFileSelectedEvent = procedure(fileinfo: TFileInfo) of object;
12 +  TNewConnectionEvent = procedure(connection: TOniData) of object;
13  
14    TForm_ToolTemplate = class(TForm)
15      panel_files: TPanel;
# Line 35 | Line 36 | type
36      btn_sort_ext_desc: TSpeedButton;
37      Label1: TLabel;
38      Label2: TLabel;
39 +    Label3: TLabel;
40 +    combo_connection: TComboBox;
41 +    Bevel1: TBevel;
42      procedure RecreateList;
43 +    procedure UpdateList;
44 +    procedure RecreateExtList;
45      procedure LoadFileNames;
46      procedure SelectFileName(filename: String);
47      procedure SelectFileID(id: Integer);
# Line 55 | Line 61 | type
61      procedure filepopupPopup(Sender: TObject);
62      procedure btn_sortClick(Sender: TObject);
63      procedure FormActivate(Sender: TObject);
64 +    procedure combo_connectionChange(Sender: TObject);
65    private
66      FSortBy: TSortType;
67      FOnNewFileSelected: TNewFileSelectedEvent;
68 +    FOnNewConnection: TNewConnectionEvent;
69      FAllowedExts: String;
70      FAllowMultiSelect: Boolean;
71      FSelectedFile: TFileInfo;
72 +    FConnection: TOniData;
73      procedure SetAllowedExts(exts: String);
74      procedure SetMultiSelect(allow: Boolean);
75    public
# Line 68 | Line 77 | type
77      procedure SetFileFilters(pattern, extension: String; zerobytes: Boolean);
78    published
79      property OnNewFileSelected: TNewFileSelectedEvent read FOnNewFileSelected write FOnNewFileSelected;
80 +    property OnNewConnection: TNewConnectionEvent read FOnNewConnection write FOnNewConnection;
81      property AllowedExts: String read FAllowedExts write SetAllowedExts;
82      property AllowMultiSelect: Boolean read FAllowMultiSelect write SetMultiSelect;
83      property SelectedFile: TFileInfo read FSelectedFile;
84 +    property Connection: TOniData read FConnection;
85    end;
86  
87   var
# Line 82 | Line 93 | implementation
93   uses Main, Exporters;
94  
95  
96 + procedure TForm_ToolTemplate.UpdateList;
97 + var
98 +  i: Integer;
99 +  fn, datatype, boxstring: String;
100 +  level: Integer;
101 +  oldcon: String;
102 + begin
103 +  oldcon := combo_connection.Items.Strings[combo_connection.ItemIndex];
104 +  combo_connection.Items.Clear;
105 +  for i := 0 to High(DataConnections) do
106 +  begin
107 +    level := DataConnections[i].LevelInfo.LevelNumber;
108 +    fn := ExtractFileName(DataConnections[i].FileName);
109 +    if DataConnections[i].Backend = ODB_Dat then
110 +      datatype := 'ONI-.dat: '
111 +    else if DataConnections[i].Backend = ODB_ADB then
112 +      datatype := 'OUP-DB: '
113 +    else
114 +      datatype := 'Unknown: ';
115 +    boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ')';
116 +    combo_connection.Items.Add(boxstring);
117 +    if oldcon = boxstring then
118 +      combo_connection.ItemIndex := combo_connection.Items.Count - 1;
119 +  end;
120 + end;
121 +
122   procedure TForm_ToolTemplate.RecreateList;
123   var
124 +  i: Integer;
125 +  fn, datatype: String;
126 +  level: Integer;
127 + begin
128 +  combo_connection.Items.Clear;
129 +  for i := 0 to High(DataConnections) do
130 +  begin
131 +    level := DataConnections[i].LevelInfo.LevelNumber;
132 +    fn := ExtractFileName(DataConnections[i].FileName);
133 +    if DataConnections[i].Backend = ODB_Dat then
134 +      datatype := 'ONI-.dat: '
135 +    else if DataConnections[i].Backend = ODB_ADB then
136 +      datatype := 'OUP-DB: '
137 +    else
138 +      datatype := 'Unknown: ';
139 +    combo_connection.Items.Add(datatype + fn + ' (Level: ' + IntToStr(level) + ')');
140 +  end;
141 +  FConnection := DataConnections[0];
142 +  combo_connection.ItemIndex := 0;
143 +  combo_connectionChange(Self);
144 + end;
145 +
146 + procedure TForm_ToolTemplate.RecreateExtList;
147 + var
148    i:    LongWord;
149    exts: TStringArray;
150   begin
151    combo_extension.Items.Clear;
152    combo_extension.Items.Add('_All files_ (' +
153 <    IntToStr(OniDataConnection.GetFilesCount) + ')');
154 <  exts := OniDataConnection.GetExtensionsList;
153 >    IntToStr(FConnection.GetFilesCount) + ')');
154 >  exts := FConnection.GetExtensionsList;
155    for i := 0 to High(exts) do
156      if Length(FAllowedExts) > 0 then
157      begin
# Line 126 | Line 187 | begin
187      else
188        Extension := '';
189  
190 <  files := OniDataConnection.GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
190 >  files := FConnection.GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
191  
192    filelist.Visible := False;
193    filelist.Items.Clear;
# Line 142 | Line 203 | var
203    id: Integer;
204    ext: String;
205   begin
206 <  id := OniDataConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
206 >  id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
207    ext := RightStr(filelist.Items.Strings[filelist.ItemIndex], 4);
208    exportd.Filter := 'Files of matching extension (*.' + ext + ')|*.' + ext + '|All files|*.*';
209    exportd.DefaultExt := ext;
210    if exportd.Execute then
211 <    ExportDatFile(id, exportd.FileName);
211 >    ExportDatFile(FConnection, id, exportd.FileName);
212   end;
213  
214   procedure TForm_ToolTemplate.popup_importClick(Sender: TObject);
# Line 157 | Line 218 | var
218    fs: TFileStream;
219    data: TData;
220   begin
221 <  id := OniDataConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
222 <  finfo := OniDataConnection.GetFileInfo(id);
221 >  id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
222 >  finfo := FConnection.GetFileInfo(id);
223  
224    importd.Filter := 'Files of matching extension (*.' + finfo.Extension + ')|*.' +
225          finfo.Extension + '|All files|*.*';
# Line 173 | Line 234 | begin
234      else begin
235        SetLength(data, fs.Size);
236        fs.Read(data[0], fs.Size);
237 <      OniDataConnection.UpdateDatFile(id, data);
237 >      FConnection.UpdateDatFile(id, data);
238        Self.listClick(Self);
239      end;
240      fs.Free;
# Line 186 | Line 247 | var
247    id: Integer;
248   begin
249    sender_name := TComponent(Sender).Name;
250 <  id := OniDataConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
250 >  id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
251    context := MidStr(sender_name, Pos('_', sender_name) + 1, Length(sender_name) - Pos('_', sender_name));
252    Form_Main.open_child(context, id);
253   end;
254  
255 + procedure TForm_ToolTemplate.combo_connectionChange(Sender: TObject);
256 + var
257 +  name: String;
258 +  nstart, nend: Integer;
259 +  i: Integer;
260 + begin
261 +  if combo_connection.ItemIndex >= 0 then
262 +  begin
263 +    name := combo_connection.Items.Strings[combo_connection.ItemIndex];
264 +    nstart := Pos(' ', name) + 1;
265 +    nend := Pos('(', name) - 1;
266 +    name := MidStr(name, nstart, nend - nstart);
267 +
268 +    for i := 0 to High(DataConnections) do
269 +    begin
270 +      if ExtractFileName(DataConnections[i].FileName) = name then
271 +      begin
272 +        FConnection := DataConnections[i];
273 +        Break;
274 +      end;
275 +    end;
276 +    if i = Length(DataConnections) then
277 +      FConnection := nil;
278 +
279 +    RecreateExtList;
280 +    if Assigned(FOnNewConnection) then
281 +      FOnNewConnection(FConnection);
282 +  end;
283 + end;
284 +
285   procedure TForm_ToolTemplate.combo_extensionClick(Sender: TObject);
286   begin
287    LoadFileNames;
# Line 204 | Line 295 | var
295   begin
296    inherited;
297    RecreateList;
298 +  FConnection := nil;
299    FSelectedFile.ID := -1;
300    FSelectedFile.FileName := '';
301    FSelectedFile.FileNameHex := '';
# Line 269 | Line 361 | var
361   begin
362    if filelist.ItemIndex > -1 then
363    begin
364 <    fileid := OniDataConnection.ExtractFileID(
364 >    fileid := FConnection.ExtractFileID(
365            filelist.Items.Strings[filelist.ItemIndex]);
366 <    FSelectedFile := OniDataConnection.GetFileInfo(fileid);
366 >    FSelectedFile := FConnection.GetFileInfo(fileid);
367      if Assigned(FOnNewFileSelected) then
368        FOnNewFileSelected(FSelectedFile);
369    end;
# Line 297 | Line 389 | begin
389    filelist.ItemIndex := -1;
390    if filelist.Items.Count > 0 then
391      for i := 0 to filelist.Items.Count - 1 do
392 <      if OniDataConnection.ExtractFileID(filelist.Items.Strings[i]) = id then
392 >      if FConnection.ExtractFileID(filelist.Items.Strings[i]) = id then
393        begin
394          filelist.ItemIndex := i;
395          Break;
# Line 320 | Line 412 | end;
412   procedure TForm_ToolTemplate.SetAllowedExts(exts: String);
413   begin
414    FAllowedExts := exts;
415 <  RecreateList;
415 >  RecreateExtList;
416   end;
417  
418   procedure TForm_ToolTemplate.SetFileFilters(pattern, extension: String;
# Line 367 | Line 459 | begin
459    Self.Width  := 260;
460    Self.Height := 300;
461    FOnNewFileSelected := nil;
462 +  FOnNewConnection := nil;
463    FAllowedExts := '';
464    FAllowMultiSelect := False;
465   end;

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)