Skip to content

Commit

Permalink
Added new settings (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Mar 22, 2021
1 parent 26de2ab commit e312723
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 3 deletions.
27 changes: 26 additions & 1 deletion InternetTest/InternetTest/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Title="SettingsPage">

<ScrollViewer HorizontalScrollBarVisibility="Hidden" Template="{DynamicResource ScrollViewerControlTemplate}" CanContentScroll="True" Height="344">
<Grid Height="390">
<Grid Height="550">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
Expand Down Expand Up @@ -58,6 +58,31 @@
</Button>
</StackPanel>

<TextBlock Text="{x:Static lang:Resources.TestSite}" Foreground="{Binding Source={StaticResource Foreground1}}" FontWeight="Bold" FontSize="20" Margin="0,10,0,0"/>
<TextBlock Text="{x:Static lang:Resources.TestSiteDescription}" Foreground="{Binding Source={StaticResource Foreground1}}" FontSize="14"/>

<StackPanel Orientation="Horizontal">
<TextBox x:Name="TestSiteTxt" TextChanged="TestSiteTxt_TextChanged" Style="{DynamicResource TextBoxStyle1}" Padding="3" Margin="0,5,5,5" Width="197" Background="{x:Null}" BorderBrush="{Binding Source={StaticResource AccentColor}}" SelectionBrush="{Binding Source={StaticResource AccentColor}}" CaretBrush="{Binding Source={StaticResource Foreground1}}" Foreground="{Binding Source={StaticResource Foreground1}}"/>
<Button x:Name="TestSiteApplyBtn" Background="{Binding Source={StaticResource AccentColor}}" Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}" Padding="10,5,10,5" Style="{StaticResource TabButtonStyle}" FontWeight="Bold" Cursor="Hand" VerticalAlignment="Center" Click="TestSiteApplyBtn_Click" Visibility="Hidden">
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xF296;" FontWeight="Regular" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Margin="0,0,5,0" VerticalAlignment="Center" FontSize="16"/>
<TextBlock Text="{x:Static lang:Resources.Apply}" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</StackPanel>

<TextBlock Text="{x:Static lang:Resources.MapProvider}" Foreground="{Binding Source={StaticResource Foreground1}}" FontWeight="Bold" FontSize="20" Margin="0,10,0,0"/>
<TextBlock Text="{x:Static lang:Resources.MapProvider}" Foreground="{Binding Source={StaticResource Foreground1}}" FontSize="14"/>
<StackPanel Orientation="Horizontal">
<ComboBox SelectionChanged="MapProviderComboBox_SelectionChanged" BorderThickness="2" Padding="5" Style="{DynamicResource ComboBoxStyle1}" x:Name="MapProviderComboBox" Background="Transparent" BorderBrush="{Binding Source={StaticResource AccentColor}}" Foreground="{Binding Source={StaticResource Foreground1}}" HorizontalAlignment="Left" Margin="0,5,10,0" VerticalAlignment="Center"/>
<Button x:Name="MapProviderApplyBtn" Background="{Binding Source={StaticResource AccentColor}}" Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}" Padding="10,5,10,5" Style="{StaticResource TabButtonStyle}" FontWeight="Bold" Cursor="Hand" VerticalAlignment="Center" Click="MapProviderApplyBtn_Click" Visibility="Hidden">
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xF296;" FontWeight="Regular" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Margin="0,0,5,0" VerticalAlignment="Center" FontSize="16"/>
<TextBlock Text="{x:Static lang:Resources.Apply}" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</StackPanel>

<TextBlock Text="{x:Static lang:Resources.Licenses}" Foreground="{Binding Source={StaticResource Foreground1}}" FontWeight="Bold" FontSize="20" Margin="0,10,0,0"/>
<TextBlock Text="{x:Static lang:Resources.SeeLicenses}" Foreground="{Binding Source={StaticResource AccentColor}}" FontSize="14" FontWeight="Bold" Cursor="Hand" MouseLeftButtonDown="TextBlock_MouseLeftButtonDown">
<TextBlock.TextDecorations>
Expand Down
53 changes: 51 additions & 2 deletions InternetTest/InternetTest/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ MIT License
SOFTWARE.
*/
using InternetTest.Classes;
using InternetTest.Enums;
using LeoCorpLibrary;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -72,15 +73,33 @@ private async void InitUI()

LangComboBox.SelectedIndex = (Global.Settings.Language == "_default") ? 0 : Global.LanguageCodeList.IndexOf(Global.Settings.Language) + 1;

LangApplyBtn.Visibility = Visibility.Hidden; // Hide
ThemeApplyBtn.Visibility = Visibility.Hidden; // Hide
// Load MapProviderComboBox
MapProviderComboBox.Items.Add("OpenStreetMap"); // Add a map provider
MapProviderComboBox.Items.Add("Bing Maps"); // Add a map provider
MapProviderComboBox.Items.Add("Google Maps"); // Add a map provider

MapProviderComboBox.SelectedIndex = Global.Settings.MapProvider switch
{
MapProviders.OpenStreetMap => 0,
MapProviders.BingMaps => 1,
MapProviders.GoogleMaps => 2,
_ => 0,
};

// Load the TestSiteTxt
TestSiteTxt.Text = Global.Settings.TestSite; // Set text

// Update the UpdateStatusTxt
isAvailable = Update.IsAvailable(Global.Version, await Update.GetLastVersionAsync(Global.LastVersionLink));

UpdateStatusTxt.Text = isAvailable ? Properties.Resources.AvailableUpdates : Properties.Resources.UpToDate; // Set the text
InstallIconTxt.Text = isAvailable ? "\uF152" : "\uF191"; // Set text
InstallMsgTxt.Text = isAvailable ? Properties.Resources.Install : Properties.Resources.CheckUpdate; // Set text

LangApplyBtn.Visibility = Visibility.Hidden; // Hide
ThemeApplyBtn.Visibility = Visibility.Hidden; // Hide
TestSiteApplyBtn.Visibility = Visibility.Hidden; // Hide
MapProviderApplyBtn.Visibility = Visibility.Hidden; // Hide
}
catch (Exception ex)
{
Expand Down Expand Up @@ -162,5 +181,35 @@ private void DisplayRestartMessage()
Environment.Exit(0); // Close
}
}

private void TestSiteApplyBtn_Click(object sender, RoutedEventArgs e)
{
Global.Settings.TestSite = TestSiteTxt.Text; // Define
SettingsManager.Save(); // Save the changes
TestSiteApplyBtn.Visibility = Visibility.Hidden; // Hide
}

private void MapProviderComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MapProviderApplyBtn.Visibility = Visibility.Visible; // Visible
}

private void TestSiteTxt_TextChanged(object sender, TextChangedEventArgs e)
{
TestSiteApplyBtn.Visibility = Visibility.Visible; // Visible
}

private void MapProviderApplyBtn_Click(object sender, RoutedEventArgs e)
{
Global.Settings.MapProvider = MapProviderComboBox.Text switch
{
"OpenStreetMap" => MapProviders.OpenStreetMap,
"Bing Maps" => MapProviders.BingMaps,
"Google Maps" => MapProviders.GoogleMaps,
_ => MapProviders.OpenStreetMap
};
SettingsManager.Save(); // Save the changes
MapProviderApplyBtn.Visibility = Visibility.Hidden; // Hide
}
}
}
27 changes: 27 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,13 @@
<data name="Version" xml:space="preserve">
<value>Version</value>
</data>
<data name="TestSite" xml:space="preserve">
<value>Test website</value>
</data>
<data name="TestSiteDescription" xml:space="preserve">
<value>The website where the connection is tested.</value>
</data>
<data name="MapProviderDescription" xml:space="preserve">
<value>The map provider used to show an IP localization.</value>
</data>
</root>
9 changes: 9 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,13 @@
<data name="Version" xml:space="preserve">
<value>Version</value>
</data>
<data name="TestSite" xml:space="preserve">
<value>Site de test</value>
</data>
<data name="TestSiteDescription" xml:space="preserve">
<value>Le site où la connexion est testée.</value>
</data>
<data name="MapProviderDescription" xml:space="preserve">
<value>Le fournisseur de cartes utilisé pour voir la localisation d'une IP.</value>
</data>
</root>
9 changes: 9 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,13 @@
<data name="Version" xml:space="preserve">
<value>Version</value>
</data>
<data name="TestSite" xml:space="preserve">
<value>Test website</value>
</data>
<data name="TestSiteDescription" xml:space="preserve">
<value>The website where the connection is tested.</value>
</data>
<data name="MapProviderDescription" xml:space="preserve">
<value>The map provider used to show an IP localization.</value>
</data>
</root>

0 comments on commit e312723

Please sign in to comment.