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 112 by alloc, Thu Feb 22 00:37:39 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 229 | Line 254 | begin
254    begin
255      AppSettings.DatPath        := ExtractFilepath(Application.EXEname);
256      AppSettings.ExtractPath    := ExtractFilepath(Application.EXEname) + '\extract';
232    AppSettings.FilenumbersAsHex := False;
257      AppSettings.CharSet        := DEFAULT_CHARSET;
258      AppSettings.HideUnusedData := False;
259    end;
# Line 292 | Line 316 | var
316    pt: TPoint;
317    tabIndex: Integer;
318    hint: String;
319 +  tool: TForm_ToolTemplate;
320   begin
321    pt.X := X;
322    pt.Y := Y;
# Line 302 | Line 327 | begin
327    begin
328      if MDITab.MDIChildren[tabIndex] is TForm_ToolTemplate then
329      begin
330 <      if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection <> nil then
330 >      tool := TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]);
331 >      if tool.ConnectionID > -1 then
332          hint := 'Connection: ' +
333 <              ExtractFileName(TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).Connection.FileName) + #13+#10
333 >              ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) + #13+#10
334        else
335          hint := 'Connection: none' + #13+#10;
336 <      if TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.ID >= 0 then
336 >      if tool.SelectedFile.ID > -1 then
337          hint := hint + 'Selected File: ' +
338 <              TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]).SelectedFile.FileName
338 >              FormatNumber(tool.SelectedFile.ID, 5, '0') + '-' +
339 >              tool.SelectedFile.Name + '.' +
340 >              tool.SelectedFile.Extension
341        else
342          hint := hint + 'Selected File: none';
343      end
# Line 386 | Line 414 | end;
414  
415   procedure TForm_Main.UpdateStatBar;
416   begin
417 <  if Length(DataConnections) > 0 then
417 >  if ConManager.Count > 0 then
418    begin
419      Self.Caption      := 'Oni Un/Packer ' + version;
420      ActivateTools(True);
421 <    statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(Length(DataConnections));
421 >    statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(ConManager.Count);
422    end
423    else
424    begin
# Line 400 | Line 428 | begin
428      statbar.Panels.Items[2].Text := '';
429      ActivateTools(False);
430    end;
431 <  menu_conns.Enabled := Length(DataConnections) > 0;
431 >  menu_conns.Enabled := ConManager.Count > 0;
432   end;
433  
434  
# Line 450 | Line 478 | begin
478          TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList;
479  
480    menu_conns.Clear;
481 <  if ConnectionManager.Count > 0 then
481 >  if ConManager.Count > 0 then
482    begin
483 <    for i := 0 to ConnectionManager.Count - 1 do
483 >    for i := 0 to ConManager.Count - 1 do
484      begin
485        entry := TTBItem.Create(menu_conns);
486 <      entry.Caption := ExtractFileName(DataConnections[i].FileName);
486 >      entry.Caption := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
487        entry.Name := 'menu_conn_' + IntToStr(i);
488        entry.OnClick := menu_conns_itemClick;
489        menu_conns.Add(entry);
# Line 467 | Line 495 | end;
495  
496   procedure TForm_Main.LoadFile(typedb: Boolean);
497   var
498 <  ext: String;
498 >  i: Integer;
499   begin
500    opend.InitialDir := AppSettings.DatPath;
501    opend.Filter     := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
# Line 477 | Line 505 | begin
505      opend.FilterIndex := 2;
506    if opend.Execute then
507    begin
508 <    ext := ExtractFileExt(opend.FileName);
509 <    if ext = '.dat' then
510 <    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');
508 >    if opend.Files.Count > 0 then
509 >      for i := 0 to opend.Files.Count - 1 do
510 >        CreateConnection(opend.Files.Strings[i]);
511      AppSettings.DatPath := ExtractFilepath(opend.FileName);
512    end;
513    UpdateStatBar;
# Line 555 | Line 577 | end;
577   {#################################}
578   procedure TForm_Main.menu_previewClick(Sender: TObject);
579   begin
580 <  open_child('preview', nil, -1);
580 >  open_child('preview', -1, -1);
581   end;
582  
583   procedure TForm_Main.menu_bineditClick(Sender: TObject);
584   begin
585 <  open_child('binedit', nil, -1);
585 >  open_child('binedit', -1, -1);
586   end;
587  
588   procedure TForm_Main.menu_raweditClick(Sender: TObject);
589   begin
590 <  open_child('rawedit', nil, -1);
590 >  open_child('rawedit', -1, -1);
591   end;
592  
593   procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
594   begin
595 <  open_child('txmpreplace', nil, -1);
595 >  open_child('txmpreplace', -1, -1);
596   end;
597  
598   procedure TForm_Main.menu_extractorClick(Sender: TObject);
599   begin
600 <  open_child('extractor', nil, -1);
600 >  open_child('extractor', -1, -1);
601   end;
602  
603   procedure TForm_Main.menu_metaClick(Sender: TObject);
# Line 585 | Line 607 | end;
607  
608   procedure TForm_Main.menu_filecompareClick(Sender: TObject);
609   begin
610 <  open_child('compare', nil, -1);
610 >  open_child('compare', -1, -1);
611   end;
612  
613  
# Line 652 | Line 674 | procedure TForm_Main.menu_conns_itemClic
674   var
675    name: String;
676    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 745 | Line 769 | begin
769    end;
770    if window_context = 'txmpreplace' then
771    begin
772 <    toolform         := TForm_TxmpReplace.Create(Application);
772 >    toolform         := TForm_TxmpReplace.Create(Self);
773      toolform.Caption := 'TXMP Replacer ' + caption_end;
774      iconindex        := 7;
775    end;
# Line 756 | Line 780 | begin
780      toolform.Tag     := tag;
781      MDITab.AddTab(TForm(toolform), iconindex);
782      toolform.Caption := AnsiReplaceStr(toolform.Caption, '       ', '');
783 <    if (fileid > -1) and (connection <> nil) then
783 >    if connection > -1 then
784      begin
785 <      toolform.SelectFileID(connection, fileid);
785 >      toolform.SelectConnection(connection);
786 >      if fileid > -1 then
787 >        toolform.SelectFileID(connection, fileid);
788      end;
789      Result := toolform;
790    end;

Diff Legend

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