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

Comparing oup/rewrite/Tools/Template.pas (file contents):
Revision 93 by alloc, Thu Jan 18 17:15:59 2007 UTC vs.
Revision 97 by alloc, Mon Jan 22 23:05:45 2007 UTC

# Line 5 | Line 5 | interface
5   uses
6    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7    Dialogs, ExtCtrls, StdCtrls, StrUtils,
8 <  ConnectionManager, {Functions,} Data, TypeDefs, Menus, Buttons;
8 >  Data, TypeDefs, Menus, Buttons;
9  
10   type
11    TNewFileSelectedEvent = procedure(FileInfo: TFileInfo) of object;
12    TNewConnectionEvent = procedure(Connection: Integer) of object;
13 +  TCheckCloseableEvent = function: Boolean of object;
14  
15    TForm_ToolTemplate = class(TForm)
16      panel_files: TPanel;
# Line 39 | Line 40 | type
40      Label3: TLabel;
41      combo_connection: TComboBox;
42      Bevel1: TBevel;
42    procedure RecreateList;
43    procedure UpdateList;
43      procedure RecreateExtList;
44 +    procedure UpdateConList;
45      procedure LoadFileNames;
46 <    procedure SelectFileName(connection: Integer; FileName: String);
47 <    procedure SelectFileID(connection: Integer; FileID: Integer);
46 >    procedure SelectFileName(ConnectionID: Integer; FileName: String);
47 >    procedure SelectFileID(ConnectionID, FileID: Integer);
48 >    procedure SelectConnection(ConnectionID: Integer);
49      procedure check_filternameClick(Sender: TObject);
50      procedure check_zerobyteClick(Sender: TObject);
51      procedure combo_extensionClick(Sender: TObject);
# Line 53 | Line 54 | type
54        Shift: TShiftState; X, Y: Integer);
55  
56      procedure FormResize(Sender: TObject);
56    procedure FormCreate(Sender: TObject);
57      procedure FormClose(Sender: TObject; var Action: TCloseAction);
58      procedure popup_importClick(Sender: TObject);
59      procedure popup_exportClick(Sender: TObject);
# Line 66 | Line 66 | type
66      FSortBy: TSortType;
67      FOnNewFileSelected: TNewFileSelectedEvent;
68      FOnNewConnection: TNewConnectionEvent;
69 +    FOnCheckCloseable: TCheckCloseableEvent;
70      FAllowedExts: String;
71      FAllowMultiSelect: Boolean;
72      FSelectedFile: TFileInfo;
73 <    FConnection: Integer;
73 >    FConnectionID: Integer;
74      procedure SetAllowedExts(exts: String);
75      procedure SetMultiSelect(allow: Boolean);
76 +    function GetToolCloseable: Boolean;
77    public
78      constructor Create(AOwner: TComponent); override;
79      procedure SetFileFilters(pattern, extension: String; zerobytes: Boolean);
80    published
81      property OnNewFileSelected: TNewFileSelectedEvent read FOnNewFileSelected write FOnNewFileSelected;
82      property OnNewConnection: TNewConnectionEvent read FOnNewConnection write FOnNewConnection;
83 +    property OnCheckCloseable: TCheckCloseableEvent read FOnCheckCloseable write FOnCheckCloseable;
84      property AllowedExts: String read FAllowedExts write SetAllowedExts;
85      property AllowMultiSelect: Boolean read FAllowMultiSelect write SetMultiSelect;
86      property SelectedFile: TFileInfo read FSelectedFile;
87 <    property Connection: Integer read FConnection;
87 >    property ConnectionID: Integer read FConnectionID;
88 >    property Closeable: Boolean read GetToolCloseable;
89    end;
90  
91   var
# Line 90 | Line 94 | procedure AddToolListEntry(context, name
94  
95   implementation
96   {$R *.dfm}
97 < uses Main, Exporters;
97 > uses Main, ConnectionManager, Exporters, Functions;
98  
99  
100 < procedure TForm_ToolTemplate.UpdateList;
100 > procedure TForm_ToolTemplate.UpdateConList;
101   var
102    i: Integer;
103    fn, datatype, boxstring: String;
104    level: Integer;
101  oldcon: String;
105   begin
103  oldcon := combo_connection.Items.Strings[combo_connection.ItemIndex];
106    combo_connection.ItemIndex := -1;
107    combo_connection.Items.Clear;
108 <  if Length(DataConnections) > 0 then
108 >  if ConManager.Count > 0 then
109    begin
110 <    for i := 0 to High(DataConnections) do
110 >    for i := 0 to ConManager.Count - 1 do
111      begin
112 <      level := DataConnections[i].LevelInfo.LevelNumber;
113 <      fn := ExtractFileName(DataConnections[i].FileName);
114 <      if DataConnections[i].Backend = ODB_Dat then
112 >      level := ConManager.ConnectionByIndex[i].LevelNumber;
113 >      fn := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
114 >      if ConManager.ConnectionByIndex[i].Backend = DB_ONI then
115          datatype := 'ONI-.dat: '
116 <      else if DataConnections[i].Backend = ODB_ADB then
116 >      else if ConManager.ConnectionByIndex[i].Backend = DB_ADB then
117          datatype := 'OUP-DB: '
118        else
119          datatype := 'Unknown: ';
120        boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ')';
121        combo_connection.Items.Add(boxstring);
122 <      if oldcon = boxstring then
122 >      if ConManager.ConnectionByIndex[i].ConnectionID = FConnectionID then
123          combo_connection.ItemIndex := combo_connection.Items.Count - 1;
124      end;
125      if combo_connection.ItemIndex = -1 then
# Line 128 | Line 130 | begin
130    end
131    else
132    begin
133 <    FConnection := nil;
133 >    FConnectionID := 0;
134      filelist.Items.Clear;
135      combo_extension.Items.Clear;
136      combo_connectionChange(Self);
137 <    FSelectedFile := GetEmptyFileInfo;
137 >    FSelectedFile.ID := -1;
138      if Assigned(FOnNewFileSelected) then
139        FOnNewFileSelected(FSelectedFile);
140    end;
141   end;
142  
141 procedure TForm_ToolTemplate.RecreateList;
142 var
143  i: Integer;
144  fn, datatype: String;
145  level: Integer;
146 begin
147  combo_connection.Items.Clear;
148  if Length(DataConnections) > 0 then
149  begin
150    for i := 0 to High(DataConnections) do
151    begin
152      level := DataConnections[i].LevelInfo.LevelNumber;
153      fn := ExtractFileName(DataConnections[i].FileName);
154      if DataConnections[i].Backend = ODB_Dat then
155        datatype := 'ONI-.dat: '
156      else if DataConnections[i].Backend = ODB_ADB then
157        datatype := 'OUP-DB: '
158      else
159        datatype := 'Unknown: ';
160      combo_connection.Items.Add(datatype + fn + ' (Level: ' + IntToStr(level) + ')');
161    end;
162    FConnection := DataConnections[0];
163    combo_connection.ItemIndex := 0;
164    combo_connectionChange(Self);
165  end
166  else
167  begin
168    FConnection := nil;
169    filelist.Items.Clear;
170    combo_extension.Items.Clear;
171    combo_connectionChange(Self);
172  end;
173 end;
174
143   procedure TForm_ToolTemplate.RecreateExtList;
144   var
145 <  i:    LongWord;
146 <  exts: TStringArray;
145 >  i:    Integer;
146 >  exts: TStrings;
147   begin
148    combo_extension.Items.Clear;
149 <  if FConnection <> nil then
149 >  if FConnectionID > -1 then
150    begin
151      combo_extension.Items.Add('_All files_ (' +
152 <      IntToStr(FConnection.GetFilesCount) + ')');
153 <    exts := FConnection.GetExtensionsList;
154 <    for i := 0 to High(exts) do
152 >      IntToStr(ConManager.Connection[FConnectionID].GetFileCount) + ')');
153 >    exts := ConManager.Connection[FConnectionID].GetExtensionsList(EF_ExtCount);
154 >    for i := 0 to exts.Count - 1 do
155        if Length(FAllowedExts) > 0 then
156        begin
157 <        if Pos(MidStr(exts[i],1,4), FAllowedExts) > 0 then
158 <        begin
159 <          combo_extension.Items.Add(exts[i]);
160 <        end;
161 <      end else
194 <        combo_extension.Items.Add(exts[i]);
157 >        if Pos(MidStr(exts.Strings[i],1,4), FAllowedExts) > 0 then
158 >          combo_extension.Items.Add(exts.Strings[i]);
159 >      end
160 >      else
161 >        combo_extension.Items.Add(exts.Strings[i]);
162      combo_extension.ItemIndex := 0;
163      combo_extensionClick(Self);
164 +    exts.Free;
165    end;
166   end;
167  
# Line 205 | Line 173 | var
173    Extension: String;
174    no_zero_bytes: Boolean;
175    pattern: String;
176 <  files: TStringArray;
177 <  i: LongWord;
176 >  files: TStrings;
177 >  i: Integer;
178   begin
179 <  if FConnection <> nil then
179 >  if FConnectionID > -1 then
180    begin
181      Extension := MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex], 1, 4);
182      no_zero_bytes := not check_zerobyte.Checked;
# Line 221 | Line 189 | begin
189        else
190          Extension := '';
191  
192 <    files := FConnection.GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
192 >    files := ConManager.Connection[FConnectionID].GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
193  
194      filelist.Visible := False;
195      filelist.Items.Clear;
196 <    if Length(files) > 0 then
197 <      for i := 0 to High(files) do
230 <        filelist.Items.Add(files[i]);
196 >    if files.Count > 0 then
197 >      filelist.Items.AddStrings(files);
198      filelist.Visible := True;
199    end;
200   end;
# Line 238 | Line 205 | var
205    id: Integer;
206    ext: String;
207   begin
208 <  id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
208 >  id := ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]);
209    ext := RightStr(filelist.Items.Strings[filelist.ItemIndex], 4);
210    exportd.Filter := 'Files of matching extension (*.' + ext + ')|*.' + ext + '|All files|*.*';
211    exportd.DefaultExt := ext;
212    if exportd.Execute then
213 <    ExportDatFile(FConnection, id, exportd.FileName);
213 >    ExportDatFile(FConnectionID, id, exportd.FileName);
214   end;
215  
216   procedure TForm_ToolTemplate.popup_importClick(Sender: TObject);
# Line 251 | Line 218 | var
218    id: Integer;
219    finfo: TFileInfo;
220    fs: TFileStream;
254  data: TData;
221   begin
222 <  id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
223 <  finfo := FConnection.GetFileInfo(id);
222 >  id := ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]);
223 >  finfo := ConManager.Connection[FConnectionID].GetFileInfo(id);
224  
225    importd.Filter := 'Files of matching extension (*.' + finfo.Extension + ')|*.' +
226          finfo.Extension + '|All files|*.*';
# Line 267 | Line 233 | begin
233          'Size of file in .dat: ' + FormatFileSize(finfo.Size) + CrLf +
234          'Size of chosen file: ' + FormatFileSize(fs.Size))
235      else begin
236 <      SetLength(data, fs.Size);
271 <      fs.Read(data[0], fs.Size);
272 <      FConnection.UpdateDatFile(id, data);
236 >      ConManager.Connection[FConnectionID].UpdateDatFile(id, fs);
237        Self.listClick(Self);
238      end;
239      fs.Free;
# Line 282 | Line 246 | var
246    id: Integer;
247   begin
248    sender_name := TComponent(Sender).Name;
249 <  id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
249 >  id := ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]);
250    context := MidStr(sender_name, Pos('_', sender_name) + 1, Length(sender_name) - Pos('_', sender_name));
251 <  Form_Main.open_child(context, FConnection, id);
251 >  Form_Main.open_child(context, FConnectionID, id);
252   end;
253  
254   procedure TForm_ToolTemplate.combo_connectionChange(Sender: TObject);
# Line 294 | Line 258 | var
258    i: Integer;
259   begin
260    if combo_connection.ItemIndex >= 0 then
261 <  begin
262 <    name := combo_connection.Items.Strings[combo_connection.ItemIndex];
263 <    nstart := Pos(' ', name) + 1;
264 <    nend := Pos('(', name) - 1;
265 <    name := MidStr(name, nstart, nend - nstart);
266 <
303 <    for i := 0 to High(DataConnections) do
304 <    begin
305 <      if ExtractFileName(DataConnections[i].FileName) = name then
306 <      begin
307 <        FConnection := DataConnections[i];
308 <        Break;
309 <      end;
310 <    end;
311 <    if i = Length(DataConnections) then
312 <      FConnection := nil;
313 <
314 <    RecreateExtList;
315 <    if Assigned(FOnNewConnection) then
316 <      FOnNewConnection(FConnection);
317 <  end;
261 >    FConnectionID := combo_connection.ItemIndex
262 >  else
263 >    FConnectionID := -1;
264 >  RecreateExtList;
265 >  if Assigned(FOnNewConnection) then
266 >    FOnNewConnection(FConnectionID);
267   end;
268  
269   procedure TForm_ToolTemplate.combo_extensionClick(Sender: TObject);
# Line 329 | Line 278 | var
278    item: TMenuItem;
279   begin
280    inherited;
281 <  RecreateList;
282 <  FSelectedFile := GetEmptyFileInfo;
281 >  Self.Width  := 260;
282 >  Self.Height := 300;
283 >  FAllowedExts := '';
284 >  FAllowMultiSelect := False;
285 >  FOnNewFileSelected := nil;
286 >  FOnNewConnection := nil;
287 >  FOnCheckCloseable := nil;
288 >  FConnectionID := -1;
289 >  FSelectedFile.ID := -1;
290 >  UpdateConList;
291    if Length(ToolList) > 0 then
292    begin
293      for i := 0 to High(ToolList) do
# Line 367 | Line 324 | end;
324   procedure TForm_ToolTemplate.btn_sortClick(Sender: TObject);
325   begin
326    if btn_sort_id_asc.Down then
327 <    FSortBy := stIDAsc
327 >    FSortBy := ST_IDAsc
328    else if btn_sort_id_desc.Down then
329 <    FSortBy := stIDDesc
329 >    FSortBy := ST_IDDesc
330    else if btn_sort_name_asc.Down then
331 <    FSortBy := stNameAsc
331 >    FSortBy := ST_NameAsc
332    else if btn_sort_name_desc.Down then
333 <    FSortBy := stNameDesc
333 >    FSortBy := ST_NameDesc
334    else if btn_sort_ext_asc.Down then
335 <    FSortBy := stExtAsc
335 >    FSortBy := ST_ExtAsc
336    else if btn_sort_ext_desc.Down then
337 <    FSortBy := stExtDesc;
337 >    FSortBy := ST_ExtDesc;
338    LoadFileNames;
339   end;
340  
# Line 393 | Line 350 | var
350   begin
351    if filelist.ItemIndex > -1 then
352    begin
353 <    fileid := FConnection.ExtractFileID(
353 >    fileid := ConManager.Connection[FConnectionID].ExtractFileIDOfName(
354            filelist.Items.Strings[filelist.ItemIndex]);
355 <    FSelectedFile := FConnection.GetFileInfo(fileid);
355 >    FSelectedFile := ConManager.Connection[FConnectionID].GetFileInfo(fileid);
356      if Assigned(FOnNewFileSelected) then
357        FOnNewFileSelected(FSelectedFile);
358    end;
# Line 414 | Line 371 | end;
371  
372  
373  
374 < procedure TForm_ToolTemplate.SelectFileID(connection: TOniData; id: Integer);
418 < var
419 <  i: Integer;
420 <  name: String;
421 <  nstart, nend: Integer;
374 > procedure TForm_ToolTemplate.SelectConnection(ConnectionID: Integer);
375   begin
376 <  for i := 0 to combo_connection.Items.Count - 1 do
376 >  if FConnectionID <> ConnectionID then
377    begin
378 <    name := combo_connection.Items.Strings[i];
379 <    nstart := Pos(' ', name) + 1;
427 <    nend := Pos('(', name) - 1;
428 <    name := MidStr(name, nstart, nend - nstart);
429 <
430 <    if ExtractFileName(connection.FileName) = name then
431 <    begin
432 <      combo_connection.ItemIndex := i;
433 <      combo_connectionChange(Self);
434 <    end;
378 >    combo_connection.ItemIndex := ConManager.ConnectionIndexByID[ConnectionID];
379 >    combo_connectionChange(Self);
380    end;
381 + end;
382 +
383 + procedure TForm_ToolTemplate.SelectFileID(ConnectionID, FileID: Integer);
384 + var
385 +  i: Integer;
386 + begin
387 +  if FConnectionID <> ConnectionID then
388 +    SelectConnection(ConnectionID);
389  
390    filelist.ItemIndex := -1;
391    if filelist.Items.Count > 0 then
392      for i := 0 to filelist.Items.Count - 1 do
393 <      if FConnection.ExtractFileID(filelist.Items.Strings[i]) = id then
393 >      if ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[i]) = FileID then
394        begin
395          filelist.ItemIndex := i;
396          Break;
# Line 445 | Line 398 | begin
398    Self.listClick(Self);
399   end;
400  
401 < procedure TForm_ToolTemplate.SelectFileName(connection: TOniData; filename: String);
401 > procedure TForm_ToolTemplate.SelectFileName(ConnectionID: Integer; filename: String);
402   var
403    i: Integer;
451  name: String;
452  nstart, nend: Integer;
404   begin
405 <  for i := 0 to combo_connection.Items.Count - 1 do
406 <  begin
456 <    name := combo_connection.Items.Strings[i];
457 <    nstart := Pos(' ', name) + 1;
458 <    nend := Pos('(', name) - 1;
459 <    name := MidStr(name, nstart, nend - nstart);
460 <
461 <    if ExtractFileName(connection.FileName) = name then
462 <    begin
463 <      combo_connection.ItemIndex := i;
464 <      combo_connectionChange(Self);
465 <    end;
466 <  end;
405 >  if FConnectionID <> ConnectionID then
406 >    SelectConnection(ConnectionID);
407  
408    filelist.ItemIndex := -1;
409    if filelist.Items.Count > 0 then
# Line 518 | Line 458 | end;
458  
459  
460  
461 < procedure TForm_ToolTemplate.FormCreate(Sender: TObject);
461 > function TForm_ToolTemplate.GetToolCloseable: Boolean;
462   begin
463 <  Self.Width  := 260;
464 <  Self.Height := 300;
465 <  FOnNewFileSelected := nil;
466 <  FOnNewConnection := nil;
527 <  FAllowedExts := '';
528 <  FAllowMultiSelect := False;
463 >  if Assigned(FOnCheckCloseable) then
464 >    Result := FOnCheckCloseable
465 >  else
466 >    Result := True;
467   end;
468  
469   procedure TForm_ToolTemplate.FormActivate(Sender: TObject);

Diff Legend

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