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 93 by alloc, Thu Jan 18 17:15:59 2007 UTC vs.
oup/current/Main.pas (file contents), Revision 172 by alloc, Sun Apr 8 23:52:14 2007 UTC

# Line 7 | Line 7 | uses
7    MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, OneInst,
8    Data, TypeDefs, ConnectionManager,
9   //  Functions, Exporters, DataStructures,
10 +  Functions,
11    Settings, {Helper_LevelDB, }
12 <  Template, BinEdit, Extractor, Preview, RawEdit, TxmpReplace;
12 >  Template,
13 >  RawEdit, BinEdit, Extractor, Preview, TxmpReplace;
14  
15   type
16    TForm_Main = class(TForm)
# Line 91 | Line 93 | type
93        Y: Integer);
94      procedure ToolbarDockChanged(Sender: TObject);
95      procedure CreateConnection(filename: String);
96 +    function CheckConnectionCloseable(index: Integer): Boolean;
97  
98      procedure menu_loadfileClick(Sender: TObject);
99      procedure menu_loaddbClick(Sender: TObject);
# Line 125 | Line 128 | type
128  
129      procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
130    private
128    ConnectionManager: TConnectionManager;
131    public
132      procedure DefaultHandler(var Message); override;
133    end;
# Line 135 | Line 137 | var
137  
138   implementation
139  
140 + uses
141 +  LevelDB;
142 +
143   {$R *.dfm}
144  
145  
# Line 153 | Line 158 | procedure TForm_Main.CreateConnection(fi
158   var
159    RepMsg: TStatusMessages;
160   begin
161 <  ConnectionManager.OpenConnection(filename, RepMsg);
161 >  ConManager.OpenConnection(filename, RepMsg);
162    ShowOpenMsg(RepMsg);
163    if RepMsg = SM_OK then
164    begin
165      UpdateStatBar;
166 +    UpdateConLists;
167    end;
168   end;
169  
170 + function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean;
171 + var
172 +  i: Integer;
173 +  toolform: TForm_ToolTemplate;
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
181 +      begin
182 +        toolform := TForm_ToolTemplate(MDITab.MDIChildren[i]);
183 +        if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then
184 +        begin
185 +          if not toolform.Closeable then
186 +          begin
187 +            ShowMessage('Can not close toolwindow: ' + toolform.Caption);
188 +            Result := False;
189 +          end;
190 +        end;
191 +      end;
192 +    end;
193 +  end;
194 + end;
195 +
196 +
197   { Eine zweite Instanz hat uns ihre Kommandozeilenparameter geschickt }
198   procedure TForm_Main.WMCopyData(var Msg: TWMCopyData);
199   var
# Line 208 | Line 241 | end;
241  
242  
243   procedure TForm_Main.FormCreate(Sender: TObject);
211 var
212  RepMsg: TStatusMessages;
244   begin
245    Self.Caption := 'Oni Un/Packer ' + version;
246    Self.FormResize(Self);
247  
248 <  ConnectionManager := TConnectionManager.Create;
218 <  ConnectionManager.OnCoonnectionListChanged := UpdateConLists;
248 >  ConManager.OnCoonnectionListChanged := UpdateConLists;
249  
250    if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then
251    begin
# Line 229 | Line 259 | begin
259    begin
260      AppSettings.DatPath        := ExtractFilepath(Application.EXEname);
261      AppSettings.ExtractPath    := ExtractFilepath(Application.EXEname) + '\extract';
232    AppSettings.FilenumbersAsHex := False;
262      AppSettings.CharSet        := DEFAULT_CHARSET;
263      AppSettings.HideUnusedData := False;
264    end;
# Line 292 | Line 321 | var
321    pt: TPoint;
322    tabIndex: Integer;
323    hint: String;
324 +  tool: TForm_ToolTemplate;
325   begin
326    pt.X := X;
327    pt.Y := Y;
# Line 302 | Line 332 | begin
332    begin
333      if MDITab.MDIChildren[tabIndex] is TForm_ToolTemplate then
334      begin
335 <      if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection <> nil then
335 >      tool := TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]);
336 >      if tool.ConnectionID > -1 then
337          hint := 'Connection: ' +
338 <              ExtractFileName(TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection.FileName) + #13+#10
338 >              ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) + #13+#10
339        else
340          hint := 'Connection: none' + #13+#10;
341 <      if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.ID >= 0 then
341 >      if tool.SelectedFile.ID > -1 then
342          hint := hint + 'Selected File: ' +
343 <              TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.FileName
343 >              FormatNumber(tool.SelectedFile.ID, 5, '0') + '-' +
344 >              tool.SelectedFile.Name + '.' +
345 >              tool.SelectedFile.Extension
346        else
347          hint := hint + 'Selected File: none';
348      end
# Line 386 | Line 419 | end;
419  
420   procedure TForm_Main.UpdateStatBar;
421   begin
422 <  if Length(DataConnections) > 0 then
422 >  if ConManager.Count > 0 then
423    begin
424      Self.Caption      := 'Oni Un/Packer ' + version;
425      ActivateTools(True);
426 <    statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(Length(DataConnections));
426 >    statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(ConManager.Count);
427    end
428    else
429    begin
# Line 400 | Line 433 | begin
433      statbar.Panels.Items[2].Text := '';
434      ActivateTools(False);
435    end;
436 <  menu_conns.Enabled := Length(DataConnections) > 0;
436 >  menu_conns.Enabled := ConManager.Count > 0;
437   end;
438  
439  
# Line 412 | Line 445 | var
445    position: TTBDockPosition;
446    mode: TTBItemDisplayMode;
447    i: Integer;
415  isEnabled: Boolean;
448   begin
449    toolbar := TTBToolbar(Sender);
450    if toolbar.Floating then
# Line 450 | Line 482 | begin
482          TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList;
483  
484    menu_conns.Clear;
485 <  if ConnectionManager.Count > 0 then
485 >  if ConManager.Count > 0 then
486    begin
487 <    for i := 0 to ConnectionManager.Count - 1 do
487 >    for i := 0 to ConManager.Count - 1 do
488      begin
489        entry := TTBItem.Create(menu_conns);
490 <      entry.Caption := ExtractFileName(DataConnections[i].FileName);
490 >      entry.Caption := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
491        entry.Name := 'menu_conn_' + IntToStr(i);
492        entry.OnClick := menu_conns_itemClick;
493        menu_conns.Add(entry);
# Line 467 | Line 499 | end;
499  
500   procedure TForm_Main.LoadFile(typedb: Boolean);
501   var
502 <  ext: String;
502 >  i: Integer;
503   begin
504    opend.InitialDir := AppSettings.DatPath;
505    opend.Filter     := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
# Line 477 | Line 509 | begin
509      opend.FilterIndex := 2;
510    if opend.Execute then
511    begin
512 <    ext := ExtractFileExt(opend.FileName);
513 <    if ext = '.dat' then
514 <    begin
483 <      CreateConnection(opend.FileName);
484 <    end else if ext = '.oldb' then
485 <    begin
486 <      CreateConnection(opend.FileName);
487 <    end else
488 <      ShowMessage('Incompatible file');
512 >    if opend.Files.Count > 0 then
513 >      for i := 0 to opend.Files.Count - 1 do
514 >        CreateConnection(opend.Files.Strings[i]);
515      AppSettings.DatPath := ExtractFilepath(opend.FileName);
516    end;
517    UpdateStatBar;
# Line 524 | Line 550 | end;
550   {####################################}
551   procedure TForm_Main.menu_createdbClick(Sender: TObject);
552   begin
553 <  ShowMessage('Not yet usable');
554 < {
553 > //  ShowMessage('Not yet usable');
554 >
555    opend.Filter     := 'Oni-Dat-Files|*.dat';
556    saved.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb';
557    saved.DefaultExt := 'oldb';
558    if opend.Execute then
559      if saved.Execute then
560        Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
535 }
561   end;
562  
563  
564   procedure TForm_Main.menu_createlvlClick(Sender: TObject);
565   begin
566 <  ShowMessage('Not yet usable');
567 < {
566 > //  ShowMessage('Not yet usable');
567 >
568    opend.Filter     := 'OUP-Level-DB (*.oldb)|*.oldb';
569    saved.Filter     := 'Oni-Dat-Files|*.dat';
570    saved.DefaultExt := 'dat';
571    if opend.Execute then
572      if saved.Execute then
573        Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
549 }
574   end;
575  
576  
# Line 555 | Line 579 | end;
579   {#################################}
580   procedure TForm_Main.menu_previewClick(Sender: TObject);
581   begin
582 <  open_child('preview', nil, -1);
582 >  open_child('preview', -1, -1);
583   end;
584  
585   procedure TForm_Main.menu_bineditClick(Sender: TObject);
586   begin
587 <  open_child('binedit', nil, -1);
587 >  open_child('binedit', -1, -1);
588   end;
589  
590   procedure TForm_Main.menu_raweditClick(Sender: TObject);
591   begin
592 <  open_child('rawedit', nil, -1);
592 >  open_child('rawedit', -1, -1);
593   end;
594  
595   procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
596   begin
597 <  open_child('txmpreplace', nil, -1);
597 >  open_child('txmpreplace', -1, -1);
598   end;
599  
600   procedure TForm_Main.menu_extractorClick(Sender: TObject);
601   begin
602 <  open_child('extractor', nil, -1);
602 >  open_child('extractor', -1, -1);
603   end;
604  
605   procedure TForm_Main.menu_metaClick(Sender: TObject);
# Line 585 | Line 609 | end;
609  
610   procedure TForm_Main.menu_filecompareClick(Sender: TObject);
611   begin
612 <  open_child('compare', nil, -1);
612 >  open_child('compare', -1, -1);
613   end;
614  
615  
# Line 651 | Line 675 | end;
675   procedure TForm_Main.menu_conns_itemClick(Sender: TObject);
676   var
677    name: String;
678 <  i: Integer;
678 >  index: Integer;
679 >  RepMsg: TStatusMessages;
680   begin
681 <  name := TTBItem(Sender).Caption;
681 > //  name := TTBItem(Sender).Caption;
682 >  index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender));
683 >  name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName);
684    if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+
685          name + '?'), PChar('Close?'), MB_YESNO + MB_ICONQUESTION) = ID_YES then
686    begin
687 <    for i := 0 to High(DataConnections) do
688 <      if ExtractFileName(DataConnections[i].FileName) = name then
689 <      begin
690 <        CloseDataConnection(DataConnections[i]);
664 <        Break;
665 <      end;
687 >    CheckConnectionCloseable(index);
688 >    ConManager.CloseConnectionByIndex(index, RepMsg);
689 >    ShowOpenMsg(RepMsg);
690 >    UpdateConLists;
691    end;
692    UpdateStatBar;
693   end;
# Line 701 | Line 726 | end;
726  
727  
728   function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate;
729 + type
730 +  TTemplate = class of TForm_ToolTemplate;
731 +  TTool = record
732 +      name: String;
733 +      icon: Integer;
734 +      caption: String;
735 +      classt: TTemplate;
736 +  end;
737 + const
738 +  Tools: array[0..4] of TTool = (
739 +    (name: 'binedit';     icon: 5; caption: 'Binary .dat-Editor'; classt: TForm_BinEdit),
740 +    (name: 'extractor';   icon: 8; caption: 'Extractor';          classt: TForm_Extractor),
741 +    (name: 'preview';     icon: 4; caption: 'Preview-Window';     classt: TForm_Preview),
742 +    (name: 'rawedit';     icon: 6; caption: 'Binary .raw-Editor'; classt: TForm_RawEdit),
743 +    (name: 'txmpreplace'; icon: 7; caption: 'TXMP Replacer';      classt: TForm_TxmpReplace)
744 +  );
745   var
746    toolform:    TForm_ToolTemplate;
747    i:           Integer;
748    tag:         Integer;
708  caption_end: String;
749    iconindex:   Integer;
750   begin
751    Result := nil;
# Line 717 | Line 757 | begin
757          tag := MDIChildren[i].Tag + 1;
758  
759    iconindex := -1;
720  caption_end := IntToStr(tag) + '       ';
760  
761 <  if window_context = 'binedit' then
762 <  begin
763 <    toolform         := TForm_BinEdit.Create(Self);
764 <    toolform.Caption := 'Binary .dat-Editor ' + caption_end;
765 <    iconindex        := 5;
766 <  end;
767 <  if window_context = 'extractor' then
768 <  begin
769 <    toolform         := TForm_Extractor.Create(Self);
770 <    toolform.Caption := 'Extractor ' + caption_end;
771 <    iconindex        := 8;
772 <  end;
734 <  if window_context = 'preview' then
735 <  begin
736 <    toolform         := TForm_Preview.Create(Self);
737 <    toolform.Caption := 'Preview-Window ' + caption_end;
738 <    iconindex        := 4;
739 <  end;
740 <  if window_context = 'rawedit' then
741 <  begin
742 <    toolform         := TForm_RawEdit.Create(Self);
743 <    toolform.Caption := 'Binary .raw-Editor ' + caption_end;
744 <    iconindex        := 6;
745 <  end;
746 <  if window_context = 'txmpreplace' then
747 <  begin
748 <    toolform         := TForm_TxmpReplace.Create(Application);
749 <    toolform.Caption := 'TXMP Replacer ' + caption_end;
750 <    iconindex        := 7;
761 >  toolform := nil;
762 >
763 >  for i := 0 to High(Tools) do
764 >    if Tools[i].name = window_context then
765 >      Break;
766 >  if i < Length(Tools) then
767 >  begin
768 >    toolform         := TTemplate(Tools[i].classt).Create(Self);
769 >    toolform.Caption := Tools[i].caption + ' ' + IntToStr(tag) + '       ';
770 >    iconindex        := Tools[i].icon;
771 >  end else begin
772 >    ShowMessage('WindowContext not found!');
773    end;
774  
775    if Assigned(toolform) then
# Line 756 | Line 778 | begin
778      toolform.Tag     := tag;
779      MDITab.AddTab(TForm(toolform), iconindex);
780      toolform.Caption := AnsiReplaceStr(toolform.Caption, '       ', '');
781 <    if (fileid > -1) and (connection <> nil) then
781 >    if connection > -1 then
782      begin
783 <      toolform.SelectFileID(connection, fileid);
783 >      toolform.SelectConnection(connection);
784 >      if fileid > -1 then
785 >        toolform.SelectFileID(connection, fileid);
786      end;
787      Result := toolform;
788    end;

Diff Legend

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