Support hyperlinks in MessageDialogs, and add a footer with a Google search link to error dialogs.

This commit is contained in:
Ansgar Becker
2012-11-30 13:27:57 +00:00
parent f8a13fc91a
commit cc8b0bc202
2 changed files with 20 additions and 3 deletions

View File

@ -2419,8 +2419,8 @@ var
m: String; m: String;
Dialog: TTaskDialog; Dialog: TTaskDialog;
Btn: TTaskDialogButtonItem; Btn: TTaskDialogButtonItem;
DialogResult: TModalResult;
MsgButton: TMsgDlgBtn; MsgButton: TMsgDlgBtn;
rx: TRegExpr;
procedure AddButton(BtnCaption: String; BtnResult: TModalResult); procedure AddButton(BtnCaption: String; BtnResult: TModalResult);
begin begin
@ -2439,12 +2439,20 @@ begin
end; end;
if Title <> Dialog.Caption then if Title <> Dialog.Caption then
Dialog.Title := Title; Dialog.Title := Title;
Dialog.Text := Msg; rx := TRegExpr.Create;
rx.Expression := 'https?\:\/\/\S+';
Dialog.Text := rx.Replace(Msg, '<a href="$0">$0</a>', True);
rx.Free;
Dialog.Flags := [tfEnableHyperlinks, tfAllowDialogCancellation]; Dialog.Flags := [tfEnableHyperlinks, tfAllowDialogCancellation];
Dialog.CommonButtons := []; Dialog.CommonButtons := [];
Dialog.OnHyperlinkClicked := MainForm.TaskDialogHyperLinkClicked;
case DlgType of case DlgType of
mtWarning: Dialog.MainIcon := tdiWarning; mtWarning: Dialog.MainIcon := tdiWarning;
mtError: Dialog.MainIcon := tdiError; mtError: begin
Dialog.MainIcon := tdiError;
Dialog.FooterText := '<a href="http://www.google.com/search?q='+EncodeURLElementUnicode(Copy(Msg, 1, 1000))+'">Find some help on this error</a>';
Dialog.FooterIcon := tdiInformation;
end;
mtInformation: Dialog.MainIcon := tdiInformation; mtInformation: Dialog.MainIcon := tdiInformation;
mtConfirmation: Dialog.MainIcon := tdiInformation; mtConfirmation: Dialog.MainIcon := tdiInformation;
else Dialog.MainIcon := tdiNone; else Dialog.MainIcon := tdiNone;

View File

@ -1039,6 +1039,7 @@ type
procedure SetProgressPosition(Value: Integer); procedure SetProgressPosition(Value: Integer);
procedure ProgressStep; procedure ProgressStep;
procedure SetProgressState(State: TProgressbarState); procedure SetProgressState(State: TProgressbarState);
procedure TaskDialogHyperLinkClicked(Sender: TObject);
end; end;
@ -10747,6 +10748,14 @@ begin
end; end;
procedure TMainForm.TaskDialogHyperLinkClicked(Sender: TObject);
begin
// Used by hyperlinks in helpers.MessageDialog()
if Sender is TTaskDialog then
ShellExec(TTaskDialog(Sender).URL);
end;
{ TQueryTab } { TQueryTab }