Browse Source

Fixed bug when changing the language 🐛

pull/17/head
oZ-Zo 5 years ago
parent
commit
2943ea117f
  1. 38
      W10SS_GUI/Classes/Gui.cs
  2. 23
      W10SS_GUI/Classes/Tags.cs
  3. 8
      W10SS_GUI/Localized/EN.xaml
  4. 10
      W10SS_GUI/Localized/RU.xaml
  5. 2
      W10SS_GUI/MainWindow.xaml
  6. 43
      W10SS_GUI/MainWindow.xaml.cs
  7. 2
      W10SS_GUI/Resource/controlsSize.xaml
  8. 2
      W10SS_GUI/W10SS_GUI.csproj

38
W10SS_GUI/Classes/Gui.cs

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using W10SS_GUI;
namespace W10SS_GUI.Classes
{
internal class Gui
{
private Dictionary<string, StackPanel> _togglesCategoryPanels = new Dictionary<string, StackPanel>();
private MainWindow MainWindow = Application.Current.MainWindow as MainWindow;
public Gui()
{
InitializeVariables();
}
private void InitializeVariables()
{
foreach (var tagValue in Application.Current.Resources.MergedDictionaries.Where(r => r.Source.Segments[2] == "tags.xaml").FirstOrDefault().Values)
{
_togglesCategoryPanels.Add(tagValue.ToString(), MainWindow.panelTogglesCategoryContainer.Children.OfType<StackPanel>().Where(p => p.Tag == tagValue).FirstOrDefault());
}
}
internal void SetActivePanel(string PanelsTag, string HeaderText)
{
foreach (KeyValuePair<string, StackPanel> kvp in _togglesCategoryPanels)
{
kvp.Value.Visibility = kvp.Key == PanelsTag ? Visibility.Visible : Visibility.Collapsed;
}
MainWindow.textTogglesHeader.Text = HeaderText;
}
}
}

23
W10SS_GUI/Classes/Tags.cs

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace W10SS_GUI
{
internal static class Tags
{
internal static readonly string Privacy = string.Format("{0}", Application.Current.Resources["tagCategoryPrivacy"]);
internal static readonly string Ui = string.Format("{0}", Application.Current.Resources["tagCategoryUi"]);
internal static readonly string OneDrive = string.Format("{0}", Application.Current.Resources["tagCategoryOneDrive"]);
internal static readonly string System = string.Format("{0}", Application.Current.Resources["tagCategorySystem"]);
internal static readonly string StartMenu = string.Format("{0}", Application.Current.Resources["tagCategoryStartMenu"]);
internal static readonly string Uwp = string.Format("{0}", Application.Current.Resources["tagCategoryUwp"]);
internal static readonly string WinGame = string.Format("{0}", Application.Current.Resources["tagCategoryWinGame"]);
internal static readonly string TaskScheduler = string.Format("{0}", Application.Current.Resources["tagCategoryTaskScheduler"]);
internal static readonly string Defender = string.Format("{0}", Application.Current.Resources["tagCategoryDefender"]);
internal static readonly string ContextMenu = string.Format("{0}", Application.Current.Resources["tagCategoryContextMenu"]);
}
}

8
W10SS_GUI/Localized/EN.xaml

@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="textWindowTitle">Windows 10 Setup Script</system:String>
<system:String x:Key="textHamburgerPrivacy">Privacy &amp; Telemetry</system:String>
<system:String x:Key="textHamburgerUi">UI &amp; Personalization</system:String>
<system:String x:Key="textHamburgerOneDrive">OneDrive</system:String>
@ -14,9 +14,9 @@
<system:String x:Key="textHamburgerDefender">Microsoft Defender</system:String>
<system:String x:Key="textHamburgerContextMenu">Context Menu</system:String>
<system:String x:Key="textHamburgerApply">Apply Settings</system:String>
<system:String x:Key="textHamburgerSave">Save Settings</system:String>
<system:String x:Key="textHamburgerLoad">Import Settings</system:String>
<system:String x:Key="textHamburgerApply">Apply</system:String>
<system:String x:Key="textHamburgerSave">Save</system:String>
<system:String x:Key="textHamburgerLoad">Import</system:String>
<system:String x:Key="textHamburgerLanguage">Русский</system:String>
<system:String x:Key="textHamburgerOpenGithub">GitHub</system:String>

10
W10SS_GUI/Localized/RU.xaml

@ -3,15 +3,15 @@
xmlns:local="clr-namespace:W10SS_GUI.Localized"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="textWindowTitle">Windows 10 Setup Script</system:String>
<system:String x:Key="textHamburgerPrivacy">Телеметрия</system:String>
<system:String x:Key="textHamburgerUi">Персонализация</system:String>
<system:String x:Key="textHamburgerPrivacy">Безопасность и телеметрия</system:String>
<system:String x:Key="textHamburgerUi">UI &amp; персонализация</system:String>
<system:String x:Key="textHamburgerOneDrive">OneDrive</system:String>
<system:String x:Key="textHamburgerSystem">Система</system:String>
<system:String x:Key="textHamburgerStartMenu">Меню "Пуск"</system:String>
<system:String x:Key="textHamburgerUwp">UWP Приложения</system:String>
<system:String x:Key="textHamburgerUwp">UWP-приложения</system:String>
<system:String x:Key="textHamburgerWinGame">Игровой режим</system:String>
<system:String x:Key="textHamburgerTaskScheduler">Планировщик</system:String>
<system:String x:Key="textHamburgerTaskScheduler">Планировщик задач</system:String>
<system:String x:Key="textHamburgerDefender">Microsoft Defender</system:String>
<system:String x:Key="textHamburgerContextMenu">Контекстное меню</system:String>

2
W10SS_GUI/MainWindow.xaml

@ -224,7 +224,7 @@
<StackPanel Name="panelTogglesCategoryContainer">
<StackPanel x:Name="panelTogglesCategoryPrivacy"
<StackPanel Name="panelTogglesCategoryPrivacy"
Tag="{StaticResource tagCategoryPrivacy}"
Visibility="Collapsed" />

43
W10SS_GUI/MainWindow.xaml.cs

@ -16,6 +16,7 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using W10SS_GUI.Controls;
using W10SS_GUI.Classes;
namespace W10SS_GUI
{
@ -24,33 +25,28 @@ namespace W10SS_GUI
/// </summary>
public partial class MainWindow : Window
{
private Dictionary<string, StackPanel> TogglesCategoryPanels = new Dictionary<string, StackPanel>();
private AppCulture AppCulture = new AppCulture();
private AppCulture AppCulture = new AppCulture();
private Gui Gui;
public MainWindow()
{
InitializeComponent();
SetUiLanguage();
InitializeVariables();
InitializeToggles();
SetUiLanguage();
InitializeToggles();
Gui.SetActivePanel(PanelsTag: Tags.Privacy, HeaderText: Resources["textHamburgerPrivacy"] as string);
}
private void InitializeToggles()
private void InitializeVariables()
{
//AppDomain.CurrentDomain.BaseDirectory
Gui = new Gui();
}
private void InitializeVariables()
private void InitializeToggles()
{
ICollection tagsDictionaryValues = Application.Current.Resources.MergedDictionaries.Where(r => r.Source.Segments[2] == "tags.xaml").FirstOrDefault().Values;
foreach (var tagValue in tagsDictionaryValues)
{
TogglesCategoryPanels.Add(tagValue.ToString(), panelTogglesCategoryContainer.Children.OfType<StackPanel>().Where(p => p.Tag == tagValue).FirstOrDefault());
}
textTogglesHeader.Text = buttonHamburgerPrivacy.Text;
}
//AppDomain.CurrentDomain.BaseDirectory
}
private void SetUiLanguage()
{
@ -60,20 +56,13 @@ namespace W10SS_GUI
private void ButtonHamburger_Click(object sender, MouseButtonEventArgs e)
{
HamburgerCategoryButton button = sender as HamburgerCategoryButton;
string tag = button.Tag.ToString();
foreach (KeyValuePair<string, StackPanel> kvp in TogglesCategoryPanels)
{
kvp.Value.Visibility = kvp.Key == tag ? Visibility.Visible : Visibility.Collapsed;
}
textTogglesHeader.Text = button.Text;
Gui.SetActivePanel(PanelsTag:button.Tag as string, HeaderText:button.Text);
}
private void ButtonHamburgerLanguageSettings_Click(object sender, MouseButtonEventArgs e)
{
Resources.MergedDictionaries.Add(AppCulture.ChangeCulture());
textTogglesHeader.Text = buttonHamburgerPrivacy.Text;
}
Gui.SetActivePanel(PanelsTag: Tags.Privacy, HeaderText: Resources["textHamburgerPrivacy"] as string);
}
}
}

2
W10SS_GUI/Resource/controlsSize.xaml

@ -17,7 +17,7 @@
<system:Double x:Key="panelHamburgerMinWidth">40</system:Double>
<system:Double x:Key="panelHamburgerWidth">200</system:Double>
<system:Double x:Key="panelHamburgerMaxWidth">200</system:Double>
<system:Double x:Key="panelHamburgerMaxWidth">250</system:Double>
<system:Double x:Key="togglesCategoryPanelWidth">500</system:Double>
<system:Double x:Key="togglesCategoryPanelHeaderHeight">40</system:Double>

2
W10SS_GUI/W10SS_GUI.csproj

@ -112,6 +112,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Classes\AppCulture.cs" />
<Compile Include="Classes\Tags.cs" />
<Compile Include="Controls\HamburgerCategoryButton.xaml.cs">
<DependentUpon>HamburgerCategoryButton.xaml</DependentUpon>
</Compile>
@ -121,6 +122,7 @@
<Compile Include="Controls\ToggleSwitch.xaml.cs">
<DependentUpon>ToggleSwitch.xaml</DependentUpon>
</Compile>
<Compile Include="Classes\Gui.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>

Loading…
Cancel
Save