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
Expand Up @@ -259,15 +259,19 @@ object connform: Tconnform
OnChange = Modification
OnExit = editTrim
end
object editHost: TEdit
object editHost: TButtonedEdit
Left = 120
Top = 73
Width = 294
Height = 21
Anchors = [akLeft, akTop, akRight]
Images = MainForm.VirtualImageListMain
RightButton.ImageIndex = 51
TabOrder = 2
OnChange = editHostChange
OnDblClick = editHostDblClick
OnExit = editTrim
OnRightButtonClick = PickFile
end
object comboNetType: TComboBox
Left = 120
Expand Down
48 changes: 41 additions & 7 deletions source/connections.pas
Expand Up @@ -37,7 +37,7 @@ Tconnform = class(TExtForm)
updownPort: TUpDown;
editPassword: TEdit;
editUsername: TEdit;
editHost: TEdit;
editHost: TButtonedEdit;
tabAdvanced: TTabSheet;
lblSSLPrivateKey: TLabel;
lblSSLCACertificate: TLabel;
Expand Down Expand Up @@ -176,6 +176,7 @@ Tconnform = class(TExtForm)
procedure editTrim(Sender: TObject);
procedure editSearchChange(Sender: TObject);
procedure editSearchRightButtonClick(Sender: TObject);
procedure editHostDblClick(Sender: TObject);
private
{ Private declarations }
FLoaded: Boolean;
Expand Down Expand Up @@ -356,15 +357,29 @@ procedure Tconnform.FormShow(Sender: TObject);
procedure Tconnform.btnOpenClick(Sender: TObject);
var
Connection: TDBConnection;
Params: TConnectionParameters;
Msg: String;
DoCreateDb: Integer;
begin
// 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
Exit;
btnOpen.Enabled := False;
FButtonAnimationStep := 0;
TimerButtonAnimation.Enabled := True;
Screen.Cursor := crHourglass;
if Mainform.InitConnection(CurrentParams, True, Connection) then
if Mainform.InitConnection(Params, True, Connection) then
ModalResult := mrOK
else begin
TimerStatistics.OnTimer(Sender);
Expand Down Expand Up @@ -1004,6 +1019,12 @@ procedure Tconnform.editHostChange(Sender: TObject);
end;


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

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

if SessionFocused then begin
// Validate session GUI stuff
if Params.NetType = ntMySQL_NamedPipe then
lblHost.Caption := _('Socket name:')
else
lblHost.Caption := _('Hostname / IP:');
editHost.RightButton.Visible := False;
case Params.NetType of
ntMySQL_NamedPipe: begin
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;
chkCleartextPluginEnabled.Enabled := Params.IsMySQL;
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;
Selector := TOpenDialog.Create(Self);
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')+' (*.*)|*.*'
else if Edit = editSSHPlinkExe then
Selector.Filter := _('Executables')+' (*.exe)|*.exe|'+_('All files')+' (*.*)|*.*'
Expand All @@ -1345,6 +1377,8 @@ procedure Tconnform.PickFile(Sender: TObject);
break;
end;
end;
if Edit = editHost then
Selector.Options := Selector.Options - [ofFileMustExist];

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

0 comments on commit c74a210

Please sign in to comment.