Improve 'Invoke-WPFPresets' Public Function - Made applying tweaks presets go blazingly fast - Made Clearing Selection work properly (#2608)

* 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
This commit is contained in:
Mr.k 2024-08-29 04:02:59 +03:00 committed by GitHub
parent 90ddfb02a4
commit be6b5b3aa0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 21 deletions

View File

@ -21,13 +21,13 @@ function Invoke-WPFButton {
Switch -Wildcard ($Button) { Switch -Wildcard ($Button) {
"WPFTab?BT" {Invoke-WPFTab $Button} "WPFTab?BT" {Invoke-WPFTab $Button}
"WPFinstall" {Invoke-WPFInstall} "WPFInstall" {Invoke-WPFInstall}
"WPFuninstall" {Invoke-WPFUnInstall} "WPFUninstall" {Invoke-WPFUnInstall}
"WPFInstallUpgrade" {Invoke-WPFInstallUpgrade} "WPFInstallUpgrade" {Invoke-WPFInstallUpgrade}
"WPFstandard" {Invoke-WPFPresets "Standard"} "WPFStandard" {Invoke-WPFPresets "Standard" -checkboxfilterpattern "WPFTweak*"}
"WPFminimal" {Invoke-WPFPresets "Minimal"} "WPFMinimal" {Invoke-WPFPresets "Minimal" -checkboxfilterpattern "WPFTweak*"}
"WPFclear" {Invoke-WPFPresets -preset $null -imported $true} "WPFClearTweaksSelection" {Invoke-WPFPresets -imported $true -checkboxfilterpattern "WPFTweak*"}
"WPFclearWinget" {Invoke-WPFPresets -preset $null -imported $true -CheckBox "WPFInstall"} "WPFClearInstallSelection" {Invoke-WPFPresets -imported $true -checkboxfilterpattern "WPFInstall*"}
"WPFtweaksbutton" {Invoke-WPFtweaksbutton} "WPFtweaksbutton" {Invoke-WPFtweaksbutton}
"WPFOOSUbutton" {Invoke-WPFOOSU} "WPFOOSUbutton" {Invoke-WPFOOSU}
"WPFAddUltPerf" {Invoke-WPFUltimatePerformance -State "Enable"} "WPFAddUltPerf" {Invoke-WPFUltimatePerformance -State "Enable"}

View File

@ -10,14 +10,20 @@ function Invoke-WPFPresets {
.PARAMETER imported .PARAMETER imported
If the preset is imported from a file, defaults to false If the preset is imported from a file, defaults to false
.PARAMETER checkbox .PARAMETER checkboxfilterpattern
The checkbox to set the options to, defaults to 'WPFTweaks' The Pattern to use when filtering through CheckBoxes, defaults to "**"
#> #>
param ( param (
$preset, [Parameter(position=0)]
[bool]$imported = $false [string]$preset = "",
[Parameter(position=1)]
[bool]$imported = $false,
[Parameter(position=2)]
[string]$checkboxfilterpattern = "**"
) )
if ($imported -eq $true) { if ($imported -eq $true) {
@ -26,13 +32,14 @@ function Invoke-WPFPresets {
$CheckBoxesToCheck = $sync.configs.preset.$preset $CheckBoxesToCheck = $sync.configs.preset.$preset
} }
$CheckBoxes = $sync.GetEnumerator() | Where-Object { $_.Value -is [System.Windows.Controls.CheckBox] -and $_.Name -notlike "WPFToggle*" } $CheckBoxes = ($sync.GetEnumerator()).where{ $_.Value -is [System.Windows.Controls.CheckBox] -and $_.Name -notlike "WPFToggle*" -and $_.Name -like "$checkboxfilterpattern"}
Write-Debug "Getting checkboxes to set $($CheckBoxes.Count)" Write-Debug "Getting checkboxes to set, number of checkboxes: $($CheckBoxes.Count)"
$CheckBoxesToCheck | ForEach-Object { if ($CheckBoxesToCheck -ne "") {
if ($_ -ne $null) { $debugMsg = "CheckBoxes to Check are: "
Write-Debug $_ $CheckBoxesToCheck | ForEach-Object { $debugMsg += "$_, " }
} $debugMsg = $debugMsg -replace (',\s*$', '')
Write-Debug "$debugMsg"
} }
foreach ($CheckBox in $CheckBoxes) { foreach ($CheckBox in $CheckBoxes) {

View File

@ -814,11 +814,11 @@
<RowDefinition Height="0.95*"/> <RowDefinition Height="0.95*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Background="{MainBackgroundColor}" Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="0" Grid.ColumnSpan="3" Margin="{TabContentMargin}"> <StackPanel Background="{MainBackgroundColor}" Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="0" Grid.ColumnSpan="3" Margin="{TabContentMargin}">
<Button Name="WPFinstall" Content=" Install/Upgrade Selected" Margin="2" /> <Button Name="WPFInstall" Content=" Install/Upgrade Selected" Margin="2" />
<Button Name="WPFInstallUpgrade" Content=" Upgrade All" Margin="2"/> <Button Name="WPFInstallUpgrade" Content=" Upgrade All" Margin="2"/>
<Button Name="WPFuninstall" Content=" Uninstall Selected" Margin="2"/> <Button Name="WPFUninstall" Content=" Uninstall Selected" Margin="2"/>
<Button Name="WPFGetInstalled" Content=" Get Installed" Margin="2"/> <Button Name="WPFGetInstalled" Content=" Get Installed" Margin="2"/>
<Button Name="WPFclearWinget" Content=" Clear Selection" Margin="2"/> <Button Name="WPFClearInstallSelection" Content=" Clear Selection" Margin="2"/>
</StackPanel> </StackPanel>
<ScrollViewer x:Name="scrollViewer" Grid.Row="1" Grid.Column="0" Margin="{TabContentMargin}" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" <ScrollViewer x:Name="scrollViewer" Grid.Row="1" Grid.Column="0" Margin="{TabContentMargin}" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"