forked from HeidiSQL/HeidiSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnections.pas
More file actions
1578 lines (1424 loc) · 54.5 KB
/
Copy pathconnections.pas
File metadata and controls
1578 lines (1424 loc) · 54.5 KB
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
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit connections;
// -------------------------------------
// Connections (start-window)
// -------------------------------------
interface
uses
Windows, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls,
VirtualTrees, Menus, Graphics, Generics.Collections, ActiveX, extra_controls, Messages,
dbconnection, gnugettext, SynRegExpr, System.Types, Vcl.GraphUtil, ADODB, StrUtils,
System.Math, System.Actions, Vcl.ActnList, Vcl.StdActns;
type
Tconnform = class(TExtForm)
btnCancel: TButton;
btnOpen: TButton;
btnSave: TButton;
btnNew: TButton;
btnDelete: TButton;
popupSessions: TPopupMenu;
menuSave: TMenuItem;
menuDelete: TMenuItem;
menuSaveAs: TMenuItem;
TimerStatistics: TTimer;
PageControlDetails: TPageControl;
tabSettings: TTabSheet;
lblPort: TLabel;
lblPassword: TLabel;
lblHost: TLabel;
lblUsername: TLabel;
lblNetworkType: TLabel;
chkCompressed: TCheckBox;
editPort: TEdit;
updownPort: TUpDown;
editPassword: TEdit;
editUsername: TEdit;
editHost: TButtonedEdit;
tabAdvanced: TTabSheet;
tabStatistics: TTabSheet;
lblLastConnectLeft: TLabel;
lblCounterLeft: TLabel;
lblCreatedLeft: TLabel;
lblCreatedRight: TLabel;
lblCounterRight1: TLabel;
lblLastConnectRight: TLabel;
tabSSHtunnel: TTabSheet;
editSSHlocalport: TEdit;
editSSHUser: TEdit;
editSSHPassword: TEdit;
lblSSHLocalPort: TLabel;
lblSSHUser: TLabel;
lblSSHPassword: TLabel;
editSSHPlinkExe: TButtonedEdit;
lblSSHPlinkExe: TLabel;
comboNetType: TComboBoxEx;
lblSSHhost: TLabel;
editSSHhost: TEdit;
editSSHport: TEdit;
editSSHPrivateKey: TButtonedEdit;
lblSSHkeyfile: TLabel;
editDatabases: TButtonedEdit;
lblDatabase: TLabel;
chkLoginPrompt: TCheckBox;
lblPlinkTimeout: TLabel;
editSSHTimeout: TEdit;
updownSSHTimeout: TUpDown;
chkWindowsAuth: TCheckBox;
chkCleartextPluginEnabled: TCheckBox;
splitterMain: TSplitter;
tabStart: TTabSheet;
lblHelp: TLabel;
btnImportSettings: TButton;
timerSettingsImport: TTimer;
popupNew: TPopupMenu;
menuNewSessionInRoot: TMenuItem;
menuNewFolderInRoot: TMenuItem;
menuContextNewFolderInFolder: TMenuItem;
menuContextNewSessionInFolder: TMenuItem;
menuNewSessionInFolder: TMenuItem;
menuNewFolderInFolder: TMenuItem;
chkLocalTimeZone: TCheckBox;
editStartupScript: TButtonedEdit;
lblStartupScript: TLabel;
chkFullTableStatus: TCheckBox;
btnMore: TButton;
popupMore: TPopupMenu;
Checkforupdates1: TMenuItem;
About1: TMenuItem;
Preferences1: TMenuItem;
Exportsettingsfile1: TMenuItem;
Importsettingsfile1: TMenuItem;
lblComment: TLabel;
memoComment: TMemo;
lblQueryTimeout: TLabel;
editQueryTimeout: TEdit;
updownQueryTimeout: TUpDown;
menuMoreGeneralHelp: TMenuItem;
menuRename: TMenuItem;
lblKeepAlive: TLabel;
editKeepAlive: TEdit;
updownKeepAlive: TUpDown;
lblCounterRight2: TLabel;
lblCounterLeft2: TLabel;
TimerButtonAnimation: TTimer;
lblBackgroundColor: TLabel;
ColorBoxBackgroundColor: TColorBox;
comboLibrary: TComboBox;
lblLibrary: TLabel;
pnlLeft: TPanel;
ListSessions: TVirtualStringTree;
editSearch: TButtonedEdit;
popupHost: TPopupMenu;
menuFindDatabaseFiles: TMenuItem;
menuAddDatabaseFiles: TMenuItem;
lblIgnoreDatabasePattern: TLabel;
editIgnoreDatabasePattern: TEdit;
ActionListConnections: TActionList;
actFilter: TAction;
Filter1: TMenuItem;
chkLogFileDdl: TCheckBox;
editLogFilePath: TButtonedEdit;
tabSSL: TTabSheet;
chkWantSSL: TCheckBox;
lblSSLPrivateKey: TLabel;
lblSSLCACertificate: TLabel;
lblSSLCertificate: TLabel;
lblSSLcipher: TLabel;
editSSLcipher: TEdit;
editSSLCertificate: TButtonedEdit;
editSSLCACertificate: TButtonedEdit;
editSSLPrivateKey: TButtonedEdit;
lblLogFile: TLabel;
chkLogFileDml: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure btnOpenClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure btnSaveAsClick(Sender: TObject);
procedure btnNewClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
procedure Modification(Sender: TObject);
procedure ListSessionsGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
procedure ListSessionsFocusChanged(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex);
procedure ListSessionsGetImageIndex(Sender: TBaseVirtualTree;
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean; var ImageIndex: TImageIndex);
procedure ListSessionsNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; NewText: String);
procedure ListSessionsFocusChanging(Sender: TBaseVirtualTree; OldNode,
NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
var Allowed: Boolean);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure TimerStatisticsTimer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ListSessionsCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex;
out EditLink: IVTEditLink);
procedure PickFile(Sender: TObject);
procedure editSSHPlinkExeChange(Sender: TObject);
procedure editHostChange(Sender: TObject);
procedure editDatabasesRightButtonClick(Sender: TObject);
procedure chkLoginPromptClick(Sender: TObject);
procedure ListSessionsGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
procedure comboNetTypeChange(Sender: TObject);
procedure splitterMainMoved(Sender: TObject);
procedure btnImportSettingsClick(Sender: TObject);
procedure timerSettingsImportTimer(Sender: TObject);
procedure ListSessionsStructureChange(Sender: TBaseVirtualTree;
Node: PVirtualNode; Reason: TChangeReason);
procedure ListSessionsDragOver(Sender: TBaseVirtualTree; Source: TObject;
Shift: TShiftState; State: TDragState; Pt: TPoint; Mode: TDropMode;
var Effect: Integer; var Accept: Boolean);
procedure ListSessionsDragDrop(Sender: TBaseVirtualTree; Source: TObject;
DataObject: IDataObject; Formats: TFormatArray; Shift: TShiftState;
Pt: TPoint; var Effect: Integer; Mode: TDropMode);
procedure btnMoreClick(Sender: TObject);
procedure menuRenameClick(Sender: TObject);
procedure TimerButtonAnimationTimer(Sender: TObject);
procedure ColorBoxBackgroundColorGetColors(Sender: TCustomColorBox;
Items: TStrings);
procedure editTrim(Sender: TObject);
procedure editSearchChange(Sender: TObject);
procedure editSearchRightButtonClick(Sender: TObject);
procedure editHostDblClick(Sender: TObject);
procedure ListSessionsNodeDblClick(Sender: TBaseVirtualTree;
const HitInfo: THitInfo);
procedure FindAddDatabaseFilesClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure ListSessionsBeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
procedure actFilterExecute(Sender: TObject);
private
{ Private declarations }
FLoaded: Boolean;
FSessionModified, FOnlyPasswordModified: Boolean;
FServerVersion: String;
FSettingsImportWaitTime: Cardinal;
FPopupDatabases: TPopupMenu;
FButtonAnimationStep: Integer;
FLastSelectedNetTypeGroup: TNetTypeGroup;
function GetSelectedNetType: TNetType;
procedure SetSelectedNetType(Value: TNetType);
procedure RefreshSessions(ParentNode: PVirtualNode);
function SelectedSessionPath: String;
function CurrentParams: TConnectionParameters;
procedure FinalizeModifications(var CanProceed: Boolean);
procedure ValidateControls;
function NodeSessionNames(Node: PVirtualNode; var RegKey: String): TStringList;
procedure MenuDatabasesClick(Sender: TObject);
procedure WMNCLBUTTONDOWN(var Msg: TWMNCLButtonDown) ; message WM_NCLBUTTONDOWN;
procedure WMNCLBUTTONUP(var Msg: TWMNCLButtonUp) ; message WM_NCLBUTTONUP;
procedure RefreshBackgroundColors;
property SelectedNetType: TNetType read GetSelectedNetType write SetSelectedNetType;
public
{ Public declarations }
end;
implementation
uses Main, apphelpers, grideditlinks;
{$I const.inc}
{$R *.DFM}
procedure Tconnform.WMNCLBUTTONDOWN(var Msg: TWMNCLButtonDown) ;
begin
if Msg.HitTest = HTHELP then
Msg.Result := 0 // "eat" the message
else
inherited;
end;
procedure Tconnform.WMNCLBUTTONUP(var Msg: TWMNCLButtonUp) ;
begin
if Msg.HitTest = HTHELP then begin
Msg.Result := 0;
Help(Self, 'connecting');
end else
inherited;
end;
procedure Tconnform.FormCreate(Sender: TObject);
var
NetTypeStr, FilenameHint: String;
nt: TNetType;
ntg: TNetTypeGroup;
Params: TConnectionParameters;
ComboItem: TComboExItem;
Placeholders: TStringList;
i: Integer;
begin
// Fix GUI stuff
HasSizeGrip := True;
Width := AppSettings.ReadInt(asSessionManagerWindowWidth);
Height := AppSettings.ReadInt(asSessionManagerWindowHeight);
Left := AppSettings.ReadInt(asSessionManagerWindowLeft, '', Left);
Top := AppSettings.ReadInt(asSessionManagerWindowTop, '', Top);
// Move to visible area if window was on a now plugged off monitor previously
MakeFullyVisible;
pnlLeft.Width := AppSettings.ReadInt(asSessionManagerListWidth);
splitterMain.OnMoved(Sender);
FixVT(ListSessions);
MainForm.RestoreListSetup(ListSessions);
ListSessions.OnCompareNodes := MainForm.AnyGridCompareNodes;
ListSessions.OnHeaderClick := MainForm.AnyGridHeaderClick;
ListSessions.OnHeaderDraggedOut := MainForm.AnyGridHeaderDraggedOut;
btnImportSettings.Caption := MainForm.actImportSettings.Caption;
FLoaded := False;
comboNetType.Clear;
Params := TConnectionParameters.Create;
for ntg := Low(ntg) to High(ntg) do begin
for nt:=Low(nt) to High(nt) do begin
Params.NetType := nt;
if Params.GetNetTypeGroup <> ntg then
Continue;
NetTypeStr := Params.NetTypeName(True);
ComboItem := TComboExItem.Create(comboNetType.ItemsEx);
ComboItem.Caption := NetTypeStr;
ComboItem.ImageIndex := Params.ImageIndex;
ComboItem.Data := Pointer(nt);
end;
end;
Params.Free;
// Create filename placeholders hint
Placeholders := GetOutputFilenamePlaceholders;
FilenameHint := _('Allows the following replacement patterns:');
for i:=0 to Placeholders.Count-1 do begin
FilenameHint := FilenameHint + CRLF + '%' + Placeholders.Names[i] + ': ' + Placeholders.ValueFromIndex[i];
end;
Placeholders.Free;
editLogFilePath.Hint := FilenameHint;
end;
procedure Tconnform.RefreshSessions(ParentNode: PVirtualNode);
var
SessionNames: TStringList;
RegKey: String;
i: Integer;
Params: TConnectionParameters;
SessNode: PVirtualNode;
begin
// Initialize session tree
// And while we're at it, collect custom colors for background color selector
if ParentNode=nil then begin
ListSessions.Clear;
end else begin
ListSessions.DeleteChildren(ParentNode, True);
end;
SessionNames := NodeSessionNames(ParentNode, RegKey);
for i:=0 to SessionNames.Count-1 do begin
Params := TConnectionParameters.Create(RegKey+SessionNames[i]);
SessNode := ListSessions.AddChild(ParentNode, PConnectionParameters(Params));
if Params.IsFolder then begin
RefreshSessions(SessNode);
end;
end;
if not Assigned(ParentNode) then
RefreshBackgroundColors;
end;
procedure Tconnform.FormResize(Sender: TObject);
begin
splitterMainMoved(splitterMain);
end;
procedure Tconnform.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
// Modifications? Ask if they should be saved.
FinalizeModifications(CanClose);
end;
procedure Tconnform.FormClose(Sender: TObject; var Action: TCloseAction);
begin
// Suspend calculating statistics as long as they're not visible
TimerStatistics.Enabled := False;
// Save GUI stuff
AppSettings.WriteInt(asSessionManagerListWidth, pnlLeft.Width);
AppSettings.WriteInt(asSessionManagerWindowWidth, Width);
AppSettings.WriteInt(asSessionManagerWindowHeight, Height);
AppSettings.WriteInt(asSessionManagerWindowLeft, Left);
AppSettings.WriteInt(asSessionManagerWindowTop, Top);
MainForm.SaveListSetup(ListSessions);
end;
procedure Tconnform.FormShow(Sender: TObject);
var
LastActiveSession: String;
LastSessions: TStringList;
PSess: PConnectionParameters;
Node: PVirtualNode;
begin
// Init sessions tree
RefreshSessions(nil);
// Focus last session
SelectNode(ListSessions, nil);
LastSessions := Explode(DELIM, AppSettings.ReadString(asLastSessions));
LastActiveSession := AppSettings.ReadString(asLastActiveSession);
if (LastActiveSession = '') and (LastSessions.Count > 0) then
LastActiveSession := LastSessions[0];
Node := ListSessions.GetFirst;
while Assigned(Node) do begin
PSess := ListSessions.GetNodeData(Node);
if PSess.SessionPath = LastActiveSession then
SelectNode(ListSessions, Node);
Node := ListSessions.GetNext(Node);
end;
ListSessions.SetFocus;
// Reactivate statistics
TimerStatistics.Enabled := True;
TimerStatistics.OnTimer(Sender);
FLoaded := True;
end;
function Tconnform.GetSelectedNetType: TNetType;
begin
Result := TNetType(comboNetType.ItemsEx[comboNetType.ItemIndex].Data);
end;
procedure Tconnform.SetSelectedNetType(Value: TNetType);
var
i: Integer;
begin
for i:=0 to comboNetType.ItemsEx.Count-1 do begin
if TNetType(comboNetType.ItemsEx[i].Data) = Value then begin
comboNetType.ItemIndex := i;
Break;
end;
end;
end;
procedure Tconnform.btnOpenClick(Sender: TObject);
var
Connection: TDBConnection;
Params: TConnectionParameters;
begin
// Connect to selected session
Params := CurrentParams;
if not btnOpen.Enabled then
Exit;
btnOpen.Enabled := False;
FButtonAnimationStep := 0;
TimerButtonAnimation.Enabled := True;
Screen.Cursor := crHourglass;
if Mainform.InitConnection(Params, True, Connection) then
ModalResult := mrOK
else begin
TimerStatistics.OnTimer(Sender);
ModalResult := mrNone;
end;
TimerButtonAnimation.Enabled := False;
btnOpen.Enabled := True;
btnOpen.Caption := _('Open');
Screen.Cursor := crDefault;
end;
procedure Tconnform.btnSaveClick(Sender: TObject);
var
Sess: PConnectionParameters;
Conn: TDBConnection;
begin
// Overtake edited values for current parameter object and save to registry
Sess := ListSessions.GetNodeData(ListSessions.FocusedNode);
Sess.Hostname := editHost.Text;
Sess.Username := editUsername.Text;
Sess.Password := editPassword.Text;
Sess.LoginPrompt := chkLoginPrompt.Checked;
Sess.WindowsAuth := chkWindowsAuth.Checked;
Sess.CleartextPluginEnabled := chkCleartextPluginEnabled.Checked;
Sess.Port := updownPort.Position;
Sess.NetType := SelectedNetType;
Sess.Compressed := chkCompressed.Checked;
Sess.QueryTimeout := updownQueryTimeout.Position;
Sess.KeepAlive := updownKeepAlive.Position;
Sess.LocalTimeZone := chkLocalTimeZone.Checked;
Sess.FullTableStatus := chkFullTableStatus.Checked;
Sess.SessionColor := ColorBoxBackgroundColor.Selected;
Sess.LibraryOrProvider := comboLibrary.Text;
Sess.AllDatabasesStr := editDatabases.Text;
Sess.Comment := memoComment.Text;
Sess.StartupScriptFilename := editStartupScript.Text;
Sess.SSHPlinkExe := editSSHPlinkExe.Text;
Sess.SSHHost := editSSHhost.Text;
Sess.SSHPort := MakeInt(editSSHport.Text);
Sess.SSHUser := editSSHUser.Text;
Sess.SSHPassword := editSSHPassword.Text;
Sess.SSHTimeout := updownSSHTimeout.Position;
Sess.SSHPrivateKey := editSSHPrivateKey.Text;
Sess.SSHLocalPort := MakeInt(editSSHlocalport.Text);
Sess.WantSSL := chkWantSSL.Checked;
Sess.SSLPrivateKey := editSSLPrivateKey.Text;
Sess.SSLCertificate := editSSLCertificate.Text;
Sess.SSLCACertificate := editSSLCACertificate.Text;
Sess.SSLCipher := editSSLCipher.Text;
Sess.IgnoreDatabasePattern := editIgnoreDatabasePattern.Text;
Sess.LogFileDdl := chkLogFileDdl.Checked;
Sess.LogFileDml := chkLogFileDml.Checked;
Sess.LogFilePath := editLogFilePath.Text;
Sess.SaveToRegistry;
FSessionModified := False;
ListSessions.Invalidate;
RefreshBackgroundColors;
ValidateControls;
// Apply session color (and othher settings) to opened connection(s)
for Conn in MainForm.Connections do begin
if Conn.Parameters.SessionPath = Sess.SessionPath then begin
Conn.Parameters.SessionColor := Sess.SessionColor;
MainForm.DBtree.Repaint;
end;
end;
end;
procedure Tconnform.btnMoreClick(Sender: TObject);
var
btn: TButton;
begin
btn := Sender as TButton;
btn.DropDownMenu.Popup(btn.ClientOrigin.X, btn.ClientOrigin.Y+btn.Height);
end;
procedure Tconnform.btnSaveAsClick(Sender: TObject);
var
newName, ParentKey: String;
NameOK: Boolean;
NewSess: TConnectionParameters;
Node: PVirtualNode;
SessionNames: TStringList;
begin
// Save session as ...
newName := _('Enter new session name ...');
NameOK := False;
SessionNames := NodeSessionNames(ListSessions.FocusedNode.Parent, ParentKey);
while not NameOK do begin
if not InputQuery(_('Clone session ...'), _('New session name:'), newName) then
Exit; // Cancelled
NameOK := SessionNames.IndexOf(newName) = -1;
if not NameOK then
ErrorDialog(f_('Session "%s" already exists!', [ParentKey+newName]))
else begin
// Create the key and save its values
NewSess := CurrentParams;
NewSess.SessionPath := ParentKey+newName;
NewSess.SaveToRegistry;
Node := ListSessions.InsertNode(ListSessions.FocusedNode, amInsertAfter, PConnectionParameters(NewSess));
FSessionModified := False;
SelectNode(ListSessions, Node);
end;
end;
SessionNames.Free;
end;
procedure Tconnform.btnImportSettingsClick(Sender: TObject);
begin
MainForm.actImportSettings.Execute;
FSettingsImportWaitTime := 0;
timerSettingsImport.Enabled := MainForm.ImportSettingsDone;
end;
procedure Tconnform.timerSettingsImportTimer(Sender: TObject);
begin
Inc(FSettingsImportWaitTime, timerSettingsImport.Interval);
RefreshSessions(nil);
if ListSessions.RootNodeCount > 0 then
timerSettingsImport.Enabled := False;
if FSettingsImportWaitTime >= 10000 then begin
timerSettingsImport.Enabled := False;
MessageDialog(f_('Imported sessions could not be detected. Restarting %s may solve that.', [APPNAME]), mtWarning, [mbOK]);
end;
end;
procedure Tconnform.btnNewClick(Sender: TObject);
var
i: Integer;
CanProceed, CreateInRoot: Boolean;
NewSess: TConnectionParameters;
ParentSess: PConnectionParameters;
ParentNode, NewNode: PVirtualNode;
ParentPath: String;
SiblingSessionNames: TStringList;
begin
// Create new session or folder
FinalizeModifications(CanProceed);
if not CanProceed then
Exit;
CreateInRoot := (Sender = menuNewSessionInRoot) or (Sender = menuNewFolderInRoot);
if Assigned(ListSessions.FocusedNode) then
ParentSess := ListSessions.GetNodeData(ListSessions.FocusedNode)
else
ParentSess := nil;
if CreateInRoot then
ParentNode := nil
else begin
if ParentSess = nil then
ParentNode := nil
else if ParentSess.IsFolder then
ParentNode := ListSessions.FocusedNode
else
ParentNode := ListSessions.FocusedNode.Parent;
end;
SiblingSessionNames := NodeSessionNames(ParentNode, ParentPath);
NewSess := TConnectionParameters.Create;
NewSess.IsFolder := (Sender = menuNewFolderInRoot) or (Sender = menuContextNewFolderInFolder) or (Sender = menuNewFolderInFolder);
NewSess.SessionPath := ParentPath + 'Unnamed';
i := 0;
while SiblingSessionNames.IndexOf(NewSess.SessionName) > -1 do begin
inc(i);
NewSess.SessionPath := ParentPath + 'Unnamed-' + IntToStr(i);
end;
NewSess.SaveToRegistry;
SiblingSessionNames.Free;
NewNode := ListSessions.AddChild(ParentNode, PConnectionParameters(NewSess));
// Select it
SelectNode(ListSessions, NewNode);
ValidateControls;
ListSessions.EditNode(NewNode, 0);
end;
procedure Tconnform.actFilterExecute(Sender: TObject);
begin
editSearch.SetFocus;
end;
procedure Tconnform.btnDeleteClick(Sender: TObject);
var
Sess: PConnectionParameters;
Node, FocusNode: PVirtualNode;
begin
Node := ListSessions.FocusedNode;
Sess := ListSessions.GetNodeData(Node);
if MessageDialog(f_('Delete session "%s"?', [Sess.SessionName]), mtConfirmation, [mbYes, mbCancel]) = mrYes then
begin
AppSettings.SessionPath := Sess.SessionPath;
AppSettings.DeleteCurrentKey;
if Assigned(Node.NextSibling) then
FocusNode := Node.NextSibling
else if Assigned(Node.PrevSibling) then
FocusNode := Node.PrevSibling
else
FocusNode := Node.Parent;
ListSessions.DeleteNode(Node);
SelectNode(ListSessions, FocusNode);
ListSessions.SetFocus;
end;
end;
function Tconnform.SelectedSessionPath: String;
var
Sess: PConnectionParameters;
begin
if not Assigned(ListSessions.FocusedNode) then
Result := ''
else begin
Sess := ListSessions.GetNodeData(ListSessions.FocusedNode);
Result := Sess.SessionPath;
end;
end;
function Tconnform.CurrentParams: TConnectionParameters;
var
FromReg: PConnectionParameters;
begin
// Return non-stored parameters
FromReg := ListSessions.GetNodeData(ListSessions.FocusedNode);
if FromReg.IsFolder then begin
Result := FromReg^;
end else begin
Result := TConnectionParameters.Create;
Result.SessionPath := SelectedSessionPath;
Result.Counter := FromReg.Counter;
Result.SessionColor := ColorBoxBackgroundColor.Selected;
Result.NetType := SelectedNetType;
Result.ServerVersion := FServerVersion;
Result.Hostname := editHost.Text;
Result.Username := editUsername.Text;
Result.Password := editPassword.Text;
Result.LoginPrompt := chkLoginPrompt.Checked;
Result.WindowsAuth := chkWindowsAuth.Checked;
Result.CleartextPluginEnabled := chkCleartextPluginEnabled.Checked;
if updownPort.Enabled then
Result.Port := updownPort.Position
else
Result.Port := 0;
Result.AllDatabasesStr := editDatabases.Text;
Result.LibraryOrProvider := comboLibrary.Text;
Result.Comment := memoComment.Text;
Result.SSHHost := editSSHHost.Text;
Result.SSHPort := MakeInt(editSSHPort.Text);
Result.SSHUser := editSSHuser.Text;
Result.SSHPassword := editSSHpassword.Text;
Result.SSHTimeout := updownSSHTimeout.Position;
Result.SSHPrivateKey := editSSHPrivateKey.Text;
Result.SSHLocalPort := MakeInt(editSSHlocalport.Text);
Result.SSHPlinkExe := editSSHplinkexe.Text;
Result.WantSSL := chkWantSSL.Checked;
Result.SSLPrivateKey := editSSLPrivateKey.Text;
Result.SSLCertificate := editSSLCertificate.Text;
Result.SSLCACertificate := editSSLCACertificate.Text;
Result.SSLCipher := editSSLCipher.Text;
Result.StartupScriptFilename := editStartupScript.Text;
Result.Compressed := chkCompressed.Checked;
Result.QueryTimeout := updownQueryTimeout.Position;
Result.KeepAlive := updownKeepAlive.Position;
Result.LocalTimeZone := chkLocalTimeZone.Checked;
Result.FullTableStatus := chkFullTableStatus.Checked;
Result.SessionColor := ColorBoxBackgroundColor.Selected;
Result.IgnoreDatabasePattern := editIgnoreDatabasePattern.Text;
Result.LogFileDdl := chkLogFileDdl.Checked;
Result.LogFileDml := chkLogFileDml.Checked;
Result.LogFilePath := editLogFilePath.Text;
end;
end;
procedure Tconnform.ListSessionsGetImageIndex(Sender: TBaseVirtualTree;
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean; var ImageIndex: TImageIndex);
var
Sess: PConnectionParameters;
begin
// An edited session gets an additional pencil symbol
if Column > 0 then
ImageIndex := -1
else case Kind of
ikNormal, ikSelected: begin
Sess := Sender.GetNodeData(Node);
ImageIndex := Sess.ImageIndex;
end;
ikOverlay:
if (Node = Sender.FocusedNode) and FSessionModified then
ImageIndex := 162;
end;
end;
procedure Tconnform.ListSessionsGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
begin
NodeDataSize := SizeOf(TConnectionParameters);
end;
procedure Tconnform.ListSessionsGetText(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText: String);
var
Sess: PConnectionParameters;
begin
// Display session name cell
Sess := Sender.GetNodeData(Node);
if Sess.IsFolder then begin
case Column of
0: CellText := Sess.SessionName;
else CellText := '';
end;
end else begin
case Column of
0: begin
CellText := Sess.SessionName;
if FSessionModified and (Node = Sender.FocusedNode) and (not Sender.IsEditing) then
CellText := CellText + ' *';
end;
1: CellText := Sess.Hostname;
2: CellText := Sess.Username;
3: CellText := Sess.ServerVersion;
4: if Sess.LastConnect>0 then
CellText := DateTimeToStr(Sess.LastConnect)
else
CellText := '';
5: CellText := FormatNumber(Sess.Counter);
6: CellText := Sess.Comment;
end;
end;
end;
function Tconnform.NodeSessionNames(Node: PVirtualNode; var RegKey: String): TStringList;
var
Sess: PConnectionParameters;
Folders: TStringList;
begin
// Find sibling session names in a folder node
if Node = nil then
Node := ListSessions.RootNode;
// Find registry sub path for given node
RegKey := '';
if Node <> ListSessions.RootNode then begin
Sess := ListSessions.GetNodeData(Node);
RegKey := Sess.SessionPath + '\';
end;
// Fetch from registry
Folders := TStringList.Create;
Result := AppSettings.GetSessionNames(RegKey, Folders);
Result.AddStrings(Folders);
Folders.Free;
end;
procedure Tconnform.ListSessionsBeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
var
Session: PConnectionParameters;
begin
// Paint custom background color
if CellPaintMode=cpmPaint then begin
Session := Sender.GetNodeData(Node);
if Session.SessionColor <> AppSettings.GetDefaultInt(asTreeBackground) then begin
TargetCanvas.Brush.Color := Session.SessionColor;
TargetCanvas.FillRect(CellRect);
end;
end;
end;
procedure Tconnform.ListSessionsCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; out EditLink: IVTEditLink);
begin
// Use our own text editor to rename a session
EditLink := TInplaceEditorLink.Create(Sender as TVirtualStringTree, True, nil);
end;
procedure Tconnform.ListSessionsDragDrop(Sender: TBaseVirtualTree;
Source: TObject; DataObject: IDataObject; Formats: TFormatArray;
Shift: TShiftState; Pt: TPoint; var Effect: Integer; Mode: TDropMode);
var
TargetNode, ParentNode: PVirtualNode;
AttachMode: TVTNodeAttachMode;
TargetSess, FocusedSess: PConnectionParameters;
ParentKey: String;
SiblingSessions: TStringList;
begin
TargetNode := Sender.GetNodeAt(Pt.X, Pt.Y);
if not Assigned(TargetNode) then begin
MessageBeep(MB_ICONEXCLAMATION);
Exit;
end;
TargetSess := Sender.GetNodeData(TargetNode);
FocusedSess := Sender.GetNodeData(ListSessions.FocusedNode);
case Mode of
dmAbove:
AttachMode := amInsertBefore;
dmOnNode:
if TargetSess.IsFolder then
AttachMode := amAddChildFirst
else
AttachMode := amInsertBefore;
dmBelow:
AttachMode := amInsertAfter;
else
AttachMode := amInsertAfter;
end;
if AttachMode in [amInsertBefore, amInsertAfter] then
ParentNode := TargetNode.Parent
else
ParentNode := TargetNode;
SiblingSessions := NodeSessionNames(ParentNode, ParentKey);
// Test if target folder has an equal named node
if SiblingSessions.IndexOf(FocusedSess.SessionName) > -1 then
ErrorDialog(f_('Session "%s" already exists!', [ParentKey+FocusedSess.SessionName]))
else begin
try
AppSettings.SessionPath := FocusedSess.SessionPath;
AppSettings.MoveCurrentKey(REGKEY_SESSIONS+'\'+ParentKey+FocusedSess.SessionName);
ListSessions.MoveTo(ListSessions.FocusedNode, TargetNode, AttachMode, False);
FocusedSess.SessionPath := ParentKey+FocusedSess.SessionName;
except
on E:Exception do
ErrorDialog(f_('Error while moving registry key: %s', [E.Message]));
end;
end;
SiblingSessions.Free;
end;
procedure Tconnform.ListSessionsDragOver(Sender: TBaseVirtualTree;
Source: TObject; Shift: TShiftState; State: TDragState; Pt: TPoint;
Mode: TDropMode; var Effect: Integer; var Accept: Boolean);
var
TargetNode, ParentNode: PVirtualNode;
TargetSess: PConnectionParameters;
begin
// Allow node dragging everywhere except within the current folder
TargetNode := Sender.GetNodeAt(Pt.X, Pt.Y);
TargetSess := Sender.GetNodeData(TargetNode);
Accept := (Source = Sender)
and Assigned(TargetSess)
and (Mode <> dmNowhere)
and (TargetNode <> ListSessions.FocusedNode.Parent);
// Moving a folder into itself would create an infinite folder structure
if Accept and TargetSess.IsFolder then
Accept := Accept and (TargetNode <> ListSessions.FocusedNode);
if Accept and (not TargetSess.IsFolder) then
Accept := Accept and (TargetNode.Parent <> ListSessions.FocusedNode.Parent);
if Accept then begin
// Do not allow focused node to be moved somewhere below itself
ParentNode := TargetNode.Parent;
while Assigned(ParentNode) do begin
Accept := Accept and (ParentNode <> ListSessions.FocusedNode);
if not Accept then
Break;
ParentNode := ParentNode.Parent;
end;
// Shows the right tooltip on Aero GUI
Effect := DROPEFFECT_MOVE;
end;
end;
procedure Tconnform.ListSessionsFocusChanged(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex);
var
SessionFocused, InFolder: Boolean;
Sess: PConnectionParameters;
begin
// select one connection!
Screen.Cursor := crHourglass;
TimerStatistics.Enabled := False;
SessionFocused := False;
InFolder := False;
Sess := nil;
if Assigned(Node) then begin
Sess := Sender.GetNodeData(Node);
SessionFocused := not Sess.IsFolder;
InFolder := (ListSessions.GetNodeLevel(Node) > 0) or Sess.IsFolder;
end;
FLoaded := False;
tabStart.TabVisible := not SessionFocused;
tabSettings.TabVisible := SessionFocused;
tabSSHtunnel.TabVisible := SessionFocused;
tabAdvanced.TabVisible := SessionFocused;
tabStatistics.TabVisible := SessionFocused;
menuRename.Enabled := Assigned(Node);
menuNewSessionInFolder.Enabled := InFolder;
menuNewFolderInFolder.Enabled := InFolder;
FreeAndNil(FPopupDatabases);
if not SessionFocused then begin
PageControlDetails.ActivePage := tabStart;
if ListSessions.RootNodeCount = 0 then
lblHelp.Caption := f_('New here? In order to connect to a server, you have to create a so called '+
'"session" at first. Just click the "New" button on the bottom left to create your first session.'+
'Give it a friendly name (e.g. "Local DB server") so you''ll recall it the next time you start %s.', [APPNAME])
else
lblHelp.Caption := _('Please click a session on the left list to edit parameters, doubleclick to open it.');
end else begin
PageControlDetails.ActivePage := tabSettings;
SelectedNetType := Sess.NetType;
FLastSelectedNetTypeGroup := Sess.NetTypeGroup;
editHost.Text := Sess.Hostname;
editUsername.Text := Sess.Username;
editPassword.Text := Sess.Password;
chkLoginPrompt.Checked := Sess.LoginPrompt;
chkWindowsAuth.Checked := Sess.WindowsAuth;
chkCleartextPluginEnabled.Checked := Sess.CleartextPluginEnabled;
updownPort.Position := Sess.Port;
chkCompressed.Checked := Sess.Compressed;
updownQueryTimeout.Position := Sess.QueryTimeout;
updownKeepAlive.Position := Sess.KeepAlive;
chkLocalTimeZone.Checked := Sess.LocalTimeZone;
chkFullTableStatus.Checked := Sess.FullTableStatus;
ColorBoxBackgroundColor.Selected := Sess.SessionColor;
editDatabases.Text := Sess.AllDatabasesStr;
comboLibrary.Items := Sess.GetLibraries;
comboLibrary.ItemIndex := comboLibrary.Items.IndexOf(Sess.LibraryOrProvider);
if (comboLibrary.ItemIndex = -1) and (comboLibrary.Items.Count > 0) then begin
comboLibrary.ItemIndex := 0;
end;
memoComment.Text := Sess.Comment;
editStartupScript.Text := Sess.StartupScriptFilename;
editSSHPlinkExe.Text := Sess.SSHPlinkExe;
editSSHHost.Text := Sess.SSHHost;
editSSHport.Text := IntToStr(Sess.SSHPort);
editSSHUser.Text := Sess.SSHUser;
editSSHPassword.Text := Sess.SSHPassword;
updownSSHTimeout.Position := Sess.SSHTimeout;
editSSHPrivateKey.Text := Sess.SSHPrivateKey;
editSSHlocalport.Text := IntToStr(Sess.SSHLocalPort);
chkWantSSL.Checked := Sess.WantSSL;
editSSLPrivateKey.Text := Sess.SSLPrivateKey;
editSSLCertificate.Text := Sess.SSLCertificate;
editSSLCACertificate.Text := Sess.SSLCACertificate;
editSSLCipher.Text := Sess.SSLCipher;
editIgnoreDatabasePattern.Text := Sess.IgnoreDatabasePattern;
chkLogFileDdl.Checked := Sess.LogFileDdl;
chkLogFileDml.Checked := Sess.LogFileDml;
editLogFilePath.Text := Sess.LogFilePath;
FServerVersion := Sess.ServerVersion;
end;
FLoaded := True;
FSessionModified := False;
ListSessions.Repaint;
ValidateControls;