Browse Source

Work for toggles initialization 🚧

pull/17/head
oZ-Zo 5 years ago
parent
commit
5f3204cfa0
  1. 145
      W10SS_GUI/Classes/Gui.cs
  2. 23
      W10SS_GUI/Classes/Tags.cs
  3. 19
      W10SS_GUI/Classes/ToggleInfo.cs
  4. 21
      W10SS_GUI/Controls/ToggleSwitch.xaml.cs
  5. 5
      W10SS_GUI/MainWindow.xaml.cs
  6. 14
      W10SS_GUI/Model/ModelGui.cs
  7. 22
      W10SS_GUI/Resource/tags.xaml
  8. 2
      W10SS_GUI/W10SS_GUI.csproj

145
W10SS_GUI/Classes/Gui.cs

@ -17,25 +17,20 @@ namespace W10SS_GUI.Classes
private Dictionary<string, StackPanel> _togglesCategoryAndPanels = new Dictionary<string, StackPanel>();
private MainWindow MainWindow = Application.Current.MainWindow as MainWindow;
private HamburgerCategoryButton _lastclickedbutton;
private List<ToggleSwitch> TogglesSwitches = new List<ToggleSwitch>();
internal string LastClickedButtonName
{
get
{
return _lastclickedbutton.Name as string;
}
}
internal string LastClickedButtonName => _lastclickedbutton.Name as string;
internal Gui()
{
InitializeVariables();
InitializeGuiVariables();
}
private void InitializeVariables()
private void InitializeGuiVariables()
{
foreach (var tagValue in Application.Current.Resources.MergedDictionaries.Where(r => r.Source.Segments[2] == "tags.xaml").FirstOrDefault().Values)
foreach (var tagValue in Application.Current.Resources.MergedDictionaries.Where(r => r.Source.LocalPath == "/Resource/tags.xaml").First().Values)
{
_togglesCategoryAndPanels.Add(tagValue.ToString(), MainWindow.panelTogglesCategoryContainer.Children.OfType<StackPanel>().Where(p => p.Tag == tagValue).FirstOrDefault());
_togglesCategoryAndPanels.Add(tagValue.ToString(), MainWindow.panelTogglesCategoryContainer.Children.OfType<StackPanel>().Where(p => p.Tag == tagValue).First());
}
}
@ -51,7 +46,7 @@ namespace W10SS_GUI.Classes
MainWindow.textTogglesHeader.Text = MainWindow.Resources[button.Name] as string;
}
internal void HamburgerReopen()
internal void HamburgerReOpen()
{
MouseEventArgs mouseLeaveArgs = new MouseEventArgs(Mouse.PrimaryDevice, 0)
{
@ -80,21 +75,121 @@ namespace W10SS_GUI.Classes
{
for (int i = 0; i < _togglesCategoryAndPanels.Keys.Count; i++)
{
string scriptsCategoryDirs = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _togglesCategoryAndPanels.Keys.ToList()[i]);
List<string> scriptsFiles = Directory.Exists(scriptsCategoryDirs)
&& Directory.EnumerateFiles(scriptsCategoryDirs, "*.*", SearchOption.AllDirectories).Where(f => f.EndsWith(".ps1")).Count() > 0
? Directory.EnumerateFiles(scriptsCategoryDirs, "*.*", SearchOption.AllDirectories).Where(f => f.EndsWith(".ps1")).ToList()
: null ;
scriptsFiles?.ForEach(s =>
{
Gui.ReadToggleData(s);
});
string categoryName = _togglesCategoryAndPanels[_togglesCategoryAndPanels.Keys.ToList()[i]].Name;
string psScriptsDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, categoryName.Name);
TogglesSwitches = Directory.Exists(psScriptsDir)
&& Directory.EnumerateFiles(psScriptsDir, "*.*", SearchOption.AllDirectories)
.Where(f => f.EndsWith(".ps1"))
.Count() > 0
? Directory.EnumerateFiles(psScriptsDir, "*.*", SearchOption.AllDirectories)
.Where(f => f.EndsWith(".ps1"))
.Select(p => CreateToogleSwitchFromScript(scriptPath:p, panelName:categoryName))
.ToList()
: null;
}
}
internal StackPanel GetPanelByName(string name) => _togglesCategoryAndPanels[name] as StackPanel;
internal ToggleSwitch CreateToogleSwitchFromScript(string scriptPath, string panelName)
{
ToggleSwitch toggleSwitch = new ToggleSwitch();
//{
// ScriptPath = scriptPath,
// PanelName = panel
//};
//try
//{
// using (StreamReader streamReader = new StreamReader(scriptPath, Encoding.UTF8))
// {
// for (int i = 0; i < 4; i++)
// {
// string textLine = streamReader.ReadLine();
// toggleInfo.IsValid = textLine.StartsWith("# ") && textLine.Length >= 10 ? true : false;
// switch (i)
// {
// case 0:
// toggleInfo.HeaderEN = textLine.Replace("# ", "");
// break;
// case 1:
// toggleInfo.DescriptionEN = textLine.Replace("# ", "");
// break;
// case 2:
// toggleInfo.HeaderRU = textLine.Replace("# ", "");
// break;
// case 3:
// toggleInfo.DescriptionRU = textLine.Replace("# ", "");
// break;
// default:
// break;
// }
// }
// }
//}
//catch (Exception)
//{
//}
return toggleSwitch;
}
//internal ToggleInfo NewToogleInfoFromScript(string scriptPath, string panelName)
//{
// ToggleInfo toggleInfo = new ToggleInfo
// {
// ScriptPath = scriptPath,
// PanelName = panelName
// };
// try
// {
// using (StreamReader streamReader = new StreamReader(scriptPath, Encoding.UTF8))
// {
// for (int i = 0; i < 4; i++)
// {
// string textLine = streamReader.ReadLine();
// toggleInfo.IsValid = textLine.StartsWith("# ") && textLine.Length >= 10 ? true : false;
// switch (i)
// {
// case 0:
// toggleInfo.HeaderEN = textLine.Replace("# ", "");
// break;
// case 1:
// toggleInfo.DescriptionEN = textLine.Replace("# ", "");
// break;
// case 2:
// toggleInfo.HeaderRU = textLine.Replace("# ", "");
// break;
// case 3:
// toggleInfo.DescriptionRU = textLine.Replace("# ", "");
// break;
// default:
// break;
// }
// }
// }
// }
// catch (Exception)
// {
// }
// return toggleInfo;
//}
}
}

23
W10SS_GUI/Classes/Tags.cs

@ -1,23 +0,0 @@
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"]);
}
}

19
W10SS_GUI/Classes/ToggleInfo.cs

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace W10SS_GUI.Classes
{
internal class ToggleInfo
{
internal string DescriptionEN { get; set; } = default(string);
internal string DescriptionRU { get; set; } = default(string);
internal string HeaderEN { get; set; } = default(string);
internal string HeaderRU { get; set; } = default(string);
internal string PanelName { get; set; } = default(string);
internal string ScriptPath { get; set; } = default(string);
internal bool IsValid { get; set; } = default(bool);
}
}

21
W10SS_GUI/Controls/ToggleSwitch.xaml.cs

@ -68,8 +68,26 @@ namespace W10SS_GUI.Controls
public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register("Description", typeof(string), typeof(ToggleSwitch), new PropertyMetadata(default(string)));
public bool IsValid
{
get { return (bool)GetValue(IsValidProperty); }
set { SetValue(IsValidProperty, value); }
}
// Using a DependencyProperty as the backing store for IsValid. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsValidProperty =
DependencyProperty.Register("IsValid", typeof(bool), typeof(ToggleSwitch), new PropertyMetadata(default(bool)));
public string ScriptPath
{
get { return (string)GetValue(ScriptPathProperty); }
set { SetValue(ScriptPathProperty, value); }
}
// Using a DependencyProperty as the backing store for ScriptPath. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ScriptPathProperty =
DependencyProperty.Register("ScriptPath", typeof(string), typeof(ToggleSwitch), new PropertyMetadata(default(string)));
private void ToggleSwitch_Click(object sender, RoutedEventArgs e)
@ -80,14 +98,11 @@ namespace W10SS_GUI.Controls
private void GridToggleSwitch_MouseEnter(object sender, MouseEventArgs e)
{
if (toggleSwitch.IsChecked == false) gridToggleSwitch.Background = brushBackgroundHover;
}
private void GridToggleSwitch_MouseLeave(object sender, MouseEventArgs e)
{
if (toggleSwitch.IsChecked == false) gridToggleSwitch.Background = brushBackground;
}
}
}

5
W10SS_GUI/MainWindow.xaml.cs

@ -60,7 +60,7 @@ namespace W10SS_GUI
{
Resources.MergedDictionaries.Add(AppCulture.ChangeCulture());
Gui.SetHamburgerWidth(AppCulture.CurrentCultureName);
Gui.HamburgerReopen();
Gui.HamburgerReOpen();
textTogglesHeader.Text = Convert.ToString(Resources[Gui.LastClickedButtonName]);
}
@ -69,8 +69,7 @@ namespace W10SS_GUI
InitializeVariables();
Gui.InitializeToggles();
SetUiLanguage();
Gui.SetHamburgerWidth(AppCulture.CurrentCultureName);
Gui.SetHamburgerWidth(AppCulture.CurrentCultureName);
Gui.SetActivePanel(HamburgerPrivacy);
}
}

14
W10SS_GUI/Model/ModelGui.cs

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace W10SS_GUI.Model
{
class ModelGui
{
}
}

22
W10SS_GUI/Resource/tags.xaml

@ -1,15 +1,15 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="tagCategoryPrivacy">Privacy &amp; Telemetry</system:String>
<system:String x:Key="tagCategoryUi">UI &amp; Personalization</system:String>
<system:String x:Key="tagCategoryOneDrive">OneDrive</system:String>
<system:String x:Key="tagCategorySystem">System</system:String>
<system:String x:Key="tagCategoryStartMenu">Start Menu</system:String>
<system:String x:Key="tagCategoryUwp">UWP Apps</system:String>
<system:String x:Key="tagCategoryWinGame">Game Mode</system:String>
<system:String x:Key="tagCategoryTaskScheduler">Task Scheduler</system:String>
<system:String x:Key="tagCategoryDefender">Microsoft Defender</system:String>
<system:String x:Key="tagCategoryContextMenu">Context Menu</system:String>
<system:String x:Key="tagCategoryPrivacy">1. Privacy &amp; Telemetry</system:String>
<system:String x:Key="tagCategoryUi">2. UI &amp; Personalization</system:String>
<system:String x:Key="tagCategoryOneDrive">3. OneDrive</system:String>
<system:String x:Key="tagCategorySystem">4. System</system:String>
<system:String x:Key="tagCategoryStartMenu">5. Start Menu</system:String>
<system:String x:Key="tagCategoryUwp">6. UWP Apps</system:String>
<system:String x:Key="tagCategoryWinGame">7. Gaming</system:String>
<system:String x:Key="tagCategoryTaskScheduler">8. Task Scheduler</system:String>
<system:String x:Key="tagCategoryDefender">9. Defender &amp; Security</system:String>
<system:String x:Key="tagCategoryContextMenu">10. Context Menu</system:String>
</ResourceDictionary>

2
W10SS_GUI/W10SS_GUI.csproj

@ -112,7 +112,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Classes\AppCulture.cs" />
<Compile Include="Classes\Tags.cs" />
<Compile Include="Classes\ToggleInfo.cs" />
<Compile Include="Controls\HamburgerCategoryButton.xaml.cs">
<DependentUpon>HamburgerCategoryButton.xaml</DependentUpon>
</Compile>

Loading…
Cancel
Save