Skip to content

Commit

Permalink
Issue #12: Provide file pick icon in SQLite database file edit box. D…
Browse files Browse the repository at this point in the history
…atabase file is created by sqlite3_open() silently if it does not yet exist. Show a confirmation message in such cases.
  • Loading branch information
ansgarbecker committed Dec 27, 2019
1 parent 021d78d commit c74a210
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
6 changes: 5 additions & 1 deletion source/connections.dfm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -259,15 +259,19 @@ object connform: Tconnform
OnChange = Modification OnChange = Modification
OnExit = editTrim OnExit = editTrim
end end
object editHost: TEdit object editHost: TButtonedEdit
Left = 120 Left = 120
Top = 73 Top = 73
Width = 294 Width = 294
Height = 21 Height = 21
Anchors = [akLeft, akTop, akRight] Anchors = [akLeft, akTop, akRight]
Images = MainForm.VirtualImageListMain
RightButton.ImageIndex = 51
TabOrder = 2 TabOrder = 2
OnChange = editHostChange OnChange = editHostChange
OnDblClick = editHostDblClick
OnExit = editTrim OnExit = editTrim
OnRightButtonClick = PickFile
end end
object comboNetType: TComboBox object comboNetType: TComboBox
Left = 120 Left = 120
Expand Down
48 changes: 41 additions & 7 deletions source/connections.pas
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Tconnform = class(TExtForm)
updownPort: TUpDown; updownPort: TUpDown;
editPassword: TEdit; editPassword: TEdit;
editUsername: TEdit; editUsername: TEdit;
editHost: TEdit; editHost: TButtonedEdit;
tabAdvanced: TTabSheet; tabAdvanced: TTabSheet;
lblSSLPrivateKey: TLabel; lblSSLPrivateKey: TLabel;
lblSSLCACertificate: TLabel; lblSSLCACertificate: TLabel;
Expand Down Expand Up @@ -176,6 +176,7 @@ Tconnform = class(TExtForm)
procedure editTrim(Sender: TObject); procedure editTrim(Sender: TObject);
procedure editSearchChange(Sender: TObject); procedure editSearchChange(Sender: TObject);
procedure editSearchRightButtonClick(Sender: TObject); procedure editSearchRightButtonClick(Sender: TObject);
procedure editHostDblClick(Sender: TObject);
private private
{ Private declarations } { Private declarations }
FLoaded: Boolean; FLoaded: Boolean;
Expand Down Expand Up @@ -356,15 +357,29 @@ procedure Tconnform.FormShow(Sender: TObject);
procedure Tconnform.btnOpenClick(Sender: TObject); procedure Tconnform.btnOpenClick(Sender: TObject);
var var
Connection: TDBConnection; Connection: TDBConnection;
Params: TConnectionParameters;
Msg: String;
DoCreateDb: Integer;
begin begin
// Connect to selected session // Connect to selected session
Params := CurrentParams;

if (CurrentParams.NetType = ntSQLite)
and (not FileExists(CurrentParams.Hostname))
then begin
Msg := f_('Database file "%s" does not exist. Shall it be created now?', [Params.Hostname]);
DoCreateDb := MessageDialog(Msg, mtConfirmation, [mbNo, mbYes]);
if DoCreateDb = mrNo then
Exit;
end;

if not btnOpen.Enabled then if not btnOpen.Enabled then
Exit; Exit;
btnOpen.Enabled := False; btnOpen.Enabled := False;
FButtonAnimationStep := 0; FButtonAnimationStep := 0;
TimerButtonAnimation.Enabled := True; TimerButtonAnimation.Enabled := True;
Screen.Cursor := crHourglass; Screen.Cursor := crHourglass;
if Mainform.InitConnection(CurrentParams, True, Connection) then if Mainform.InitConnection(Params, True, Connection) then
ModalResult := mrOK ModalResult := mrOK
else begin else begin
TimerStatistics.OnTimer(Sender); TimerStatistics.OnTimer(Sender);
Expand Down Expand Up @@ -1004,6 +1019,12 @@ procedure Tconnform.editHostChange(Sender: TObject);
end; end;




procedure Tconnform.editHostDblClick(Sender: TObject);
begin
if CurrentParams.NetType = ntSQLite then
PickFile(Sender);
end;

procedure Tconnform.editTrim(Sender: TObject); procedure Tconnform.editTrim(Sender: TObject);
var var
Edit: TCustomEdit; Edit: TCustomEdit;
Expand Down Expand Up @@ -1244,10 +1265,19 @@ procedure Tconnform.ValidateControls;


if SessionFocused then begin if SessionFocused then begin
// Validate session GUI stuff // Validate session GUI stuff
if Params.NetType = ntMySQL_NamedPipe then editHost.RightButton.Visible := False;
lblHost.Caption := _('Socket name:') case Params.NetType of
else ntMySQL_NamedPipe: begin
lblHost.Caption := _('Hostname / IP:'); lblHost.Caption := _('Socket name:');
end;
ntSQLite: begin
lblHost.Caption := _('Database filename')+':';
editHost.RightButton.Visible := True;
end
else begin
lblHost.Caption := _('Hostname / IP:');
end;
end;
chkWindowsAuth.Enabled := Params.IsMSSQL; chkWindowsAuth.Enabled := Params.IsMSSQL;
chkCleartextPluginEnabled.Enabled := Params.IsMySQL; chkCleartextPluginEnabled.Enabled := Params.IsMySQL;
lblUsername.Enabled := ((not chkLoginPrompt.Checked) or (not chkLoginPrompt.Enabled)) lblUsername.Enabled := ((not chkLoginPrompt.Checked) or (not chkLoginPrompt.Enabled))
Expand Down Expand Up @@ -1329,7 +1359,9 @@ procedure Tconnform.PickFile(Sender: TObject);
Edit := Sender as TButtonedEdit; Edit := Sender as TButtonedEdit;
Selector := TOpenDialog.Create(Self); Selector := TOpenDialog.Create(Self);
Selector.FileName := editStartupScript.Text; Selector.FileName := editStartupScript.Text;
if Edit = editStartupScript then if Edit = editHost then
Selector.Filter := 'SQLite databases (*.sqlite3;*.db;*.s3db)|*.sqlite3;*.db;*.s3db|'+_('All files')+' (*.*)|*.*'
else if Edit = editStartupScript then
Selector.Filter := _('SQL files')+' (*.sql)|*.sql|'+_('All files')+' (*.*)|*.*' Selector.Filter := _('SQL files')+' (*.sql)|*.sql|'+_('All files')+' (*.*)|*.*'
else if Edit = editSSHPlinkExe then else if Edit = editSSHPlinkExe then
Selector.Filter := _('Executables')+' (*.exe)|*.exe|'+_('All files')+' (*.*)|*.*' Selector.Filter := _('Executables')+' (*.exe)|*.exe|'+_('All files')+' (*.*)|*.*'
Expand All @@ -1345,6 +1377,8 @@ procedure Tconnform.PickFile(Sender: TObject);
break; break;
end; end;
end; end;
if Edit = editHost then
Selector.Options := Selector.Options - [ofFileMustExist];


if Selector.Execute then begin if Selector.Execute then begin
// Remove path if it's the application directory // Remove path if it's the application directory
Expand Down

0 comments on commit c74a210

Please sign in to comment.