source: oup/current/Main.pas@ 192

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