source: oup/current/Main.pas@ 260

Last change on this file since 260 was 248, checked in by alloc, 17 years ago
File size: 24.0 KB
RevLine 
[93]1unit Main;
2interface
3uses
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus, Grids,
6 MPHexEditor, ToolWin, ImgList, Tabs,
7 MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, OneInst,
8 Data, TypeDefs, ConnectionManager,
[222]9 Functions, Settings,
10 RawEdit, BinEdit, Extractor, Preview, TxmpReplace,
11 _BaseTemplate, _TemplateFile, _TemplateFileList;
[93]12
13type
14 TForm_Main = class(TForm)
15 saved: TSaveDialog;
16 opend: TOpenDialog;
17 statbar: TStatusBar;
18 MenuImages: TImageList;
19 DockTop: TTBDock;
20 MainMenu: TTBToolbar;
21 menu_main: TTBSubmenuItem;
22 menu_loadfile: TTBItem;
23 menu_sep1: TTBSeparatorItem;
24 menu_settings: TTBItem;
25 menu_sep4: TTBSeparatorItem;
26 menu_exit: TTBItem;
27 menu_convert: TTBSubmenuItem;
28 menu_createdb: TTBItem;
29 menu_createlvl: TTBItem;
30 menu_tools: TTBSubmenuItem;
31 menu_preview: TTBItem;
32 menu_binedit: TTBItem;
33 menu_rawedit: TTBItem;
34 menu_txmpreplace: TTBItem;
35 menu_extractor: TTBItem;
36 menu_filecompare: TTBItem;
37 menu_levelstructedit: TTBItem;
38 menu_view: TTBSubmenuItem;
39 menu_windows_cascade: TTBItem;
40 menu_windows_tile: TTBItem;
41 menu_windows_closeall: TTBItem;
42 menu_sep3: TTBSeparatorItem;
43 menu_windows_next: TTBItem;
44 menu_windows_previous: TTBItem;
45 menu_sep2: TTBSeparatorItem;
46 menu_About: TTBItem;
[227]47 Toolbar_main: TTBToolbar;
[93]48 tbOpen: TTBItem;
49 DockLeft: TTBDock;
50 DockRight: TTBDock;
51 DockBottom: TTBDock;
52 MDIToolbar: TTBToolbar;
53 TBControlItem1: TTBControlItem;
54 MDITab: TMDITab;
55 menu_toolbars: TTBSubmenuItem;
56 menu_view_mdibar: TTBItem;
57 menu_view_statusbar: TTBItem;
58 menu_view_toolbar: TTBItem;
59 tb_separator1: TTBSeparatorItem;
60 menu_windows_tilevert: TTBItem;
61 menu_meta: TTBItem;
62 TBSeparatorItem1: TTBSeparatorItem;
63 tb_db2dat: TTBItem;
64 tb_dat2db: TTBItem;
65 menu_loaddb: TTBItem;
66 tb_opendb: TTBItem;
67 Images_Close: TImageList;
68 menu_conns: TTBSubmenuItem;
69 menu_windows: TTBSubmenuItem;
[227]70 menu_filemanager: TTBItem;
71 Toolbar_tools: TTBToolbar;
72 tb_preview: TTBItem;
73 tb_datedit: TTBItem;
74 tb_rawedit: TTBItem;
75 tb_txmpreplacer: TTBItem;
76 tb_extractor: TTBItem;
77 tb_meta: TTBItem;
78 tb_filemanager: TTBItem;
79 tb_compare: TTBItem;
80 tb_structure: TTBItem;
81 menu_view_toolbar_tools: TTBItem;
[93]82 procedure FormClose(Sender: TObject; var Action: TCloseAction);
83 procedure FormResize(Sender: TObject);
84 procedure FormCreate(Sender: TObject);
85 procedure ActivateTools(active: Boolean);
86 procedure UpdateStatBar;
87 procedure UpdateConLists;
88 procedure LoadFile(typedb: Boolean);
89 function TryCloseAll: Boolean;
90 procedure MDITabDrawTab(Control: TCustomTabControl; TabIndex: Integer;
91 const Rect: TRect; Active: Boolean);
92 procedure MDITabMouseUp(Sender: TObject; Button: TMouseButton;
93 Shift: TShiftState; X, Y: Integer);
94 procedure MDITabMouseMove(Sender: TObject; Shift: TShiftState; X,
95 Y: Integer);
[227]96 procedure Toolbar_mainDockChanged(Sender: TObject);
[93]97 procedure CreateConnection(filename: String);
[97]98 function CheckConnectionCloseable(index: Integer): Boolean;
[93]99
100 procedure menu_loadfileClick(Sender: TObject);
101 procedure menu_loaddbClick(Sender: TObject);
102 procedure menu_settingsClick(Sender: TObject);
103 procedure menu_exitClick(Sender: TObject);
104
105 procedure menu_createlvlClick(Sender: TObject);
106 procedure menu_createdbClick(Sender: TObject);
107
108 procedure menu_bineditClick(Sender: TObject);
109 procedure menu_filecompareClick(Sender: TObject);
110 procedure menu_raweditClick(Sender: TObject);
111 procedure menu_extractorClick(Sender: TObject);
112 procedure menu_txmpreplaceClick(Sender: TObject);
113 procedure menu_previewClick(Sender: TObject);
114 procedure menu_metaClick(Sender: TObject);
115
116 procedure menu_windows_cascadeClick(Sender: TObject);
117 procedure menu_windows_tilevertClick(Sender: TObject);
118 procedure menu_windows_tileClick(Sender: TObject);
119 procedure menu_windows_closeallClick(Sender: TObject);
120 procedure menu_windows_previousClick(Sender: TObject);
121 procedure menu_windows_nextClick(Sender: TObject);
122 procedure menu_conns_itemClick(Sender: TObject);
123 procedure menu_windows_itemClick(Sender: TObject);
124 procedure menu_view_mdibarClick(Sender: TObject);
125 procedure menu_view_statusbarClick(Sender: TObject);
126 procedure menu_view_toolbarClick(Sender: TObject);
127
128 procedure menu_AboutClick(Sender: TObject);
129
130 procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
[227]131 procedure menu_filemanagerClick(Sender: TObject);
132 procedure menu_view_toolbar_toolsClick(Sender: TObject);
[93]133 private
134 public
[222]135 function open_child(window_context: String; Connection, FileID: Integer): TForm_BaseTemplate; overload;
136 function open_child(window_context: String; Connection: Integer): TForm_BaseTemplate; overload;
137 function open_child(window_context: String): TForm_BaseTemplate; overload;
[93]138 procedure DefaultHandler(var Message); override;
139 end;
140
141var
142 Form_Main: TForm_Main;
143
144implementation
145
[129]146uses
[227]147 LevelDB, MetaEditor, FileManager;
[129]148
[93]149{$R *.dfm}
150
151
152procedure ShowOpenMsg(msg: TStatusMessages);
153begin
154 case msg of
155 SM_AlreadyOpened: ShowMessage('File already opened.');
156 SM_FileNotFound: ShowMessage('File not found.');
157 SM_UnknownExtension: ShowMessage('Unknown extension.');
158 SM_IncompatibleFile: ShowMessage('Incompatible file format.');
159 SM_UnknownError: ShowMessage('Unknown error.');
160 end;
161end;
162
163procedure TForm_Main.CreateConnection(filename: String);
164var
165 RepMsg: TStatusMessages;
166begin
[97]167 ConManager.OpenConnection(filename, RepMsg);
[93]168 ShowOpenMsg(RepMsg);
169 if RepMsg = SM_OK then
170 begin
171 UpdateStatBar;
[105]172 UpdateConLists;
[93]173 end;
174end;
175
[97]176function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean;
177var
178 i: Integer;
[222]179 toolform: TForm_BaseTemplate;
[97]180begin
[113]181 Result := True;
[97]182 if MDITab.MDIChildCount > 0 then
183 begin
184 for i := 0 to MDITab.MDIChildCount - 1 do
185 begin
[222]186 if MDITab.MDIChildren[i] is TForm_BaseTemplate then
[97]187 begin
[222]188 toolform := TForm_BaseTemplate(MDITab.MDIChildren[i]);
[97]189 if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then
190 begin
191 if not toolform.Closeable then
[113]192 begin
193 ShowMessage('Can not close toolwindow: ' + toolform.Caption);
194 Result := False;
195 end;
[97]196 end;
197 end;
198 end;
199 end;
200end;
201
202
[93]203{ Eine zweite Instanz hat uns ihre Kommandozeilenparameter geschickt }
204procedure TForm_Main.WMCopyData(var Msg: TWMCopyData);
205var
206 strings: TStringList;
207begin
208 if (Msg.CopyDataStruct.dwData = SecondInstMsgId) and (SecondInstMsgId <> 0) then
209 begin
210 Application.BringToFront;
211
212 strings := TStringList.Create;
213 strings.Text := ParamBlobToStr(Msg.CopyDataStruct.lpData);
214 if strings.Count = 2 then
215 begin
216 if strings.Strings[0] = 'opf' then
217 begin
218 ShowMessage('Load OPF-File: ' + ParamStr(2));
219 end
[247]220 else if (strings.Strings[0] = 'oldb') or (strings.Strings[0] = 'dat') or (strings.Strings[0] = 'oni') then
[93]221 begin
222 CreateConnection(strings.Strings[1]);
223 end;
224 end;
225 end
226 else
227 inherited;
228end;
229
230{----------------------------------------------------------------------------}
231{ Wir überschreiben den DefaultHandler, der alle Nachrichten zuerst bekommt, }
232{ damit wir auf die Nachricht mit der ID SecondInstMsgId reagieren können. }
233{ (Dies ist notwendig, da wir jetzt noch nicht wissen welchen Wert }
234{ die ID haben wird, weswegen wir keine statische Message-Prozedure, }
235{ so wie bei WM_COPYDATA, schreiben können.) }
236{----------------------------------------------------------------------------}
237procedure TForm_Main.DefaultHandler(var Message);
238begin
239 if TMessage(Message).Msg = SecondInstMsgId then
240 { Eine zweite Instanz hat uns nach dem Handle gefragt }
241 { Es wird in die Message-Queue des Threads gepostet. }
242 PostThreadMessage(TMessage(Message).WParam, SecondInstMsgId, Handle, 0)
243 else
244 inherited;
245end;
246
247
248
249procedure TForm_Main.FormCreate(Sender: TObject);
250begin
251 Self.Caption := 'Oni Un/Packer ' + version;
252 Self.FormResize(Self);
253
[97]254 ConManager.OnCoonnectionListChanged := UpdateConLists;
[93]255
[241]256 Application.HintPause := 250;
257 Application.HintHidePause := 5000;
258
[93]259 if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then
260 begin
261 AssignFile(AppSettingsFile, ExtractFilepath(Application.EXEname) +
262 '\oniunpacker.ini');
263 Reset(AppSettingsFile);
264 Read(AppSettingsFile, AppSettings);
265 CloseFile(AppSettingsFile);
266 end
267 else
268 begin
[197]269 ShowMessage('Warning!' + #13#10 +
270 'It seems like this is the first time you OUP.' + #13#10 +
271 'I do not take any responsibility for messed up data files' + #13+#10 +
272 'Do not forget to make backup copies of your *.dat/*.raw/*.sep files!');
[93]273 AppSettings.DatPath := ExtractFilepath(Application.EXEname);
274 AppSettings.ExtractPath := ExtractFilepath(Application.EXEname) + '\extract';
275 AppSettings.CharSet := DEFAULT_CHARSET;
276 AppSettings.HideUnusedData := False;
277 end;
278
279 if MidStr(ParamStr(1), 1, 3) = 'opf' then
280 begin
281 ShowMessage('Load OPF-File: ' + ParamStr(2));
282 end
[247]283 else if (MidStr(ParamStr(1), 1, 4) = 'oldb') or (MidStr(ParamStr(1), 1, 3) = 'dat') or (MidStr(ParamStr(1), 1, 3) = 'oni') then
[93]284 begin
285 CreateConnection(ParamStr(2));
286 end;
287 UpdateStatBar;
288end;
289
290
291
292
293procedure TForm_Main.FormResize(Sender: TObject);
294begin
295 statbar.Panels.Items[0].Width := Self.Width - 200;
296 MDITab.Width := Self.Width - 20;
297end;
298
299
300
301
302procedure TForm_Main.MDITabDrawTab(Control: TCustomTabControl;
303 TabIndex: Integer; const Rect: TRect; Active: Boolean);
304var
305 x, y: Integer;
306 iconindex: Integer;
307 caption: String;
308begin
309 iconindex := TMDITab(Control).Glyphs[TabIndex];
310 caption := TMDITab(Control).Captions[TabIndex];
311 if active then
312 begin
313 Control.Canvas.Font.Style := Control.Canvas.Font.Style + [fsItalic];
314 y := Rect.Top + 1;
315 end else
316 y := Rect.Top;
317 if iconindex >= 0 then
318 begin
319 TMDITab(Control).Images.Draw(Control.Canvas, Rect.Left + 4, y, iconindex);
320 x := Rect.Left + 26;
321 end else
322 x := Rect.Left + 4;
323 Control.Canvas.TextOut(x, y + 2, caption);
324 if active then
325 Images_Close.Draw(Control.Canvas, Rect.Right - 18, y, 0)
326 else
327 Images_Close.Draw(Control.Canvas, Rect.Right - 18, y, 1);
328end;
329
330
331procedure TForm_Main.MDITabMouseMove(Sender: TObject; Shift: TShiftState; X,
332 Y: Integer);
333var
334 pt: TPoint;
335 tabIndex: Integer;
336 hint: String;
[222]337 tool: TForm_BaseTemplate;
[93]338begin
339 pt.X := X;
340 pt.Y := Y;
341 tabIndex := MDITab.GetTabAtPos(pt);
342 hint := '';
343
344 if tabIndex >= 0 then
345 begin
[222]346 if MDITab.MDIChildren[tabIndex] is TForm_BaseTemplate then
[93]347 begin
[222]348 tool := TForm_BaseTemplate(MDITab.MDIChildren[tabIndex]);
[97]349 if tool.ConnectionID > -1 then
[93]350 hint := 'Connection: ' +
[222]351 ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName)
[93]352 else
[222]353 hint := 'Connection: none';
354 if tool is TForm_TemplateFile then
355 begin
356 if TForm_TemplateFile(tool).SelectedFile.ID > -1 then
357 hint := hint + #13+#10 + 'Selected File: ' +
358 FormatNumber(TForm_TemplateFile(tool).SelectedFile.ID, 5, '0') + '-' +
359 TForm_TemplateFile(tool).SelectedFile.Name + '.' +
360 TForm_TemplateFile(tool).SelectedFile.Extension
361 else
362 hint := hint + #13+#10 + 'Selected File: none';
363 end;
[93]364 end
365 else
366 hint := 'Window: ' + MDITab.MDIChildren[tabIndex].Caption;
367 if hint <> MDITab.Hint then
368 begin
369 MDITab.Hint := hint;
370 MDITab.ShowHint := True;
371 end;
372 end
373 else
374 begin
375 MDITab.ShowHint := False;
376 MDITab.Hint := '';
377 end;
378end;
379
380procedure TForm_Main.MDITabMouseUp(Sender: TObject; Button: TMouseButton;
381 Shift: TShiftState; X, Y: Integer);
382var
383 pt: TPoint;
384 tabIndex: Integer;
385 tabRect: TRect;
386 tabX, tabY, tabWidth: Integer;
387begin
388 pt.X := X;
389 pt.Y := Y;
390 tabIndex := MDITab.GetTabAtPos(pt);
391
392// if (Button = mbRight) and (tabIndex >= 0) then
393// MDITab.MDIChildren[tabIndex].Close;
394
395 if (Button = mbLeft) and (tabIndex >= 0) then
396 begin
397 tabrect := MDITab.TabRect(tabIndex);
398 tabX := X - tabrect.Left;
399 tabY := Y - tabrect.Top;
400 tabwidth := tabrect.Right - tabrect.Left;
401 if (tabY >= 4) and (tabY <= 17) then
402 if (tabX >= tabwidth - 19) and (tabX <= tabwidth - 7) then
403 MDITab.MDIChildren[tabIndex].Close;
404 end;
405end;
406
407
408
409
410procedure TForm_Main.FormClose(Sender: TObject; var Action: TCloseAction);
411begin
412 AssignFile(AppSettingsFile, ExtractFilepath(Application.EXEname) + '\oniunpacker.ini');
413 if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then
414 Reset(AppSettingsFile)
415 else
416 Rewrite(AppSettingsFile);
417 Write(AppSettingsFile, AppSettings);
418 CloseFile(AppSettingsFile);
419 Action := caFree;
420end;
421
422
423
424procedure TForm_Main.ActivateTools(active: Boolean);
425begin
426 menu_tools.Enabled := active;
427 tb_preview.Enabled := active;
428 tb_datedit.Enabled := active;
429 tb_rawedit.Enabled := active;
430 tb_txmpreplacer.Enabled := active;
431 tb_extractor.Enabled := active;
[209]432 tb_meta.Enabled := active;
[93]433// tb_compare.Enabled := active;
434// tb_structure.Enabled := active;
435end;
436
437procedure TForm_Main.UpdateStatBar;
438begin
[97]439 if ConManager.Count > 0 then
[93]440 begin
441 Self.Caption := 'Oni Un/Packer ' + version;
442 ActivateTools(True);
[97]443 statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(ConManager.Count);
[93]444 end
445 else
446 begin
447 Self.Caption := 'Oni Un/Packer ' + version;
448 statbar.Panels.Items[0].Text := '';
449 statbar.Panels.Items[1].Text := 'Connections: -';
450 statbar.Panels.Items[2].Text := '';
451 ActivateTools(False);
452 end;
[97]453 menu_conns.Enabled := ConManager.Count > 0;
[93]454end;
455
456
457
458
[227]459procedure TForm_Main.Toolbar_mainDockChanged(Sender: TObject);
[93]460var
461 toolbar: TTBToolbar;
462 position: TTBDockPosition;
463 mode: TTBItemDisplayMode;
464 i: Integer;
465begin
466 toolbar := TTBToolbar(Sender);
467 if toolbar.Floating then
468 mode := nbdmImageAndText
469 else begin
470 position := toolbar.CurrentDock.Position;
471 if position in [dpLeft, dpRight] then
472 mode := nbdmDefault
473 else
474 mode := nbdmImageAndText;
475 end;
476 for i := 0 to toolbar.Items.Count - 1 do
477 toolbar.Items.Items[i].DisplayMode := mode;
478end;
479
480function TForm_Main.TryCloseAll: Boolean;
481begin
482 menu_windows_closeallClick(Self);
483 Application.ProcessMessages;
484 if MDITab.MDIChildCount = 0 then
485 Result := True
486 else
487 Result := False;
488end;
489
490
491procedure TForm_Main.UpdateConLists;
492var
493 i: Integer;
494 entry: TTBItem;
495begin
496 if MDITab.MDIChildCount > 0 then
497 for i := 0 to MDITab.MDIChildCount - 1 do
[222]498 if MDITab.MDIChildren[i] is TForm_BaseTemplate then
499 TForm_BaseTemplate(MDITab.MDIChildren[i]).UpdateConList;
[93]500
501 menu_conns.Clear;
[97]502 if ConManager.Count > 0 then
[93]503 begin
[97]504 for i := 0 to ConManager.Count - 1 do
[93]505 begin
506 entry := TTBItem.Create(menu_conns);
[97]507 entry.Caption := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
[93]508 entry.Name := 'menu_conn_' + IntToStr(i);
509 entry.OnClick := menu_conns_itemClick;
510 menu_conns.Add(entry);
511 end;
512 end;
513end;
514
515
516procedure TForm_Main.LoadFile(typedb: Boolean);
517var
[105]518 i: Integer;
[93]519begin
520 opend.InitialDir := AppSettings.DatPath;
[247]521 opend.Filter := 'Compatible level files|*.dat;*.oni;*.oldb|Oni level (*.dat)|*.dat|OniSplit Archive (*.oni)|*.oni|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
[93]522 if typedb then
[248]523 opend.FilterIndex := 4
[93]524 else
525 opend.FilterIndex := 2;
526 if opend.Execute then
527 begin
[105]528 if opend.Files.Count > 0 then
529 for i := 0 to opend.Files.Count - 1 do
530 CreateConnection(opend.Files.Strings[i]);
[93]531 AppSettings.DatPath := ExtractFilepath(opend.FileName);
532 end;
533 UpdateStatBar;
534end;
535
536
537 {#################################}
538 {##### Main-Menu-Handlers #####}
539 {#################################}
540procedure TForm_Main.menu_loaddbClick(Sender: TObject);
541begin
542 LoadFile(True);
543end;
544
545procedure TForm_Main.menu_loadfileClick(Sender: TObject);
546begin
547 LoadFile(False);
548end;
549
550
551procedure TForm_Main.menu_settingsClick(Sender: TObject);
552begin
553 Form_Settings.Visible := True;
554 Self.Enabled := False;
555end;
556
557
558procedure TForm_Main.menu_exitClick(Sender: TObject);
559begin
560 Self.Close;
561end;
562
563
564 {####################################}
565 {##### Converters-Menu-Handlers #####}
566 {####################################}
567procedure TForm_Main.menu_createdbClick(Sender: TObject);
568begin
569 opend.Filter := 'Oni-Dat-Files|*.dat';
570 saved.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
571 saved.DefaultExt := 'oldb';
572 if opend.Execute then
573 if saved.Execute then
574 Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
575end;
576
577
578procedure TForm_Main.menu_createlvlClick(Sender: TObject);
579begin
580 opend.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
581 saved.Filter := 'Oni-Dat-Files|*.dat';
582 saved.DefaultExt := 'dat';
583 if opend.Execute then
584 if saved.Execute then
585 Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
586end;
587
588
589 {#################################}
590 {##### Tools-Menu-Handlers #####}
591 {#################################}
592procedure TForm_Main.menu_previewClick(Sender: TObject);
593begin
[222]594 open_child('preview');
[93]595end;
596
597procedure TForm_Main.menu_bineditClick(Sender: TObject);
598begin
[222]599 open_child('binedit');
[93]600end;
601
602procedure TForm_Main.menu_raweditClick(Sender: TObject);
603begin
[222]604 open_child('rawedit');
[93]605end;
606
607procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
608begin
[222]609 open_child('txmpreplace');
[93]610end;
611
612procedure TForm_Main.menu_extractorClick(Sender: TObject);
613begin
[222]614 open_child('extractor');
[93]615end;
616
617procedure TForm_Main.menu_metaClick(Sender: TObject);
618begin
[222]619 open_child('meta');
[93]620end;
621
622procedure TForm_Main.menu_filecompareClick(Sender: TObject);
623begin
[222]624 open_child('compare');
[93]625end;
626
627
[227]628 procedure TForm_Main.menu_filemanagerClick(Sender: TObject);
629begin
630 open_child('filemanager');
631end;
632
633{#################################}
[93]634 {##### View-Menu-Handlers #####}
635 {#################################}
636procedure TForm_Main.menu_windows_cascadeClick(Sender: TObject);
637begin
638 Self.Cascade;
639end;
640
641procedure TForm_Main.menu_windows_tilevertClick(Sender: TObject);
642begin
643 Self.TileMode := tbVertical;
644 Self.Tile;
645end;
646
647procedure TForm_Main.menu_windows_tileClick(Sender: TObject);
648begin
649 Self.TileMode := tbHorizontal;
650 Self.Tile;
651end;
652
653procedure TForm_Main.menu_windows_closeallClick(Sender: TObject);
654begin
655 MDITab.CloseAll;
656end;
657
658procedure TForm_Main.menu_windows_nextClick(Sender: TObject);
659begin
660 if MDIChildCount > 1 then
661 if MDITab.TabIndex = MDITab.MDIChildCount - 1 then
662 MDITab.MDIChildren[0].BringToFront
663 else
664 MDITab.MDIChildren[MDITab.TabIndex + 1].BringToFront;
665end;
666
667procedure TForm_Main.menu_windows_previousClick(Sender: TObject);
668begin
669 if MDIChildCount > 1 then
670 if MDITab.TabIndex = 0 then
671 MDITab.MDIChildren[MDITab.MDIChildCount - 1].BringToFront
672 else
673 MDITab.MDIChildren[MDITab.TabIndex - 1].BringToFront;
674end;
675
676
677 {##################################}
678 {##### Windows-Menu-Handlers #####}
679 {##################################}
680procedure TForm_Main.menu_windows_itemClick(Sender: TObject);
681var
682 name: String;
683begin
684 name := TTBItem(Sender).Name;
685end;
686
687
688
689 {######################################}
690 {##### Connections-Menu-Handlers #####}
691 {######################################}
692procedure TForm_Main.menu_conns_itemClick(Sender: TObject);
693var
694 name: String;
[97]695 index: Integer;
696 RepMsg: TStatusMessages;
[93]697begin
[97]698 index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender));
699 name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName);
[93]700 if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+
701 name + '?'), PChar('Close?'), MB_YESNO + MB_ICONQUESTION) = ID_YES then
702 begin
[97]703 CheckConnectionCloseable(index);
704 ConManager.CloseConnectionByIndex(index, RepMsg);
[105]705 ShowOpenMsg(RepMsg);
706 UpdateConLists;
[93]707 end;
708 UpdateStatBar;
709end;
710
711
712 {###################################}
713 {##### Toolbars-Menu-Handlers #####}
714 {###################################}
715procedure TForm_Main.menu_view_toolbarClick(Sender: TObject);
716begin
717 menu_view_toolbar.Checked := not menu_view_toolbar.Checked;
[227]718 Toolbar_main.Visible := menu_view_toolbar.Checked;
[93]719end;
720
[227]721procedure TForm_Main.menu_view_toolbar_toolsClick(Sender: TObject);
722begin
723 menu_view_toolbar_tools.Checked := not menu_view_toolbar_tools.Checked;
724 Toolbar_tools.Visible := menu_view_toolbar_tools.Checked;
725end;
726
[93]727procedure TForm_Main.menu_view_statusbarClick(Sender: TObject);
728begin
729 menu_view_statusbar.Checked := not menu_view_statusbar.Checked;
730 statbar.Visible := menu_view_statusbar.Checked;
731end;
732
733procedure TForm_Main.menu_view_mdibarClick(Sender: TObject);
734begin
735 menu_view_mdibar.Checked := not menu_view_mdibar.Checked;
736 mditoolbar.Visible := menu_view_mdibar.Checked;
737end;
738
739
740
741procedure TForm_Main.menu_AboutClick(Sender: TObject);
742begin
743 ShowMessage('Will be implemented later ;)');
744end;
745
746
747
748
749
[222]750function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_BaseTemplate;
[172]751type
[222]752 TTemplate = class of TForm_BaseTemplate;
[172]753 TTool = record
754 name: String;
755 icon: Integer;
756 caption: String;
757 classt: TTemplate;
758 end;
759const
[227]760 Tools: array[0..6] of TTool = (
[172]761 (name: 'binedit'; icon: 5; caption: 'Binary .dat-Editor'; classt: TForm_BinEdit),
762 (name: 'extractor'; icon: 8; caption: 'Extractor'; classt: TForm_Extractor),
763 (name: 'preview'; icon: 4; caption: 'Preview-Window'; classt: TForm_Preview),
764 (name: 'rawedit'; icon: 6; caption: 'Binary .raw-Editor'; classt: TForm_RawEdit),
[224]765 (name: 'txmpreplace'; icon: 7; caption: 'TXMP Replacer'; classt: TForm_TxmpReplace),
[227]766 (name: 'filemanager'; icon:-1; caption: 'FileManager'; classt: TForm_FileManager),
[222]767 (name: 'meta'; icon: 11; caption: 'MetaEditor'; classt: TForm_Meta)
[172]768 );
[93]769var
[222]770 toolform: TForm_BaseTemplate;
[93]771 i: Integer;
772 tag: Integer;
773 iconindex: Integer;
774begin
775 Result := nil;
776
777 tag := 1;
778 if MDIChildCount > 0 then
779 for i := 0 to MDIChildCount - 1 do
780 if MDIChildren[i].Tag >= tag then
781 tag := MDIChildren[i].Tag + 1;
782
783 iconindex := -1;
784
[113]785 toolform := nil;
786
[172]787 for i := 0 to High(Tools) do
788 if Tools[i].name = window_context then
789 Break;
790 if i < Length(Tools) then
[93]791 begin
[172]792 toolform := TTemplate(Tools[i].classt).Create(Self);
793 toolform.Caption := Tools[i].caption + ' ' + IntToStr(tag) + ' ';
794 iconindex := Tools[i].icon;
795 end else begin
796 ShowMessage('WindowContext not found!');
[93]797 end;
798
799 if Assigned(toolform) then
800 begin
801 toolform.Name := window_context + IntToStr(tag);
802 toolform.Tag := tag;
803 MDITab.AddTab(TForm(toolform), iconindex);
804 toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', '');
[222]805 if Connection > -1 then
[93]806 begin
[97]807 toolform.SelectConnection(connection);
[222]808 if (FileID > -1) and (toolform is TForm_TemplateFile) then
809 TForm_TemplateFile(toolform).SelectFileID(Connection, FileID);
[93]810 end;
811 Result := toolform;
812 end;
813end;
814
[222]815function TForm_Main.open_child(window_context: String; Connection: Integer): TForm_BaseTemplate;
816begin
[239]817 Result := open_child(window_context, Connection, -1);
[222]818end;
819
820function TForm_Main.open_child(window_context: String): TForm_BaseTemplate;
821begin
[239]822 Result := open_child(window_context, -1, -1);
[222]823end;
824
[93]825end.
Note: See TracBrowser for help on using the repository browser.