source: oup/current/Main.pas@ 225

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