aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2019-12-12 22:12:17 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2019-12-12 22:12:17 +0200
commit791ecdccc3d9ecc6311d6b1440e462119e65dc92 (patch)
tree2ed363a38e5a823f83f32042266e45fdbcc3220a /Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser
parent5e705b938989409332ac929e1319b398b5a930a5 (diff)
downloadTango-791ecdccc3d9ecc6311d6b1440e462119e65dc92.tar.gz
Tango-791ecdccc3d9ecc6311d6b1440e462119e65dc92.zip
Improvements on browser module.
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser')
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs16
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml55
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs83
3 files changed, 144 insertions, 10 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs
index a73700fef..4da2f4f98 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs
@@ -8,6 +8,8 @@ using Tango.BL.Enumerations;
using Tango.PPC.Common;
using Tango.PPC.Browser.Views;
using Tango.SharedUI.Helpers;
+using Tango.Core.DI;
+using Tango.PPC.Common.Application;
namespace Tango.PPC.Browser
{
@@ -23,7 +25,7 @@ namespace Tango.PPC.Browser
/// </summary>
public BrowserModule()
{
- IsVisibleInMenu = true;
+ IsVisibleInMenu = false;
}
/// <summary>
@@ -81,6 +83,18 @@ namespace Tango.PPC.Browser
}
}
+ public override void OnTechnicianEntered()
+ {
+ base.OnTechnicianEntered();
+ IsVisibleInMenu = true;
+ }
+
+ public override void OnTechnicianExited()
+ {
+ base.OnTechnicianExited();
+ IsVisibleInMenu = false;
+ }
+
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml
index 7b5854101..5c62d6915 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml
@@ -18,12 +18,59 @@
<touch:TouchButton Command="{Binding GoCommand}" DockPanel.Dock="Right" Padding="10" Width="150" CornerRadius="20" Margin="20 0 0 0">
<touch:TouchIcon Icon="ArrowRightBold" Height="20" />
</touch:TouchButton>
- <Border Background="{StaticResource TangoMidBackgroundBrush}" Padding="2" BorderBrush="{StaticResource TangoLightBorderBrush}" BorderThickness="1" CornerRadius="15">
- <TextBox x:Name="txtAddress" GotFocus="TxtAddress_GotFocus" PreviewMouseUp="TxtAddress_MouseUp" LostFocus="TxtAddress_LostFocus" KeyDown="TxtAddress_KeyDown" VerticalContentAlignment="Center" Text="{Binding Address,UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" FontSize="{StaticResource TangoDefaultFontSize}" Padding="5" Background="Transparent"></TextBox>
- </Border>
+ <Grid>
+ <Border Background="{StaticResource TangoMidBackgroundBrush}" Padding="2" BorderBrush="{StaticResource TangoLightBorderBrush}" BorderThickness="1" CornerRadius="20">
+ <TextBox x:Name="txtAddress" PreviewMouseDoubleClick="TxtAddress_PreviewMouseDoubleClick" GotFocus="TxtAddress_GotFocus" PreviewMouseUp="TxtAddress_MouseUp" LostFocus="TxtAddress_LostFocus" KeyDown="TxtAddress_KeyDown" VerticalContentAlignment="Center" Text="{Binding Address,UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" FontSize="{StaticResource TangoDefaultFontSize}" Padding="5" Background="Transparent"></TextBox>
+ </Border>
+ <Border CornerRadius="20" IsHitTestVisible="False" Visibility="{Binding ElementName=Browser,Path=IsLoading,Converter={StaticResource BooleanToVisibilityConverter}}">
+ <Border.Background>
+ <LinearGradientBrush>
+ <GradientStop Offset="0" Color="Transparent" />
+ <GradientStop Offset="0.5" Color="#7612D433" />
+ <GradientStop Offset="1" Color="Transparent" />
+ </LinearGradientBrush>
+ </Border.Background>
+ <Border.Style>
+ <Style TargetType="Border">
+ <Style.Triggers>
+ <DataTrigger Binding="{Binding ElementName=Browser,Path=IsLoading}" Value="True">
+ <DataTrigger.EnterActions>
+ <BeginStoryboard Name="loadingStory">
+ <Storyboard>
+ <DoubleAnimation Storyboard.TargetProperty="Background.GradientStops[1].Offset" From="0" To="1" AutoReverse="True" RepeatBehavior="Forever" />
+ </Storyboard>
+ </BeginStoryboard>
+ </DataTrigger.EnterActions>
+ <DataTrigger.ExitActions>
+ <RemoveStoryboard BeginStoryboardName="loadingStory" />
+ </DataTrigger.ExitActions>
+ </DataTrigger>
+ </Style.Triggers>
+ </Style>
+ </Border.Style>
+ </Border>
+ </Grid>
</DockPanel>
</Border>
- <wpf:ChromiumWebBrowser x:Name="Browser" Address="http://www.google.com" />
+
+ <Grid>
+ <wpf:ChromiumWebBrowser x:Name="Browser" Address="https://twine-s.com/" />
+ <Grid Background="White" IsHitTestVisible="False" Visibility="Hidden" x:Name="gridError">
+ <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
+ <touch:TouchIcon Icon="Alert" Foreground="{StaticResource TangoGrayTextBrush}" Width="100" Height="100" />
+ <TextBlock HorizontalAlignment="Center" Foreground="{StaticResource TangoGrayTextBrush}" FontSize="40" Margin="0 20 0 0">Page Not Found</TextBlock>
+ <TextBlock Margin="0 10 0 0" Foreground="{StaticResource TangoGrayTextBrush}" HorizontalAlignment="Center" Width="600" TextAlignment="Center">
+ <Run>The page at '</Run><Run Text="{Binding ElementName=txtAddress,Path=Text,Mode=OneWay}"></Run><Run>'</Run>
+ <Run>could not be reached.</Run>
+ <LineBreak/>
+ <Run>Please check your internet connection.</Run>
+ <LineBreak/>
+ <LineBreak/>
+ <Run x:Name="runError" Text="Unspecified"></Run>
+ </TextBlock>
+ </StackPanel>
+ </Grid>
+ </Grid>
</DockPanel>
</Grid>
</UserControl>
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs
index 2717c77d3..aeb1b5c41 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
+using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
@@ -46,14 +47,46 @@ namespace Tango.PPC.Browser.Views
var handler = new RequestHandlers.ChromiumRequestHandler();
handler.AddressChanged += Handler_AddressChanged;
Browser.RequestHandler = handler;
+ Browser.LoadError += Browser_LoadError;
+ Browser.LoadingStateChanged += Browser_LoadingStateChanged;
}
- private void Handler_AddressChanged(object sender, string e)
+ private void Browser_LoadError(object sender, LoadErrorEventArgs e)
{
- Dispatcher.BeginInvoke(new Action(() =>
+ //if (e.ErrorCode == CefErrorCode.ConnectionTimedOut || e.ErrorCode == CefErrorCode.NameNotResolved)
+ //{
+ InvokeUI(() =>
{
- AddressChanged?.Invoke(this, Browser.Address);
- }));
+ runError.Text = e.ErrorText;
+ gridError.Visibility = Visibility.Visible;
+ });
+ //}
+ }
+
+ private void Browser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
+ {
+ if (!e.IsLoading)
+ {
+ InvokeUI(() =>
+ {
+ KeyboardHelper.CloseKeyboard();
+ });
+ }
+ else
+ {
+ InvokeUI(() =>
+ {
+ gridError.Visibility = Visibility.Hidden;
+ });
+ }
+ }
+
+ private void Handler_AddressChanged(object sender, string address)
+ {
+ InvokeUI(() =>
+ {
+ AddressChanged?.Invoke(this, address);
+ });
}
private void Default_KeyboardClosed(object sender, EventArgs e)
@@ -75,7 +108,35 @@ namespace Tango.PPC.Browser.Views
public void NavigateTo(string address)
{
- Browser.Address = address;
+ if (Browser.Address != address)
+ {
+ Uri uri;
+
+ if (ValidHttpURL(address, out uri))
+ {
+ Browser.Address = uri.ToString();
+ }
+ else
+ {
+ Browser.Address = $"google.com/search?q={address.Replace(" ", "+")}";
+ }
+ }
+ else
+ {
+ Browser.Reload();
+ }
+ }
+
+ public static bool ValidHttpURL(string s, out Uri resultURI)
+ {
+ if (!Regex.IsMatch(s, @"^https?:\/\/", RegexOptions.IgnoreCase))
+ s = "http://" + s;
+
+ if (Uri.TryCreate(s, UriKind.Absolute, out resultURI))
+ return (resultURI.Scheme == Uri.UriSchemeHttp ||
+ resultURI.Scheme == Uri.UriSchemeHttps);
+
+ return false;
}
public void GoBack()
@@ -111,5 +172,17 @@ namespace Tango.PPC.Browser.Views
{
KeyboardHelper.OpenKeyboard(KeyboardActionKeyMode.Go);
}
+
+ private async void TxtAddress_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
+ {
+ KeyboardHelper.OpenKeyboard(KeyboardActionKeyMode.Go);
+ await Task.Delay(100);
+ txtAddress.SelectAll();
+ }
+
+ private void InvokeUI(Action action)
+ {
+ Dispatcher.BeginInvoke(action);
+ }
}
}