diff --git a/ToggleAndTextGenerator.ps1 b/ToggleAndTextGenerator.ps1 index b2e2662f..c3e45084 100644 --- a/ToggleAndTextGenerator.ps1 +++ b/ToggleAndTextGenerator.ps1 @@ -375,7 +375,7 @@ $category | %{ - + - - + @@ -479,16 +459,36 @@ - - + + - - - + + + + + + + + + - - - + + + + @@ -1224,7 +1224,7 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"@ + +#endregion Xaml Markup + +$xamlGui = [System.Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $xamlMarkup)) +$xamlMarkup.SelectNodes('//*[@Name]') | ForEach-Object { + New-Variable -Name $_.Name -Value $xamlGui.FindName($_.Name) -Force +} + +#region Fill Gui Elements Arrays +$hamburgerText = New-Object System.Collections.ArrayList($null) +(Get-Variable -Name "Textblock_Hamburger_*").Name | ForEach-Object { + $ham = $Window.FindName($_) + [Void]$hamburgerText.Add($ham) +} + +$toggleText = New-Object System.Collections.ArrayList($null) +(Get-Variable -Name "Text_*").Name | ForEach-Object { + $toggle = $Window.FindName($_) + [Void]$toggleText.Add($toggle) +} + +$toggleSwitch = New-Object System.Collections.ArrayList($null) +(Get-Variable -Name "Toggle_*").Name | ForEach-Object { + $switch = $Window.FindName($_) + [Void]$toggleSwitch.Add($switch) +} + +$togglesPanels = $PanelToggle_ContextMenu, $PanelToggle_Defender, $PanelToggle_Edge, $PanelToggle_Game, + $PanelToggle_OneDrive, $PanelToggle_Privacy, $PanelToggle_StartMenu, $PanelToggle_System, + $PanelToggle_Tasks, $PanelToggle_Ui, $PanelToggle_UserInfo, $PanelToggle_Uwp + +#endregion Gui Elements Array Collections + +#region Script Functions +function Hide-Console { + <# + .SYNOPSIS + Hide Powershell console before show WPF GUI. + #> + + [CmdletBinding()] + param () + + Add-Type -Name Window -Namespace Console -MemberDefinition ' + [DllImport("Kernel32.dll")] + public static extern IntPtr GetConsoleWindow(); + + [DllImport("user32.dll")] + public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow); +' + [Console.Window]::ShowWindow([Console.Window]::GetConsoleWindow(), 0) +} + +function Click-HamburgerMenu { + <# + .SYNOPSIS + Show or hide hamburger menu. + #> + + [CmdletBinding()] + param () + + $minWidth = 50 + $maxWidth = 250 + $duration = New-Object System.Windows.Duration([timespan]::FromSeconds(1)) + $widthProperty = New-Object System.Windows.PropertyPath([System.Windows.Controls.Canvas]::WidthProperty) + + if ($HamburgerMenu.ActualWidth -eq $minWidth) + { + $animation = New-Object System.Windows.Media.Animation.DoubleAnimation($minWidth, $maxWidth, $duration) + $Window.Width += 200 + } + + else + { + $animation = New-Object System.Windows.Media.Animation.DoubleAnimation($maxWidth, $minWidth, $duration) + $Window.Width -= 200 + } + + $animation.SpeedRatio ="2" + $storyboard = New-Object System.Windows.Media.Animation.Storyboard + [System.Windows.Media.Animation.Storyboard]::SetTargetProperty($animation, $widthProperty) + $storyboard.Children.Add($animation) + $storyboard.Begin($HamburgerMenu) +} + +function Set-HamburgerHover { + <# + .SYNOPSIS + Mouse hover effect for hamburger button. + #> + + [CmdletBinding()] + param + ( + [Parameter(Mandatory=$false)] + [switch]$Active + ) + + + if ($Active) + { + $ButtonHamburger.Background = "#2196F3" + } + + else + { + $ButtonHamburger.Background = "#3F51B5" + } +} + +function Set-ActivePanel { + <# + .SYNOPSIS + Set Active Panel by Name. + #> + + [CmdletBinding()] + param + ( + [Parameter(Mandatory=$true, ValueFromPipeline=$true, HelpMessage="Name for select panel: ContextMenu, Defender, Edge, Game, OneDrive, Privacy, StartMenu, System, Tasks, Ui, UserInfo, Uwp")] + [ValidateSet("ContextMenu", "Defender", "Edge", "Game", "OneDrive", "Privacy", "StartMenu", "System", "Tasks", "Ui", "UserInfo", "Uwp")] + [ValidateNotNull()] + [string]$Name + ) + + $panelName = "PanelToggle_{0}"-f $Name + for ($i=0;$i -lt $togglesPanels.Count;$i++) + { + if ($togglesPanels[$i].Name -eq $panelName) + { + $togglesPanels[$i].Visibility = "Visible" + + if ($RU) + { + $TextBlock_Category.Text = $headerRu[$i] + } + + else + { + $TextBlock_Category.Text = $headerEng[$i] + } + } + + else + { + $togglesPanels[$i].Visibility = "Collapsed" + } + } +} + +function Get-ActivePanel { + <# + .SYNOPSIS + Return Current Active Panel Name. + #> + + [CmdletBinding()] + param () + + for ($i=0;$i -lt $togglesPanels.Count;$i++) + { + if ($togglesPanels[$i].Visibility -eq "Visible") + { + $panelName = $togglesPanels[$i].Name -replace "PanelToggle_","" + return $panelName + } + } +} + +function Click-ToggleButton { + <# + .SYNOPSIS + Click event to Toggle Buttons. + #> + + [CmdletBinding()] + param + ( + [Parameter(Mandatory=$false)] + [switch]$IsChecked + ) + + if ($IsChecked) + { + $Global:clickedToggle++ + } + + elseif (!$IsChecked) + { + $Global:clickedToggle-- + } + + if ($clickedToggle -gt 0) + { + $ButtonApply.IsEnabled = $true + $ButtonSave.IsEnabled = $true + } + + else + { + $ButtonApply.IsEnabled = $false + $ButtonSave.IsEnabled = $false + } +} + +function Set-GuiLanguage { + <# + .SYNOPSIS + Change Gui Language + #> + + [CmdletBinding()] + param + ( + [Parameter(Mandatory=$false)] + [switch]$Switch + ) + + if ($Switch) + { + $Global:RU = (!$Global:RU) + } + + #region Set Save Load Apply Buttons + + if ($RU) + { + $TextButtonApply.Text = "Применить" + $TextButtonLoad.Text = "Загрузить" + $TextButtonSave.Text = "Сохранить" + } + + else + { + $TextButtonApply.Text = "Apply" + $TextButtonLoad.Text = "Load" + $TextButtonSave.Text = "Save" + } + + #endregion Set Save Load Apply Buttons + + #region Set Hamburger Buttons + + if ($RU) + { + for ($i=0;$i -lt $hamburgerText.Count;$i++) + { + $hamburgerText[$i].Text = $hamburgerRu[$i] + } + } + + else + { + for ($i=0;$i -lt $hamburgerText.Count;$i++) + { + $hamburgerText[$i].Text = $hamburgerEng[$i] + } + } + + #endregion Set Hamburger Buttons + + #region Set Toggle Text Language + + if ($RU) + { + for ($i=0;$i -lt $toggleText.Count;$i++) + { + $toggleText[$i].Text = $TextRu[$toggleText[$i].Uid] + } + } + + else + { + for ($i=0;$i -lt $toggleText.Count;$i++) + { + $toggleText[$i].Text = $TextEng[$toggleText[$i].Uid] + } + } + + #endregion Set Toggle Text Language +} + +function Show-InfoPanel { + <# + .SYNOPSIS + Show Message for User + #> + + [CmdletBinding()] + param + ( + [Parameter(Mandatory=$false)] + [ValidateNotNull()] + [string]$TextRu, + + [Parameter(Mandatory=$false)] + [ValidateNotNull()] + [string]$TextEng, + + [Parameter(Mandatory=$false)] + [switch]$ShowAnimation, + + [Parameter(Mandatory=$false)] + [switch]$Hide + ) + + $TextBlock_Category.Text = "" + $panelName = "PanelToggle_UserInfo" + + for ($i=0;$i -lt $togglesPanels.Count;$i++) + { + if ($togglesPanels[$i].Name -eq $panelName) + { + if ($Hide) + { + $togglesPanels[$i].Visibility = "Collapsed" + $UserInfo_TextBlock.Text = "" + } + + else + { + $togglesPanels[$i].Visibility = "Visible" + } + } + + else + { + $togglesPanels[$i].Visibility = "Collapsed" + } + } + + if ($ShowAnimation) + { + $UserInfo_Border.Visibility = "Visible" + } + + else + { + $UserInfo_Border.Visibility = "Collapsed" + } + + if ($RU) + { + $UserInfo_TextBlock.Text = $TextRu + } + + else + { + $UserInfo_TextBlock.Text = $TextEng + } +} + +function Follow-OnGitHub { + <# + .SYNOPSIS + Open Farag2 GitHub in Default Browser + #> + + [CmdletBinding()] + param () + + Start-Process -FilePath $gitHub +} + +#endregion + +#region Controls Events + +$ButtonHamburger.Add_MouseLeftButtonDown({ + Click-HamburgerMenu +}) + +$ButtonHamburger.Add_MouseEnter({ + Set-HamburgerHover -Active +}) + +$ButtonHamburger.Add_MouseLeave({ + Set-HamburgerHover +}) + +$Button_Hamburger_ChangeLanguage.Add_MouseLeftButtonDown({ + $panelName = Get-ActivePanel + Set-GuiLanguage -Switch + Set-ActivePanel -Name $panelName +}) + +$Button_Hamburger_ContextMenu.Add_MouseLeftButtonDown({ + Set-ActivePanel -Name "ContextMenu" +}) + +$Button_Hamburger_Defender.Add_MouseLeftButtonDown({ + Set-ActivePanel -Name "Defender" +}) + +$Button_Hamburger_Edge.Add_MouseLeftButtonDown({ + Set-ActivePanel -Name "Edge" +}) + +$Button_Hamburger_Game.Add_MouseLeftButtonDown({ + Set-ActivePanel -Name "Game" +}) + +$Button_Hamburger_GitHub.Add_MouseLeftButtonDown({ + Follow-OnGitHub +}) + +$Button_Hamburger_OneDrive.Add_MouseLeftButtonDown({ + Set-ActivePanel -Name "OneDrive" +}) + +$Button_Hamburger_Privacy.Add_MouseLeftButtonDown({ + Set-ActivePanel -Name "Privacy" +}) + +$Button_Hamburger_StartMenu.Add_MouseLeftButtonDown({ + Set-ActivePanel -Name "StartMenu" +}) + +$Button_Hamburger_System.Add_MouseLeftButtonDown({ + Set-ActivePanel -Name "System" +}) + +$Button_Hamburger_Tasks.Add_MouseLeftButtonDown({ + Set-ActivePanel -Name "Tasks" +}) + +$Button_Hamburger_UI.Add_MouseLeftButtonDown({ + Set-ActivePanel -Name "Ui" +}) + +$Button_Hamburger_Uwp.Add_MouseLeftButtonDown({ + Set-ActivePanel -Name "Uwp" +}) + +#region Add Toggle Buttons Click Event + +for ($i=0;$i -lt $toggleSwitch.Count;$i++) +{ + $toggleSwitch[$i].Add_Checked({ + Click-ToggleButton -IsChecked + }) + + $toggleSwitch[$i].Add_Unchecked({ + Click-ToggleButton + }) +} + +#endregion Add Toggle Buttons Click Event + +#endregion Controls Events + +Set-ActivePanel -Name "Privacy" +Set-GuiLanguage +Hide-Console | Out-Null +$Window.ShowDialog() | Out-Null