2026-03-22 22:07:51 +01:00
|
|
|
function Show-RevertSettingsModal {
|
|
|
|
|
param (
|
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
|
|
|
[System.Windows.Window]$Owner = $null,
|
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
|
$LastUsedSettings
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
Add-Type -AssemblyName PresentationFramework,PresentationCore,WindowsBase | Out-Null
|
|
|
|
|
|
|
|
|
|
$usesDarkMode = GetSystemUsesDarkMode
|
|
|
|
|
|
|
|
|
|
# Determine owner window
|
|
|
|
|
$ownerWindow = if ($Owner) { $Owner } else { $script:GuiWindow }
|
|
|
|
|
|
|
|
|
|
# Show overlay if owner window exists
|
|
|
|
|
$overlay = $null
|
|
|
|
|
$overlayWasAlreadyVisible = $false
|
|
|
|
|
if ($ownerWindow) {
|
|
|
|
|
try {
|
|
|
|
|
$overlay = $ownerWindow.FindName('ModalOverlay')
|
|
|
|
|
if ($overlay) {
|
|
|
|
|
$overlayWasAlreadyVisible = ($overlay.Visibility -eq 'Visible')
|
|
|
|
|
if (-not $overlayWasAlreadyVisible) {
|
|
|
|
|
$ownerWindow.Dispatcher.Invoke([action]{ $overlay.Visibility = 'Visible' })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Load XAML from file
|
|
|
|
|
$xaml = Get-Content -Path $script:RevertSettingsWindowSchema -Raw
|
|
|
|
|
$reader = [System.Xml.XmlReader]::Create([System.IO.StringReader]::new($xaml))
|
|
|
|
|
try {
|
|
|
|
|
$revertWindow = [System.Windows.Markup.XamlReader]::Load($reader)
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
$reader.Close()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($ownerWindow) {
|
|
|
|
|
try {
|
|
|
|
|
$revertWindow.Owner = $ownerWindow
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetWindowThemeResources -window $revertWindow -usesDarkMode $usesDarkMode
|
|
|
|
|
|
|
|
|
|
$itemsPanel = $revertWindow.FindName('RevertItemsPanel')
|
|
|
|
|
$countText = $revertWindow.FindName('RevertSelectionCount')
|
|
|
|
|
$selectAllBtn = $revertWindow.FindName('RevertSelectAllBtn')
|
|
|
|
|
$clearBtn = $revertWindow.FindName('RevertClearBtn')
|
|
|
|
|
$applyBtn = $revertWindow.FindName('RevertApplyBtn')
|
|
|
|
|
$cancelBtn = $revertWindow.FindName('RevertCancelBtn')
|
|
|
|
|
$restartExplorerCheckbox = $revertWindow.FindName('RevertRestartExplorerCheckBox')
|
2026-03-23 21:35:33 +01:00
|
|
|
$featureCheckboxStyle = $revertWindow.FindResource('FeatureCheckboxStyle')
|
|
|
|
|
$restartExplorerCheckbox.Style = $featureCheckboxStyle
|
2026-03-22 22:07:51 +01:00
|
|
|
$entryCheckboxes = @()
|
|
|
|
|
|
|
|
|
|
foreach ($setting in $LastUsedSettings.Settings) {
|
|
|
|
|
if ($setting.Value -ne $true) { continue }
|
|
|
|
|
if ($setting.Name -eq 'Apps' -or $setting.Name -eq 'RemoveApps' -or $setting.Name -eq 'CreateRestorePoint') { continue }
|
|
|
|
|
|
|
|
|
|
$feature = $null
|
|
|
|
|
if ($script:Features.ContainsKey($setting.Name)) {
|
|
|
|
|
$feature = $script:Features[$setting.Name]
|
|
|
|
|
}
|
|
|
|
|
$undoFeature = GetUndoFeatureForParam -paramKey $setting.Name
|
|
|
|
|
|
|
|
|
|
$label = $setting.Name
|
2026-04-01 21:33:24 +02:00
|
|
|
if ($feature -and $feature.Action) {
|
|
|
|
|
$label = $feature.Action
|
2026-03-22 22:07:51 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-01 21:33:24 +02:00
|
|
|
$undoLabel = if ($undoFeature -and $undoFeature.UndoAction) {
|
|
|
|
|
$undoFeature.UndoAction
|
2026-03-22 22:07:51 +01:00
|
|
|
} else {
|
|
|
|
|
'No revert action available'
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 21:35:33 +01:00
|
|
|
$canUndo = ($null -ne $undoFeature)
|
2026-03-22 22:07:51 +01:00
|
|
|
|
|
|
|
|
$itemBorder = New-Object System.Windows.Controls.Border
|
|
|
|
|
$itemBorder.Style = $revertWindow.FindResource('RevertItemBorderStyle')
|
|
|
|
|
|
|
|
|
|
$row = New-Object System.Windows.Controls.StackPanel
|
|
|
|
|
$row.Style = $revertWindow.FindResource('RevertItemRowStyle')
|
|
|
|
|
|
|
|
|
|
$checkbox = New-Object System.Windows.Controls.CheckBox
|
|
|
|
|
$checkbox.Content = $label
|
|
|
|
|
$checkbox.Tag = $setting.Name
|
2026-03-23 21:35:33 +01:00
|
|
|
$checkbox.Style = $featureCheckboxStyle
|
2026-03-22 22:07:51 +01:00
|
|
|
$checkbox.IsEnabled = $canUndo
|
|
|
|
|
|
|
|
|
|
$undoText = New-Object System.Windows.Controls.TextBlock
|
|
|
|
|
$undoText.Text = if ($canUndo) { "Revert to: $undoLabel" } else { 'Revert not supported for this setting' }
|
|
|
|
|
$undoText.Style = $revertWindow.FindResource('RevertItemUndoTextStyle')
|
|
|
|
|
$undoText.Opacity = if ($canUndo) { 0.75 } else { 0.4 }
|
|
|
|
|
|
|
|
|
|
$row.Children.Add($checkbox) | Out-Null
|
|
|
|
|
$row.Children.Add($undoText) | Out-Null
|
|
|
|
|
$itemBorder.Child = $row
|
|
|
|
|
|
|
|
|
|
$itemsPanel.Children.Add($itemBorder) | Out-Null
|
|
|
|
|
$entryCheckboxes += $checkbox
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Remove the divider from the last entry for cleaner list termination.
|
|
|
|
|
if ($itemsPanel.Children.Count -gt 0) {
|
|
|
|
|
$lastItem = $itemsPanel.Children[$itemsPanel.Children.Count - 1]
|
|
|
|
|
if ($lastItem -is [System.Windows.Controls.Border]) {
|
|
|
|
|
$lastItem.BorderThickness = [System.Windows.Thickness]::new(0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($entryCheckboxes.Count -eq 0) {
|
|
|
|
|
$emptyText = New-Object System.Windows.Controls.TextBlock
|
|
|
|
|
$emptyText.Text = 'No previously applied tweaks can be reverted'
|
|
|
|
|
$emptyText.Style = $revertWindow.FindResource('RevertEmptyTextStyle')
|
|
|
|
|
$itemsPanel.Children.Add($emptyText) | Out-Null
|
|
|
|
|
$selectAllBtn.IsEnabled = $false
|
|
|
|
|
$clearBtn.IsEnabled = $false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$updateState = {
|
|
|
|
|
$selectedCount = 0
|
|
|
|
|
foreach ($cb in $entryCheckboxes) {
|
|
|
|
|
if ($cb.IsEnabled -and $cb.IsChecked -eq $true) {
|
|
|
|
|
$selectedCount++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$countText.Text = "$selectedCount settings selected"
|
|
|
|
|
$applyBtn.IsEnabled = ($selectedCount -gt 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($cb in $entryCheckboxes) {
|
|
|
|
|
$cb.Add_Checked($updateState)
|
|
|
|
|
$cb.Add_Unchecked($updateState)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$selectAllBtn.Add_Click({
|
|
|
|
|
foreach ($cb in $entryCheckboxes) {
|
|
|
|
|
if ($cb.IsEnabled) {
|
|
|
|
|
$cb.IsChecked = $true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
$clearBtn.Add_Click({
|
|
|
|
|
foreach ($cb in $entryCheckboxes) {
|
|
|
|
|
if ($cb.IsEnabled) {
|
|
|
|
|
$cb.IsChecked = $false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
$cancelHandler = {
|
|
|
|
|
$revertWindow.Close()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$cancelBtn.Add_Click($cancelHandler)
|
|
|
|
|
|
|
|
|
|
$applyBtn.Add_Click({
|
|
|
|
|
$selected = @()
|
|
|
|
|
foreach ($cb in $entryCheckboxes) {
|
|
|
|
|
if ($cb.IsEnabled -and $cb.IsChecked -eq $true -and $cb.Tag) {
|
|
|
|
|
$selected += $cb.Tag
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$revertWindow.Tag = [PSCustomObject]@{
|
|
|
|
|
SelectedFeatureIds = $selected
|
|
|
|
|
RestartExplorer = ($restartExplorerCheckbox -and $restartExplorerCheckbox.IsChecked -eq $true)
|
|
|
|
|
}
|
|
|
|
|
$revertWindow.Close()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
$revertWindow.ShowDialog() | Out-Null
|
|
|
|
|
|
|
|
|
|
if ($overlay -and -not $overlayWasAlreadyVisible) {
|
|
|
|
|
try {
|
|
|
|
|
$ownerWindow.Dispatcher.Invoke([action]{ $overlay.Visibility = 'Collapsed' })
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($revertWindow.Tag) {
|
|
|
|
|
return $revertWindow.Tag
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [PSCustomObject]@{
|
|
|
|
|
SelectedFeatureIds = @()
|
2026-03-22 23:57:19 +01:00
|
|
|
RestartExplorer = $false
|
2026-03-22 22:07:51 +01:00
|
|
|
}
|
|
|
|
|
}
|