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

Comparing:
oup/rewrite/Main.pas (file contents), Revision 97 by alloc, Mon Jan 22 23:05:45 2007 UTC vs.
oup/current/Main.pas (file contents), Revision 239 by alloc, Sat Jul 14 20:22:05 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 <  Preview;
14 < //  BinEdit, Extractor, RawEdit, TxmpReplace;
9 >  Functions, Settings,
10 >  RawEdit, BinEdit, Extractor, Preview, TxmpReplace,
11 >  _BaseTemplate, _TemplateFile, _TemplateFileList;
12  
13   type
14    TForm_Main = class(TForm)
# Line 47 | Line 44 | type
44      menu_windows_previous: TTBItem;
45      menu_sep2:  TTBSeparatorItem;
46      menu_About: TTBItem;
47 <    Toolbar:    TTBToolbar;
47 >    Toolbar_main: TTBToolbar;
48      tbOpen:     TTBItem;
49      DockLeft:   TTBDock;
50      DockRight:  TTBDock;
# Line 60 | Line 57 | type
57      menu_view_statusbar: TTBItem;
58      menu_view_toolbar: TTBItem;
59      tb_separator1: TTBSeparatorItem;
63    tb_preview: TTBItem;
64    tb_structure: TTBItem;
65    tb_compare: TTBItem;
66    tb_extractor: TTBItem;
67    tb_txmpreplacer: TTBItem;
68    tb_rawedit: TTBItem;
69    tb_datedit: TTBItem;
60      menu_windows_tilevert: TTBItem;
71    tb_meta: TTBItem;
61      menu_meta: TTBItem;
62      TBSeparatorItem1: TTBSeparatorItem;
63      tb_db2dat: TTBItem;
# Line 78 | Line 67 | type
67      Images_Close: TImageList;
68      menu_conns: TTBSubmenuItem;
69      menu_windows: TTBSubmenuItem;
70 +    menu_filemanager: TTBItem;
71 +    Toolbar_tools: TTBToolbar;
72 +    tb_preview: TTBItem;
73 +    tb_datedit: TTBItem;
74 +    tb_rawedit: TTBItem;
75 +    tb_txmpreplacer: TTBItem;
76 +    tb_extractor: TTBItem;
77 +    tb_meta: TTBItem;
78 +    tb_filemanager: TTBItem;
79 +    tb_compare: TTBItem;
80 +    tb_structure: TTBItem;
81 +    menu_view_toolbar_tools: TTBItem;
82      procedure FormClose(Sender: TObject; var Action: TCloseAction);
83      procedure FormResize(Sender: TObject);
84      procedure FormCreate(Sender: TObject);
# Line 92 | Line 93 | type
93        Shift: TShiftState; X, Y: Integer);
94      procedure MDITabMouseMove(Sender: TObject; Shift: TShiftState; X,
95        Y: Integer);
96 <    procedure ToolbarDockChanged(Sender: TObject);
96 >    procedure Toolbar_mainDockChanged(Sender: TObject);
97      procedure CreateConnection(filename: String);
98      function CheckConnectionCloseable(index: Integer): Boolean;
99  
# Line 111 | Line 112 | type
112      procedure menu_txmpreplaceClick(Sender: TObject);
113      procedure menu_previewClick(Sender: TObject);
114      procedure menu_metaClick(Sender: TObject);
114    function open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate;
115  
116      procedure menu_windows_cascadeClick(Sender: TObject);
117      procedure menu_windows_tilevertClick(Sender: TObject);
# Line 128 | Line 128 | type
128      procedure menu_AboutClick(Sender: TObject);
129  
130      procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
131 +    procedure menu_filemanagerClick(Sender: TObject);
132 +    procedure menu_view_toolbar_toolsClick(Sender: TObject);
133    private
134    public
135 +    function open_child(window_context: String; Connection, FileID: Integer): TForm_BaseTemplate; overload;
136 +    function open_child(window_context: String; Connection: Integer): TForm_BaseTemplate; overload;
137 +    function open_child(window_context: String): TForm_BaseTemplate; overload;
138      procedure DefaultHandler(var Message); override;
139    end;
140  
# Line 138 | Line 143 | var
143  
144   implementation
145  
146 + uses
147 +  LevelDB, MetaEditor, FileManager;
148 +
149   {$R *.dfm}
150  
151  
# Line 161 | Line 169 | begin
169    if RepMsg = SM_OK then
170    begin
171      UpdateStatBar;
172 +    UpdateConLists;
173    end;
174   end;
175  
176   function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean;
177   var
178    i: Integer;
179 <  toolform: TForm_ToolTemplate;
179 >  toolform: TForm_BaseTemplate;
180   begin
181 +  Result := True;
182    if MDITab.MDIChildCount > 0 then
183    begin
184      for i := 0 to MDITab.MDIChildCount - 1 do
185      begin
186 <      if MDITab.MDIChildren[i] is TForm_ToolTemplate then
186 >      if MDITab.MDIChildren[i] is TForm_BaseTemplate then
187        begin
188 <        toolform := TForm_ToolTemplate(MDITab.MDIChildren[i]);
188 >        toolform := TForm_BaseTemplate(MDITab.MDIChildren[i]);
189          if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then
190          begin
191            if not toolform.Closeable then
192 <            ShowMessage('Can not close toolwindow: ' + toolform.Caption);
192 >          begin
193 >            ShowMessage('Can not close toolwindow: ' + toolform.Caption);
194 >            Result := False;
195 >          end;
196          end;
197        end;
198      end;
# Line 234 | Line 247 | end;
247  
248  
249   procedure TForm_Main.FormCreate(Sender: TObject);
237 var
238  RepMsg: TStatusMessages;
250   begin
251    Self.Caption := 'Oni Un/Packer ' + version;
252    Self.FormResize(Self);
# Line 252 | Line 263 | begin
263    end
264    else
265    begin
266 +    ShowMessage('Warning!' + #13#10 +
267 +                'It seems like this is the first time you OUP.' + #13#10 +
268 +                'I do not take any responsibility for messed up data files' + #13+#10 +
269 +                'Do not forget to make backup copies of your *.dat/*.raw/*.sep files!');
270      AppSettings.DatPath        := ExtractFilepath(Application.EXEname);
271      AppSettings.ExtractPath    := ExtractFilepath(Application.EXEname) + '\extract';
257    AppSettings.FilenumbersAsHex := False;
272      AppSettings.CharSet        := DEFAULT_CHARSET;
273      AppSettings.HideUnusedData := False;
274    end;
# Line 317 | Line 331 | var
331    pt: TPoint;
332    tabIndex: Integer;
333    hint: String;
334 <  tool: TForm_ToolTemplate;
334 >  tool: TForm_BaseTemplate;
335   begin
336    pt.X := X;
337    pt.Y := Y;
# Line 326 | Line 340 | begin
340  
341    if tabIndex >= 0 then
342    begin
343 <    if MDITab.MDIChildren[tabIndex] is TForm_ToolTemplate then
343 >    if MDITab.MDIChildren[tabIndex] is TForm_BaseTemplate then
344      begin
345 <      tool := TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]);
345 >      tool := TForm_BaseTemplate(MDITab.MDIChildren[tabIndex]);
346        if tool.ConnectionID > -1 then
347          hint := 'Connection: ' +
348 <              ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) + #13+#10
348 >              ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName)
349        else
350 <        hint := 'Connection: none' + #13+#10;
351 <      if tool.SelectedFile.ID > -1 then
352 <        hint := hint + 'Selected File: ' +
353 <              FormatNumber(tool.SelectedFile.ID, 5, '0') + '-' +
354 <              tool.SelectedFile.Name + '.' +
355 <              tool.SelectedFile.Extension
356 <      else
357 <        hint := hint + 'Selected File: none';
350 >        hint := 'Connection: none';
351 >      if tool is TForm_TemplateFile then
352 >      begin
353 >        if TForm_TemplateFile(tool).SelectedFile.ID > -1 then
354 >          hint := hint + #13+#10 + 'Selected File: ' +
355 >                FormatNumber(TForm_TemplateFile(tool).SelectedFile.ID, 5, '0') + '-' +
356 >                TForm_TemplateFile(tool).SelectedFile.Name + '.' +
357 >                TForm_TemplateFile(tool).SelectedFile.Extension
358 >        else
359 >          hint := hint + #13+#10 + 'Selected File: none';
360 >      end;
361      end
362      else
363        hint := 'Window: ' + MDITab.MDIChildren[tabIndex].Caption;
# Line 409 | Line 426 | begin
426    tb_rawedit.Enabled := active;
427    tb_txmpreplacer.Enabled := active;
428    tb_extractor.Enabled := active;
429 +  tb_meta.Enabled := active;
430   //  tb_compare.Enabled := active;
431   //  tb_structure.Enabled := active;
432   end;
# Line 435 | Line 453 | end;
453  
454  
455  
456 < procedure TForm_Main.ToolbarDockChanged(Sender: TObject);
456 > procedure TForm_Main.Toolbar_mainDockChanged(Sender: TObject);
457   var
458    toolbar: TTBToolbar;
459    position: TTBDockPosition;
460    mode: TTBItemDisplayMode;
461    i: Integer;
444  isEnabled: Boolean;
462   begin
463    toolbar := TTBToolbar(Sender);
464    if toolbar.Floating then
# Line 475 | Line 492 | var
492   begin
493    if MDITab.MDIChildCount > 0 then
494      for i := 0 to MDITab.MDIChildCount - 1 do
495 <      if MDITab.MDIChildren[i] is TForm_ToolTemplate then
496 <        TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList;
495 >      if MDITab.MDIChildren[i] is TForm_BaseTemplate then
496 >        TForm_BaseTemplate(MDITab.MDIChildren[i]).UpdateConList;
497  
498    menu_conns.Clear;
499    if ConManager.Count > 0 then
# Line 496 | Line 513 | end;
513  
514   procedure TForm_Main.LoadFile(typedb: Boolean);
515   var
516 <  ext: String;
516 >  i: Integer;
517   begin
518    opend.InitialDir := AppSettings.DatPath;
519    opend.Filter     := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
# Line 506 | Line 523 | begin
523      opend.FilterIndex := 2;
524    if opend.Execute then
525    begin
526 <    ext := ExtractFileExt(opend.FileName);
527 <    if ext = '.dat' then
528 <    begin
512 <      CreateConnection(opend.FileName);
513 <    end else if ext = '.oldb' then
514 <    begin
515 <      CreateConnection(opend.FileName);
516 <    end else
517 <      ShowMessage('Incompatible file');
526 >    if opend.Files.Count > 0 then
527 >      for i := 0 to opend.Files.Count - 1 do
528 >        CreateConnection(opend.Files.Strings[i]);
529      AppSettings.DatPath := ExtractFilepath(opend.FileName);
530    end;
531    UpdateStatBar;
# Line 553 | Line 564 | end;
564   {####################################}
565   procedure TForm_Main.menu_createdbClick(Sender: TObject);
566   begin
556  ShowMessage('Not yet usable');
557 {
567    opend.Filter     := 'Oni-Dat-Files|*.dat';
568    saved.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb';
569    saved.DefaultExt := 'oldb';
570    if opend.Execute then
571      if saved.Execute then
572        Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
564 }
573   end;
574  
575  
576   procedure TForm_Main.menu_createlvlClick(Sender: TObject);
577   begin
570  ShowMessage('Not yet usable');
571 {
578    opend.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb';
579    saved.Filter     := 'Oni-Dat-Files|*.dat';
580    saved.DefaultExt := 'dat';
581    if opend.Execute then
582      if saved.Execute then
583        Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
578 }
584   end;
585  
586  
# Line 584 | Line 589 | end;
589   {#################################}
590   procedure TForm_Main.menu_previewClick(Sender: TObject);
591   begin
592 <  open_child('preview', -1, -1);
592 >  open_child('preview');
593   end;
594  
595   procedure TForm_Main.menu_bineditClick(Sender: TObject);
596   begin
597 <  open_child('binedit', -1, -1);
597 >  open_child('binedit');
598   end;
599  
600   procedure TForm_Main.menu_raweditClick(Sender: TObject);
601   begin
602 <  open_child('rawedit', -1, -1);
602 >  open_child('rawedit');
603   end;
604  
605   procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
606   begin
607 <  open_child('txmpreplace', -1, -1);
607 >  open_child('txmpreplace');
608   end;
609  
610   procedure TForm_Main.menu_extractorClick(Sender: TObject);
611   begin
612 <  open_child('extractor', -1, -1);
612 >  open_child('extractor');
613   end;
614  
615   procedure TForm_Main.menu_metaClick(Sender: TObject);
616   begin
617 <  ShowMessage('TBD');
617 >  open_child('meta');
618   end;
619  
620   procedure TForm_Main.menu_filecompareClick(Sender: TObject);
621   begin
622 <  open_child('compare', -1, -1);
622 >  open_child('compare');
623   end;
624  
625  
626 < {#################################}
626 > procedure TForm_Main.menu_filemanagerClick(Sender: TObject);
627 > begin
628 >  open_child('filemanager');
629 > end;
630 >
631 > {#################################}
632   {#####   View-Menu-Handlers  #####}
633   {#################################}
634   procedure TForm_Main.menu_windows_cascadeClick(Sender: TObject);
# Line 680 | Line 690 | end;
690   procedure TForm_Main.menu_conns_itemClick(Sender: TObject);
691   var
692    name: String;
683  i: Integer;
693    index: Integer;
694    RepMsg: TStatusMessages;
695   begin
687 //  name := TTBItem(Sender).Caption;
696    index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender));
697    name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName);
698    if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+
# Line 692 | Line 700 | begin
700    begin
701      CheckConnectionCloseable(index);
702      ConManager.CloseConnectionByIndex(index, RepMsg);
703 +    ShowOpenMsg(RepMsg);
704 +    UpdateConLists;
705    end;
706    UpdateStatBar;
707   end;
# Line 703 | Line 713 | end;
713   procedure TForm_Main.menu_view_toolbarClick(Sender: TObject);
714   begin
715    menu_view_toolbar.Checked := not menu_view_toolbar.Checked;
716 <  Toolbar.Visible := menu_view_toolbar.Checked;
716 >  Toolbar_main.Visible := menu_view_toolbar.Checked;
717 > end;
718 >
719 > procedure TForm_Main.menu_view_toolbar_toolsClick(Sender: TObject);
720 > begin
721 >  menu_view_toolbar_tools.Checked := not menu_view_toolbar_tools.Checked;
722 >  Toolbar_tools.Visible := menu_view_toolbar_tools.Checked;
723   end;
724  
725   procedure TForm_Main.menu_view_statusbarClick(Sender: TObject);
# Line 729 | Line 745 | end;
745  
746  
747  
748 < function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate;
748 > function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_BaseTemplate;
749 > type
750 >  TTemplate = class of TForm_BaseTemplate;
751 >  TTool = record
752 >      name: String;
753 >      icon: Integer;
754 >      caption: String;
755 >      classt: TTemplate;
756 >  end;
757 > const
758 >  Tools: array[0..6] of TTool = (
759 >    (name: 'binedit';     icon: 5; caption: 'Binary .dat-Editor'; classt: TForm_BinEdit),
760 >    (name: 'extractor';   icon: 8; caption: 'Extractor';          classt: TForm_Extractor),
761 >    (name: 'preview';     icon: 4; caption: 'Preview-Window';     classt: TForm_Preview),
762 >    (name: 'rawedit';     icon: 6; caption: 'Binary .raw-Editor'; classt: TForm_RawEdit),
763 >    (name: 'txmpreplace'; icon: 7; caption: 'TXMP Replacer';      classt: TForm_TxmpReplace),
764 >    (name: 'filemanager'; icon:-1; caption: 'FileManager';        classt: TForm_FileManager),
765 >    (name: 'meta'; icon: 11; caption: 'MetaEditor'; classt: TForm_Meta)
766 >  );
767   var
768 <  toolform:    TForm_ToolTemplate;
768 >  toolform:    TForm_BaseTemplate;
769    i:           Integer;
770    tag:         Integer;
737  caption_end: String;
771    iconindex:   Integer;
772   begin
773    Result := nil;
# Line 746 | Line 779 | begin
779          tag := MDIChildren[i].Tag + 1;
780  
781    iconindex := -1;
749  caption_end := IntToStr(tag) + '       ';
782  
783 <  if window_context = 'binedit' then
784 <  begin
785 < //    toolform         := TForm_BinEdit.Create(Self);
786 <    toolform.Caption := 'Binary .dat-Editor ' + caption_end;
787 <    iconindex        := 5;
788 <  end;
789 <  if window_context = 'extractor' then
790 <  begin
791 < //    toolform         := TForm_Extractor.Create(Self);
792 <    toolform.Caption := 'Extractor ' + caption_end;
793 <    iconindex        := 8;
794 <  end;
763 <  if window_context = 'preview' then
764 <  begin
765 <    toolform         := TForm_Preview.Create(Self);
766 <    toolform.Caption := 'Preview-Window ' + caption_end;
767 <    iconindex        := 4;
768 <  end;
769 <  if window_context = 'rawedit' then
770 <  begin
771 < //    toolform         := TForm_RawEdit.Create(Self);
772 <    toolform.Caption := 'Binary .raw-Editor ' + caption_end;
773 <    iconindex        := 6;
774 <  end;
775 <  if window_context = 'txmpreplace' then
776 <  begin
777 < //    toolform         := TForm_TxmpReplace.Create(Application);
778 <    toolform.Caption := 'TXMP Replacer ' + caption_end;
779 <    iconindex        := 7;
783 >  toolform := nil;
784 >
785 >  for i := 0 to High(Tools) do
786 >    if Tools[i].name = window_context then
787 >      Break;
788 >  if i < Length(Tools) then
789 >  begin
790 >    toolform         := TTemplate(Tools[i].classt).Create(Self);
791 >    toolform.Caption := Tools[i].caption + ' ' + IntToStr(tag) + '       ';
792 >    iconindex        := Tools[i].icon;
793 >  end else begin
794 >    ShowMessage('WindowContext not found!');
795    end;
796  
797    if Assigned(toolform) then
# Line 785 | Line 800 | begin
800      toolform.Tag     := tag;
801      MDITab.AddTab(TForm(toolform), iconindex);
802      toolform.Caption := AnsiReplaceStr(toolform.Caption, '       ', '');
803 <    if connection > -1 then
803 >    if Connection > -1 then
804      begin
805        toolform.SelectConnection(connection);
806 <      if fileid > -1 then
807 <        toolform.SelectFileID(connection, fileid);
806 >      if (FileID > -1) and (toolform is TForm_TemplateFile) then
807 >        TForm_TemplateFile(toolform).SelectFileID(Connection, FileID);
808      end;
809      Result := toolform;
810    end;
811   end;
812  
813 + function TForm_Main.open_child(window_context: String; Connection: Integer): TForm_BaseTemplate;
814 + begin
815 +  Result := open_child(window_context, Connection, -1);
816 + end;
817 +
818 + function TForm_Main.open_child(window_context: String): TForm_BaseTemplate;
819 + begin
820 +  Result := open_child(window_context, -1, -1);
821 + end;
822 +
823   end.

Diff Legend

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