Index: oup/current/Tools/BinEdit.dfm
===================================================================
--- oup/current/Tools/BinEdit.dfm	(revision 87)
+++ oup/current/Tools/BinEdit.dfm	(revision 92)
@@ -4,12 +4,8 @@
   OnCloseQuery = FormCloseQuery
   OnKeyUp = FormKeyUp
+  ExplicitWidth = 500
+  ExplicitHeight = 450
   PixelsPerInch = 96
   TextHeight = 13
-  inherited panel_files: TPanel
-    inherited filelist: TListBox
-      ExplicitTop = 153
-      ExplicitHeight = 270
-    end
-  end
   inherited content: TPanel
     object Splitter2: TSplitter
@@ -93,4 +89,5 @@
       Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goColSizing]
       PopupMenu = value_viewer_context
+      ScrollBars = ssVertical
       TabOrder = 1
       OnDblClick = value_viewerDblClick
@@ -194,4 +191,5 @@
   object value_viewer_context: TPopupMenu [3]
     AutoHotkeys = maManual
+    AutoLineReduction = maManual
     OnPopup = value_viewer_contextPopup
     Left = 280
Index: oup/current/Tools/BinEdit.pas
===================================================================
--- oup/current/Tools/BinEdit.pas	(revision 87)
+++ oup/current/Tools/BinEdit.pas	(revision 92)
@@ -32,5 +32,5 @@
     procedure hexChange(Sender: TObject);
 
-    procedure LoadDat(_fileid: LongWord);
+    procedure LoadDat(_fileid: Integer);
     function Save: Boolean;
     function GetValue(datatype: Word; offset: LongWord): String;
@@ -57,4 +57,5 @@
     procedure value_viewer_contextPopup(Sender: TObject);
   private
+    con: TOniData;
     fileid: Integer;
   public
@@ -93,4 +94,5 @@
   value_viewer.RowCount := 8;
   value_viewer.FixedRows := 1;
+  value_viewer.FixedCols := 1;
   value_viewer.Cells[0, 0] := 'Type';
   value_viewer.Cells[1, 0] := 'Value';
@@ -102,6 +104,6 @@
   value_viewer.Cells[0, 6] := 'String';
   value_viewer.Cells[0, 7] := 'Selected length';
-//  value_viewer.ColWidths[0] := 100;
-//  value_viewer.ColWidths[1] := value_viewer.Width - 150;
+  value_viewer.ColWidths[0] := 120;
+  value_viewer.ColWidths[1] := 1000;
 //  hex.Height := content.Height - 215;
   //
@@ -135,34 +137,48 @@
 
 
-procedure TForm_BinEdit.LoadDat(_fileid: LongWord);
+procedure TForm_BinEdit.LoadDat(_fileid: Integer);
 var
   mem:  TMemoryStream;
   Data: Tdata;
 begin
-  if hex.Modified then
-  begin
-    if not Save then
-    begin
-      Self.SelectFileID(fileid);
-      Exit;
-    end;
-  end;
-  fileid := _fileid;
-  if OniDataConnection.ExtractFileID(
-        filelist.Items.Strings[filelist.ItemIndex]) <> fileid then
-    Self.SelectFileID(fileid);
-  Self.ClearStructViewer;
-  Data := OniDataConnection.LoadDatFile(fileid);
-  if Length(Data) > 0 then
-  begin
-    mem := TMemoryStream.Create;
-    mem.Write(Data[0], Length(Data));
-    mem.Seek(0, soFromBeginning);
-    hex.LoadFromStream(mem);
-    mem.Free;
-    WriteStructureInfos;
+  if con <> nil then
+  begin
+    if hex.Modified then
+    begin
+      if not Save then
+      begin
+        Self.SelectFileID(Connection, fileid);
+        Exit;
+      end;
+    end;
+  end;
+  if _fileid >= 0 then
+  begin
+    fileid := _fileid;
+    con := Connection;
+    if con.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]) <> fileid then
+      Self.SelectFileID(Connection, fileid);
+    Self.ClearStructViewer;
+    Data := con.LoadDatFile(fileid);
+    if Length(Data) > 0 then
+    begin
+      mem := TMemoryStream.Create;
+      mem.Write(Data[0], Length(Data));
+      mem.Seek(0, soFromBeginning);
+      hex.LoadFromStream(mem);
+      mem.Free;
+      WriteStructureInfos;
+    end
+    else
+    begin
+      ClearValues;
+      hex.DataSize := 0;
+    end;
   end
   else
   begin
+    fileid := _fileid;
+    con := nil;
+    Self.ClearStructViewer;
     ClearValues;
     hex.DataSize := 0;
@@ -226,5 +242,5 @@
       Result := IntToBin(hex.Data[offset]);
     11:
-      Result := '0x' + IntToHex(OniDataConnection.GetRawInfo(fileid, offset).raw_addr, 8);
+      Result := '0x' + IntToHex(con.GetRawInfo(fileid, offset).raw_addr, 8);
     12:
       Result := FormatNumber(hex.Data[offset + 1] + hex.Data[offset + 2] * 256 +
@@ -291,5 +307,5 @@
   if VST.RootNodeCount = 0 then
   begin
-    structs := LoadStructureDefinition(Connection, fileid);
+    structs := LoadStructureDefinition(con, fileid);
     if structs.Data then
     begin
@@ -501,5 +517,5 @@
 begin
   case MessageBox(Self.Handle, PChar('Save changes to file ' +
-      OniDataConnection.GetFileInfo(fileid).FileName + '?'), PChar('Data changed...'),
+      con.GetFileInfo(fileid).FileName + '?'), PChar('Data changed...'),
       MB_YESNOCANCEL) of
     idYes:
@@ -511,5 +527,5 @@
       mem.Read(Data[0], mem.Size);
       mem.Free;
-      OniDataConnection.UpdateDatFile(fileid, Data);
+      con.UpdateDatFile(fileid, Data);
       hex.Modified := False;
       for i := 0 to hex.Datasize - 1 do
@@ -762,15 +778,15 @@
       if nodedata.DataType = 11 then
       begin
-        if OniDataConnection.GetRawInfo(fileid, nodedata.offset).raw_size > 0 then
-          Form_Main.open_child('rawedit', fileid);
+        if con.GetRawInfo(fileid, nodedata.offset).raw_size > 0 then
+          Form_Main.open_child('rawedit', Connection, fileid);
       end;
       if nodedata.DataType = 12 then
       begin
-        if (StrToInt(nodedata.Value) < OniDataConnection.GetFilesCount) and
+        if (StrToInt(nodedata.Value) < con.GetFilesCount) and
           (StrToInt(nodedata.Value) > 0) and
           (StrToInt(nodedata.Value) <> fileid) then
         begin
-          if OniDataConnection.GetFileInfo(StrToInt(nodedata.Value)).Size > 0 then
-            Form_Main.open_child('binedit', StrToInt(nodedata.Value))
+          if con.GetFileInfo(StrToInt(nodedata.Value)).Size > 0 then
+            Form_Main.open_child('binedit', Connection, StrToInt(nodedata.Value))
           else
             ShowMessage('Linked filed is a zero-byte-file');
@@ -779,5 +795,5 @@
       if (nodedata.DataType >= 100) and (nodedata.DataType <= 300) then
       begin
-        form := Form_Main.open_child('binedit', -1);
+        form := Form_Main.open_child('binedit', Connection, -1);
         if Assigned(form) then
           form.SetFileFilters(nodedata.Value, '', False);
Index: oup/current/Tools/Extractor.dfm
===================================================================
--- oup/current/Tools/Extractor.dfm	(revision 87)
+++ oup/current/Tools/Extractor.dfm	(revision 92)
@@ -22,5 +22,4 @@
       Width = 333
       Height = 338
-      ExplicitTop = 153
       ExplicitWidth = 333
       ExplicitHeight = 338
@@ -29,4 +28,8 @@
       Width = 333
       ExplicitWidth = 333
+      inherited Bevel1: TBevel
+        Width = 327
+        ExplicitWidth = 327
+      end
       inherited combo_extension: TComboBox
         Width = 325
@@ -39,4 +42,8 @@
         Width = 325
         ExplicitWidth = 325
+      end
+      inherited combo_connection: TComboBox
+        Width = 263
+        ExplicitWidth = 263
       end
     end
Index: oup/current/Tools/Extractor.pas
===================================================================
--- oup/current/Tools/Extractor.pas	(revision 87)
+++ oup/current/Tools/Extractor.pas	(revision 92)
@@ -105,5 +105,5 @@
     if (selonly and filelist.Selected[i]) or not selonly then
     begin
-      fileid := OniDataConnection.ExtractFileID(filelist.Items.Strings[i]);
+      fileid := Connection.ExtractFileID(filelist.Items.Strings[i]);
       filename := GetWinFilename(filelist.Items.Strings[i]);
       if check_dat.Checked then
Index: oup/current/Tools/RawEdit.dfm
===================================================================
--- oup/current/Tools/RawEdit.dfm	(revision 87)
+++ oup/current/Tools/RawEdit.dfm	(revision 92)
@@ -23,6 +23,6 @@
     end
     inherited filelist: TListBox
-      Height = 76
-      ExplicitHeight = 76
+      Height = 52
+      ExplicitHeight = 52
     end
     object panel_imexport: TPanel
@@ -79,5 +79,4 @@
   end
   inherited content: TPanel
-    OnResize = panel_contentResize
     object Splitter2: TSplitter
       Left = 0
@@ -152,4 +151,5 @@
       ParentFont = False
       PopupMenu = value_viewer_context
+      ScrollBars = ssVertical
       TabOrder = 1
       OnDblClick = value_viewerDblClick
Index: oup/current/Tools/RawEdit.pas
===================================================================
--- oup/current/Tools/RawEdit.pas	(revision 87)
+++ oup/current/Tools/RawEdit.pas	(revision 92)
@@ -39,6 +39,4 @@
     procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
 
-    procedure panel_contentResize(Sender: TObject);
-
     function GetValue(datatype: Word; offset: LongWord): String;
     procedure ClearValues;
@@ -58,5 +56,5 @@
     fileid:     Integer;
     dat_offset: LongWord;
-    fileid_opened, dat_offset_opened: LongWord;
+    fileid_opened, dat_offset_opened: Integer;
   public
   end;
@@ -74,20 +72,30 @@
   i: Integer;
 begin
-  if hex.Modified then
-    if not Save then
-      Exit;
-  ClearValues;
-  hex.DataSize := 0;
-  fileid := fileinfo.ID;
-  list_offset.Enabled := False;
-  if fileinfo.size > 0 then
-  begin
-    offsets := OniDataConnection.GetRawList(fileid);
+  if fileinfo.ID >= 0 then
+  begin
+    if hex.Modified then
+      if not Save then
+        Exit;
+    ClearValues;
+    hex.DataSize := 0;
+    fileid := fileinfo.ID;
+    list_offset.Enabled := False;
+    if fileinfo.size > 0 then
+    begin
+      offsets := Connection.GetRawList(fileid);
+      list_offset.Items.Clear;
+      if Length(offsets) > 0 then
+        for i := 0 to High(offsets) do
+          list_offset.Items.Add('0x' + IntToHex(offsets[i].src_offset, 8) +
+                ', ' + IntToStr(offsets[i].raw_size) + ' bytes');
+      list_offset.Enabled := True;
+    end;
+  end
+  else
+  begin
+    ClearValues;
+    hex.DataSize := 0;
+    fileid := -1;
     list_offset.Items.Clear;
-    if Length(offsets) > 0 then
-      for i := 0 to High(offsets) do
-        list_offset.Items.Add('0x' + IntToHex(offsets[i].src_offset, 8) +
-              ', ' + IntToStr(offsets[i].raw_size) + ' bytes');
-    list_offset.Enabled := True;
   end;
 end;
@@ -109,5 +117,5 @@
     for i := 0 to filelist.Count - 1 do
     begin
-      if OniDataConnection.ExtractFileID(filelist.Items.Strings[i]) = raw_info.src_id then
+      if Connection.ExtractFileID(filelist.Items.Strings[i]) = raw_info.src_id then
       begin
         filelist.ItemIndex := i;
@@ -126,5 +134,5 @@
   end;
   SetLength(Data, raw_info.raw_size);
-  OniDataConnection.LoadRawFile(raw_info.src_id, raw_info.src_offset, @Data[0]);
+  Connection.LoadRawFile(raw_info.src_id, raw_info.src_offset, @Data[0]);
   if Length(Data) > 0 then
   begin
@@ -158,5 +166,5 @@
   dat_offset := StrToInt('$' + MidStr(
     list_offset.Items.Strings[list_offset.ItemIndex], 3, 8));
-  LoadRaw(OniDataConnection.GetRawInfo(fileid, dat_offset));
+  LoadRaw(Connection.GetRawInfo(fileid, dat_offset));
 end;
 
@@ -391,4 +399,5 @@
 }
   value_viewer.FixedRows := 1;
+  value_viewer.FixedCols := 1;
   value_viewer.Cells[0, 0] := 'Type';
   value_viewer.Cells[1, 0] := 'Value';
@@ -400,5 +409,6 @@
   value_viewer.Cells[0, 6] := 'String';
   value_viewer.Cells[0, 7] := 'Selected length';
-  value_viewer.ColWidths[0] := 100;
+  value_viewer.ColWidths[0] := 125;
+  value_viewer.ColWidths[1] := 1000;
   //
   value_viewer.Font.Charset := AppSettings.CharSet;
@@ -416,5 +426,5 @@
 begin
   case MessageBox(Self.Handle, PChar('Save changes to .raw-part of file ' +
-      OniDataConnection.GetFileInfo(fileid).FileName + '?'), PChar('Data changed...'),
+      Connection.GetFileInfo(fileid).FileName + '?'), PChar('Data changed...'),
       MB_YESNOCANCEL) of
     idYes:
@@ -426,5 +436,5 @@
       mem.Read(Data[0], mem.Size);
       mem.Free;
-      OniDataConnection.UpdateRawFile(fileid_opened, dat_offset_opened,
+      Connection.UpdateRawFile(fileid_opened, dat_offset_opened,
         Length(Data), @Data[0]);
       hex.Modified := False;
@@ -452,13 +462,4 @@
       CanClose := False;
   end;
-end;
-
-
-
-
-procedure TForm_RawEdit.panel_contentResize(Sender: TObject);
-begin
-  if fileid >= 0 then
-    value_viewer.ColWidths[1] := value_viewer.Width - value_viewer.ColWidths[0] - 50;
 end;
 
@@ -546,8 +547,8 @@
   fs: TFileStream;
 begin
-  saved.Filter     := 'Files of matching extension (*.' + OniDataConnection.GetFileInfo(
-    fileid).Extension + ')|*.' + OniDataConnection.GetFileInfo(fileid).Extension +
+  saved.Filter     := 'Files of matching extension (*.' + Connection.GetFileInfo(
+    fileid).Extension + ')|*.' + Connection.GetFileInfo(fileid).Extension +
     '|All files|*.*';
-  saved.DefaultExt := OniDataConnection.GetFileInfo(fileid).Extension;
+  saved.DefaultExt := Connection.GetFileInfo(fileid).Extension;
   if saved.Execute then
   begin
@@ -566,6 +567,6 @@
   fs:   TFileStream;
 begin
-  opend.Filter := 'Files of matching extension (*.' + OniDataConnection.GetFileInfo(
-    fileid).Extension + ')|*.' + OniDataConnection.GetFileInfo(fileid).Extension +
+  opend.Filter := 'Files of matching extension (*.' + Connection.GetFileInfo(
+    fileid).Extension + ')|*.' + Connection.GetFileInfo(fileid).Extension +
     '|All files|*.*';
   if opend.Execute then
Index: oup/current/Tools/Template.dfm
===================================================================
--- oup/current/Tools/Template.dfm	(revision 87)
+++ oup/current/Tools/Template.dfm	(revision 92)
@@ -52,6 +52,4 @@
       OnClick = listClick
       OnMouseDown = listMouseDown
-      ExplicitTop = 129
-      ExplicitHeight = 294
     end
     object panel_extension: TPanel
Index: oup/current/Tools/Template.pas
===================================================================
--- oup/current/Tools/Template.pas	(revision 87)
+++ oup/current/Tools/Template.pas	(revision 92)
@@ -44,6 +44,6 @@
     procedure RecreateExtList;
     procedure LoadFileNames;
-    procedure SelectFileName(filename: String);
-    procedure SelectFileID(id: Integer);
+    procedure SelectFileName(connection: TOniData; filename: String);
+    procedure SelectFileID(connection: TOniData; id: Integer);
     procedure check_filternameClick(Sender: TObject);
     procedure check_zerobyteClick(Sender: TObject);
@@ -285,5 +285,5 @@
   id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
   context := MidStr(sender_name, Pos('_', sender_name) + 1, Length(sender_name) - Pos('_', sender_name));
-  Form_Main.open_child(context, id);
+  Form_Main.open_child(context, FConnection, id);
 end;
 
@@ -415,8 +415,24 @@
 
 
-procedure TForm_ToolTemplate.SelectFileID(id: Integer);
-var
-  i: Integer;
-begin
+procedure TForm_ToolTemplate.SelectFileID(connection: TOniData; id: Integer);
+var
+  i: Integer;
+  name: String;
+  nstart, nend: Integer;
+begin
+  for i := 0 to combo_connection.Items.Count - 1 do
+  begin
+    name := combo_connection.Items.Strings[i];
+    nstart := Pos(' ', name) + 1;
+    nend := Pos('(', name) - 1;
+    name := MidStr(name, nstart, nend - nstart);
+
+    if ExtractFileName(connection.FileName) = name then
+    begin
+      combo_connection.ItemIndex := i;
+      combo_connectionChange(Self);
+    end;
+  end;
+
   filelist.ItemIndex := -1;
   if filelist.Items.Count > 0 then
@@ -430,8 +446,24 @@
 end;
 
-procedure TForm_ToolTemplate.SelectFileName(filename: String);
-var
-  i: Integer;
-begin
+procedure TForm_ToolTemplate.SelectFileName(connection: TOniData; filename: String);
+var
+  i: Integer;
+  name: String;
+  nstart, nend: Integer;
+begin
+  for i := 0 to combo_connection.Items.Count - 1 do
+  begin
+    name := combo_connection.Items.Strings[i];
+    nstart := Pos(' ', name) + 1;
+    nend := Pos('(', name) - 1;
+    name := MidStr(name, nstart, nend - nstart);
+
+    if ExtractFileName(connection.FileName) = name then
+    begin
+      combo_connection.ItemIndex := i;
+      combo_connectionChange(Self);
+    end;
+  end;
+
   filelist.ItemIndex := -1;
   if filelist.Items.Count > 0 then
Index: oup/current/Tools/TxmpReplace.dfm
===================================================================
--- oup/current/Tools/TxmpReplace.dfm	(revision 87)
+++ oup/current/Tools/TxmpReplace.dfm	(revision 92)
@@ -1,6 +1,4 @@
 inherited Form_TxmpReplace: TForm_TxmpReplace
   Caption = 'TxmpReplace'
-  ExplicitWidth = 320
-  ExplicitHeight = 240
   PixelsPerInch = 96
   TextHeight = 13
@@ -37,5 +35,4 @@
       Height = 146
       Align = alTop
-      ExplicitTop = 153
       ExplicitHeight = 146
     end
Index: oup/current/Tools/TxmpReplace.pas
===================================================================
--- oup/current/Tools/TxmpReplace.pas	(revision 87)
+++ oup/current/Tools/TxmpReplace.pas	(revision 92)
@@ -52,7 +52,7 @@
 begin
   fileid := fileinfo.ID;
-  OniDataConnection.LoadDatFilePart(fileid, $88, SizeOf(fadingbyte), @fadingbyte);
-  OniDataConnection.LoadDatFilePart(fileid, $89, SizeOf(depthbyte), @depthbyte);
-  OniDataConnection.LoadDatFilePart(fileid, $90, SizeOf(storebyte), @storebyte);
+  Connection.LoadDatFilePart(fileid, $88, SizeOf(fadingbyte), @fadingbyte);
+  Connection.LoadDatFilePart(fileid, $89, SizeOf(depthbyte), @depthbyte);
+  Connection.LoadDatFilePart(fileid, $90, SizeOf(storebyte), @storebyte);
   check_fading.Checked := (fadingbyte and $01) > 0;
   check_transparency.Checked := (depthbyte and $04) > 0;
@@ -103,9 +103,9 @@
   if filelist.ItemIndex >= 0 then
   begin
-    OniDataConnection.LoadDatFilePart(fileid, $88, 1, @oldfading);
-    if OniDataConnection.OSisMac then
-      OniDataConnection.UpdateDatFilePart(fileid, $A0, 4, @old_rawaddr)
+    Connection.LoadDatFilePart(fileid, $88, 1, @oldfading);
+    if Connection.OSisMac then
+      Connection.UpdateDatFilePart(fileid, $A0, 4, @old_rawaddr)
     else
-      OniDataConnection.LoadDatFilePart(fileid, $9C, 4, @old_rawaddr);
+      Connection.LoadDatFilePart(fileid, $9C, 4, @old_rawaddr);
 
     if (OniImage_Old.Width <> OniImage_New.Width) or
@@ -138,11 +138,11 @@
     newsize := OniImage_New.GetImageDataSize(check_fading.Checked);
 
-    if (newsize > old_size) and (OniDataConnection.Backend = ODB_Dat) then
-      new_rawaddr := OniDataConnection.AppendRawFile(
-        OniDataConnection.OSisMac, Length(tempd), tempd)
+    if (newsize > old_size) and (Connection.Backend = ODB_Dat) then
+      new_rawaddr := Connection.AppendRawFile(
+        Connection.OSisMac, Length(tempd), tempd)
     else
     begin
       new_rawaddr := old_rawaddr;
-      OniDataConnection.UpdateRawFile(fileid, $9C, Length(tempd), tempd);
+      Connection.UpdateRawFile(fileid, $9C, Length(tempd), tempd);
     end;
 
@@ -150,17 +150,17 @@
     if check_fading.Checked then
       datbyte := datbyte or $01;
-    OniDataConnection.UpdateDatFilePart(fileid, $88, 1, @datbyte);
+    Connection.UpdateDatFilePart(fileid, $88, 1, @datbyte);
     datbyte := $10;
     if check_transparency.Checked then
       datbyte := datbyte or $04;
-    OniDataConnection.UpdateDatFilePart(fileid, $89, 1, @datbyte);
-    OniDataConnection.UpdateDatFilePart(fileid, $8C, 2, @OniImage_New.Width);
-    OniDataConnection.UpdateDatFilePart(fileid, $8E, 2, @OniImage_New.Height);
+    Connection.UpdateDatFilePart(fileid, $89, 1, @datbyte);
+    Connection.UpdateDatFilePart(fileid, $8C, 2, @OniImage_New.Width);
+    Connection.UpdateDatFilePart(fileid, $8E, 2, @OniImage_New.Height);
     datbyte := $08;
-    OniDataConnection.UpdateDatFilePart(fileid, $90, 1, @datbyte);
-    if OniDataConnection.OSisMac then
-      OniDataConnection.UpdateDatFilePart(fileid, $A0, 4, @new_rawaddr)
+    Connection.UpdateDatFilePart(fileid, $90, 1, @datbyte);
+    if Connection.OSisMac then
+      Connection.UpdateDatFilePart(fileid, $A0, 4, @new_rawaddr)
     else
-      OniDataConnection.UpdateDatFilePart(fileid, $9C, 4, @new_rawaddr);
+      Connection.UpdateDatFilePart(fileid, $9C, 4, @new_rawaddr);
 
     ShowMessage('TXMP-image replaced');
