mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-15 15:15:51 -06:00
be6b5b3aa0
* Improve 'Invoke-WPFPresets.ps1' Public Function as well as Simple Optimizations * Simple Optimization by providing more info to 'Invoke-WPFPresets.ps1' function calls inside 'Invoke-WPFButton.ps1' * Fix some logic issue in 'Invoke-WPFPresets.ps1' Public Function * Rename Button Names to more clear and Make them follow CamelCase Naming
65 lines
1.9 KiB
PowerShell
65 lines
1.9 KiB
PowerShell
function Invoke-WPFPresets {
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
Sets the options in the tweaks panel to the given preset
|
|
|
|
.PARAMETER preset
|
|
The preset to set the options to
|
|
|
|
.PARAMETER imported
|
|
If the preset is imported from a file, defaults to false
|
|
|
|
.PARAMETER checkboxfilterpattern
|
|
The Pattern to use when filtering through CheckBoxes, defaults to "**"
|
|
|
|
#>
|
|
|
|
param (
|
|
[Parameter(position=0)]
|
|
[string]$preset = "",
|
|
|
|
[Parameter(position=1)]
|
|
[bool]$imported = $false,
|
|
|
|
[Parameter(position=2)]
|
|
[string]$checkboxfilterpattern = "**"
|
|
)
|
|
|
|
if ($imported -eq $true) {
|
|
$CheckBoxesToCheck = $preset
|
|
} else {
|
|
$CheckBoxesToCheck = $sync.configs.preset.$preset
|
|
}
|
|
|
|
$CheckBoxes = ($sync.GetEnumerator()).where{ $_.Value -is [System.Windows.Controls.CheckBox] -and $_.Name -notlike "WPFToggle*" -and $_.Name -like "$checkboxfilterpattern"}
|
|
Write-Debug "Getting checkboxes to set, number of checkboxes: $($CheckBoxes.Count)"
|
|
|
|
if ($CheckBoxesToCheck -ne "") {
|
|
$debugMsg = "CheckBoxes to Check are: "
|
|
$CheckBoxesToCheck | ForEach-Object { $debugMsg += "$_, " }
|
|
$debugMsg = $debugMsg -replace (',\s*$', '')
|
|
Write-Debug "$debugMsg"
|
|
}
|
|
|
|
foreach ($CheckBox in $CheckBoxes) {
|
|
$checkboxName = $CheckBox.Key
|
|
|
|
if (-not $CheckBoxesToCheck) {
|
|
$sync.$checkboxName.IsChecked = $false
|
|
continue
|
|
}
|
|
|
|
# Check if the checkbox name exists in the flattened JSON hashtable
|
|
if ($CheckBoxesToCheck.Contains($checkboxName)) {
|
|
# If it exists, set IsChecked to true
|
|
$sync.$checkboxName.IsChecked = $true
|
|
Write-Debug "$checkboxName is checked"
|
|
} else {
|
|
# If it doesn't exist, set IsChecked to false
|
|
$sync.$checkboxName.IsChecked = $false
|
|
Write-Debug "$checkboxName is not checked"
|
|
}
|
|
}
|
|
}
|