source: oup/current/Main.pas@ 219

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