File: Main.pas

package info (click to toggle)
mysql-gui-tools 5.0r12-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 105,540 kB
  • ctags: 50,897
  • sloc: sql: 348,439; pascal: 285,780; cpp: 94,578; ansic: 90,768; objc: 33,761; sh: 25,629; xml: 10,924; yacc: 10,755; java: 9,986; php: 2,806; python: 2,068; makefile: 1,945; perl: 3
file content (808 lines) | stat: -rw-r--r-- 27,029 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
unit Main;

interface

uses
  gnugettext, Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, ExtCtrls, ImgList, Contnrs, Menus,
  ApplicationDataModule, MySQLConnection, AdditionalClasses,
  AdminServerInfo, AdminServiceControl, AdminUsers,
  AdminStartupVariables, AdminServerHealth, AdminServerConnections,
  AdminCatalog, AdminBackup, AdminServerLogs, AdminReplication,
  AdminRestore, ClipBrd,
  AuxFuncs, PNGImage, myx_public_interface, myx_admin_public_interface,
  Sections, Options, OptionsEditor, AdminOptionPages,
  CommonFuncs, TntForms, TntComCtrls, TntExtCtrls, TntMenus,
  MySQLCommonFuncs, AppInstanceMgmt;

{$include Consts.ini}

type
  TMainForm = class(TTntForm)
    StatusBar: TTntStatusBar;
    TopPnl: TTntPanel;
    Panel1: TTntPanel;
    Panel2: TTntPanel;
    MainMenu: TTntMainMenu;
    FileMI: TTntMenuItem;
    ConnecttoServerMI: TTntMenuItem;
    SaveConnectionMI: TTntMenuItem;
    N3: TTntMenuItem;
    CopyActivePageAsTextMI: TTntMenuItem;
    N2: TTntMenuItem;
    CloseMI: TTntMenuItem;
    Edit1: TTntMenuItem;
    CopyMI: TTntMenuItem;
    CutMI: TTntMenuItem;
    PasteMI: TTntMenuItem;
    HelpMI: TTntMenuItem;
    OnlineHelpMI: TTntMenuItem;
    N6: TTntMenuItem;
    ReportBugMI: TTntMenuItem;
    VisitMySQLcomMI: TTntMenuItem;
    N7: TTntMenuItem;
    AboutMI: TTntMenuItem;
    ManageConnectionsMI: TTntMenuItem;
    OptionsMI: TTntMenuItem;
    ToolsMI: TTntMenuItem;
    ViewMI: TTntMenuItem;
    MySQLCommandlineclientMI: TTntMenuItem;
    WindowsCommandLineMI: TTntMenuItem;
    ReconnectMI: TTntMenuItem;
    SelectAllMI: TTntMenuItem;
    MySQLQueryBrowserMI: TTntMenuItem;
    N1: TTntMenuItem;
    MySQLSystemTrayMonitorMI: TTntMenuItem;
    ListopenMySQLAdministratorBugsMI: TTntMenuItem;
    N5: TTntMenuItem;
    N9: TTntMenuItem;
    WindowMI: TTntMenuItem;
    N01: TTntMenuItem;
    N4: TTntMenuItem;
    MEMySQLEnterpriseMI: TTntMenuItem;
    MESoftwareMI: TTntMenuItem;
    MEKnowledgeBaseMI: TTntMenuItem;
    MEUpdateServiceMI: TTntMenuItem;
    MEHomeMI: TTntMenuItem;
    MEMonitoringServiceMI: TTntMenuItem;
    METechnicalSupportMI: TTntMenuItem;

    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);

    procedure BuildSectionTree;
    procedure DoCurrentSectionChanged(Sender: TObject);
    function CreateSectionForm(AOwner: TComponent; SidebarSectionType: integer): TSectionForm;

    procedure ConnecttoServerMIClick(Sender: TObject);
    procedure CloseMIClick(Sender: TObject);

    procedure StatusBarDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const R: TRect);
    procedure StatusBarMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SaveConnectionMIClick(Sender: TObject);
    procedure PasteMIClick(Sender: TObject);
    procedure OptionsMIClick(Sender: TObject);
    procedure ManageConnectionsMIClick(Sender: TObject);
    procedure ConnectionLost(var Message: TMessage); message WM_CONNECTION_LOST;
    procedure ConnectionEstablished(var Message: TMessage); message WM_CONNECTION_ESTABLISHED;

    procedure MySQLCommandlineclientMIClick(Sender: TObject);
    procedure WindowsCommandLineMIClick(Sender: TObject);
    procedure ReportBugMIClick(Sender: TObject);
    procedure VisitMySQLcomMIClick(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure OnlineHelpMIClick(Sender: TObject);
    procedure AboutMIClick(Sender: TObject);
    procedure ReconnectMIClick(Sender: TObject);

    procedure HandleIdle(Sender: TObject; var Done: Boolean);
    procedure CutMIClick(Sender: TObject);
    procedure CopyMIClick(Sender: TObject);
    procedure SelectAllMIClick(Sender: TObject);

    procedure CopyActivePageAsTextMIClick(Sender: TObject);
    procedure MySQLQueryBrowserMIClick(Sender: TObject);
    procedure MySQLSystemTrayMonitorMIClick(Sender: TObject);
    procedure ListopenMySQLAdministratorBugsMIClick(Sender: TObject);

    procedure DoException(Sender: TObject; E: Exception);

    procedure WMInitMenuPopup(var MSG: TWMInitMenuPopup); message WM_INITMENUPOPUP;
    procedure TntFormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
      var Handled: Boolean);
    procedure MEHomeMIClick(Sender: TObject);
    procedure MESoftwareMIClick(Sender: TObject);
    procedure MEKnowledgeBaseMIClick(Sender: TObject);
    procedure MEUpdateServiceMIClick(Sender: TObject);
    procedure MEMonitoringServiceMIClick(Sender: TObject);
    procedure METechnicalSupportMIClick(Sender: TObject);
  private
    CatalogSection, BackupRestoreSection,
    UserAdministrationSection: TSidebarSection;

    PNGThreadStop: TPNGObject;
  public
    SectionControls: TSectionControls;
    procedure PrepareGUI();
  end;

const
  SSTAdmin_ServerInfo = 1;
  SSTAdmin_ServerConfig = 2;
  SSTAdmin_ServiceControl = 3;
  SSTAdmin_StartupVariables = 4;
  SSTAdmin_ServerConnections = 5;
  SSTAdmin_UserAdministration = 6;
  SSTAdmin_ServerHealth = 7;
  SSTAdmin_ServerLogs = 8;
  SSTAdmin_Backup = 9;
  SSTAdmin_Restore = 10;
  SSTAdmin_Replication = 11;
  SSTAdmin_Catalog = 12;

var
  MainForm: TMainForm;

implementation

uses
  About, PNGTools, TntClipbrd;

{$R *.dfm}

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.FormCreate(Sender: TObject);

begin
  InitForm(self);

  RegisterMySQLApplication(Application.Title, product_version, ExtractFilePath(Application.ExeName));

  ApplicationDM.CurrentConnection.UseStatusBar(StatusBar);
  MainMenu.AutoHotkeys := maAutomatic;

  PNGThreadStop := LoadPNGImageFromResource('thread_stop', nil);

  if not ApplicationDM.Options.RestoreWindowPos(Self) then
  begin
    if(Screen.Width>=1024)then
    begin
      if(Screen.Height>=1024)then
      begin
        Width := 900;
        Height := 720;
      end
      else
      begin
        Width := 900;
        Height := 680;
      end;

      //Align center (till position is stored)
      Left := (Screen.Width+Width) div 2 - Width;
      Top := (Screen.Height+Height) div 2 - Height;
    end
    else
    begin
      Width := 800;
      Height := 572;

      Left := (Screen.Width+Width) div 2 - Width;
      Top := 0;

      WindowState := wsMaximized;
    end;
  end;

  SectionControls := TSectionControls.Create(self,
    CreateSectionForm,
    ViewMI,
    ApplicationDM.Options.SectionSidebarHidden,
    ApplicationDM.Options.SectionSidebarWidth,
    ApplicationDM.SectionImageList,
    11);


  Application.OnIdle := HandleIdle;
  Application.OnException := DoException;

end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.FormDestroy(Sender: TObject);

begin
  SectionControls.Free;

  ApplicationDM.Options.AddWindowPos(self);

  PNGThreadStop.Free;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);

begin
  if GetKeyState(VK_CONTROL) < 0 then
    ConnectToServerMIClick(Self);

  ApplicationDM.ApplicationIsTerminating := True;

  Action := caFree;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.PrepareGUI();

begin
  // Set the Caption
  if ApplicationDM.CurrentConnection.GetConnectionCaption <> '' then
    Caption := _('MySQL Administrator') + ' - ' + ApplicationDM.CurrentConnection.GetConnectionCaption;

  // Build the Admin Tree
  BuildSectionTree;

  // Select first page
  if(ApplicationDM.Options.StartSection>0)and
    (ApplicationDM.Options.StartSection<=
      SectionControls.AdminTreeView.Items.Count)then
    SectionControls.AdminTreeView.Selected := 
      SectionControls.AdminTreeView.Items[
      ApplicationDM.Options.StartSection-1];

  // Enable Tools Menu Items
  MySQLQueryBrowserMI.Enabled := GetMySQLQueryBrowserCmd <> '';
  MySQLCommandlineclientMI.Enabled := (GetMySQLCommandLineClientPath <> '') and
    Assigned(ApplicationDM.CurrentConnection.UserConnection);
  WindowsCommandLineMI.Enabled := FileExists(GetSystemDir+'cmd.exe');
  MySQLSystemTrayMonitorMI.Enabled := FileExists(
    ExtractFilePath(Application.ExeName)+'MySQLSystemTrayMonitor.exe');
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.ConnecttoServerMIClick(Sender: TObject);

begin
  CreateSubProcess(Application.ExeName, '');
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.CloseMIClick(Sender: TObject);

begin
  Close;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.StatusBarDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const R: TRect);

begin
  if (Panel.Index = 0) and ApplicationDM.CurrentConnection.FetchingData then
    PNGThreadStop.Draw(StatusBar.Canvas, Rect(R.Left + 1, R.Top + 1, R.Left + 1 + 13, R.Top + 1 + 13));
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.StatusBarMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

begin
  if (X < 20) and ApplicationDM.CurrentConnection.FetchingData then
  begin
    ApplicationDM.CurrentConnection.ClearWorkList;

    Statusbar.Panels[1].Text := '';
    StatusBar.Invalidate;
  end;
end;

//----------------------------------------------------------------------------------------------------------------------

type
  TControlCast = class(TControl);

procedure TMainForm.TntFormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
  var Handled: Boolean);

// Forward mouse wheel messages as scroll messages to scroll boxes (if there is one under the mouse).

var
  Control: TControl;
  Message: TMessage;

begin
  Control := FindDragTarget(MousePos, False);
  while Assigned(Control) and not (Control is TScrollBox) do
    Control := Control.Parent;

  if Control is TScrollBox then
  begin
    FillChar(Message, SizeOf(Message), 0);
    Message.Msg := WM_VSCROLL;
    if WheelDelta < 0 then
      Message.WParam := MakeWParam(SB_LINEDOWN, 0)
    else
      Message.WParam := MakeWParam(SB_LINEUP, 0);

    TControlCast(Control).WndProc(Message);
    Handled := True;
  end
  else
    Handled := False;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.OptionsMIClick(Sender: TObject);

var
  OptionsForm: TOptionsForm;

begin
  OptionsForm := TOptionsForm.Create(self, TAdminOptionPagesForm.Create(self), ApplicationDM.CurrentConnection.MySQL);
  try
    OptionsForm.ShowModal;
  finally
    OptionsForm.Free;
  end;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.SaveConnectionMIClick(Sender: TObject);

var
  OptionsForm: TOptionsForm;

begin
  OptionsForm := TOptionsForm.Create(self, TAdminOptionPagesForm.Create(self), ApplicationDM.CurrentConnection.MySQL);
  try
    // Activate connections page.
    OptionsForm.ShowOptionPage(ConnectionsPage);

    OptionsForm.AddConnection(ApplicationDM.CurrentConnection.UserConnection);
    OptionsForm.ActiveControl := OptionsForm.ConnectionEd;

    OptionsForm.ShowModal;
  finally
    OptionsForm.Free;
  end;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.ManageConnectionsMIClick(Sender: TObject);

var
  OptionsForm: TOptionsForm;
  
begin
  OptionsForm := TOptionsForm.Create(self, TAdminOptionPagesForm.Create(self), ApplicationDM.CurrentConnection.MySQL);
  try
    //Select Connections Page
    OptionsForm.ShowOptionPage(ConnectionsPage);

    OptionsForm.ShowModal;
  finally
    OptionsForm.Free;
  end;
end;

procedure TMainForm.MEHomeMIClick(Sender: TObject);
begin
  BrowseWebPage('https://enterprise.mysql.com/');
end;

procedure TMainForm.MEKnowledgeBaseMIClick(Sender: TObject);
begin
  BrowseWebPage('https://kb.mysql.com/index.php');
end;

procedure TMainForm.MEMonitoringServiceMIClick(Sender: TObject);
begin
  BrowseWebPage('https://enterprise.mysql.com/monitoring/');
end;

procedure TMainForm.MESoftwareMIClick(Sender: TObject);
begin
  BrowseWebPage('https://enterprise.mysql.com/software/enterprise.php');
end;

procedure TMainForm.METechnicalSupportMIClick(Sender: TObject);
begin
  BrowseWebPage('https://support.mysql.com/main.php/');
end;

procedure TMainForm.MEUpdateServiceMIClick(Sender: TObject);
begin
  BrowseWebPage('https://enterprise.mysql.com/updates/index.php');
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.ConnectionLost(var Message: TMessage);

begin
  with ApplicationDM do
    SectionControls.RefreshSidebarIcons(False, CurrentConnection.IsLocalServer, Options.ShowOnlyServiceSections);
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.ConnectionEstablished(var Message: TMessage);

begin
  with ApplicationDM do
    SectionControls.RefreshSidebarIcons(True, CurrentConnection.IsLocalServer, Options.ShowOnlyServiceSections);
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.MySQLCommandlineclientMIClick(Sender: TObject);

var
  Command: WideString;

begin
  Command := GetMySQLCommandLineClientPath;
  with ApplicationDM do
    if (Command<>'') and Assigned(CurrentConnection.UserConnection) then
      CreateSubProcess(Command + ' -h' + CurrentConnection.UserConnection.hostname +
        ' -u' + CurrentConnection.UserConnection.username +
        ' -p' + CurrentConnection.UserConnection.password +
        ' -P' + IntToStr(CurrentConnection.UserConnection.port), '');
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.WindowsCommandLineMIClick(Sender: TObject);

var
  cmd: WideString;

begin
  cmd := GetSystemDir+'cmd.exe';
  if(FileExists(cmd))then
    CreateSubProcess(cmd, GetHomeDir);
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.ReportBugMIClick(Sender: TObject);

begin
  BrowseWebPage('http://bugs.mysql.com');
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.VisitMySQLcomMIClick(Sender: TObject);

begin
  BrowseWebPage('http://www.mysql.com');
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);

begin
  if(Key=VK_F1)then
    ShowHelp;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.OnlineHelpMIClick(Sender: TObject);

begin
  ShowHelp;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.AboutMIClick(Sender: TObject);

begin
  ShowAboutDialog('MySQL Administrator',
    product_version+' '+product_build_level,
    _('Michael G. Zinner, main concept, graphical design, '+
    'Windows development, library coding | '+
    'Alfredo Kengi Kojima, Linux development, library coding | '+
    'Ulrich Bayer, library coding, WIX | Victor Vagin, library coding, '+
    ' QA | '+
    'Brian Aker, conceptual design, supervising | '+
    'Stefan Hinz, documentation | '+
    'Mike Hillyer, documentation'));
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.BuildSectionTree;

begin
  SectionControls.AdminTreeView.Items.Clear;

  // Create all AdminTree nodes and attach the corresponding action.
  if not ApplicationDM.Options.ShowOnlyServiceSections then
  begin
    // Create Server Information Section
    SectionControls.AddSection(_('Server Information'), TSidebarSection.Create(SSTAdmin_ServerInfo, 0, 1, True, False));
  end;

  // Create Service Control Section
  SectionControls.AddSection(_('Service Control'),
    TSidebarSection.Create(SSTAdmin_ServiceControl, 2, 3, False, True, nil,
      ApplicationDM.Options.ShowOnlyServiceSections));

  // Create Server Variables Section
  SectionControls.AddSection(_('Startup Variables'),
    TSidebarSection.Create(SSTAdmin_StartupVariables, 4, 5, False, True, nil,
      ApplicationDM.Options.ShowOnlyServiceSections));

  if not ApplicationDM.Options.ShowOnlyServiceSections then
  begin
    // Create User Administration Section
    UserAdministrationSection := 
      TSidebarSection.Create(SSTAdmin_UserAdministration, 8, 9, True, False, nil, True);
    SectionControls.AddSection(_('User Administration'), UserAdministrationSection);

    //Create Server Connections Section
    SectionControls.AddSection(_('Server Connections'),
      TSidebarSection.Create(SSTAdmin_ServerConnections, 6, 7, True, False));

    //Create Health Section
    SectionControls.AddSection(_('Health'),
      TSidebarSection.Create(SSTAdmin_ServerHealth, 10, 11, True, False));
  end;

  //Create Server Logs Section
  SectionControls.AddSection(_('Server Logs'),
    TSidebarSection.Create(SSTAdmin_ServerLogs, 12, 13, False, True, nil,
      ApplicationDM.Options.ShowOnlyServiceSections));

  if not ApplicationDM.Options.ShowOnlyServiceSections then
  begin
    //Create Replication Status Section
    SectionControls.AddSection(_('Replication Status'),
      TSidebarSection.Create(SSTAdmin_Replication, 18, 19, True, False));

    //Create Backup Section
    BackupRestoreSection := TSidebarSection.Create(SSTAdmin_Backup, 14, 15, True, False, nil, True);
    SectionControls.AddSection(_('Backup'), BackupRestoreSection);

    //Create Restore Section
    SectionControls.AddSection(_('Restore'), TSidebarSection.Create(SSTAdmin_Restore, 16, 17, True, False, nil, True));

    //Create Catalogs Section
    CatalogSection := TSidebarSection.Create(SSTAdmin_Catalog, 20, 21, True, False, nil, True);
    SectionControls.AddSection(_('Catalogs'), CatalogSection);
  end;

  with ApplicationDM do
    SectionControls.RefreshSidebarIcons(CurrentConnection.Connected, CurrentConnection.IsLocalServer,
      Options.ShowOnlyServiceSections);

  if ApplicationDM.Options.ShowOnlyServiceSections then
    SaveConnectionMI.Enabled := False;

  SectionControls.OnCurrentSectionChanged := DoCurrentSectionChanged;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.DoCurrentSectionChanged(Sender: TObject);

var
  S: WideString;

begin
  S := SectionControls.CurrentSidebarSection.SectionForm.GetFormContentAsText;
  CopyActivePageAsTextMI.Enabled := S <> '';
end;

//----------------------------------------------------------------------------------------------------------------------

function TMainForm.CreateSectionForm(AOwner: TComponent; SidebarSectionType: integer): TSectionForm;

begin
  Result := nil;

  with ApplicationDM do
  begin
    // Do *not* give the forms an owner otherwise they will be implicitly destroyed.
    // However the section control takes care for that so this would collide.
    case SidebarSectionType of
      SSTAdmin_ServerInfo:
        Result := TAdminServerInfoForm.Create(nil, CurrentConnection, StatusBar);
      SSTAdmin_ServiceControl:
        Result := TAdminServiceControlForm.Create(nil, CurrentConnection, StatusBar);
      SSTAdmin_StartupVariables:
        Result := TAdminStartupVariablesForm.Create(nil, CurrentConnection, StatusBar);
      SSTAdmin_ServerHealth:
        Result := TAdminServerHealthForm.Create(nil, CurrentConnection, StatusBar);
      SSTAdmin_ServerConnections:
        Result := TAdminServerConnectionsForm.Create(nil, CurrentConnection, StatusBar);
      SSTAdmin_UserAdministration:
        Result := TAdminUsersForm.Create(nil, CurrentConnection, StatusBar);
      SSTAdmin_Catalog:
        Result := TAdminCatalogForm.Create(nil, CurrentConnection, StatusBar);
      SSTAdmin_Backup:
        Result := TAdminBackupForm.Create(nil, CurrentConnection, StatusBar);
      SSTAdmin_Restore:
        Result := TAdminRestoreForm.Create(nil, CurrentConnection, StatusBar);
      SSTAdmin_ServerLogs:
        Result := TAdminServerLogsForm.Create(nil, CurrentConnection, StatusBar);
      SSTAdmin_replication:
        Result := TAdminReplicationForm.Create(nil, CurrentConnection, StatusBar);
    end;
  end;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.ReconnectMIClick(Sender: TObject);

begin
  ConnecttoServerMIClick(self);

  Close;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.HandleIdle(Sender: TObject; var Done: Boolean);

var
  Enable: Boolean;

begin
  if(ActiveControl is TCustomEdit)then
  begin
    Enable := TCustomEdit(Self.ActiveControl).SelLength>0;
    CutMI.Enabled := Enable;
    CopyMI.Enabled := Enable;
    Enable := Clipboard.HasFormat(CF_TEXT);
    PasteMI.Enabled := Enable;
    SelectAllMI.Enabled := Enable;
  end
  else
  begin
    CutMI.Enabled := False;
    CopyMI.Enabled := False;
    PasteMI.Enabled := False;
  end;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.CutMIClick(Sender: TObject);

begin
  SendMessage(ActiveControl.Handle, WM_Cut, 0, 0);
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.CopyMIClick(Sender: TObject);

begin
  SendMessage(ActiveControl.Handle, WM_COPY, 0, 0);
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.PasteMIClick(Sender: TObject);

begin
  SendMessage(ActiveControl.Handle, WM_Paste, 0, 0);
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.SelectAllMIClick(Sender: TObject);

begin
  if(ActiveControl is TCustomEdit)then
    TCustomEdit(ActiveControl).SelectAll;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.CopyActivePageAsTextMIClick(Sender: TObject);

var
  S: WideString;

begin
  S := SectionControls.CurrentSidebarSection.SectionForm.GetFormContentAsText;
  if S <> '' then
    TntClipboard.AsWideText := S;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.MySQLQueryBrowserMIClick(Sender: TObject);

  //---------------------------------------------------------------------------

  function ConvertToHex(const S: WideString): string;

  var
    Utf8String: string;
    
  begin
    Utf8String := Utf8Encode(S);
    SetLength(Result, 2 * Length(Utf8String));
    BinToHex(PChar(Utf8String), PChar(Result), Length(Utf8String));
  end;

  //---------------------------------------------------------------------------

var
  Command: WideString;

begin
  Command := GetMySQLQueryBrowserCmd;

  with ApplicationDM do
    if Assigned(CurrentConnection.UserConnection) then
    begin
      Command := Command + ' "-u' + CurrentConnection.UserConnection.username + '"';
      if CurrentConnection.UserConnection.password <> '' then
        Command := Command + ' -x' + ConvertToHex(CurrentConnection.UserConnection.password);
      Command := Command+' "-h' + CurrentConnection.UserConnection.hostname + '"';
      Command := Command+' "-P' + IntToStr(CurrentConnection.UserConnection.port) + '"';
    end;

  CreateSubProcess(Command, '');
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.MySQLSystemTrayMonitorMIClick(Sender: TObject);

begin
  CreateSubProcess(ExtractFilePath(Application.ExeName) + 'MySQLSystemTrayMonitor.exe', '');
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.ListopenMySQLAdministratorBugsMIClick(Sender: TObject);

begin
  BrowseWebPage('http://bugs.mysql.com/search.php?search_for=&limit=All&order_by=&direction=ASC&cmd=display&status=Active&severity=&showstopper=&bug_type=MySQL+Administrator&php_os=&phpver=&assign=&bug_age=0');
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.DoException(Sender: TObject; E: Exception);

begin
  ShowModalDialog(Application.Title + ' ' + _('Exception'), E.Message, myx_mtError, _('OK'));
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TMainForm.WMInitMenuPopup(var MSG: TWMInitMenuPopup);

begin
  if (Msg.MenuPopup = WindowMI.Handle) then
    BuildRegisterApplicationMenuItems(WindowMI);

  inherited;
end;

//----------------------------------------------------------------------------------------------------------------------

end.