source: oup/current/Main.pas@ 245

Last change on this file since 245 was 241, checked in by alloc, 17 years ago
File size: 23.9 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,
10 RawEdit, BinEdit, Extractor, Preview, TxmpReplace,
11 _BaseTemplate, _TemplateFile, _TemplateFileList;
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;
47 Toolbar_main: TTBToolbar;
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;
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;
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);
96 procedure Toolbar_mainDockChanged(Sender: TObject);
97 procedure CreateConnection(filename: String);
98 function CheckConnectionCloseable(index: Integer): Boolean;
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;
131 procedure menu_filemanagerClick(Sender: TObject);
132 procedure menu_view_toolbar_toolsClick(Sender: TObject);
133 private
134 public
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;
138 procedure DefaultHandler(var Message); override;
139 end;
140
141var
142 Form_Main: TForm_Main;
143
144implementation
145
146uses
147 LevelDB, MetaEditor, FileManager;
148
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
167 ConManager.OpenConnection(filename, RepMsg);
168 ShowOpenMsg(RepMsg);
169 if RepMsg = SM_OK then
170 begin
171 UpdateStatBar;
172 UpdateConLists;
173 end;
174end;
175
176function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean;
177var
178 i: Integer;
179 toolform: TForm_BaseTemplate;
180begin
181 Result := True;
182 if MDITab.MDIChildCount > 0 then
183 begin
184 for i := 0 to MDITab.MDIChildCount - 1 do
185 begin
186 if MDITab.MDIChildren[i] is TForm_BaseTemplate then
187 begin
188 toolform := TForm_BaseTemplate(MDITab.MDIChildren[i]);
189 if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then
190 begin
191 if not toolform.Closeable then
192 begin
193 ShowMessage('Can not close toolwindow: ' + toolform.Caption);
194 Result := False;
195 end;
196 end;
197 end;
198 end;
199 end;
200end;
201
202
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
220 else if (strings.Strings[0] = 'oldb') or (strings.Strings[0] = 'dat') then
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
254 ConManager.OnCoonnectionListChanged := UpdateConLists;
255
256 Application.HintPause := 250;
257 Application.HintHidePause := 5000;
258
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
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!');
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
283 else if (MidStr(ParamStr(1), 1, 4) = 'oldb') or (MidStr(ParamStr(1), 1, 3) = 'dat') then
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;
337 tool: TForm_BaseTemplate;
338begin
339 pt.X := X;
340 pt.Y := Y;
341 tabIndex := MDITab.GetTabAtPos(pt);
342 hint := '';
343
344 if tabIndex >= 0 then
345 begin
346 if MDITab.MDIChildren[tabIndex] is TForm_BaseTemplate then
347 begin
348 tool := TForm_BaseTemplate(MDITab.MDIChildren[tabIndex]);
349 if tool.ConnectionID > -1 then
350 hint := 'Connection: ' +
351 ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName)
352 else
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;
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;
432 tb_meta.Enabled := active;
433// tb_compare.Enabled := active;
434// tb_structure.Enabled := active;
435end;
436
437procedure TForm_Main.UpdateStatBar;
438begin
439 if ConManager.Count > 0 then
440 begin
441 Self.Caption := 'Oni Un/Packer ' + version;
442 ActivateTools(True);
443 statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(ConManager.Count);
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;
453 menu_conns.Enabled := ConManager.Count > 0;
454end;
455
456
457
458
459procedure TForm_Main.Toolbar_mainDockChanged(Sender: TObject);
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
498 if MDITab.MDIChildren[i] is TForm_BaseTemplate then
499 TForm_BaseTemplate(MDITab.MDIChildren[i]).UpdateConList;
500
501 menu_conns.Clear;
502 if ConManager.Count > 0 then
503 begin
504 for i := 0 to ConManager.Count - 1 do
505 begin
506 entry := TTBItem.Create(menu_conns);
507 entry.Caption := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
508 entry.Name := 'menu_conn_' + IntToStr(i);
509 entry.OnClick := menu_conns_itemClick;
510 menu_conns.Add(entry);
511 entry := nil;
512 end;
513 end;
514end;
515
516
517procedure TForm_Main.LoadFile(typedb: Boolean);
518var
519 i: Integer;
520begin
521 opend.InitialDir := AppSettings.DatPath;
522 opend.Filter := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
523 if typedb then
524 opend.FilterIndex := 3
525 else
526 opend.FilterIndex := 2;
527 if opend.Execute then
528 begin
529 if opend.Files.Count > 0 then
530 for i := 0 to opend.Files.Count - 1 do
531 CreateConnection(opend.Files.Strings[i]);
532 AppSettings.DatPath := ExtractFilepath(opend.FileName);
533 end;
534 UpdateStatBar;
535end;
536
537
538 {#################################}
539 {##### Main-Menu-Handlers #####}
540 {#################################}
541procedure TForm_Main.menu_loaddbClick(Sender: TObject);
542begin
543 LoadFile(True);
544end;
545
546procedure TForm_Main.menu_loadfileClick(Sender: TObject);
547begin
548 LoadFile(False);
549end;
550
551
552procedure TForm_Main.menu_settingsClick(Sender: TObject);
553begin
554 Form_Settings.Visible := True;
555 Self.Enabled := False;
556end;
557
558
559procedure TForm_Main.menu_exitClick(Sender: TObject);
560begin
561 Self.Close;
562end;
563
564
565 {####################################}
566 {##### Converters-Menu-Handlers #####}
567 {####################################}
568procedure TForm_Main.menu_createdbClick(Sender: TObject);
569begin
570 opend.Filter := 'Oni-Dat-Files|*.dat';
571 saved.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
572 saved.DefaultExt := 'oldb';
573 if opend.Execute then
574 if saved.Execute then
575 Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
576end;
577
578
579procedure TForm_Main.menu_createlvlClick(Sender: TObject);
580begin
581 opend.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
582 saved.Filter := 'Oni-Dat-Files|*.dat';
583 saved.DefaultExt := 'dat';
584 if opend.Execute then
585 if saved.Execute then
586 Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
587end;
588
589
590 {#################################}
591 {##### Tools-Menu-Handlers #####}
592 {#################################}
593procedure TForm_Main.menu_previewClick(Sender: TObject);
594begin
595 open_child('preview');
596end;
597
598procedure TForm_Main.menu_bineditClick(Sender: TObject);
599begin
600 open_child('binedit');
601end;
602
603procedure TForm_Main.menu_raweditClick(Sender: TObject);
604begin
605 open_child('rawedit');
606end;
607
608procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
609begin
610 open_child('txmpreplace');
611end;
612
613procedure TForm_Main.menu_extractorClick(Sender: TObject);
614begin
615 open_child('extractor');
616end;
617
618procedure TForm_Main.menu_metaClick(Sender: TObject);
619begin
620 open_child('meta');
621end;
622
623procedure TForm_Main.menu_filecompareClick(Sender: TObject);
624begin
625 open_child('compare');
626end;
627
628
629 procedure TForm_Main.menu_filemanagerClick(Sender: TObject);
630begin
631 open_child('filemanager');
632end;
633
634{#################################}
635 {##### View-Menu-Handlers #####}
636 {#################################}
637procedure TForm_Main.menu_windows_cascadeClick(Sender: TObject);
638begin
639 Self.Cascade;
640end;
641
642procedure TForm_Main.menu_windows_tilevertClick(Sender: TObject);
643begin
644 Self.TileMode := tbVertical;
645 Self.Tile;
646end;
647
648procedure TForm_Main.menu_windows_tileClick(Sender: TObject);
649begin
650 Self.TileMode := tbHorizontal;
651 Self.Tile;
652end;
653
654procedure TForm_Main.menu_windows_closeallClick(Sender: TObject);
655begin
656 MDITab.CloseAll;
657end;
658
659procedure TForm_Main.menu_windows_nextClick(Sender: TObject);
660begin
661 if MDIChildCount > 1 then
662 if MDITab.TabIndex = MDITab.MDIChildCount - 1 then
663 MDITab.MDIChildren[0].BringToFront
664 else
665 MDITab.MDIChildren[MDITab.TabIndex + 1].BringToFront;
666end;
667
668procedure TForm_Main.menu_windows_previousClick(Sender: TObject);
669begin
670 if MDIChildCount > 1 then
671 if MDITab.TabIndex = 0 then
672 MDITab.MDIChildren[MDITab.MDIChildCount - 1].BringToFront
673 else
674 MDITab.MDIChildren[MDITab.TabIndex - 1].BringToFront;
675end;
676
677
678 {##################################}
679 {##### Windows-Menu-Handlers #####}
680 {##################################}
681procedure TForm_Main.menu_windows_itemClick(Sender: TObject);
682var
683 name: String;
684begin
685 name := TTBItem(Sender).Name;
686end;
687
688
689
690 {######################################}
691 {##### Connections-Menu-Handlers #####}
692 {######################################}
693procedure TForm_Main.menu_conns_itemClick(Sender: TObject);
694var
695 name: String;
696 index: Integer;
697 RepMsg: TStatusMessages;
698begin
699 index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender));
700 name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName);
701 if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+
702 name + '?'), PChar('Close?'), MB_YESNO + MB_ICONQUESTION) = ID_YES then
703 begin
704 CheckConnectionCloseable(index);
705 ConManager.CloseConnectionByIndex(index, RepMsg);
706 ShowOpenMsg(RepMsg);
707 UpdateConLists;
708 end;
709 UpdateStatBar;
710end;
711
712
713 {###################################}
714 {##### Toolbars-Menu-Handlers #####}
715 {###################################}
716procedure TForm_Main.menu_view_toolbarClick(Sender: TObject);
717begin
718 menu_view_toolbar.Checked := not menu_view_toolbar.Checked;
719 Toolbar_main.Visible := menu_view_toolbar.Checked;
720end;
721
722procedure TForm_Main.menu_view_toolbar_toolsClick(Sender: TObject);
723begin
724 menu_view_toolbar_tools.Checked := not menu_view_toolbar_tools.Checked;
725 Toolbar_tools.Visible := menu_view_toolbar_tools.Checked;
726end;
727
728procedure TForm_Main.menu_view_statusbarClick(Sender: TObject);
729begin
730 menu_view_statusbar.Checked := not menu_view_statusbar.Checked;
731 statbar.Visible := menu_view_statusbar.Checked;
732end;
733
734procedure TForm_Main.menu_view_mdibarClick(Sender: TObject);
735begin
736 menu_view_mdibar.Checked := not menu_view_mdibar.Checked;
737 mditoolbar.Visible := menu_view_mdibar.Checked;
738end;
739
740
741
742procedure TForm_Main.menu_AboutClick(Sender: TObject);
743begin
744 ShowMessage('Will be implemented later ;)');
745end;
746
747
748
749
750
751function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_BaseTemplate;
752type
753 TTemplate = class of TForm_BaseTemplate;
754 TTool = record
755 name: String;
756 icon: Integer;
757 caption: String;
758 classt: TTemplate;
759 end;
760const
761 Tools: array[0..6] of TTool = (
762 (name: 'binedit'; icon: 5; caption: 'Binary .dat-Editor'; classt: TForm_BinEdit),
763 (name: 'extractor'; icon: 8; caption: 'Extractor'; classt: TForm_Extractor),
764 (name: 'preview'; icon: 4; caption: 'Preview-Window'; classt: TForm_Preview),
765 (name: 'rawedit'; icon: 6; caption: 'Binary .raw-Editor'; classt: TForm_RawEdit),
766 (name: 'txmpreplace'; icon: 7; caption: 'TXMP Replacer'; classt: TForm_TxmpReplace),
767 (name: 'filemanager'; icon:-1; caption: 'FileManager'; classt: TForm_FileManager),
768 (name: 'meta'; icon: 11; caption: 'MetaEditor'; classt: TForm_Meta)
769 );
770var
771 toolform: TForm_BaseTemplate;
772 i: Integer;
773 tag: Integer;
774 iconindex: Integer;
775begin
776 Result := nil;
777
778 tag := 1;
779 if MDIChildCount > 0 then
780 for i := 0 to MDIChildCount - 1 do
781 if MDIChildren[i].Tag >= tag then
782 tag := MDIChildren[i].Tag + 1;
783
784 iconindex := -1;
785
786 toolform := nil;
787
788 for i := 0 to High(Tools) do
789 if Tools[i].name = window_context then
790 Break;
791 if i < Length(Tools) then
792 begin
793 toolform := TTemplate(Tools[i].classt).Create(Self);
794 toolform.Caption := Tools[i].caption + ' ' + IntToStr(tag) + ' ';
795 iconindex := Tools[i].icon;
796 end else begin
797 ShowMessage('WindowContext not found!');
798 end;
799
800 if Assigned(toolform) then
801 begin
802 toolform.Name := window_context + IntToStr(tag);
803 toolform.Tag := tag;
804 MDITab.AddTab(TForm(toolform), iconindex);
805 toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', '');
806 if Connection > -1 then
807 begin
808 toolform.SelectConnection(connection);
809 if (FileID > -1) and (toolform is TForm_TemplateFile) then
810 TForm_TemplateFile(toolform).SelectFileID(Connection, FileID);
811 end;
812 Result := toolform;
813 end;
814end;
815
816function TForm_Main.open_child(window_context: String; Connection: Integer): TForm_BaseTemplate;
817begin
818 Result := open_child(window_context, Connection, -1);
819end;
820
821function TForm_Main.open_child(window_context: String): TForm_BaseTemplate;
822begin
823 Result := open_child(window_context, -1, -1);
824end;
825
826end.
Note: See TracBrowser for help on using the repository browser.