From 89560cc4a02a4d2435cc09200c410bf96596711c Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sat, 12 Oct 2024 15:31:58 +0200 Subject: [PATCH] Issue #1992: Escape ampersand in caption of menus and tabs, preventing underlined hotkey generation for names of session, database and tables --- source/apphelpers.pas | 8 ++++++++ source/main.pas | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/source/apphelpers.pas b/source/apphelpers.pas index 81ba7cb2..960344d2 100644 --- a/source/apphelpers.pas +++ b/source/apphelpers.pas @@ -424,6 +424,7 @@ type function WebColorStrToColorDef(WebColor: string; Default: TColor): TColor; function UserAgent(OwnerComponent: TComponent): String; function CodeIndent(Steps: Integer=1): String; + function EscapeHotkeyPrefix(Text: String): String; var AppSettings: TAppSettings; @@ -3011,6 +3012,13 @@ begin end; +function EscapeHotkeyPrefix(Text: String): String; +begin + // Issue #1992: Escape ampersand in caption of menus and tabs, preventing underlined hotkey generation + Result := StringReplace(Text, Vcl.Menus.cHotkeyPrefix, Vcl.Menus.cHotkeyPrefix + Vcl.Menus.cHotkeyPrefix, [rfReplaceAll]); +end; + + { Get SID of current Windows user, probably useful in the future function GetCurrentUserSID: string; type diff --git a/source/main.pas b/source/main.pas index efbf01b5..82c118f2 100644 --- a/source/main.pas +++ b/source/main.pas @@ -3069,7 +3069,7 @@ begin AppSettings.GetSessionPaths('', SessionPaths); for i:=0 to SessionPaths.Count-1 do begin item := TMenuItem.Create(menuConnections); - item.Caption := SessionPaths[i]; + item.Caption := EscapeHotkeyPrefix(SessionPaths[i]); item.OnClick := SessionConnect; for Connection in Connections do begin if SessionPaths[i] = Connection.Parameters.SessionPath then begin @@ -3096,7 +3096,7 @@ begin AppSettings.GetSessionPaths('', SessionPaths); for i:=0 to SessionPaths.Count-1 do begin Item := TMenuItem.Create(menuConnectTo); - Item.Caption := SessionPaths[i]; + Item.Caption := EscapeHotkeyPrefix(SessionPaths[i]); Item.OnClick := SessionConnect; for Connection in Connections do begin if SessionPaths[i] = Connection.Parameters.SessionPath then begin @@ -12855,6 +12855,8 @@ begin // Some cases pass -1 which triggers a "List index out of bounds" in below cast if PageIndex = -1 then Exit; + // Escape hotkey accelerator in name of session, database or table + Text := EscapeHotkeyPrefix(Text); Text := StrEllipsis(Text, 70); // Special case if passed text is empty: Reset query tab caption to "Query #123" if (PageIndex = tabQuery.PageIndex) and (Text = '') then