public void HandleLinkClick(GeckoAnchorElement anchor, DomEventArgs eventArgs, string workingDirectoryForFileLinks)
{
Debug.Assert(!InvokeRequired);
if (anchor.Href.ToLowerInvariant().StartsWith("http")) //will cover https also
{
Process.Start(anchor.Href);
eventArgs.Handled = true;
return;
}
if (anchor.Href.ToLowerInvariant().StartsWith("file"))
//links to files are handled externally if we can tell they aren't html/javascript related
{
// TODO: at this point spaces in the file name will cause the link to fail.
// That seems to be a problem in the DomEventArgs.Target.CastToGeckoElement() method.
var href = anchor.Href;
var path = href.Replace("file:///", "");
if (new List<string>(new[] { ".pdf", ".odt", ".doc", ".docx", ".txt" }).Contains(Path.GetExtension(path).ToLowerInvariant()))
{
eventArgs.Handled = true;
Process.Start(new ProcessStartInfo()
{
FileName = path,
WorkingDirectory = workingDirectoryForFileLinks
});
return;
}
eventArgs.Handled = false; //let gecko handle it
return;
}
else if (anchor.Href.ToLowerInvariant().StartsWith("mailto"))
{
eventArgs.Handled = true;
Process.Start(anchor.Href); //let the system open the email program
Debug.WriteLine("Opening email program " + anchor.Href);
}
else
{
ErrorReport.NotifyUserOfProblem("Bloom did not understand this link: " + anchor.Href);
eventArgs.Handled = true;
}
}