source: oup/current/Main.pas@ 1043

Last change on this file since 1043 was 330, checked in by alloc, 15 years ago

Testchange

File size: 24.0 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') or (strings.Strings[0] = 'oni') 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') or (MidStr(ParamStr(1), 1, 3) = 'oni') 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 end;
512 end;
513end;
514
515
516procedure TForm_Main.LoadFile(typedb: Boolean);
517var
518 i: Integer;
519begin
520 opend.InitialDir := AppSettings.DatPath;
521 opend.Filter := 'Compatible level files|*.dat;*.oni;*.oldb|Oni level (*.dat)|*.dat|OniSplit Archive (*.oni)|*.oni|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
522 if typedb then
523 opend.FilterIndex := 4
524 else
525 opend.FilterIndex := 2;
526 if opend.Execute then
527 begin
528 if opend.Files.Count > 0 then
529 for i := 0 to opend.Files.Count - 1 do
530 CreateConnection(opend.Files.Strings[i]);
531 AppSettings.DatPath := ExtractFilepath(opend.FileName);
532 end;
533 UpdateStatBar;
534end;
535
536
537 {#################################}
538 {##### Main-Menu-Handlers #####}
539 {#################################}
540procedure TForm_Main.menu_loaddbClick(Sender: TObject);
541begin
542 LoadFile(True);
543end;
544
545procedure TForm_Main.menu_loadfileClick(Sender: TObject);
546begin
547 LoadFile(False);
548end;
549
550
551procedure TForm_Main.menu_settingsClick(Sender: TObject);
552begin
553 Form_Settings.Visible := True;
554 Self.Enabled := False;
555end;
556
557
558procedure TForm_Main.menu_exitClick(Sender: TObject);
559begin
560 Self.Close;
561end;
562
563
564 {####################################}
565 {##### Converters-Menu-Handlers #####}
566 {####################################}
567procedure TForm_Main.menu_createdbClick(Sender: TObject);
568begin
569 opend.Filter := 'Oni-Dat-Files|*.dat';
570 saved.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
571 saved.DefaultExt := 'oldb';
572 if opend.Execute then
573 if saved.Execute then
574 Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
575end;
576
577
578procedure TForm_Main.menu_createlvlClick(Sender: TObject);
579begin
580 opend.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
581 saved.Filter := 'Oni-Dat-Files|*.dat';
582 saved.DefaultExt := 'dat';
583 if opend.Execute then
584 if saved.Execute then
585 Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
586end;
587
588
589 {#################################}
590 {##### Tools-Menu-Handlers #####}
591 {#################################}
592procedure TForm_Main.menu_previewClick(Sender: TObject);
593begin
594 open_child('preview');
595end;
596
597procedure TForm_Main.menu_bineditClick(Sender: TObject);
598begin
599 open_child('binedit');
600end;
601
602procedure TForm_Main.menu_raweditClick(Sender: TObject);
603begin
604 open_child('rawedit');
605end;
606
607procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
608begin
609 open_child('txmpreplace');
610end;
611
612procedure TForm_Main.menu_extractorClick(Sender: TObject);
613begin
614 open_child('extractor');
615end;
616
617procedure TForm_Main.menu_metaClick(Sender: TObject);
618begin
619 open_child('meta');
620end;
621
622procedure TForm_Main.menu_filecompareClick(Sender: TObject);
623begin
624 open_child('compare');
625end;
626
627
628 procedure TForm_Main.menu_filemanagerClick(Sender: TObject);
629begin
630 open_child('filemanager');
631end;
632
633{#################################}
634 {##### View-Menu-Handlers #####}
635 {#################################}
636procedure TForm_Main.menu_windows_cascadeClick(Sender: TObject);
637begin
638 Self.Cascade;
639end;
640
641procedure TForm_Main.menu_windows_tilevertClick(Sender: TObject);
642begin
643 Self.TileMode := tbVertical;
644 Self.Tile;
645end;
646
647procedure TForm_Main.menu_windows_tileClick(Sender: TObject);
648begin
649 Self.TileMode := tbHorizontal;
650 Self.Tile;
651end;
652
653procedure TForm_Main.menu_windows_closeallClick(Sender: TObject);
654begin
655 MDITab.CloseAll;
656end;
657
658procedure TForm_Main.menu_windows_nextClick(Sender: TObject);
659begin
660 if MDIChildCount > 1 then
661 if MDITab.TabIndex = MDITab.MDIChildCount - 1 then
662 MDITab.MDIChildren[0].BringToFront
663 else
664 MDITab.MDIChildren[MDITab.TabIndex + 1].BringToFront;
665end;
666
667procedure TForm_Main.menu_windows_previousClick(Sender: TObject);
668begin
669 if MDIChildCount > 1 then
670 if MDITab.TabIndex = 0 then
671 MDITab.MDIChildren[MDITab.MDIChildCount - 1].BringToFront
672 else
673 MDITab.MDIChildren[MDITab.TabIndex - 1].BringToFront;
674end;
675
676
677 {##################################}
678 {##### Windows-Menu-Handlers #####}
679 {##################################}
680procedure TForm_Main.menu_windows_itemClick(Sender: TObject);
681var
682 name: String;
683begin
684 name := TTBItem(Sender).Name;
685end;
686
687
688
689 {######################################}
690 {##### Connections-Menu-Handlers #####}
691 {######################################}
692procedure TForm_Main.menu_conns_itemClick(Sender: TObject);
693var
694 name: String;
695 index: Integer;
696 RepMsg: TStatusMessages;
697begin
698 index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender));
699 name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName);
700 if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+
701 name + '?'), PChar('Close?'), MB_YESNO + MB_ICONQUESTION) = ID_YES then
702 begin
703 CheckConnectionCloseable(index);
704 ConManager.CloseConnectionByIndex(index, RepMsg);
705 ShowOpenMsg(RepMsg);
706 UpdateConLists;
707 end;
708 UpdateStatBar;
709end;
710
711
712 {###################################}
713 {##### Toolbars-Menu-Handlers #####}
714 {###################################}
715procedure TForm_Main.menu_view_toolbarClick(Sender: TObject);
716begin
717 menu_view_toolbar.Checked := not menu_view_toolbar.Checked;
718 Toolbar_main.Visible := menu_view_toolbar.Checked;
719end;
720
721procedure TForm_Main.menu_view_toolbar_toolsClick(Sender: TObject);
722begin
723 menu_view_toolbar_tools.Checked := not menu_view_toolbar_tools.Checked;
724 Toolbar_tools.Visible := menu_view_toolbar_tools.Checked;
725end;
726
727procedure TForm_Main.menu_view_statusbarClick(Sender: TObject);
728begin
729 menu_view_statusbar.Checked := not menu_view_statusbar.Checked;
730 statbar.Visible := menu_view_statusbar.Checked;
731end;
732
733procedure TForm_Main.menu_view_mdibarClick(Sender: TObject);
734begin
735 menu_view_mdibar.Checked := not menu_view_mdibar.Checked;
736 mditoolbar.Visible := menu_view_mdibar.Checked;
737end;
738
739
740
741procedure TForm_Main.menu_AboutClick(Sender: TObject);
742begin
743 ShowMessage('Will be implemented later ;)');
744end;
745
746
747
748
749
750function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_BaseTemplate;
751type
752 TTemplate = class of TForm_BaseTemplate;
753 TTool = record
754 name: String;
755 icon: Integer;
756 caption: String;
757 classt: TTemplate;
758 end;
759const
760 Tools: array[0..6] of TTool = (
761 (name: 'binedit'; icon: 5; caption: 'Binary .dat-Editor'; classt: TForm_BinEdit),
762 (name: 'extractor'; icon: 8; caption: 'Extractor'; classt: TForm_Extractor),
763 (name: 'preview'; icon: 4; caption: 'Preview-Window'; classt: TForm_Preview),
764 (name: 'rawedit'; icon: 6; caption: 'Binary .raw-Editor'; classt: TForm_RawEdit),
765 (name: 'txmpreplace'; icon: 7; caption: 'TXMP Replacer'; classt: TForm_TxmpReplace),
766 (name: 'filemanager'; icon:-1; caption: 'FileManager'; classt: TForm_FileManager),
767 (name: 'meta'; icon: 11; caption: 'MetaEditor'; classt: TForm_Meta)
768 );
769var
770 toolform: TForm_BaseTemplate;
771 i: Integer;
772 tag: Integer;
773 iconindex: Integer;
774begin
775 Result := nil;
776
777 tag := 1;
778 if MDIChildCount > 0 then
779 for i := 0 to MDIChildCount - 1 do
780 if MDIChildren[i].Tag >= tag then
781 tag := MDIChildren[i].Tag + 1;
782
783 iconindex := -1;
784
785 toolform := nil;
786
787 for i := 0 to High(Tools) do
788 if Tools[i].name = window_context then
789 Break;
790 if i < Length(Tools) then
791 begin
792 toolform := TTemplate(Tools[i].classt).Create(Self);
793 toolform.Caption := Tools[i].caption + ' ' + IntToStr(tag) + ' ';
794 iconindex := Tools[i].icon;
795 end else begin
796 ShowMessage('WindowContext not found!');
797 end;
798
799 if Assigned(toolform) then
800 begin
801 toolform.Name := window_context + IntToStr(tag);
802 toolform.Tag := tag;
803 MDITab.AddTab(TForm(toolform), iconindex);
804 toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', '');
805 if Connection > -1 then
806 begin
807 toolform.SelectConnection(connection);
808 if (FileID > -1) and (toolform is TForm_TemplateFile) then
809 TForm_TemplateFile(toolform).SelectFileID(Connection, FileID);
810 end;
811 Result := toolform;
812 end;
813end;
814
815function TForm_Main.open_child(window_context: String; Connection: Integer): TForm_BaseTemplate;
816begin
817 Result := open_child(window_context, Connection, -1);
818end;
819
820function TForm_Main.open_child(window_context: String): TForm_BaseTemplate;
821begin
822 Result := open_child(window_context, -1, -1);
823end;
824
825end.
826
Note: See TracBrowser for help on using the repository browser.