Cache list of available databases after first click on "Databases" pulldown menu, so we do not have to connect probably slow servers for each click.

This commit is contained in:
Ansgar Becker
2014-03-07 15:53:35 +00:00
parent 305551e62f
commit 3a3ea2fb73
2 changed files with 33 additions and 28 deletions

View File

@ -864,9 +864,4 @@ object connform: Tconnform
Action = MainForm.actAboutBox Action = MainForm.actAboutBox
end end
end end
object popupDatabases: TPopupMenu
AutoHotkeys = maManual
Left = 104
Top = 144
end
end end

View File

@ -70,7 +70,6 @@ type
lblSSHkeyfile: TLabel; lblSSHkeyfile: TLabel;
lblDownloadPlink: TLabel; lblDownloadPlink: TLabel;
editDatabases: TButtonedEdit; editDatabases: TButtonedEdit;
popupDatabases: TPopupMenu;
lblDatabase: TLabel; lblDatabase: TLabel;
chkLoginPrompt: TCheckBox; chkLoginPrompt: TCheckBox;
lblPlinkTimeout: TLabel; lblPlinkTimeout: TLabel;
@ -157,6 +156,7 @@ type
FServerVersion: String; FServerVersion: String;
FSessionColor: TColor; FSessionColor: TColor;
FSettingsImportWaitTime: Cardinal; FSettingsImportWaitTime: Cardinal;
FPopupDatabases: TPopupMenu;
procedure RefreshSessions(ParentNode: PVirtualNode); procedure RefreshSessions(ParentNode: PVirtualNode);
function SelectedSessionPath: String; function SelectedSessionPath: String;
function CurrentParams: TConnectionParameters; function CurrentParams: TConnectionParameters;
@ -744,6 +744,7 @@ begin
tabStatistics.TabVisible := SessionFocused; tabStatistics.TabVisible := SessionFocused;
menuNewSessionInFolder.Enabled := InFolder; menuNewSessionInFolder.Enabled := InFolder;
menuNewFolderInFolder.Enabled := InFolder; menuNewFolderInFolder.Enabled := InFolder;
FreeAndNil(FPopupDatabases);
if not SessionFocused then begin if not SessionFocused then begin
PageControlDetails.ActivePage := tabStart; PageControlDetails.ActivePage := tabStart;
@ -920,30 +921,34 @@ var
p: TPoint; p: TPoint;
Databases: TStringList; Databases: TStringList;
begin begin
// Try to connect and lookup database names if FPopupDatabases = nil then begin
Params := CurrentParams; // Try to connect and lookup database names
Connection := Params.CreateConnection(Self); Params := CurrentParams;
Connection.Parameters.AllDatabasesStr := ''; Connection := Params.CreateConnection(Self);
Connection.LogPrefix := SelectedSessionPath; Connection.Parameters.AllDatabasesStr := '';
Connection.OnLog := Mainform.LogSQL; Connection.LogPrefix := SelectedSessionPath;
popupDatabases.Items.Clear; Connection.OnLog := Mainform.LogSQL;
Databases := Explode(';', editDatabases.Text); FPopupDatabases := TPopupMenu.Create(Self);
Screen.Cursor := crHourglass; FPopupDatabases.AutoHotkeys := maManual;
try Databases := Explode(';', editDatabases.Text);
Connection.Active := True; Screen.Cursor := crHourglass;
for DB in Connection.AllDatabases do begin try
Item := TMenuItem.Create(popupDatabases); Connection.Active := True;
Item.Caption := DB; for DB in Connection.AllDatabases do begin
Item.OnClick := MenuDatabasesClick; Item := TMenuItem.Create(FPopupDatabases);
Item.Checked := Databases.IndexOf(DB) > -1; Item.Caption := DB;
popupDatabases.Items.Add(Item); Item.OnClick := MenuDatabasesClick;
Item.Checked := Databases.IndexOf(DB) > -1;
Item.AutoCheck := True;
FPopupDatabases.Items.Add(Item);
end;
except
// Silence connection errors here - should be sufficient to log them
end; end;
except FreeAndNil(Connection);
// Silence connection errors here - should be sufficient to log them
end; end;
FreeAndNil(Connection);
p := editDatabases.ClientToScreen(editDatabases.ClientRect.BottomRight); p := editDatabases.ClientToScreen(editDatabases.ClientRect.BottomRight);
popupDatabases.Popup(p.X-editDatabases.Images.Width, p.Y); FPopupDatabases.Popup(p.X-editDatabases.Images.Width, p.Y);
Screen.Cursor := crDefault; Screen.Cursor := crDefault;
end; end;
@ -956,7 +961,7 @@ var
begin begin
Item := Sender as TMenuItem; Item := Sender as TMenuItem;
Databases := Explode(';', editDatabases.Text); Databases := Explode(';', editDatabases.Text);
if not Item.Checked then if Item.Checked then
Databases.Add(Item.Caption) Databases.Add(Item.Caption)
else else
Databases.Delete(Databases.IndexOf(Item.Caption)); Databases.Delete(Databases.IndexOf(Item.Caption));
@ -1020,6 +1025,11 @@ begin
PasswordModified := Sess.Password <> editPassword.Text; PasswordModified := Sess.Password <> editPassword.Text;
FOnlyPasswordModified := PasswordModified and (not FSessionModified); FOnlyPasswordModified := PasswordModified and (not FSessionModified);
FSessionModified := FSessionModified or PasswordModified; FSessionModified := FSessionModified or PasswordModified;
if (Sender=editHost) or (Sender=editUsername) or (Sender=editPassword) or
(Sender=comboNetType) or (Sender=chkWindowsAuth) or (Sender=editPort) then begin
// Be sure to use the modified connection params next time the user clicks the "Databases" pulldown
FreeAndNil(FPopupDatabases);
end;
ListSessions.Repaint; ListSessions.Repaint;
ValidateControls; ValidateControls;