Skip to content

Commit 15eb52b

Browse files
committed
feat: re-enable support for hyperlinks in message dialogues, and use TTaskDialog again for simple messages on Windows
1 parent 9723210 commit 15eb52b

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

source/apphelpers.pas

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,18 +2321,23 @@ function MessageDialog(const Title, Msg: string; DlgType: TMsgDlgType; Buttons:
23212321
end;
23222322
begin
23232323

2324+
{$IFNDEF WINDOWS}
23242325
if (KeepAskingSetting = asUnused) and (FooterText.IsEmpty) then begin
2325-
// Show the more native MessageDlg when we don't need additional dialog features
2326+
// Show the more native MessageDlg when we don't need additional dialog features.
2327+
// Especially useful on macOS and Linux where the TTaskDialog looks really different than MessageDlg.
23262328
Result := MessageDlg(Title, Msg, DlgType, Buttons, 0);
23272329
Exit;
23282330
end;
2331+
{$ENDIF}
23292332

23302333
// Remember current path and restore it later, so the caller does not try to read from the wrong path after this dialog
23312334
AppSettings.StorePath;
23322335

23332336
Dialog := TTaskDialog.Create(nil);
23342337
Dialog.Flags := [tfEnableHyperlinks, tfAllowDialogCancellation];
23352338
Dialog.CommonButtons := [];
2339+
if Assigned(MainForm) then
2340+
Dialog.OnHyperlinkClicked := MainForm.TaskDialogHyperLinkClicked;
23362341

23372342
// Caption, title and text
23382343
case DlgType of
@@ -2343,15 +2348,33 @@ function MessageDialog(const Title, Msg: string; DlgType: TMsgDlgType; Buttons:
23432348
end;
23442349
if Title <> Dialog.Caption then
23452350
Dialog.Title := Title;
2346-
Dialog.Text := Msg;
2351+
if Assigned(MainForm) and (MainForm.ActiveConnection <> nil) then
2352+
Dialog.Caption := MainForm.ActiveConnection.Parameters.SessionName + ': ' + Dialog.Caption;
2353+
rx := TRegExpr.Create;
2354+
rx.Expression := 'https?://[^\s"]+';
2355+
if ThemeIsDark then
2356+
Dialog.Text := Msg
2357+
else // See issue #2036
2358+
Dialog.Text := rx.Replace(Msg, '<a href="$0">$0</a>', True);
2359+
rx.Free;
23472360

23482361
// Main icon, and footer link
23492362
case DlgType of
23502363
mtWarning:
23512364
Dialog.MainIcon := tdiWarning;
23522365
mtError: begin
23532366
Dialog.MainIcon := tdiError;
2354-
Dialog.FooterText := FooterText;
2367+
WebSearchUrl := AppSettings.ReadString(asWebSearchBaseUrl);
2368+
WebSearchUrl := StringReplace(WebSearchUrl, '%q', EncodeURLParam(Copy(Msg, 1, 1000)), []);
2369+
rx := TRegExpr.Create;
2370+
rx.Expression := 'https?://(www\.)?([^/]+)/';
2371+
if rx.Exec(WebSearchUrl) then
2372+
WebSearchHost := rx.Match[2]
2373+
else
2374+
WebSearchHost := '[unknown host]';
2375+
rx.Free;
2376+
Dialog.FooterText := IfThen(FooterText.IsEmpty, '', FooterText + sLineBreak + sLineBreak) +
2377+
'<a href="'+WebSearchUrl+'">'+_('Find some help on this error')+' (=> '+WebSearchHost+')</a>';
23552378
Dialog.FooterIcon := tdiInformation;
23562379
end;
23572380
mtInformation:

source/main.pas

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ TMainForm = class(TExtForm)
13791379
procedure SetProgressPosition(Value: Integer);
13801380
procedure ProgressStep;
13811381
procedure SetProgressState(State: TProgressbarState);
1382-
//procedure TaskDialogHyperLinkClicked(Sender: TObject);
1382+
procedure TaskDialogHyperLinkClicked(Sender: TObject);
13831383
function HasDonated(ForceCheck: Boolean): TThreeStateBoolean;
13841384
procedure ApplyVTFilter(FromTimer: Boolean);
13851385
procedure ApplyFontToGrids;
@@ -14540,7 +14540,6 @@ procedure TMainForm.ApplicationShowHint(var HintStr: string; var CanShow: Boolea
1454014540
MainTabIndex, QueryTabIndex, NewHideTimeout: Integer;
1454114541
pt: TPoint;
1454214542
Conn: TDBConnection;
14543-
Editor: TSynMemo;
1454414543
Infos, HintSQL: TStringList;
1454514544
i, PanelIndex, TabIndex: Integer;
1454614545
QueryTab: TQueryTab;
@@ -14567,7 +14566,6 @@ procedure TMainForm.ApplicationShowHint(var HintStr: string; var CanShow: Boolea
1456714566

1456814567
else if HintInfo.HintControl is TSynMemo then begin
1456914568
// Token hint displaying through SynEdit's OnShowHint event
14570-
Editor := TSynMemo(HintInfo.HintControl);
1457114569
NewHideTimeout := Min(Length(HintStr) * 100, 60*1000);
1457214570
if NewHideTimeout > HintInfo.HideTimeout then
1457314571
HintInfo.HideTimeout := NewHideTimeout;
@@ -14741,12 +14739,12 @@ procedure TMainForm.SetProgressState(State: TProgressbarState);
1474114739
end;
1474214740

1474314741

14744-
{procedure TMainForm.TaskDialogHyperLinkClicked(Sender: TObject);
14742+
procedure TMainForm.TaskDialogHyperLinkClicked(Sender: TObject);
1474514743
begin
1474614744
// Used by hyperlinks in helpers.MessageDialog()
1474714745
if Sender is TTaskDialog then
1474814746
ShellExec(TTaskDialog(Sender).URL);
14749-
end;}
14747+
end;
1475014748

1475114749

1475214750
function TMainForm.HasDonated(ForceCheck: Boolean): TThreeStateBoolean;

0 commit comments

Comments
 (0)