Fix Settings Popup not closing after losing focus - Add trivial null checks for better debugging of UI code

This commit is contained in:
Mr.k 2024-10-25 12:34:13 +03:00
parent 0e7a34c5e5
commit 2b2b11e4f2
No known key found for this signature in database

View File

@ -254,12 +254,12 @@ $commonKeyEvents = {
$sync["Form"].Add_PreViewKeyDown($commonKeyEvents) $sync["Form"].Add_PreViewKeyDown($commonKeyEvents)
$sync["Form"].Add_MouseLeftButtonDown({ $sync["Form"].Add_MouseLeftButtonDown({
# Hide Settings and Theme Popup on click anywhere else if ($sync.SettingsPopup -eq $null -or
if ($sync.SettingsButton.IsOpen -or $sync.ThemePopup -eq $null) {
$sync.ThemePopup.IsOpen) { Write-Host "Either Settings or Theme Popup is null, this's not allowed to happen in the first place. Please double check your UI code." -ForegroundColor Red
}
$sync.SettingsPopup.IsOpen = $false $sync.SettingsPopup.IsOpen = $false
$sync.ThemePopup.IsOpen = $false $sync.ThemePopup.IsOpen = $false
}
$sync["Form"].DragMove() $sync["Form"].DragMove()
}) })
@ -277,12 +277,12 @@ $sync["Form"].Add_MouseDoubleClick({
$sync["Form"].Add_Deactivated({ $sync["Form"].Add_Deactivated({
Write-Debug "WinUtil lost focus" Write-Debug "WinUtil lost focus"
# Hide Settings and Theme Popup on Winutil Focus Loss if ($sync.SettingsPopup -eq $null -or
if ($sync.SettingsButton.IsOpen -or $sync.ThemePopup -eq $null) {
$sync.ThemePopup.IsOpen) { Write-Host "Either Settings or Theme Popup is null, this's not allowed to happen in the first place. Please double check your UI code." -ForegroundColor Red
}
$sync.SettingsPopup.IsOpen = $false $sync.SettingsPopup.IsOpen = $false
$sync.ThemePopup.IsOpen = $false $sync.ThemePopup.IsOpen = $false
}
}) })
$sync["Form"].Add_ContentRendered({ $sync["Form"].Add_ContentRendered({
@ -525,29 +525,39 @@ $sync["Form"].Add_Activated({
}) })
# Define event handler for ThemeButton click # Define event handler for ThemeButton click
$sync["ThemeButton"].Add_Click({ $sync["ThemeButton"].Add_Click({
if ($sync.ThemePopup.IsOpen) { if ($sync.SettingsPopup -eq $null -or
$sync.ThemePopup.IsOpen = $false $sync.ThemePopup -eq $null) {
} Write-Host "Either Settings or Theme Popup is null, this's not allowed to happen in the first place. Please double check your UI code." -ForegroundColor Red
else{
$sync.ThemePopup.IsOpen = $true
} }
# Hide the settings popup and toggle the themes popup
$sync.ThemePopup.IsOpen = -not $sync.ThemePopup.IsOpen
$sync.SettingsPopup.IsOpen = $false $sync.SettingsPopup.IsOpen = $false
$_.Handled = $false
}) })
# Define event handlers for menu items # Define event handlers for menu items
$sync["AutoThemeMenuItem"].Add_Click({ $sync["AutoThemeMenuItem"].Add_Click({
if ($sync.ThemePopup -eq $null) {
Write-Host "Theme Popup is null, this's not allowed to happen in the first place. Please double check your UI code." -ForegroundColor Red
}
$sync.ThemePopup.IsOpen = $false $sync.ThemePopup.IsOpen = $false
Invoke-WinutilThemeChange -theme "Auto" Invoke-WinutilThemeChange -theme "Auto"
$_.Handled = $false $_.Handled = $false
}) })
# Define event handlers for menu items # Define event handlers for menu items
$sync["DarkThemeMenuItem"].Add_Click({ $sync["DarkThemeMenuItem"].Add_Click({
if ($sync.ThemePopup -eq $null) {
Write-Host "Theme Popup is null, this's not allowed to happen in the first place. Please double check your UI code." -ForegroundColor Red
}
$sync.ThemePopup.IsOpen = $false $sync.ThemePopup.IsOpen = $false
Invoke-WinutilThemeChange -theme "Dark" Invoke-WinutilThemeChange -theme "Dark"
$_.Handled = $false $_.Handled = $false
}) })
# Define event handlers for menu items # Define event handlers for menu items
$sync["LightThemeMenuItem"].Add_Click({ $sync["LightThemeMenuItem"].Add_Click({
if ($sync.ThemePopup -eq $null) {
Write-Host "Theme Popup is null, this's not allowed to happen in the first place. Please double check your UI code." -ForegroundColor Red
}
$sync.ThemePopup.IsOpen = $false $sync.ThemePopup.IsOpen = $false
Invoke-WinutilThemeChange -theme "Light" Invoke-WinutilThemeChange -theme "Light"
$_.Handled = $false $_.Handled = $false
@ -557,12 +567,12 @@ $sync["LightThemeMenuItem"].Add_Click({
# Define event handler for button click # Define event handler for button click
$sync["SettingsButton"].Add_Click({ $sync["SettingsButton"].Add_Click({
Write-Debug "SettingsButton clicked" Write-Debug "SettingsButton clicked"
if ($sync.SettingsPopup.IsOpen) { if ($sync.SettingsPopup -eq $null -or
$sync.SettingsPopup.IsOpen = $false $sync.ThemePopup -eq $null) {
} Write-Host "Either Settings or Theme Popup is null, this's not allowed to happen in the first place. Please double check your UI code." -ForegroundColor Red
else{
$sync.SettingsPopup.IsOpen = $true
} }
# Hide the themes popup and toggle the settings popup
$sync.SettingsPopup.IsOpen = -not $sync.SettingsPopup.IsOpen
$sync.ThemePopup.IsOpen = $false $sync.ThemePopup.IsOpen = $false
$_.Handled = $false $_.Handled = $false
}) })
@ -571,7 +581,10 @@ $sync["SettingsButton"].Add_Click({
$sync["ImportMenuItem"].Add_Click({ $sync["ImportMenuItem"].Add_Click({
# Handle Import menu item click # Handle Import menu item click
Write-Debug "Import clicked" Write-Debug "Import clicked"
$sync["SettingsPopup"].IsOpen = $false if ($sync.SettingsPopup -eq $null) {
Write-Host "Either Settings is null, this's not allowed to happen in the first place. Please double check your UI code." -ForegroundColor Red
}
$sync.SettingsPopup.IsOpen = $false
Invoke-WPFImpex -type "import" Invoke-WPFImpex -type "import"
$_.Handled = $false $_.Handled = $false
}) })
@ -579,7 +592,10 @@ $sync["ImportMenuItem"].Add_Click({
$sync["ExportMenuItem"].Add_Click({ $sync["ExportMenuItem"].Add_Click({
# Handle Export menu item click # Handle Export menu item click
Write-Debug "Export clicked" Write-Debug "Export clicked"
$sync["SettingsPopup"].IsOpen = $false if ($sync.SettingsPopup -eq $null) {
Write-Host "Either Settings is null, this's not allowed to happen in the first place. Please double check your UI code." -ForegroundColor Red
}
$sync.SettingsPopup.IsOpen = $false
Invoke-WPFImpex -type "export" Invoke-WPFImpex -type "export"
$_.Handled = $false $_.Handled = $false
}) })
@ -587,7 +603,10 @@ $sync["ExportMenuItem"].Add_Click({
$sync["AboutMenuItem"].Add_Click({ $sync["AboutMenuItem"].Add_Click({
# Handle Export menu item click # Handle Export menu item click
Write-Debug "About clicked" Write-Debug "About clicked"
$sync["SettingsPopup"].IsOpen = $false if ($sync.SettingsPopup -eq $null) {
Write-Host "Either Settings is null, this's not allowed to happen in the first place. Please double check your UI code." -ForegroundColor Red
}
$sync.SettingsPopup.IsOpen = $false
$authorInfo = @" $authorInfo = @"
Author : <a href="https://github.com/ChrisTitusTech">@christitustech</a> Author : <a href="https://github.com/ChrisTitusTech">@christitustech</a>
Runspace : <a href="https://github.com/DeveloperDurp">@DeveloperDurp</a> Runspace : <a href="https://github.com/DeveloperDurp">@DeveloperDurp</a>
@ -602,7 +621,10 @@ Version : <a href="https://github.com/ChrisTitusTech/winutil/releases/tag/$($sy
$sync["SponsorMenuItem"].Add_Click({ $sync["SponsorMenuItem"].Add_Click({
# Handle Export menu item click # Handle Export menu item click
Write-Debug "Sponsors clicked" Write-Debug "Sponsors clicked"
$sync["SettingsPopup"].IsOpen = $false if ($sync.SettingsPopup -eq $null) {
Write-Host "Either Settings is null, this's not allowed to happen in the first place. Please double check your UI code." -ForegroundColor Red
}
$sync.SettingsPopup.IsOpen = $false
$authorInfo = @" $authorInfo = @"
<a href="https://github.com/sponsors/ChrisTitusTech">Current sponsors for ChrisTitusTech:</a> <a href="https://github.com/sponsors/ChrisTitusTech">Current sponsors for ChrisTitusTech:</a>
"@ "@