source: oup/releases/0.34a/Main.pas@ 280

Last change on this file since 280 was 200, checked in by alloc, 18 years ago
File size: 22.4 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, Settings, Template,
10 RawEdit, BinEdit, Extractor, Preview, TxmpReplace;
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);
93 function CheckConnectionCloseable(index: Integer): Boolean;
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
137uses
138 LevelDB;
139
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
158 ConManager.OpenConnection(filename, RepMsg);
159 ShowOpenMsg(RepMsg);
160 if RepMsg = SM_OK then
161 begin
162 UpdateStatBar;
163 UpdateConLists;
164 end;
165end;
166
167function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean;
168var
169 i: Integer;
170 toolform: TForm_ToolTemplate;
171begin
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;
191end;
192
193
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
245 ConManager.OnCoonnectionListChanged := UpdateConLists;
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
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!');
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;
325 tool: TForm_ToolTemplate;
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
336 tool := TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]);
337 if tool.ConnectionID > -1 then
338 hint := 'Connection: ' +
339 ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) + #13+#10
340 else
341 hint := 'Connection: none' + #13+#10;
342 if tool.SelectedFile.ID > -1 then
343 hint := hint + 'Selected File: ' +
344 FormatNumber(tool.SelectedFile.ID, 5, '0') + '-' +
345 tool.SelectedFile.Name + '.' +
346 tool.SelectedFile.Extension
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;
417// tb_compare.Enabled := active;
418// tb_structure.Enabled := active;
419end;
420
421procedure TForm_Main.UpdateStatBar;
422begin
423 if ConManager.Count > 0 then
424 begin
425 Self.Caption := 'Oni Un/Packer ' + version;
426 ActivateTools(True);
427 statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(ConManager.Count);
428 end
429 else
430 begin
431 Self.Caption := 'Oni Un/Packer ' + version;
432 statbar.Panels.Items[0].Text := '';
433 statbar.Panels.Items[1].Text := 'Connections: -';
434 statbar.Panels.Items[2].Text := '';
435 ActivateTools(False);
436 end;
437 menu_conns.Enabled := ConManager.Count > 0;
438end;
439
440
441
442
443procedure TForm_Main.ToolbarDockChanged(Sender: TObject);
444var
445 toolbar: TTBToolbar;
446 position: TTBDockPosition;
447 mode: TTBItemDisplayMode;
448 i: Integer;
449begin
450 toolbar := TTBToolbar(Sender);
451 if toolbar.Floating then
452 mode := nbdmImageAndText
453 else begin
454 position := toolbar.CurrentDock.Position;
455 if position in [dpLeft, dpRight] then
456 mode := nbdmDefault
457 else
458 mode := nbdmImageAndText;
459 end;
460 for i := 0 to toolbar.Items.Count - 1 do
461 toolbar.Items.Items[i].DisplayMode := mode;
462end;
463
464function TForm_Main.TryCloseAll: Boolean;
465begin
466 menu_windows_closeallClick(Self);
467 Application.ProcessMessages;
468 if MDITab.MDIChildCount = 0 then
469 Result := True
470 else
471 Result := False;
472end;
473
474
475procedure TForm_Main.UpdateConLists;
476var
477 i: Integer;
478 entry: TTBItem;
479begin
480 if MDITab.MDIChildCount > 0 then
481 for i := 0 to MDITab.MDIChildCount - 1 do
482 if MDITab.MDIChildren[i] is TForm_ToolTemplate then
483 TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList;
484
485 menu_conns.Clear;
486 if ConManager.Count > 0 then
487 begin
488 for i := 0 to ConManager.Count - 1 do
489 begin
490 entry := TTBItem.Create(menu_conns);
491 entry.Caption := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
492 entry.Name := 'menu_conn_' + IntToStr(i);
493 entry.OnClick := menu_conns_itemClick;
494 menu_conns.Add(entry);
495 entry := nil;
496 end;
497 end;
498end;
499
500
501procedure TForm_Main.LoadFile(typedb: Boolean);
502var
503 i: Integer;
504begin
505 opend.InitialDir := AppSettings.DatPath;
506 opend.Filter := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
507 if typedb then
508 opend.FilterIndex := 3
509 else
510 opend.FilterIndex := 2;
511 if opend.Execute then
512 begin
513 if opend.Files.Count > 0 then
514 for i := 0 to opend.Files.Count - 1 do
515 CreateConnection(opend.Files.Strings[i]);
516 AppSettings.DatPath := ExtractFilepath(opend.FileName);
517 end;
518 UpdateStatBar;
519end;
520
521
522 {#################################}
523 {##### Main-Menu-Handlers #####}
524 {#################################}
525procedure TForm_Main.menu_loaddbClick(Sender: TObject);
526begin
527 LoadFile(True);
528end;
529
530procedure TForm_Main.menu_loadfileClick(Sender: TObject);
531begin
532 LoadFile(False);
533end;
534
535
536procedure TForm_Main.menu_settingsClick(Sender: TObject);
537begin
538 Form_Settings.Visible := True;
539 Self.Enabled := False;
540end;
541
542
543procedure TForm_Main.menu_exitClick(Sender: TObject);
544begin
545 Self.Close;
546end;
547
548
549 {####################################}
550 {##### Converters-Menu-Handlers #####}
551 {####################################}
552procedure TForm_Main.menu_createdbClick(Sender: TObject);
553begin
554// ShowMessage('Not yet usable');
555
556 opend.Filter := 'Oni-Dat-Files|*.dat';
557 saved.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
558 saved.DefaultExt := 'oldb';
559 if opend.Execute then
560 if saved.Execute then
561 Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
562end;
563
564
565procedure TForm_Main.menu_createlvlClick(Sender: TObject);
566begin
567// ShowMessage('Not yet usable');
568
569 opend.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
570 saved.Filter := 'Oni-Dat-Files|*.dat';
571 saved.DefaultExt := 'dat';
572 if opend.Execute then
573 if saved.Execute then
574 Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
575end;
576
577
578 {#################################}
579 {##### Tools-Menu-Handlers #####}
580 {#################################}
581procedure TForm_Main.menu_previewClick(Sender: TObject);
582begin
583 open_child('preview', -1, -1);
584end;
585
586procedure TForm_Main.menu_bineditClick(Sender: TObject);
587begin
588 open_child('binedit', -1, -1);
589end;
590
591procedure TForm_Main.menu_raweditClick(Sender: TObject);
592begin
593 open_child('rawedit', -1, -1);
594end;
595
596procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
597begin
598 open_child('txmpreplace', -1, -1);
599end;
600
601procedure TForm_Main.menu_extractorClick(Sender: TObject);
602begin
603 open_child('extractor', -1, -1);
604end;
605
606procedure TForm_Main.menu_metaClick(Sender: TObject);
607begin
608 ShowMessage('TBD');
609end;
610
611procedure TForm_Main.menu_filecompareClick(Sender: TObject);
612begin
613 open_child('compare', -1, -1);
614end;
615
616
617 {#################################}
618 {##### View-Menu-Handlers #####}
619 {#################################}
620procedure TForm_Main.menu_windows_cascadeClick(Sender: TObject);
621begin
622 Self.Cascade;
623end;
624
625procedure TForm_Main.menu_windows_tilevertClick(Sender: TObject);
626begin
627 Self.TileMode := tbVertical;
628 Self.Tile;
629end;
630
631procedure TForm_Main.menu_windows_tileClick(Sender: TObject);
632begin
633 Self.TileMode := tbHorizontal;
634 Self.Tile;
635end;
636
637procedure TForm_Main.menu_windows_closeallClick(Sender: TObject);
638begin
639 MDITab.CloseAll;
640end;
641
642procedure TForm_Main.menu_windows_nextClick(Sender: TObject);
643begin
644 if MDIChildCount > 1 then
645 if MDITab.TabIndex = MDITab.MDIChildCount - 1 then
646 MDITab.MDIChildren[0].BringToFront
647 else
648 MDITab.MDIChildren[MDITab.TabIndex + 1].BringToFront;
649end;
650
651procedure TForm_Main.menu_windows_previousClick(Sender: TObject);
652begin
653 if MDIChildCount > 1 then
654 if MDITab.TabIndex = 0 then
655 MDITab.MDIChildren[MDITab.MDIChildCount - 1].BringToFront
656 else
657 MDITab.MDIChildren[MDITab.TabIndex - 1].BringToFront;
658end;
659
660
661 {##################################}
662 {##### Windows-Menu-Handlers #####}
663 {##################################}
664procedure TForm_Main.menu_windows_itemClick(Sender: TObject);
665var
666 name: String;
667begin
668 name := TTBItem(Sender).Name;
669end;
670
671
672
673 {######################################}
674 {##### Connections-Menu-Handlers #####}
675 {######################################}
676procedure TForm_Main.menu_conns_itemClick(Sender: TObject);
677var
678 name: String;
679 index: Integer;
680 RepMsg: TStatusMessages;
681begin
682// name := TTBItem(Sender).Caption;
683 index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender));
684 name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName);
685 if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+
686 name + '?'), PChar('Close?'), MB_YESNO + MB_ICONQUESTION) = ID_YES then
687 begin
688 CheckConnectionCloseable(index);
689 ConManager.CloseConnectionByIndex(index, RepMsg);
690 ShowOpenMsg(RepMsg);
691 UpdateConLists;
692 end;
693 UpdateStatBar;
694end;
695
696
697 {###################################}
698 {##### Toolbars-Menu-Handlers #####}
699 {###################################}
700procedure TForm_Main.menu_view_toolbarClick(Sender: TObject);
701begin
702 menu_view_toolbar.Checked := not menu_view_toolbar.Checked;
703 Toolbar.Visible := menu_view_toolbar.Checked;
704end;
705
706procedure TForm_Main.menu_view_statusbarClick(Sender: TObject);
707begin
708 menu_view_statusbar.Checked := not menu_view_statusbar.Checked;
709 statbar.Visible := menu_view_statusbar.Checked;
710end;
711
712procedure TForm_Main.menu_view_mdibarClick(Sender: TObject);
713begin
714 menu_view_mdibar.Checked := not menu_view_mdibar.Checked;
715 mditoolbar.Visible := menu_view_mdibar.Checked;
716end;
717
718
719
720procedure TForm_Main.menu_AboutClick(Sender: TObject);
721begin
722 ShowMessage('Will be implemented later ;)');
723end;
724
725
726
727
728
729function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate;
730type
731 TTemplate = class of TForm_ToolTemplate;
732 TTool = record
733 name: String;
734 icon: Integer;
735 caption: String;
736 classt: TTemplate;
737 end;
738const
739 Tools: array[0..4] of TTool = (
740 (name: 'binedit'; icon: 5; caption: 'Binary .dat-Editor'; classt: TForm_BinEdit),
741 (name: 'extractor'; icon: 8; caption: 'Extractor'; classt: TForm_Extractor),
742 (name: 'preview'; icon: 4; caption: 'Preview-Window'; classt: TForm_Preview),
743 (name: 'rawedit'; icon: 6; caption: 'Binary .raw-Editor'; classt: TForm_RawEdit),
744 (name: 'txmpreplace'; icon: 7; caption: 'TXMP Replacer'; classt: TForm_TxmpReplace)
745 );
746var
747 toolform: TForm_ToolTemplate;
748 i: Integer;
749 tag: Integer;
750 iconindex: Integer;
751begin
752 Result := nil;
753
754 tag := 1;
755 if MDIChildCount > 0 then
756 for i := 0 to MDIChildCount - 1 do
757 if MDIChildren[i].Tag >= tag then
758 tag := MDIChildren[i].Tag + 1;
759
760 iconindex := -1;
761
762 toolform := nil;
763
764 for i := 0 to High(Tools) do
765 if Tools[i].name = window_context then
766 Break;
767 if i < Length(Tools) then
768 begin
769 toolform := TTemplate(Tools[i].classt).Create(Self);
770 toolform.Caption := Tools[i].caption + ' ' + IntToStr(tag) + ' ';
771 iconindex := Tools[i].icon;
772 end else begin
773 ShowMessage('WindowContext not found!');
774 end;
775
776 if Assigned(toolform) then
777 begin
778 toolform.Name := window_context + IntToStr(tag);
779 toolform.Tag := tag;
780 MDITab.AddTab(TForm(toolform), iconindex);
781 toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', '');
782 if connection > -1 then
783 begin
784 toolform.SelectConnection(connection);
785 if fileid > -1 then
786 toolform.SelectFileID(connection, fileid);
787 end;
788 Result := toolform;
789 end;
790end;
791
792end.
Note: See TracBrowser for help on using the repository browser.