Issue #1992: Escape ampersand in caption of menus and tabs, preventing underlined hotkey generation for names of session, database and tables

This commit is contained in:
Ansgar Becker
2024-10-12 15:31:58 +02:00
parent bc479591f0
commit 89560cc4a0
2 changed files with 12 additions and 2 deletions

View File

@ -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

View File

@ -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