Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix opening links without http and https #640

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Orc.Controls.Example/Views/LinkLabel.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="5" >
<TextBlock Text="LinkLabel" VerticalAlignment="Center" Width="160" />
<orccontrols:LinkLabel Content="Action" ToolTip="Action" Command="{Binding DefaultAction}"
HoverForeground="Orange" Url="http://catelproject.com"
HoverForeground="Orange" Url="catelproject.com"
ClickBehavior="OpenUrlInBrowser"/>
</StackPanel>
</catel:UserControl>
29 changes: 24 additions & 5 deletions src/Orc.Controls/Controls/LinkLabel/LinkLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Navigation;
using Automation;
using Catel;
using Catel.Logging;
using Orc.Controls.Automation;

/// <summary>
/// A label looking like the known hyperlink.
Expand Down Expand Up @@ -199,7 +200,7 @@ public IInputElement? CommandTarget
/// <summary>
/// ClickEvent
/// </summary>
[Category("Behavior")]
[Category("Behavior")]
public static readonly RoutedEvent? ClickEvent;

/// <summary>
Expand All @@ -214,7 +215,7 @@ public event RoutedEventHandler? Click
/// <summary>
/// RequestNavigateEvent
/// </summary>
[Category("Behavior")]
[Category("Behavior")]
public static readonly RoutedEvent? RequestNavigateEvent;

/// <summary>
Expand Down Expand Up @@ -339,8 +340,26 @@ private static void OpenBrowserBehaviorImpl(object sender, RoutedEventArgs args)
return;
}

var destinationUrl = hyperlinkSender?.NavigateUri ?? linklabelSender?.Url;
if (destinationUrl is null || string.IsNullOrEmpty(destinationUrl.ToString()))
var uri = linklabelSender?.Url;
if (uri is null)
{
return;
}

if (!uri.IsAbsoluteUri)
{
uri = new Uri($"https://{uri}");
}
if (!uri.Scheme.Contains("://") && !uri.Scheme.StartsWithAnyIgnoreCase("http", "https") && !uri.IsFile)
{
var relativePart = uri.GetComponents(UriComponents.PathAndQuery | UriComponents.Fragment,
UriFormat.UriEscaped);

uri = new Uri($"https://{relativePart}");
}

var destinationUrl = hyperlinkSender?.NavigateUri ?? uri;
if (string.IsNullOrEmpty(destinationUrl.ToString()))
{
return;
}
Expand Down