source: oup/current/Main.pas@ 228

Last change on this file since 228 was 227, checked in by alloc, 17 years ago
File size: 23.8 KB
RevLine 
[93]1unit Main;
2interface
3uses
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus, Grids,
6 MPHexEditor, ToolWin, ImgList, Tabs,
7 MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, OneInst,
8 Data, TypeDefs, ConnectionManager,
[222]9 Functions, Settings,
10 RawEdit, BinEdit, Extractor, Preview, TxmpReplace,
11 _BaseTemplate, _TemplateFile, _TemplateFileList;
[93]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;
[227]47 Toolbar_main: TTBToolbar;
[93]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;
[227]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;
[93]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);
[227]96 procedure Toolbar_mainDockChanged(Sender: TObject);
[93]97 procedure CreateConnection(filename: String);
[97]98 function CheckConnectionCloseable(index: Integer): Boolean;
[93]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;
[227]131 procedure menu_filemanagerClick(Sender: TObject);
132 procedure menu_view_toolbar_toolsClick(Sender: TObject);
[93]133 private
134 public
[222]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;
[93]138 procedure DefaultHandler(var Message); override;
139 end;
140
141var
142 Form_Main: TForm_Main;
143
144implementation
145
[129]146uses
[227]147 LevelDB, MetaEditor, FileManager;
[129]148
[93]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
[97]167 ConManager.OpenConnection(filename, RepMsg);
[93]168 ShowOpenMsg(RepMsg);
169 if RepMsg = SM_OK then
170 begin
171 UpdateStatBar;
[105]172 UpdateConLists;
[93]173 end;
174end;
175
[97]176function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean;
177var
178 i: Integer;
[222]179 toolform: TForm_BaseTemplate;
[97]180begin
[113]181 Result := True;
[97]182 if MDITab.MDIChildCount > 0 then
183 begin
184 for i := 0 to MDITab.MDIChildCount - 1 do
185 begin
[222]186 if MDITab.MDIChildren[i] is TForm_BaseTemplate then
[97]187 begin
[222]188 toolform := TForm_BaseTemplate(MDITab.MDIChildren[i]);
[97]189 if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then
190 begin
191 if not toolform.Closeable then
[113]192 begin
193 ShowMessage('Can not close toolwindow: ' + toolform.Caption);
194 Result := False;
195 end;
[97]196 end;
197 end;
198 end;
199 end;
200end;
201
202
[93]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
[97]254 ConManager.OnCoonnectionListChanged := UpdateConLists;
[93]255
256 if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then
257 begin
258 AssignFile(AppSettingsFile, ExtractFilepath(Application.EXEname) +
259 '\oniunpacker.ini');
260 Reset(AppSettingsFile);
261 Read(AppSettingsFile, AppSettings);
262 CloseFile(AppSettingsFile);
263 end
264 else
265 begin
[197]266 ShowMessage('Warning!' + #13#10 +
267 'It seems like this is the first time you OUP.' + #13#10 +
268 'I do not take any responsibility for messed up data files' + #13+#10 +
269 'Do not forget to make backup copies of your *.dat/*.raw/*.sep files!');
[93]270 AppSettings.DatPath := ExtractFilepath(Application.EXEname);
271 AppSettings.ExtractPath := ExtractFilepath(Application.EXEname) + '\extract';
272 AppSettings.CharSet := DEFAULT_CHARSET;
273 AppSettings.HideUnusedData := False;
274 end;
275
276 if MidStr(ParamStr(1), 1, 3) = 'opf' then
277 begin
278 ShowMessage('Load OPF-File: ' + ParamStr(2));
279 end
280 else if (MidStr(ParamStr(1), 1, 4) = 'oldb') or (MidStr(ParamStr(1), 1, 3) = 'dat') then
281 begin
282 CreateConnection(ParamStr(2));
283 end;
284 UpdateStatBar;
285end;
286
287
288
289
290procedure TForm_Main.FormResize(Sender: TObject);
291begin
292 statbar.Panels.Items[0].Width := Self.Width - 200;
293 MDITab.Width := Self.Width - 20;
294end;
295
296
297
298
299procedure TForm_Main.MDITabDrawTab(Control: TCustomTabControl;
300 TabIndex: Integer; const Rect: TRect; Active: Boolean);
301var
302 x, y: Integer;
303 iconindex: Integer;
304 caption: String;
305begin
306 iconindex := TMDITab(Control).Glyphs[TabIndex];
307 caption := TMDITab(Control).Captions[TabIndex];
308 if active then
309 begin
310 Control.Canvas.Font.Style := Control.Canvas.Font.Style + [fsItalic];
311 y := Rect.Top + 1;
312 end else
313 y := Rect.Top;
314 if iconindex >= 0 then
315 begin
316 TMDITab(Control).Images.Draw(Control.Canvas, Rect.Left + 4, y, iconindex);
317 x := Rect.Left + 26;
318 end else
319 x := Rect.Left + 4;
320 Control.Canvas.TextOut(x, y + 2, caption);
321 if active then
322 Images_Close.Draw(Control.Canvas, Rect.Right - 18, y, 0)
323 else
324 Images_Close.Draw(Control.Canvas, Rect.Right - 18, y, 1);
325end;
326
327
328procedure TForm_Main.MDITabMouseMove(Sender: TObject; Shift: TShiftState; X,
329 Y: Integer);
330var
331 pt: TPoint;
332 tabIndex: Integer;
333 hint: String;
[222]334 tool: TForm_BaseTemplate;
[93]335begin
336 pt.X := X;
337 pt.Y := Y;
338 tabIndex := MDITab.GetTabAtPos(pt);
339 hint := '';
340
341 if tabIndex >= 0 then
342 begin
[222]343 if MDITab.MDIChildren[tabIndex] is TForm_BaseTemplate then
[93]344 begin
[222]345 tool := TForm_BaseTemplate(MDITab.MDIChildren[tabIndex]);
[97]346 if tool.ConnectionID > -1 then
[93]347 hint := 'Connection: ' +
[222]348 ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName)
[93]349 else
[222]350 hint := 'Connection: none';
351 if tool is TForm_TemplateFile then
352 begin
353 if TForm_TemplateFile(tool).SelectedFile.ID > -1 then
354 hint := hint + #13+#10 + 'Selected File: ' +
355 FormatNumber(TForm_TemplateFile(tool).SelectedFile.ID, 5, '0') + '-' +
356 TForm_TemplateFile(tool).SelectedFile.Name + '.' +
357 TForm_TemplateFile(tool).SelectedFile.Extension
358 else
359 hint := hint + #13+#10 + 'Selected File: none';
360 end;
[93]361 end
362 else
363 hint := 'Window: ' + MDITab.MDIChildren[tabIndex].Caption;
364 if hint <> MDITab.Hint then
365 begin
366 MDITab.Hint := hint;
367 MDITab.ShowHint := True;
368 end;
369 end
370 else
371 begin
372 MDITab.ShowHint := False;
373 MDITab.Hint := '';
374 end;
375end;
376
377procedure TForm_Main.MDITabMouseUp(Sender: TObject; Button: TMouseButton;
378 Shift: TShiftState; X, Y: Integer);
379var
380 pt: TPoint;
381 tabIndex: Integer;
382 tabRect: TRect;
383 tabX, tabY, tabWidth: Integer;
384begin
385 pt.X := X;
386 pt.Y := Y;
387 tabIndex := MDITab.GetTabAtPos(pt);
388
389// if (Button = mbRight) and (tabIndex >= 0) then
390// MDITab.MDIChildren[tabIndex].Close;
391
392 if (Button = mbLeft) and (tabIndex >= 0) then
393 begin
394 tabrect := MDITab.TabRect(tabIndex);
395 tabX := X - tabrect.Left;
396 tabY := Y - tabrect.Top;
397 tabwidth := tabrect.Right - tabrect.Left;
398 if (tabY >= 4) and (tabY <= 17) then
399 if (tabX >= tabwidth - 19) and (tabX <= tabwidth - 7) then
400 MDITab.MDIChildren[tabIndex].Close;
401 end;
402end;
403
404
405
406
407procedure TForm_Main.FormClose(Sender: TObject; var Action: TCloseAction);
408begin
409 AssignFile(AppSettingsFile, ExtractFilepath(Application.EXEname) + '\oniunpacker.ini');
410 if FileExists(ExtractFilepath(Application.EXEname) + '\oniunpacker.ini') then
411 Reset(AppSettingsFile)
412 else
413 Rewrite(AppSettingsFile);
414 Write(AppSettingsFile, AppSettings);
415 CloseFile(AppSettingsFile);
416 Action := caFree;
417end;
418
419
420
421procedure TForm_Main.ActivateTools(active: Boolean);
422begin
423 menu_tools.Enabled := active;
424 tb_preview.Enabled := active;
425 tb_datedit.Enabled := active;
426 tb_rawedit.Enabled := active;
427 tb_txmpreplacer.Enabled := active;
428 tb_extractor.Enabled := active;
[209]429 tb_meta.Enabled := active;
[93]430// tb_compare.Enabled := active;
431// tb_structure.Enabled := active;
432end;
433
434procedure TForm_Main.UpdateStatBar;
435begin
[97]436 if ConManager.Count > 0 then
[93]437 begin
438 Self.Caption := 'Oni Un/Packer ' + version;
439 ActivateTools(True);
[97]440 statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(ConManager.Count);
[93]441 end
442 else
443 begin
444 Self.Caption := 'Oni Un/Packer ' + version;
445 statbar.Panels.Items[0].Text := '';
446 statbar.Panels.Items[1].Text := 'Connections: -';
447 statbar.Panels.Items[2].Text := '';
448 ActivateTools(False);
449 end;
[97]450 menu_conns.Enabled := ConManager.Count > 0;
[93]451end;
452
453
454
455
[227]456procedure TForm_Main.Toolbar_mainDockChanged(Sender: TObject);
[93]457var
458 toolbar: TTBToolbar;
459 position: TTBDockPosition;
460 mode: TTBItemDisplayMode;
461 i: Integer;
462begin
463 toolbar := TTBToolbar(Sender);
464 if toolbar.Floating then
465 mode := nbdmImageAndText
466 else begin
467 position := toolbar.CurrentDock.Position;
468 if position in [dpLeft, dpRight] then
469 mode := nbdmDefault
470 else
471 mode := nbdmImageAndText;
472 end;
473 for i := 0 to toolbar.Items.Count - 1 do
474 toolbar.Items.Items[i].DisplayMode := mode;
475end;
476
477function TForm_Main.TryCloseAll: Boolean;
478begin
479 menu_windows_closeallClick(Self);
480 Application.ProcessMessages;
481 if MDITab.MDIChildCount = 0 then
482 Result := True
483 else
484 Result := False;
485end;
486
487
488procedure TForm_Main.UpdateConLists;
489var
490 i: Integer;
491 entry: TTBItem;
492begin
493 if MDITab.MDIChildCount > 0 then
494 for i := 0 to MDITab.MDIChildCount - 1 do
[222]495 if MDITab.MDIChildren[i] is TForm_BaseTemplate then
496 TForm_BaseTemplate(MDITab.MDIChildren[i]).UpdateConList;
[93]497
498 menu_conns.Clear;
[97]499 if ConManager.Count > 0 then
[93]500 begin
[97]501 for i := 0 to ConManager.Count - 1 do
[93]502 begin
503 entry := TTBItem.Create(menu_conns);
[97]504 entry.Caption := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
[93]505 entry.Name := 'menu_conn_' + IntToStr(i);
506 entry.OnClick := menu_conns_itemClick;
507 menu_conns.Add(entry);
508 entry := nil;
509 end;
510 end;
511end;
512
513
514procedure TForm_Main.LoadFile(typedb: Boolean);
515var
[105]516 i: Integer;
[93]517begin
518 opend.InitialDir := AppSettings.DatPath;
519 opend.Filter := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
520 if typedb then
521 opend.FilterIndex := 3
522 else
523 opend.FilterIndex := 2;
524 if opend.Execute then
525 begin
[105]526 if opend.Files.Count > 0 then
527 for i := 0 to opend.Files.Count - 1 do
528 CreateConnection(opend.Files.Strings[i]);
[93]529 AppSettings.DatPath := ExtractFilepath(opend.FileName);
530 end;
531 UpdateStatBar;
532end;
533
534
535 {#################################}
536 {##### Main-Menu-Handlers #####}
537 {#################################}
538procedure TForm_Main.menu_loaddbClick(Sender: TObject);
539begin
540 LoadFile(True);
541end;
542
543procedure TForm_Main.menu_loadfileClick(Sender: TObject);
544begin
545 LoadFile(False);
546end;
547
548
549procedure TForm_Main.menu_settingsClick(Sender: TObject);
550begin
551 Form_Settings.Visible := True;
552 Self.Enabled := False;
553end;
554
555
556procedure TForm_Main.menu_exitClick(Sender: TObject);
557begin
558 Self.Close;
559end;
560
561
562 {####################################}
563 {##### Converters-Menu-Handlers #####}
564 {####################################}
565procedure TForm_Main.menu_createdbClick(Sender: TObject);
566begin
567 opend.Filter := 'Oni-Dat-Files|*.dat';
568 saved.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
569 saved.DefaultExt := 'oldb';
570 if opend.Execute then
571 if saved.Execute then
572 Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
573end;
574
575
576procedure TForm_Main.menu_createlvlClick(Sender: TObject);
577begin
578 opend.Filter := 'OUP-Level-DB (*.oldb)|*.oldb';
579 saved.Filter := 'Oni-Dat-Files|*.dat';
580 saved.DefaultExt := 'dat';
581 if opend.Execute then
582 if saved.Execute then
583 Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
584end;
585
586
587 {#################################}
588 {##### Tools-Menu-Handlers #####}
589 {#################################}
590procedure TForm_Main.menu_previewClick(Sender: TObject);
591begin
[222]592 open_child('preview');
[93]593end;
594
595procedure TForm_Main.menu_bineditClick(Sender: TObject);
596begin
[222]597 open_child('binedit');
[93]598end;
599
600procedure TForm_Main.menu_raweditClick(Sender: TObject);
601begin
[222]602 open_child('rawedit');
[93]603end;
604
605procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject);
606begin
[222]607 open_child('txmpreplace');
[93]608end;
609
610procedure TForm_Main.menu_extractorClick(Sender: TObject);
611begin
[222]612 open_child('extractor');
[93]613end;
614
615procedure TForm_Main.menu_metaClick(Sender: TObject);
616begin
[222]617 open_child('meta');
[93]618end;
619
620procedure TForm_Main.menu_filecompareClick(Sender: TObject);
621begin
[222]622 open_child('compare');
[93]623end;
624
625
[227]626 procedure TForm_Main.menu_filemanagerClick(Sender: TObject);
627begin
628 open_child('filemanager');
629end;
630
631{#################################}
[93]632 {##### View-Menu-Handlers #####}
633 {#################################}
634procedure TForm_Main.menu_windows_cascadeClick(Sender: TObject);
635begin
636 Self.Cascade;
637end;
638
639procedure TForm_Main.menu_windows_tilevertClick(Sender: TObject);
640begin
641 Self.TileMode := tbVertical;
642 Self.Tile;
643end;
644
645procedure TForm_Main.menu_windows_tileClick(Sender: TObject);
646begin
647 Self.TileMode := tbHorizontal;
648 Self.Tile;
649end;
650
651procedure TForm_Main.menu_windows_closeallClick(Sender: TObject);
652begin
653 MDITab.CloseAll;
654end;
655
656procedure TForm_Main.menu_windows_nextClick(Sender: TObject);
657begin
658 if MDIChildCount > 1 then
659 if MDITab.TabIndex = MDITab.MDIChildCount - 1 then
660 MDITab.MDIChildren[0].BringToFront
661 else
662 MDITab.MDIChildren[MDITab.TabIndex + 1].BringToFront;
663end;
664
665procedure TForm_Main.menu_windows_previousClick(Sender: TObject);
666begin
667 if MDIChildCount > 1 then
668 if MDITab.TabIndex = 0 then
669 MDITab.MDIChildren[MDITab.MDIChildCount - 1].BringToFront
670 else
671 MDITab.MDIChildren[MDITab.TabIndex - 1].BringToFront;
672end;
673
674
675 {##################################}
676 {##### Windows-Menu-Handlers #####}
677 {##################################}
678procedure TForm_Main.menu_windows_itemClick(Sender: TObject);
679var
680 name: String;
681begin
682 name := TTBItem(Sender).Name;
683end;
684
685
686
687 {######################################}
688 {##### Connections-Menu-Handlers #####}
689 {######################################}
690procedure TForm_Main.menu_conns_itemClick(Sender: TObject);
691var
692 name: String;
[97]693 index: Integer;
694 RepMsg: TStatusMessages;
[93]695begin
[97]696 index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender));
697 name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName);
[93]698 if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+
699 name + '?'), PChar('Close?'), MB_YESNO + MB_ICONQUESTION) = ID_YES then
700 begin
[97]701 CheckConnectionCloseable(index);
702 ConManager.CloseConnectionByIndex(index, RepMsg);
[105]703 ShowOpenMsg(RepMsg);
704 UpdateConLists;
[93]705 end;
706 UpdateStatBar;
707end;
708
709
710 {###################################}
711 {##### Toolbars-Menu-Handlers #####}
712 {###################################}
713procedure TForm_Main.menu_view_toolbarClick(Sender: TObject);
714begin
715 menu_view_toolbar.Checked := not menu_view_toolbar.Checked;
[227]716 Toolbar_main.Visible := menu_view_toolbar.Checked;
[93]717end;
718
[227]719procedure TForm_Main.menu_view_toolbar_toolsClick(Sender: TObject);
720begin
721 menu_view_toolbar_tools.Checked := not menu_view_toolbar_tools.Checked;
722 Toolbar_tools.Visible := menu_view_toolbar_tools.Checked;
723end;
724
[93]725procedure TForm_Main.menu_view_statusbarClick(Sender: TObject);
726begin
727 menu_view_statusbar.Checked := not menu_view_statusbar.Checked;
728 statbar.Visible := menu_view_statusbar.Checked;
729end;
730
731procedure TForm_Main.menu_view_mdibarClick(Sender: TObject);
732begin
733 menu_view_mdibar.Checked := not menu_view_mdibar.Checked;
734 mditoolbar.Visible := menu_view_mdibar.Checked;
735end;
736
737
738
739procedure TForm_Main.menu_AboutClick(Sender: TObject);
740begin
741 ShowMessage('Will be implemented later ;)');
742end;
743
744
745
746
747
[222]748function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_BaseTemplate;
[172]749type
[222]750 TTemplate = class of TForm_BaseTemplate;
[172]751 TTool = record
752 name: String;
753 icon: Integer;
754 caption: String;
755 classt: TTemplate;
756 end;
757const
[227]758 Tools: array[0..6] of TTool = (
[172]759 (name: 'binedit'; icon: 5; caption: 'Binary .dat-Editor'; classt: TForm_BinEdit),
760 (name: 'extractor'; icon: 8; caption: 'Extractor'; classt: TForm_Extractor),
761 (name: 'preview'; icon: 4; caption: 'Preview-Window'; classt: TForm_Preview),
762 (name: 'rawedit'; icon: 6; caption: 'Binary .raw-Editor'; classt: TForm_RawEdit),
[224]763 (name: 'txmpreplace'; icon: 7; caption: 'TXMP Replacer'; classt: TForm_TxmpReplace),
[227]764 (name: 'filemanager'; icon:-1; caption: 'FileManager'; classt: TForm_FileManager),
[222]765 (name: 'meta'; icon: 11; caption: 'MetaEditor'; classt: TForm_Meta)
[172]766 );
[93]767var
[222]768 toolform: TForm_BaseTemplate;
[93]769 i: Integer;
770 tag: Integer;
771 iconindex: Integer;
772begin
773 Result := nil;
774
775 tag := 1;
776 if MDIChildCount > 0 then
777 for i := 0 to MDIChildCount - 1 do
778 if MDIChildren[i].Tag >= tag then
779 tag := MDIChildren[i].Tag + 1;
780
781 iconindex := -1;
782
[113]783 toolform := nil;
784
[172]785 for i := 0 to High(Tools) do
786 if Tools[i].name = window_context then
787 Break;
788 if i < Length(Tools) then
[93]789 begin
[172]790 toolform := TTemplate(Tools[i].classt).Create(Self);
791 toolform.Caption := Tools[i].caption + ' ' + IntToStr(tag) + ' ';
792 iconindex := Tools[i].icon;
793 end else begin
794 ShowMessage('WindowContext not found!');
[93]795 end;
796
797 if Assigned(toolform) then
798 begin
799 toolform.Name := window_context + IntToStr(tag);
800 toolform.Tag := tag;
801 MDITab.AddTab(TForm(toolform), iconindex);
802 toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', '');
[222]803 if Connection > -1 then
[93]804 begin
[97]805 toolform.SelectConnection(connection);
[222]806 if (FileID > -1) and (toolform is TForm_TemplateFile) then
807 TForm_TemplateFile(toolform).SelectFileID(Connection, FileID);
[93]808 end;
809 Result := toolform;
810 end;
811end;
812
[222]813function TForm_Main.open_child(window_context: String; Connection: Integer): TForm_BaseTemplate;
814begin
815 open_child(window_context, Connection, -1);
816end;
817
818function TForm_Main.open_child(window_context: String): TForm_BaseTemplate;
819begin
820 open_child(window_context, -1, -1);
821end;
822
[93]823end.
Note: See TracBrowser for help on using the repository browser.