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

Comparing oup/current/Main.pas (file contents):
Revision 109 by alloc, Wed Feb 21 03:12:33 2007 UTC vs.
Revision 224 by alloc, Mon Jun 18 14:49:24 2007 UTC

# Line 6 | Line 6 | uses
6    MPHexEditor, ToolWin, ImgList, Tabs,
7    MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, OneInst,
8    Data, TypeDefs, ConnectionManager,
9 < //  Functions, Exporters, DataStructures,
10 <  Functions,
11 <  Settings, {Helper_LevelDB, }
12 <  Template,
13 <  RawEdit, BinEdit, Extractor, Preview, TxmpReplace;
9 >  Functions, Settings,
10 >  RawEdit, BinEdit, Extractor, Preview, TxmpReplace,
11 >  _BaseTemplate, _TemplateFile, _TemplateFileList;
12  
13   type
14    TForm_Main = class(TForm)
# Line 110 | Line 108 | type
108      procedure menu_txmpreplaceClick(Sender: TObject);
109      procedure menu_previewClick(Sender: TObject);
110      procedure menu_metaClick(Sender: TObject);
113    function open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate;
111  
112      procedure menu_windows_cascadeClick(Sender: TObject);
113      procedure menu_windows_tilevertClick(Sender: TObject);
# Line 129 | Line 126 | type
126      procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
127    private
128    public
129 +    function open_child(window_context: String; Connection, FileID: Integer): TForm_BaseTemplate; overload;
130 +    function open_child(window_context: String; Connection: Integer): TForm_BaseTemplate; overload;
131 +    function open_child(window_context: String): TForm_BaseTemplate; overload;
132      procedure DefaultHandler(var Message); override;
133    end;
134  
# Line 137 | Line 137 | var
137  
138   implementation
139  
140 + uses
141 +  LevelDB, MetaEditor;
142 +
143   {$R *.dfm}
144  
145  
# Line 167 | Line 170 | end;
170   function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean;
171   var
172    i: Integer;
173 <  toolform: TForm_ToolTemplate;
173 >  toolform: TForm_BaseTemplate;
174   begin
175 +  Result := True;
176    if MDITab.MDIChildCount > 0 then
177    begin
178      for i := 0 to MDITab.MDIChildCount - 1 do
179      begin
180 <      if MDITab.MDIChildren[i] is TForm_ToolTemplate then
180 >      if MDITab.MDIChildren[i] is TForm_BaseTemplate then
181        begin
182 <        toolform := TForm_ToolTemplate(MDITab.MDIChildren[i]);
182 >        toolform := TForm_BaseTemplate(MDITab.MDIChildren[i]);
183          if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then
184          begin
185            if not toolform.Closeable then
186 <            ShowMessage('Can not close toolwindow: ' + toolform.Caption);
186 >          begin
187 >            ShowMessage('Can not close toolwindow: ' + toolform.Caption);
188 >            Result := False;
189 >          end;
190          end;
191        end;
192      end;
# Line 234 | Line 241 | end;
241  
242  
243   procedure TForm_Main.FormCreate(Sender: TObject);
237 var
238  RepMsg: TStatusMessages;
244   begin
245    Self.Caption := 'Oni Un/Packer ' + version;
246    Self.FormResize(Self);
# Line 252 | Line 257 | begin
257    end
258    else
259    begin
260 +    ShowMessage('Warning!' + #13#10 +
261 +                'It seems like this is the first time you OUP.' + #13#10 +
262 +                'I do not take any responsibility for messed up data files' + #13+#10 +
263 +                'Do not forget to make backup copies of your *.dat/*.raw/*.sep files!');
264      AppSettings.DatPath        := ExtractFilepath(Application.EXEname);
265      AppSettings.ExtractPath    := ExtractFilepath(Application.EXEname) + '\extract';
257    AppSettings.FilenumbersAsHex := False;
266      AppSettings.CharSet        := DEFAULT_CHARSET;
267      AppSettings.HideUnusedData := False;
268    end;
# Line 317 | Line 325 | var
325    pt: TPoint;
326    tabIndex: Integer;
327    hint: String;
328 <  tool: TForm_ToolTemplate;
328 >  tool: TForm_BaseTemplate;
329   begin
330    pt.X := X;
331    pt.Y := Y;
# Line 326 | Line 334 | begin
334  
335    if tabIndex >= 0 then
336    begin
337 <    if MDITab.MDIChildren[tabIndex] is TForm_ToolTemplate then
337 >    if MDITab.MDIChildren[tabIndex] is TForm_BaseTemplate then
338      begin
339 <      tool := TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]);
339 >      tool := TForm_BaseTemplate(MDITab.MDIChildren[tabIndex]);
340        if tool.ConnectionID > -1 then
341          hint := 'Connection: ' +
342 <              ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) + #13+#10
342 >              ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName)
343        else
344 <        hint := 'Connection: none' + #13+#10;
345 <      if tool.SelectedFile.ID > -1 then
346 <        hint := hint + 'Selected File: ' +
347 <              FormatNumber(tool.SelectedFile.ID, 5, '0') + '-' +
348 <              tool.SelectedFile.Name + '.' +
349 <              tool.SelectedFile.Extension
350 <      else
351 <        hint := hint + 'Selected File: none';
344 >        hint := 'Connection: none';
345 >      if tool is TForm_TemplateFile then
346 >      begin
347 >        if TForm_TemplateFile(tool).SelectedFile.ID > -1 then
348 >          hint := hint + #13+#10 + 'Selected File: ' +
349 >                FormatNumber(TForm_TemplateFile(tool).SelectedFile.ID, 5, '0') + '-' +
350 >                TForm_TemplateFile(tool).SelectedFile.Name + '.' +
351 >                TForm_TemplateFile(tool).SelectedFile.Extension
352 >        else
353 >          hint := hint + #13+#10 + 'Selected File: none';
354 >      end;
355      end
356      else
357        hint := 'Window: ' + MDITab.MDIChildren[tabIndex].Caption;
# Line 409 | Line 420 | begin
420    tb_rawedit.Enabled := active;
421    tb_txmpreplacer.Enabled := active;
422    tb_extractor.Enabled := active;
423 +  tb_meta.Enabled := active;
424   //  tb_compare.Enabled := active;
425   //  tb_structure.Enabled := active;
426   end;
# Line 441 | Line 453 | var
453    position: TTBDockPosition;
454    mode: TTBItemDisplayMode;
455    i: Integer;
444  isEnabled: Boolean;
456   begin
457    toolbar := TTBToolbar(Sender);
458    if toolbar.Floating then
# Line 475 | Line 486 | var
486   begin
487    if MDITab.MDIChildCount > 0 then
488      for i := 0 to MDITab.MDIChildCount - 1 do
489 <      if MDITab.MDIChildren[i] is TForm_ToolTemplate then
490 <        TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList;
489 >      if MDITab.MDIChildren[i] is TForm_BaseTemplate then
490 >        TForm_BaseTemplate(MDITab.MDIChildren[i]).UpdateConList;
491  
492    menu_conns.Clear;
493    if ConManager.Count > 0 then
# Line 547 | Line 558 | end;
558   {####################################}
559   procedure TForm_Main.menu_createdbClick(Sender: TObject);
560   begin
550  ShowMessage('Not yet usable');
551 {
561    opend.Filter     := 'Oni-Dat-Files|*.dat';
562    saved.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb';
563    saved.DefaultExt := 'oldb';
564    if opend.Execute then
565      if saved.Execute then
566        Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
558 }
567   end;
568  
569  
570   procedure TForm_Main.menu_createlvlClick(Sender: TObject);
571   begin
564  ShowMessage('Not yet usable');
565 {
572    opend.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb';
573    saved.Filter     := 'Oni-Dat-Files|*.dat';
574    saved.DefaultExt := 'dat';
575    if opend.Execute then
576      if saved.Execute then
577        Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
572 }
578   end;
579  
580  
# Line 578 | Line 583 | end;
583   {#################################}
584   procedure TForm_Main.menu_previewClick(Sender: TObject);
585   begin
586 <  open_child('preview', -1, -1);
586 >  open_child('preview');
587   end;
588  
589   procedure TForm_Main.menu_bineditClick(Sender: TObject);
590   begin
591 <  open_child('binedit', -1, -1);
591 >  open_child('binedit');
592   end;
593  
594   procedure TForm_Main.menu_raweditClick(Sender: TObject);
595   begin
596 <  open_child('rawedit', -1, -1);
596 >  open_child('rawedit');
597   end;
598  
599   procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
600   begin
601 <  open_child('txmpreplace', -1, -1);
601 >  open_child('txmpreplace');
602   end;
603  
604   procedure TForm_Main.menu_extractorClick(Sender: TObject);
605   begin
606 <  open_child('extractor', -1, -1);
606 >  open_child('extractor');
607   end;
608  
609   procedure TForm_Main.menu_metaClick(Sender: TObject);
610   begin
611 <  ShowMessage('TBD');
611 >  open_child('meta');
612   end;
613  
614   procedure TForm_Main.menu_filecompareClick(Sender: TObject);
615   begin
616 <  open_child('compare', -1, -1);
616 >  open_child('compare');
617   end;
618  
619  
# Line 674 | Line 679 | end;
679   procedure TForm_Main.menu_conns_itemClick(Sender: TObject);
680   var
681    name: String;
677  i: Integer;
682    index: Integer;
683    RepMsg: TStatusMessages;
684   begin
681 //  name := TTBItem(Sender).Caption;
685    index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender));
686    name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName);
687    if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+
# Line 725 | Line 728 | end;
728  
729  
730  
731 < function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate;
731 > function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_BaseTemplate;
732 > type
733 >  TTemplate = class of TForm_BaseTemplate;
734 >  TTool = record
735 >      name: String;
736 >      icon: Integer;
737 >      caption: String;
738 >      classt: TTemplate;
739 >  end;
740 > const
741 >  Tools: array[0..5] of TTool = (
742 >    (name: 'binedit';     icon: 5; caption: 'Binary .dat-Editor'; classt: TForm_BinEdit),
743 >    (name: 'extractor';   icon: 8; caption: 'Extractor';          classt: TForm_Extractor),
744 >    (name: 'preview';     icon: 4; caption: 'Preview-Window';     classt: TForm_Preview),
745 >    (name: 'rawedit';     icon: 6; caption: 'Binary .raw-Editor'; classt: TForm_RawEdit),
746 >    (name: 'txmpreplace'; icon: 7; caption: 'TXMP Replacer';      classt: TForm_TxmpReplace),
747 >    (name: 'meta'; icon: 11; caption: 'MetaEditor'; classt: TForm_Meta)
748 >  );
749   var
750 <  toolform:    TForm_ToolTemplate;
750 >  toolform:    TForm_BaseTemplate;
751    i:           Integer;
752    tag:         Integer;
733  caption_end: String;
753    iconindex:   Integer;
754   begin
755    Result := nil;
# Line 742 | Line 761 | begin
761          tag := MDIChildren[i].Tag + 1;
762  
763    iconindex := -1;
745  caption_end := IntToStr(tag) + '       ';
764  
765 <  if window_context = 'binedit' then
766 <  begin
767 <    toolform         := TForm_BinEdit.Create(Self);
768 <    toolform.Caption := 'Binary .dat-Editor ' + caption_end;
769 <    iconindex        := 5;
770 <  end;
771 <  if window_context = 'extractor' then
772 <  begin
773 <    toolform         := TForm_Extractor.Create(Self);
774 <    toolform.Caption := 'Extractor ' + caption_end;
775 <    iconindex        := 8;
776 <  end;
759 <  if window_context = 'preview' then
760 <  begin
761 <    toolform         := TForm_Preview.Create(Self);
762 <    toolform.Caption := 'Preview-Window ' + caption_end;
763 <    iconindex        := 4;
764 <  end;
765 <  if window_context = 'rawedit' then
766 <  begin
767 <    toolform         := TForm_RawEdit.Create(Self);
768 <    toolform.Caption := 'Binary .raw-Editor ' + caption_end;
769 <    iconindex        := 6;
770 <  end;
771 <  if window_context = 'txmpreplace' then
772 <  begin
773 <    toolform         := TForm_TxmpReplace.Create(Self);
774 <    toolform.Caption := 'TXMP Replacer ' + caption_end;
775 <    iconindex        := 7;
765 >  toolform := nil;
766 >
767 >  for i := 0 to High(Tools) do
768 >    if Tools[i].name = window_context then
769 >      Break;
770 >  if i < Length(Tools) then
771 >  begin
772 >    toolform         := TTemplate(Tools[i].classt).Create(Self);
773 >    toolform.Caption := Tools[i].caption + ' ' + IntToStr(tag) + '       ';
774 >    iconindex        := Tools[i].icon;
775 >  end else begin
776 >    ShowMessage('WindowContext not found!');
777    end;
778  
779    if Assigned(toolform) then
# Line 781 | Line 782 | begin
782      toolform.Tag     := tag;
783      MDITab.AddTab(TForm(toolform), iconindex);
784      toolform.Caption := AnsiReplaceStr(toolform.Caption, '       ', '');
785 <    if connection > -1 then
785 >    if Connection > -1 then
786      begin
787        toolform.SelectConnection(connection);
788 <      if fileid > -1 then
789 <        toolform.SelectFileID(connection, fileid);
788 >      if (FileID > -1) and (toolform is TForm_TemplateFile) then
789 >        TForm_TemplateFile(toolform).SelectFileID(Connection, FileID);
790      end;
791      Result := toolform;
792    end;
793   end;
794  
795 + function TForm_Main.open_child(window_context: String; Connection: Integer): TForm_BaseTemplate;
796 + begin
797 +  open_child(window_context, Connection, -1);
798 + end;
799 +
800 + function TForm_Main.open_child(window_context: String): TForm_BaseTemplate;
801 + begin
802 +  open_child(window_context, -1, -1);
803 + end;
804 +
805   end.

Diff Legend

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