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 109 by alloc, Wed Feb 21 03:12:33 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 153 | Line 155 | procedure TForm_Main.CreateConnection(fi
155   var
156    RepMsg: TStatusMessages;
157   begin
158 <  ConnectionManager.OpenConnection(filename, RepMsg);
158 >  ConManager.OpenConnection(filename, RepMsg);
159    ShowOpenMsg(RepMsg);
160    if RepMsg = SM_OK then
161    begin
162      UpdateStatBar;
163 +    UpdateConLists;
164    end;
165   end;
166  
167 + function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean;
168 + var
169 +  i: Integer;
170 +  toolform: TForm_ToolTemplate;
171 + begin
172 +  if MDITab.MDIChildCount > 0 then
173 +  begin
174 +    for i := 0 to MDITab.MDIChildCount - 1 do
175 +    begin
176 +      if MDITab.MDIChildren[i] is TForm_ToolTemplate then
177 +      begin
178 +        toolform := TForm_ToolTemplate(MDITab.MDIChildren[i]);
179 +        if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then
180 +        begin
181 +          if not toolform.Closeable then
182 +            ShowMessage('Can not close toolwindow: ' + toolform.Caption);
183 +        end;
184 +      end;
185 +    end;
186 +  end;
187 + end;
188 +
189 +
190   { Eine zweite Instanz hat uns ihre Kommandozeilenparameter geschickt }
191   procedure TForm_Main.WMCopyData(var Msg: TWMCopyData);
192   var
# Line 214 | Line 240 | begin
240    Self.Caption := 'Oni Un/Packer ' + version;
241    Self.FormResize(Self);
242  
243 <  ConnectionManager := TConnectionManager.Create;
218 <  ConnectionManager.OnCoonnectionListChanged := UpdateConLists;
243 >  ConManager.OnCoonnectionListChanged := UpdateConLists;
244  
245    if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then
246    begin
# Line 292 | Line 317 | var
317    pt: TPoint;
318    tabIndex: Integer;
319    hint: String;
320 +  tool: TForm_ToolTemplate;
321   begin
322    pt.X := X;
323    pt.Y := Y;
# Line 302 | Line 328 | begin
328    begin
329      if MDITab.MDIChildren[tabIndex] is TForm_ToolTemplate then
330      begin
331 <      if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection <> nil then
331 >      tool := TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]);
332 >      if tool.ConnectionID > -1 then
333          hint := 'Connection: ' +
334 <              ExtractFileName(TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection.FileName) + #13+#10
334 >              ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) + #13+#10
335        else
336          hint := 'Connection: none' + #13+#10;
337 <      if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.ID >= 0 then
337 >      if tool.SelectedFile.ID > -1 then
338          hint := hint + 'Selected File: ' +
339 <              TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.FileName
339 >              FormatNumber(tool.SelectedFile.ID, 5, '0') + '-' +
340 >              tool.SelectedFile.Name + '.' +
341 >              tool.SelectedFile.Extension
342        else
343          hint := hint + 'Selected File: none';
344      end
# Line 386 | Line 415 | end;
415  
416   procedure TForm_Main.UpdateStatBar;
417   begin
418 <  if Length(DataConnections) > 0 then
418 >  if ConManager.Count > 0 then
419    begin
420      Self.Caption      := 'Oni Un/Packer ' + version;
421      ActivateTools(True);
422 <    statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(Length(DataConnections));
422 >    statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(ConManager.Count);
423    end
424    else
425    begin
# Line 400 | Line 429 | begin
429      statbar.Panels.Items[2].Text := '';
430      ActivateTools(False);
431    end;
432 <  menu_conns.Enabled := Length(DataConnections) > 0;
432 >  menu_conns.Enabled := ConManager.Count > 0;
433   end;
434  
435  
# Line 450 | Line 479 | begin
479          TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList;
480  
481    menu_conns.Clear;
482 <  if ConnectionManager.Count > 0 then
482 >  if ConManager.Count > 0 then
483    begin
484 <    for i := 0 to ConnectionManager.Count - 1 do
484 >    for i := 0 to ConManager.Count - 1 do
485      begin
486        entry := TTBItem.Create(menu_conns);
487 <      entry.Caption := ExtractFileName(DataConnections[i].FileName);
487 >      entry.Caption := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
488        entry.Name := 'menu_conn_' + IntToStr(i);
489        entry.OnClick := menu_conns_itemClick;
490        menu_conns.Add(entry);
# Line 467 | Line 496 | end;
496  
497   procedure TForm_Main.LoadFile(typedb: Boolean);
498   var
499 <  ext: String;
499 >  i: Integer;
500   begin
501    opend.InitialDir := AppSettings.DatPath;
502    opend.Filter     := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
# Line 477 | Line 506 | begin
506      opend.FilterIndex := 2;
507    if opend.Execute then
508    begin
509 <    ext := ExtractFileExt(opend.FileName);
510 <    if ext = '.dat' then
511 <    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');
509 >    if opend.Files.Count > 0 then
510 >      for i := 0 to opend.Files.Count - 1 do
511 >        CreateConnection(opend.Files.Strings[i]);
512      AppSettings.DatPath := ExtractFilepath(opend.FileName);
513    end;
514    UpdateStatBar;
# Line 555 | Line 578 | end;
578   {#################################}
579   procedure TForm_Main.menu_previewClick(Sender: TObject);
580   begin
581 <  open_child('preview', nil, -1);
581 >  open_child('preview', -1, -1);
582   end;
583  
584   procedure TForm_Main.menu_bineditClick(Sender: TObject);
585   begin
586 <  open_child('binedit', nil, -1);
586 >  open_child('binedit', -1, -1);
587   end;
588  
589   procedure TForm_Main.menu_raweditClick(Sender: TObject);
590   begin
591 <  open_child('rawedit', nil, -1);
591 >  open_child('rawedit', -1, -1);
592   end;
593  
594   procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
595   begin
596 <  open_child('txmpreplace', nil, -1);
596 >  open_child('txmpreplace', -1, -1);
597   end;
598  
599   procedure TForm_Main.menu_extractorClick(Sender: TObject);
600   begin
601 <  open_child('extractor', nil, -1);
601 >  open_child('extractor', -1, -1);
602   end;
603  
604   procedure TForm_Main.menu_metaClick(Sender: TObject);
# Line 585 | Line 608 | end;
608  
609   procedure TForm_Main.menu_filecompareClick(Sender: TObject);
610   begin
611 <  open_child('compare', nil, -1);
611 >  open_child('compare', -1, -1);
612   end;
613  
614  
# Line 652 | Line 675 | procedure TForm_Main.menu_conns_itemClic
675   var
676    name: String;
677    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 745 | Line 770 | begin
770    end;
771    if window_context = 'txmpreplace' then
772    begin
773 <    toolform         := TForm_TxmpReplace.Create(Application);
773 >    toolform         := TForm_TxmpReplace.Create(Self);
774      toolform.Caption := 'TXMP Replacer ' + caption_end;
775      iconindex        := 7;
776    end;
# Line 756 | Line 781 | begin
781      toolform.Tag     := tag;
782      MDITab.AddTab(TForm(toolform), iconindex);
783      toolform.Caption := AnsiReplaceStr(toolform.Caption, '       ', '');
784 <    if (fileid > -1) and (connection <> nil) then
784 >    if connection > -1 then
785      begin
786 <      toolform.SelectFileID(connection, fileid);
786 >      toolform.SelectConnection(connection);
787 >      if fileid > -1 then
788 >        toolform.SelectFileID(connection, fileid);
789      end;
790      Result := toolform;
791    end;

Diff Legend

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