From b4963b01c2afee258b25cc593aa1bca22691a557 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Wed, 9 Feb 2022 20:33:31 +0100 Subject: [PATCH] Issue #362: turn edit box for SSH executable into a drop-down, providing plink files in application directory, plus newly supported ssh.exe --- source/connections.dfm | 27 ++++++++++----------------- source/connections.pas | 42 +++++++++++++++++++----------------------- 2 files changed, 29 insertions(+), 40 deletions(-) diff --git a/source/connections.dfm b/source/connections.dfm index cc9bc380..b637efdb 100644 --- a/source/connections.dfm +++ b/source/connections.dfm @@ -444,23 +444,6 @@ object connform: Tconnform TextHint = 'Your secure shell password' OnChange = Modification end - object editSSHExe: TButtonedEdit - Left = 190 - Top = 9 - Width = 320 - Height = 21 - Anchors = [akLeft, akTop, akRight] - Images = MainForm.VirtualImageListMain - RightButton.ImageIndex = 51 - RightButton.Visible = True - TabOrder = 0 - Text = 'editSSHExe' - TextHint = 'Doubleclick to select file' - OnChange = editSSHExeChange - OnDblClick = PickFile - OnExit = editTrim - OnRightButtonClick = PickFile - end object editSSHhost: TEdit Left = 190 Top = 36 @@ -520,6 +503,16 @@ object connform: Tconnform TabOrder = 6 Wrap = True end + object comboSSHExe: TComboBox + Left = 190 + Top = 8 + Width = 320 + Height = 22 + Anchors = [akLeft, akTop, akRight] + TabOrder = 0 + Text = 'comboSSHExe' + OnChange = Modification + end end object tabAdvanced: TTabSheet Caption = 'Advanced' diff --git a/source/connections.pas b/source/connections.pas index 25d7995e..a08758d0 100644 --- a/source/connections.pas +++ b/source/connections.pas @@ -12,7 +12,7 @@ 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; + System.Math, System.Actions, System.IOUtils, Vcl.ActnList, Vcl.StdActns; type Tconnform = class(TExtForm) @@ -54,7 +54,6 @@ type lblSSHLocalPort: TLabel; lblSSHUser: TLabel; lblSSHPassword: TLabel; - editSSHExe: TButtonedEdit; lblSSHExe: TLabel; comboNetType: TComboBoxEx; lblSSHhost: TLabel; @@ -136,6 +135,7 @@ type lblLogFile: TLabel; chkLogFileDml: TCheckBox; timerEditFilterDelay: TTimer; + comboSSHExe: TComboBox; procedure FormCreate(Sender: TObject); procedure btnOpenClick(Sender: TObject); procedure FormShow(Sender: TObject); @@ -162,7 +162,6 @@ type procedure ListSessionsCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; out EditLink: IVTEditLink); procedure PickFile(Sender: TObject); - procedure editSSHExeChange(Sender: TObject); procedure editHostChange(Sender: TObject); procedure editDatabasesRightButtonClick(Sender: TObject); procedure chkLoginPromptClick(Sender: TObject); @@ -255,13 +254,14 @@ end; procedure Tconnform.FormCreate(Sender: TObject); var - NetTypeStr, FilenameHint: String; + NetTypeStr, FilenameHint, ExePath, ExeFile: String; nt: TNetType; ntg: TNetTypeGroup; Params: TConnectionParameters; ComboItem: TComboExItem; Placeholders: TStringList; i: Integer; + ExeFiles: TStringDynArray; begin // Fix GUI stuff HasSizeGrip := True; @@ -296,6 +296,17 @@ begin end; Placeholders.Free; editLogFilePath.Hint := FilenameHint; + + // Populate dropdown with supported SSH executables + ExeFiles := TDirectory.GetFiles(ExtractFilePath(ParamStr(0)), '*.exe'); + for ExePath in ExeFiles do begin + ExeFile := ExtractFileName(ExePath); + if ExecRegExprI('([pk]link|putty)', ExeFile) then begin + comboSSHExe.Items.Add(ExeFile); + end; + end; + SetLength(ExeFiles, 0); + comboSSHExe.Items.Add('ssh.exe'); end; @@ -467,7 +478,7 @@ begin Sess.AllDatabasesStr := editDatabases.Text; Sess.Comment := memoComment.Text; Sess.StartupScriptFilename := editStartupScript.Text; - Sess.SSHExe := editSSHExe.Text; + Sess.SSHExe := comboSSHExe.Text; Sess.SSHHost := editSSHhost.Text; Sess.SSHPort := MakeInt(editSSHport.Text); Sess.SSHUser := editSSHUser.Text; @@ -690,7 +701,7 @@ begin Result.SSHTimeout := updownSSHTimeout.Position; Result.SSHPrivateKey := editSSHPrivateKey.Text; Result.SSHLocalPort := MakeInt(editSSHlocalport.Text); - Result.SSHExe := editSSHexe.Text; + Result.SSHExe := comboSSHExe.Text; Result.WantSSL := chkWantSSL.Checked; Result.SSLPrivateKey := editSSLPrivateKey.Text; Result.SSLCertificate := editSSLCertificate.Text; @@ -976,7 +987,7 @@ begin end; memoComment.Text := Sess.Comment; editStartupScript.Text := Sess.StartupScriptFilename; - editSSHExe.Text := Sess.SSHExe; + comboSSHExe.Text := Sess.SSHExe; editSSHHost.Text := Sess.SSHHost; editSSHport.Text := IntToStr(Sess.SSHPort); editSSHUser.Text := Sess.SSHUser; @@ -1325,7 +1336,7 @@ begin or (Sess.Comment <> memoComment.Text) or (Sess.SSHHost <> editSSHHost.Text) or (IntToStr(Sess.SSHPort) <> editSSHPort.Text) - or (Sess.SSHExe <> editSSHExe.Text) + or (Sess.SSHExe <> comboSSHExe.Text) or (IntToStr(Sess.SSHLocalPort) <> editSSHlocalport.Text) or (Sess.SSHUser <> editSSHUser.Text) or (Sess.SSHPassword <> editSSHPassword.Text) @@ -1525,8 +1536,6 @@ begin Selector.DefaultExt := FILEEXT_SQLITEDB; end else if (Edit = editStartupScript) or (Edit = editLogFilePath) then Selector.Filter := _('SQL files')+' (*.sql)|*.sql|'+_('All files')+' (*.*)|*.*' - else if Edit = editSSHExe then - Selector.Filter := _('Executables')+' (*.exe)|*.exe|'+_('All files')+' (*.*)|*.*' else if Edit = editSSHPrivateKey then Selector.Filter := _('All files')+' (*.*)|*.*' else @@ -1577,17 +1586,4 @@ begin editSearch.Clear; end; -procedure Tconnform.editSSHExeChange(Sender: TObject); -var - Path: String; -begin - Path := editSSHExe.Text; - if (not FileExists(Path)) and Path.ToLowerInvariant.Contains('plink') then - editSSHExe.Font.Color := clRed - else - editSSHExe.Font.Color := GetThemeColor(clWindowText); - Modification(Sender); -end; - - end.