Index: oup/current/Main.pas
===================================================================
--- oup/current/Main.pas	(revision 43)
+++ oup/current/Main.pas	(revision 45)
@@ -7,8 +7,8 @@
   Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus, Grids,
   MPHexEditor, ToolWin, ImgList, Tabs,
-  Code_Functions, Data, Code_DataStructures,
-  Helper_LevelDB, Code_Exporters, Settings,
-  Tool_Preview, Tool_TxmpReplace, Tool_BinEdit, Tool_Extractor, Tool_RawEdit,
-  Code_OniDataClass, MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI;
+  MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI,
+  Code_Functions, Data, Code_DataStructures, Code_OniDataClass,
+  Helper_LevelDB, Code_Exporters, Settings, Tool_Template,
+  Tool_BinEdit, Tool_Extractor, Tool_Preview, Tool_RawEdit, Tool_TxmpReplace;
 
 type
@@ -77,5 +77,5 @@
     procedure menu_windows_nextClick(Sender: TObject);
     procedure menu_windows_tileClick(Sender: TObject);
-    function open_child(window_context: String): Boolean;
+    function open_child(window_context: String; fileid: Integer): Boolean;
     procedure menu_windows_closeallClick(Sender: TObject);
     procedure menu_windows_cascadeClick(Sender: TObject);
@@ -305,12 +305,14 @@
       ext := ExtractFileExt(opend.FileName);
       if ext = '.dat' then
+      begin
         if not CreateDataConnection(opend.FileName, ODB_Dat) then
           ShowMessage('Error while loading the file:' + CrLf + opend.FileName +
-            CrLf + 'Perhaps not an Oni-.dat-file?')
-      else if ext = '.oldb' then
+            CrLf + 'Perhaps not an Oni-.dat-file?');
+      end else if ext = '.oldb' then
+      begin
         if not CreateDataConnection(opend.FileName, ODB_ADB) then
           ShowMessage('Error while loading the file:' + CrLf + opend.FileName +
-            CrLf + 'Perhaps not an OniUnPacker-LevelDatabase-file?')
-      else
+            CrLf + 'Perhaps not an OniUnPacker-LevelDatabase-file?');
+      end else
         ShowMessage('Incompatible file');
       AppSettings.DatPath := ExtractFilepath(opend.FileName);
@@ -394,5 +396,5 @@
 procedure TForm_Main.menu_previewClick(Sender: TObject);
 begin
-  open_child('preview');
+  open_child('preview', -1);
 end;
 
@@ -400,5 +402,5 @@
 procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
 begin
-  open_child('txmpreplace');
+  open_child('txmpreplace', -1);
 end;
 
@@ -406,5 +408,5 @@
 procedure TForm_Main.menu_bineditClick(Sender: TObject);
 begin
-  open_child('binedit');
+  open_child('binedit', -1);
 end;
 
@@ -412,5 +414,5 @@
 procedure TForm_Main.menu_raweditClick(Sender: TObject);
 begin
-  open_child('rawedit');
+  open_child('rawedit', -1);
 end;
 
@@ -418,5 +420,5 @@
 procedure TForm_Main.menu_extractorClick(Sender: TObject);
 begin
-  open_child('extractor');
+  open_child('extractor', -1);
 end;
 
@@ -424,5 +426,5 @@
 procedure TForm_Main.menu_filecompareClick(Sender: TObject);
 begin
-  open_child('compare');
+  open_child('compare', -1);
 end;
 
@@ -515,7 +517,7 @@
 
 
-function TForm_Main.open_child(window_context: String): Boolean;
+function TForm_Main.open_child(window_context: String; fileid: Integer): Boolean;
 var
-  form:    TCustomForm;
+  toolform: TForm_ToolTemplate;
   i:       Integer;
   tag:     Integer;
@@ -534,38 +536,37 @@
   if window_context = 'binedit' then
   begin
-    form      := TForm_BinEdit.Create(Application);
-    TForm_BinEdit(form).Recreatelist;
-    form.Caption := 'Binary .dat-Editor ' + IntToStr(tag);
-    iconindex := 0;
+    toolform         := TForm_BinEdit.Create(Self);
+    toolform.Caption := 'Binary .dat-Editor ' + IntToStr(tag);
+    iconindex        := 0;
+  end;
+  if window_context = 'extractor' then
+  begin
+    toolform         := TForm_Extractor.Create(Self);
+    toolform.Caption := 'Extractor ' + IntToStr(tag);
+  end;
+  if window_context = 'preview' then
+  begin
+    toolform         := TForm_Preview.Create(Self);
+    toolform.Caption := 'Preview-Window ' + IntToStr(tag);
   end;
   if window_context = 'rawedit' then
   begin
-    form      := TForm_RawEdit.Create(Application);
-    TForm_RawEdit(form).Recreatelist;
-    form.Caption := 'Binary .raw-Editor ' + IntToStr(tag);
-  end;
-  if window_context = 'preview' then
-  begin
-    form      := TForm_Preview.Create(Application);
-    TForm_Preview(form).Recreatelist;
-    form.Caption := 'Preview-Window ' + IntToStr(tag);
+    toolform         := TForm_RawEdit.Create(Self);
+    toolform.Caption := 'Binary .raw-Editor ' + IntToStr(tag);
   end;
   if window_context = 'txmpreplace' then
   begin
-    form      := TForm_TxmpReplace.Create(Application);
-    TForm_TxmpReplace(form).Recreatelist;
-    form.Caption := 'TXMP Replacer ' + IntToStr(tag);
-  end;
-  if window_context = 'extractor' then
-  begin
-    form      := TForm_Extractor.Create(Application);
-    TForm_Extractor(form).Recreatelist;
-    form.Caption := 'Extractor ' + IntToStr(tag);
-  end;
-
-  form.Name := window_context + IntToStr(tag);
-  form.Tag  := tag;
-
-  MDITab.AddTab(TForm(form), iconindex);
+    toolform         := TForm_TxmpReplace.Create(Application);
+    toolform.Caption := 'TXMP Replacer ' + IntToStr(tag);
+  end;
+
+  if Assigned(toolform) then
+  begin
+    toolform.Name    := window_context + IntToStr(tag);
+    toolform.Tag     := tag;
+    MDITab.AddTab(TForm(toolform), iconindex);
+    if fileid > -1 then
+      toolform.SelectFileID(fileid);
+  end;
 end;
 
