--- oup/current/Main.pas 2007/03/30 00:51:58 139 +++ oup/current/Main.pas 2007/07/14 20:22:05 239 @@ -6,11 +6,9 @@ uses MPHexEditor, ToolWin, ImgList, Tabs, MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, OneInst, Data, TypeDefs, ConnectionManager, -// Functions, Exporters, DataStructures, - Functions, - Settings, {Helper_LevelDB, } - Template, - RawEdit, BinEdit, Extractor, Preview, TxmpReplace; + Functions, Settings, + RawEdit, BinEdit, Extractor, Preview, TxmpReplace, + _BaseTemplate, _TemplateFile, _TemplateFileList; type TForm_Main = class(TForm) @@ -46,7 +44,7 @@ type menu_windows_previous: TTBItem; menu_sep2: TTBSeparatorItem; menu_About: TTBItem; - Toolbar: TTBToolbar; + Toolbar_main: TTBToolbar; tbOpen: TTBItem; DockLeft: TTBDock; DockRight: TTBDock; @@ -59,15 +57,7 @@ type menu_view_statusbar: TTBItem; menu_view_toolbar: TTBItem; tb_separator1: TTBSeparatorItem; - tb_preview: TTBItem; - tb_structure: TTBItem; - tb_compare: TTBItem; - tb_extractor: TTBItem; - tb_txmpreplacer: TTBItem; - tb_rawedit: TTBItem; - tb_datedit: TTBItem; menu_windows_tilevert: TTBItem; - tb_meta: TTBItem; menu_meta: TTBItem; TBSeparatorItem1: TTBSeparatorItem; tb_db2dat: TTBItem; @@ -77,6 +67,18 @@ type Images_Close: TImageList; menu_conns: TTBSubmenuItem; menu_windows: TTBSubmenuItem; + menu_filemanager: TTBItem; + Toolbar_tools: TTBToolbar; + tb_preview: TTBItem; + tb_datedit: TTBItem; + tb_rawedit: TTBItem; + tb_txmpreplacer: TTBItem; + tb_extractor: TTBItem; + tb_meta: TTBItem; + tb_filemanager: TTBItem; + tb_compare: TTBItem; + tb_structure: TTBItem; + menu_view_toolbar_tools: TTBItem; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormResize(Sender: TObject); procedure FormCreate(Sender: TObject); @@ -91,7 +93,7 @@ type Shift: TShiftState; X, Y: Integer); procedure MDITabMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); - procedure ToolbarDockChanged(Sender: TObject); + procedure Toolbar_mainDockChanged(Sender: TObject); procedure CreateConnection(filename: String); function CheckConnectionCloseable(index: Integer): Boolean; @@ -110,7 +112,6 @@ type procedure menu_txmpreplaceClick(Sender: TObject); procedure menu_previewClick(Sender: TObject); procedure menu_metaClick(Sender: TObject); - function open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate; procedure menu_windows_cascadeClick(Sender: TObject); procedure menu_windows_tilevertClick(Sender: TObject); @@ -127,8 +128,13 @@ type procedure menu_AboutClick(Sender: TObject); procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA; + procedure menu_filemanagerClick(Sender: TObject); + procedure menu_view_toolbar_toolsClick(Sender: TObject); private public + function open_child(window_context: String; Connection, FileID: Integer): TForm_BaseTemplate; overload; + function open_child(window_context: String; Connection: Integer): TForm_BaseTemplate; overload; + function open_child(window_context: String): TForm_BaseTemplate; overload; procedure DefaultHandler(var Message); override; end; @@ -138,7 +144,7 @@ var implementation uses - LevelDB; + LevelDB, MetaEditor, FileManager; {$R *.dfm} @@ -170,16 +176,16 @@ end; function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean; var i: Integer; - toolform: TForm_ToolTemplate; + toolform: TForm_BaseTemplate; begin Result := True; if MDITab.MDIChildCount > 0 then begin for i := 0 to MDITab.MDIChildCount - 1 do begin - if MDITab.MDIChildren[i] is TForm_ToolTemplate then + if MDITab.MDIChildren[i] is TForm_BaseTemplate then begin - toolform := TForm_ToolTemplate(MDITab.MDIChildren[i]); + toolform := TForm_BaseTemplate(MDITab.MDIChildren[i]); if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then begin if not toolform.Closeable then @@ -257,6 +263,10 @@ begin end else begin + ShowMessage('Warning!' + #13#10 + + 'It seems like this is the first time you OUP.' + #13#10 + + 'I do not take any responsibility for messed up data files' + #13+#10 + + 'Do not forget to make backup copies of your *.dat/*.raw/*.sep files!'); AppSettings.DatPath := ExtractFilepath(Application.EXEname); AppSettings.ExtractPath := ExtractFilepath(Application.EXEname) + '\extract'; AppSettings.CharSet := DEFAULT_CHARSET; @@ -321,7 +331,7 @@ var pt: TPoint; tabIndex: Integer; hint: String; - tool: TForm_ToolTemplate; + tool: TForm_BaseTemplate; begin pt.X := X; pt.Y := Y; @@ -330,21 +340,24 @@ begin if tabIndex >= 0 then begin - if MDITab.MDIChildren[tabIndex] is TForm_ToolTemplate then + if MDITab.MDIChildren[tabIndex] is TForm_BaseTemplate then begin - tool := TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]); + tool := TForm_BaseTemplate(MDITab.MDIChildren[tabIndex]); if tool.ConnectionID > -1 then hint := 'Connection: ' + - ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) + #13+#10 - else - hint := 'Connection: none' + #13+#10; - if tool.SelectedFile.ID > -1 then - hint := hint + 'Selected File: ' + - FormatNumber(tool.SelectedFile.ID, 5, '0') + '-' + - tool.SelectedFile.Name + '.' + - tool.SelectedFile.Extension + ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) else - hint := hint + 'Selected File: none'; + hint := 'Connection: none'; + if tool is TForm_TemplateFile then + begin + if TForm_TemplateFile(tool).SelectedFile.ID > -1 then + hint := hint + #13+#10 + 'Selected File: ' + + FormatNumber(TForm_TemplateFile(tool).SelectedFile.ID, 5, '0') + '-' + + TForm_TemplateFile(tool).SelectedFile.Name + '.' + + TForm_TemplateFile(tool).SelectedFile.Extension + else + hint := hint + #13+#10 + 'Selected File: none'; + end; end else hint := 'Window: ' + MDITab.MDIChildren[tabIndex].Caption; @@ -413,6 +426,7 @@ begin tb_rawedit.Enabled := active; tb_txmpreplacer.Enabled := active; tb_extractor.Enabled := active; + tb_meta.Enabled := active; // tb_compare.Enabled := active; // tb_structure.Enabled := active; end; @@ -439,7 +453,7 @@ end; -procedure TForm_Main.ToolbarDockChanged(Sender: TObject); +procedure TForm_Main.Toolbar_mainDockChanged(Sender: TObject); var toolbar: TTBToolbar; position: TTBDockPosition; @@ -478,8 +492,8 @@ var begin if MDITab.MDIChildCount > 0 then for i := 0 to MDITab.MDIChildCount - 1 do - if MDITab.MDIChildren[i] is TForm_ToolTemplate then - TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList; + if MDITab.MDIChildren[i] is TForm_BaseTemplate then + TForm_BaseTemplate(MDITab.MDIChildren[i]).UpdateConList; menu_conns.Clear; if ConManager.Count > 0 then @@ -550,8 +564,6 @@ end; {####################################} procedure TForm_Main.menu_createdbClick(Sender: TObject); begin -// ShowMessage('Not yet usable'); - opend.Filter := 'Oni-Dat-Files|*.dat'; saved.Filter := 'OUP-Level-DB (*.oldb)|*.oldb'; saved.DefaultExt := 'oldb'; @@ -563,8 +575,6 @@ end; procedure TForm_Main.menu_createlvlClick(Sender: TObject); begin -// ShowMessage('Not yet usable'); - opend.Filter := 'OUP-Level-DB (*.oldb)|*.oldb'; saved.Filter := 'Oni-Dat-Files|*.dat'; saved.DefaultExt := 'dat'; @@ -579,41 +589,46 @@ end; {#################################} procedure TForm_Main.menu_previewClick(Sender: TObject); begin - open_child('preview', -1, -1); + open_child('preview'); end; procedure TForm_Main.menu_bineditClick(Sender: TObject); begin - open_child('binedit', -1, -1); + open_child('binedit'); end; procedure TForm_Main.menu_raweditClick(Sender: TObject); begin - open_child('rawedit', -1, -1); + open_child('rawedit'); end; procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject); begin - open_child('txmpreplace', -1, -1); + open_child('txmpreplace'); end; procedure TForm_Main.menu_extractorClick(Sender: TObject); begin - open_child('extractor', -1, -1); + open_child('extractor'); end; procedure TForm_Main.menu_metaClick(Sender: TObject); begin - ShowMessage('TBD'); + open_child('meta'); end; procedure TForm_Main.menu_filecompareClick(Sender: TObject); begin - open_child('compare', -1, -1); + open_child('compare'); end; - {#################################} + procedure TForm_Main.menu_filemanagerClick(Sender: TObject); +begin + open_child('filemanager'); +end; + +{#################################} {##### View-Menu-Handlers #####} {#################################} procedure TForm_Main.menu_windows_cascadeClick(Sender: TObject); @@ -678,7 +693,6 @@ var index: Integer; RepMsg: TStatusMessages; begin -// name := TTBItem(Sender).Caption; index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender)); name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName); if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+ @@ -699,7 +713,13 @@ end; procedure TForm_Main.menu_view_toolbarClick(Sender: TObject); begin menu_view_toolbar.Checked := not menu_view_toolbar.Checked; - Toolbar.Visible := menu_view_toolbar.Checked; + Toolbar_main.Visible := menu_view_toolbar.Checked; +end; + +procedure TForm_Main.menu_view_toolbar_toolsClick(Sender: TObject); +begin + menu_view_toolbar_tools.Checked := not menu_view_toolbar_tools.Checked; + Toolbar_tools.Visible := menu_view_toolbar_tools.Checked; end; procedure TForm_Main.menu_view_statusbarClick(Sender: TObject); @@ -725,12 +745,29 @@ end; -function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate; +function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_BaseTemplate; +type + TTemplate = class of TForm_BaseTemplate; + TTool = record + name: String; + icon: Integer; + caption: String; + classt: TTemplate; + end; +const + Tools: array[0..6] of TTool = ( + (name: 'binedit'; icon: 5; caption: 'Binary .dat-Editor'; classt: TForm_BinEdit), + (name: 'extractor'; icon: 8; caption: 'Extractor'; classt: TForm_Extractor), + (name: 'preview'; icon: 4; caption: 'Preview-Window'; classt: TForm_Preview), + (name: 'rawedit'; icon: 6; caption: 'Binary .raw-Editor'; classt: TForm_RawEdit), + (name: 'txmpreplace'; icon: 7; caption: 'TXMP Replacer'; classt: TForm_TxmpReplace), + (name: 'filemanager'; icon:-1; caption: 'FileManager'; classt: TForm_FileManager), + (name: 'meta'; icon: 11; caption: 'MetaEditor'; classt: TForm_Meta) + ); var - toolform: TForm_ToolTemplate; + toolform: TForm_BaseTemplate; i: Integer; tag: Integer; - caption_end: String; iconindex: Integer; begin Result := nil; @@ -742,39 +779,19 @@ begin tag := MDIChildren[i].Tag + 1; iconindex := -1; - caption_end := IntToStr(tag) + ' '; toolform := nil; - if window_context = 'binedit' then - begin - toolform := TForm_BinEdit.Create(Self); - toolform.Caption := 'Binary .dat-Editor ' + caption_end; - iconindex := 5; - end; - if window_context = 'extractor' then - begin - toolform := TForm_Extractor.Create(Self); - toolform.Caption := 'Extractor ' + caption_end; - iconindex := 8; - end; - if window_context = 'preview' then - begin - toolform := TForm_Preview.Create(Self); - toolform.Caption := 'Preview-Window ' + caption_end; - iconindex := 4; - end; - if window_context = 'rawedit' then - begin - toolform := TForm_RawEdit.Create(Self); - toolform.Caption := 'Binary .raw-Editor ' + caption_end; - iconindex := 6; - end; - if window_context = 'txmpreplace' then - begin - toolform := TForm_TxmpReplace.Create(Self); - toolform.Caption := 'TXMP Replacer ' + caption_end; - iconindex := 7; + for i := 0 to High(Tools) do + if Tools[i].name = window_context then + Break; + if i < Length(Tools) then + begin + toolform := TTemplate(Tools[i].classt).Create(Self); + toolform.Caption := Tools[i].caption + ' ' + IntToStr(tag) + ' '; + iconindex := Tools[i].icon; + end else begin + ShowMessage('WindowContext not found!'); end; if Assigned(toolform) then @@ -783,14 +800,24 @@ begin toolform.Tag := tag; MDITab.AddTab(TForm(toolform), iconindex); toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', ''); - if connection > -1 then + if Connection > -1 then begin toolform.SelectConnection(connection); - if fileid > -1 then - toolform.SelectFileID(connection, fileid); + if (FileID > -1) and (toolform is TForm_TemplateFile) then + TForm_TemplateFile(toolform).SelectFileID(Connection, FileID); end; Result := toolform; end; end; +function TForm_Main.open_child(window_context: String; Connection: Integer): TForm_BaseTemplate; +begin + Result := open_child(window_context, Connection, -1); +end; + +function TForm_Main.open_child(window_context: String): TForm_BaseTemplate; +begin + Result := open_child(window_context, -1, -1); +end; + end.