Index: oup/current/Tools/Template.pas
===================================================================
--- oup/current/Tools/Template.pas	(revision 83)
+++ oup/current/Tools/Template.pas	(revision 86)
@@ -10,4 +10,5 @@
 type
   TNewFileSelectedEvent = procedure(fileinfo: TFileInfo) of object;
+  TNewConnectionEvent = procedure(connection: TOniData) of object;
 
   TForm_ToolTemplate = class(TForm)
@@ -36,5 +37,10 @@
     Label1: TLabel;
     Label2: TLabel;
+    Label3: TLabel;
+    combo_connection: TComboBox;
+    Bevel1: TBevel;
     procedure RecreateList;
+    procedure UpdateList;
+    procedure RecreateExtList;
     procedure LoadFileNames;
     procedure SelectFileName(filename: String);
@@ -56,10 +62,13 @@
     procedure btn_sortClick(Sender: TObject);
     procedure FormActivate(Sender: TObject);
+    procedure combo_connectionChange(Sender: TObject);
   private
     FSortBy: TSortType;
     FOnNewFileSelected: TNewFileSelectedEvent;
+    FOnNewConnection: TNewConnectionEvent;
     FAllowedExts: String;
     FAllowMultiSelect: Boolean;
     FSelectedFile: TFileInfo;
+    FConnection: TOniData;
     procedure SetAllowedExts(exts: String);
     procedure SetMultiSelect(allow: Boolean);
@@ -69,7 +78,9 @@
   published
     property OnNewFileSelected: TNewFileSelectedEvent read FOnNewFileSelected write FOnNewFileSelected;
+    property OnNewConnection: TNewConnectionEvent read FOnNewConnection write FOnNewConnection;
     property AllowedExts: String read FAllowedExts write SetAllowedExts;
     property AllowMultiSelect: Boolean read FAllowMultiSelect write SetMultiSelect;
     property SelectedFile: TFileInfo read FSelectedFile;
+    property Connection: TOniData read FConnection;
   end;
 
@@ -83,5 +94,55 @@
 
 
+procedure TForm_ToolTemplate.UpdateList;
+var
+  i: Integer;
+  fn, datatype, boxstring: String;
+  level: Integer;
+  oldcon: String;
+begin
+  oldcon := combo_connection.Items.Strings[combo_connection.ItemIndex];
+  combo_connection.Items.Clear;
+  for i := 0 to High(DataConnections) do
+  begin
+    level := DataConnections[i].LevelInfo.LevelNumber;
+    fn := ExtractFileName(DataConnections[i].FileName);
+    if DataConnections[i].Backend = ODB_Dat then
+      datatype := 'ONI-.dat: '
+    else if DataConnections[i].Backend = ODB_ADB then
+      datatype := 'OUP-DB: '
+    else
+      datatype := 'Unknown: ';
+    boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ')';
+    combo_connection.Items.Add(boxstring);
+    if oldcon = boxstring then
+      combo_connection.ItemIndex := combo_connection.Items.Count - 1;
+  end;
+end;
+
 procedure TForm_ToolTemplate.RecreateList;
+var
+  i: Integer;
+  fn, datatype: String;
+  level: Integer;
+begin
+  combo_connection.Items.Clear;
+  for i := 0 to High(DataConnections) do
+  begin
+    level := DataConnections[i].LevelInfo.LevelNumber;
+    fn := ExtractFileName(DataConnections[i].FileName);
+    if DataConnections[i].Backend = ODB_Dat then
+      datatype := 'ONI-.dat: '
+    else if DataConnections[i].Backend = ODB_ADB then
+      datatype := 'OUP-DB: '
+    else
+      datatype := 'Unknown: ';
+    combo_connection.Items.Add(datatype + fn + ' (Level: ' + IntToStr(level) + ')');
+  end;
+  FConnection := DataConnections[0];
+  combo_connection.ItemIndex := 0;
+  combo_connectionChange(Self);
+end;
+
+procedure TForm_ToolTemplate.RecreateExtList;
 var
   i:    LongWord;
@@ -90,6 +151,6 @@
   combo_extension.Items.Clear;
   combo_extension.Items.Add('_All files_ (' +
-    IntToStr(OniDataConnection.GetFilesCount) + ')');
-  exts := OniDataConnection.GetExtensionsList;
+    IntToStr(FConnection.GetFilesCount) + ')');
+  exts := FConnection.GetExtensionsList;
   for i := 0 to High(exts) do
     if Length(FAllowedExts) > 0 then
@@ -127,5 +188,5 @@
       Extension := '';
 
-  files := OniDataConnection.GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
+  files := FConnection.GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
 
   filelist.Visible := False;
@@ -143,10 +204,10 @@
   ext: String;
 begin
-  id := OniDataConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
+  id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
   ext := RightStr(filelist.Items.Strings[filelist.ItemIndex], 4);
   exportd.Filter := 'Files of matching extension (*.' + ext + ')|*.' + ext + '|All files|*.*';
   exportd.DefaultExt := ext;
   if exportd.Execute then
-    ExportDatFile(id, exportd.FileName);
+    ExportDatFile(FConnection, id, exportd.FileName);
 end;
 
@@ -158,6 +219,6 @@
   data: TData;
 begin
-  id := OniDataConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
-  finfo := OniDataConnection.GetFileInfo(id);
+  id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
+  finfo := FConnection.GetFileInfo(id);
 
   importd.Filter := 'Files of matching extension (*.' + finfo.Extension + ')|*.' +
@@ -174,5 +235,5 @@
       SetLength(data, fs.Size);
       fs.Read(data[0], fs.Size);
-      OniDataConnection.UpdateDatFile(id, data);
+      FConnection.UpdateDatFile(id, data);
       Self.listClick(Self);
     end;
@@ -187,9 +248,39 @@
 begin
   sender_name := TComponent(Sender).Name;
-  id := OniDataConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
+  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);
 end;
 
+procedure TForm_ToolTemplate.combo_connectionChange(Sender: TObject);
+var
+  name: String;
+  nstart, nend: Integer;
+  i: Integer;
+begin
+  if combo_connection.ItemIndex >= 0 then
+  begin
+    name := combo_connection.Items.Strings[combo_connection.ItemIndex];
+    nstart := Pos(' ', name) + 1;
+    nend := Pos('(', name) - 1;
+    name := MidStr(name, nstart, nend - nstart);
+
+    for i := 0 to High(DataConnections) do
+    begin
+      if ExtractFileName(DataConnections[i].FileName) = name then
+      begin
+        FConnection := DataConnections[i];
+        Break;
+      end;
+    end;
+    if i = Length(DataConnections) then
+      FConnection := nil;
+
+    RecreateExtList;
+    if Assigned(FOnNewConnection) then
+      FOnNewConnection(FConnection);
+  end;
+end;
+
 procedure TForm_ToolTemplate.combo_extensionClick(Sender: TObject);
 begin
@@ -205,4 +296,5 @@
   inherited;
   RecreateList;
+  FConnection := nil;
   FSelectedFile.ID := -1;
   FSelectedFile.FileName := '';
@@ -270,7 +362,7 @@
   if filelist.ItemIndex > -1 then
   begin
-    fileid := OniDataConnection.ExtractFileID(
+    fileid := FConnection.ExtractFileID(
           filelist.Items.Strings[filelist.ItemIndex]);
-    FSelectedFile := OniDataConnection.GetFileInfo(fileid);
+    FSelectedFile := FConnection.GetFileInfo(fileid);
     if Assigned(FOnNewFileSelected) then
       FOnNewFileSelected(FSelectedFile);
@@ -298,5 +390,5 @@
   if filelist.Items.Count > 0 then
     for i := 0 to filelist.Items.Count - 1 do
-      if OniDataConnection.ExtractFileID(filelist.Items.Strings[i]) = id then
+      if FConnection.ExtractFileID(filelist.Items.Strings[i]) = id then
       begin
         filelist.ItemIndex := i;
@@ -321,5 +413,5 @@
 begin
   FAllowedExts := exts;
-  RecreateList;
+  RecreateExtList;
 end;
 
@@ -368,4 +460,5 @@
   Self.Height := 300;
   FOnNewFileSelected := nil;
+  FOnNewConnection := nil;
   FAllowedExts := '';
   FAllowMultiSelect := False;
