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 113 by alloc, Sun Feb 25 17:20:22 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 +  Result := True;
173 +  if MDITab.MDIChildCount > 0 then
174 +  begin
175 +    for i := 0 to MDITab.MDIChildCount - 1 do
176 +    begin
177 +      if MDITab.MDIChildren[i] is TForm_ToolTemplate then
178 +      begin
179 +        toolform := TForm_ToolTemplate(MDITab.MDIChildren[i]);
180 +        if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then
181 +        begin
182 +          if not toolform.Closeable then
183 +          begin
184 +            ShowMessage('Can not close toolwindow: ' + toolform.Caption);
185 +            Result := False;
186 +          end;
187 +        end;
188 +      end;
189 +    end;
190 +  end;
191 + end;
192 +
193 +
194   { Eine zweite Instanz hat uns ihre Kommandozeilenparameter geschickt }
195   procedure TForm_Main.WMCopyData(var Msg: TWMCopyData);
196   var
# Line 208 | Line 238 | end;
238  
239  
240   procedure TForm_Main.FormCreate(Sender: TObject);
211 var
212  RepMsg: TStatusMessages;
241   begin
242    Self.Caption := 'Oni Un/Packer ' + version;
243    Self.FormResize(Self);
244  
245 <  ConnectionManager := TConnectionManager.Create;
218 <  ConnectionManager.OnCoonnectionListChanged := UpdateConLists;
245 >  ConManager.OnCoonnectionListChanged := UpdateConLists;
246  
247    if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then
248    begin
# Line 229 | Line 256 | begin
256    begin
257      AppSettings.DatPath        := ExtractFilepath(Application.EXEname);
258      AppSettings.ExtractPath    := ExtractFilepath(Application.EXEname) + '\extract';
232    AppSettings.FilenumbersAsHex := False;
259      AppSettings.CharSet        := DEFAULT_CHARSET;
260      AppSettings.HideUnusedData := False;
261    end;
# Line 292 | Line 318 | var
318    pt: TPoint;
319    tabIndex: Integer;
320    hint: String;
321 +  tool: TForm_ToolTemplate;
322   begin
323    pt.X := X;
324    pt.Y := Y;
# Line 302 | Line 329 | begin
329    begin
330      if MDITab.MDIChildren[tabIndex] is TForm_ToolTemplate then
331      begin
332 <      if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection <> nil then
332 >      tool := TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]);
333 >      if tool.ConnectionID > -1 then
334          hint := 'Connection: ' +
335 <              ExtractFileName(TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection.FileName) + #13+#10
335 >              ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) + #13+#10
336        else
337          hint := 'Connection: none' + #13+#10;
338 <      if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.ID >= 0 then
338 >      if tool.SelectedFile.ID > -1 then
339          hint := hint + 'Selected File: ' +
340 <              TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.FileName
340 >              FormatNumber(tool.SelectedFile.ID, 5, '0') + '-' +
341 >              tool.SelectedFile.Name + '.' +
342 >              tool.SelectedFile.Extension
343        else
344          hint := hint + 'Selected File: none';
345      end
# Line 386 | Line 416 | end;
416  
417   procedure TForm_Main.UpdateStatBar;
418   begin
419 <  if Length(DataConnections) > 0 then
419 >  if ConManager.Count > 0 then
420    begin
421      Self.Caption      := 'Oni Un/Packer ' + version;
422      ActivateTools(True);
423 <    statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(Length(DataConnections));
423 >    statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(ConManager.Count);
424    end
425    else
426    begin
# Line 400 | Line 430 | begin
430      statbar.Panels.Items[2].Text := '';
431      ActivateTools(False);
432    end;
433 <  menu_conns.Enabled := Length(DataConnections) > 0;
433 >  menu_conns.Enabled := ConManager.Count > 0;
434   end;
435  
436  
# Line 412 | Line 442 | var
442    position: TTBDockPosition;
443    mode: TTBItemDisplayMode;
444    i: Integer;
415  isEnabled: Boolean;
445   begin
446    toolbar := TTBToolbar(Sender);
447    if toolbar.Floating then
# 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 651 | Line 674 | end;
674   procedure TForm_Main.menu_conns_itemClick(Sender: TObject);
675   var
676    name: String;
677 <  i: Integer;
677 >  index: Integer;
678 >  RepMsg: TStatusMessages;
679   begin
680 <  name := TTBItem(Sender).Caption;
680 > //  name := TTBItem(Sender).Caption;
681 >  index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender));
682 >  name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName);
683    if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+
684          name + '?'), PChar('Close?'), MB_YESNO + MB_ICONQUESTION) = ID_YES then
685    begin
686 <    for i := 0 to High(DataConnections) do
687 <      if ExtractFileName(DataConnections[i].FileName) = name then
688 <      begin
689 <        CloseDataConnection(DataConnections[i]);
664 <        Break;
665 <      end;
686 >    CheckConnectionCloseable(index);
687 >    ConManager.CloseConnectionByIndex(index, RepMsg);
688 >    ShowOpenMsg(RepMsg);
689 >    UpdateConLists;
690    end;
691    UpdateStatBar;
692   end;
# Line 719 | Line 743 | begin
743    iconindex := -1;
744    caption_end := IntToStr(tag) + '       ';
745  
746 +  toolform := nil;
747 +
748    if window_context = 'binedit' then
749    begin
750      toolform         := TForm_BinEdit.Create(Self);
# Line 745 | Line 771 | begin
771    end;
772    if window_context = 'txmpreplace' then
773    begin
774 <    toolform         := TForm_TxmpReplace.Create(Application);
774 >    toolform         := TForm_TxmpReplace.Create(Self);
775      toolform.Caption := 'TXMP Replacer ' + caption_end;
776      iconindex        := 7;
777    end;
# Line 756 | Line 782 | begin
782      toolform.Tag     := tag;
783      MDITab.AddTab(TForm(toolform), iconindex);
784      toolform.Caption := AnsiReplaceStr(toolform.Caption, '       ', '');
785 <    if (fileid > -1) and (connection <> nil) then
785 >    if connection > -1 then
786      begin
787 <      toolform.SelectFileID(connection, fileid);
787 >      toolform.SelectConnection(connection);
788 >      if fileid > -1 then
789 >        toolform.SelectFileID(connection, fileid);
790      end;
791      Result := toolform;
792    end;

Diff Legend

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