@@ -254,12 +254,12 @@ $commonKeyEvents = {
254
254
$sync [" Form" ].Add_PreViewKeyDown($commonKeyEvents )
255
255
256
256
$sync [" Form" ].Add_MouseLeftButtonDown({
257
- # Hide Settings and Theme Popup on click anywhere else
258
- if ( $sync.SettingsButton.IsOpen -or
259
- $sync .ThemePopup.IsOpen ) {
260
- $sync .SettingsPopup.IsOpen = $false
261
- $sync.ThemePopup .IsOpen = $false
262
- }
257
+ if ( $sync .SettingsPopup -eq $null -or
258
+ $sync.ThemePopup -eq $null ) {
259
+ 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
260
+ }
261
+ $sync.SettingsPopup .IsOpen = $false
262
+ $sync .ThemePopup.IsOpen = $false
263
263
$sync [" Form" ].DragMove()
264
264
})
265
265
@@ -277,12 +277,12 @@ $sync["Form"].Add_MouseDoubleClick({
277
277
278
278
$sync [" Form" ].Add_Deactivated({
279
279
Write-Debug " WinUtil lost focus"
280
- # Hide Settings and Theme Popup on Winutil Focus Loss
281
- if ($sync.SettingsButton.IsOpen -or
282
- $sync.ThemePopup.IsOpen ) {
283
- $sync.SettingsPopup.IsOpen = $false
284
- $sync.ThemePopup.IsOpen = $false
280
+ if ($sync.SettingsPopup -eq $null -or
281
+ $sync.ThemePopup -eq $null ) {
282
+ 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
285
283
}
284
+ $sync.SettingsPopup.IsOpen = $false
285
+ $sync.ThemePopup.IsOpen = $false
286
286
})
287
287
288
288
$sync [" Form" ].Add_ContentRendered({
@@ -525,29 +525,39 @@ $sync["Form"].Add_Activated({
525
525
})
526
526
# Define event handler for ThemeButton click
527
527
$sync [" ThemeButton" ].Add_Click({
528
- if ($sync.ThemePopup.IsOpen ) {
529
- $sync.ThemePopup.IsOpen = $false
530
- }
531
- else {
532
- $sync.ThemePopup.IsOpen = $true
528
+ if ($sync.SettingsPopup -eq $null -or
529
+ $sync.ThemePopup -eq $null ) {
530
+ 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
533
531
}
532
+ # Hide the settings popup and toggle the themes popup
533
+ $sync.ThemePopup.IsOpen = -not $sync.ThemePopup.IsOpen
534
534
$sync.SettingsPopup.IsOpen = $false
535
+ $_.Handled = $false
535
536
})
536
537
537
538
# Define event handlers for menu items
538
539
$sync [" AutoThemeMenuItem" ].Add_Click({
540
+ if ($sync.ThemePopup -eq $null ) {
541
+ Write-Host " Theme Popup is null, this's not allowed to happen in the first place. Please double check your UI code." - ForegroundColor Red
542
+ }
539
543
$sync.ThemePopup.IsOpen = $false
540
544
Invoke-WinutilThemeChange - theme " Auto"
541
545
$_.Handled = $false
542
546
})
543
547
# Define event handlers for menu items
544
548
$sync [" DarkThemeMenuItem" ].Add_Click({
549
+ if ($sync.ThemePopup -eq $null ) {
550
+ Write-Host " Theme Popup is null, this's not allowed to happen in the first place. Please double check your UI code." - ForegroundColor Red
551
+ }
545
552
$sync.ThemePopup.IsOpen = $false
546
553
Invoke-WinutilThemeChange - theme " Dark"
547
554
$_.Handled = $false
548
555
})
549
556
# Define event handlers for menu items
550
557
$sync [" LightThemeMenuItem" ].Add_Click({
558
+ if ($sync.ThemePopup -eq $null ) {
559
+ Write-Host " Theme Popup is null, this's not allowed to happen in the first place. Please double check your UI code." - ForegroundColor Red
560
+ }
551
561
$sync.ThemePopup.IsOpen = $false
552
562
Invoke-WinutilThemeChange - theme " Light"
553
563
$_.Handled = $false
@@ -557,37 +567,46 @@ $sync["LightThemeMenuItem"].Add_Click({
557
567
# Define event handler for button click
558
568
$sync [" SettingsButton" ].Add_Click({
559
569
Write-Debug " SettingsButton clicked"
560
- if ($sync.SettingsPopup.IsOpen ) {
561
- $sync.SettingsPopup.IsOpen = $false
562
- }
563
- else {
564
- $sync.SettingsPopup.IsOpen = $true
570
+ if ($sync.SettingsPopup -eq $null -or
571
+ $sync.ThemePopup -eq $null ) {
572
+ 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
565
573
}
574
+ # Hide the themes popup and toggle the settings popup
575
+ $sync.SettingsPopup.IsOpen = -not $sync.SettingsPopup.IsOpen
566
576
$sync.ThemePopup.IsOpen = $false
567
577
$_.Handled = $false
568
578
})
569
579
570
580
# Define event handlers for menu items
571
581
$sync [" ImportMenuItem" ].Add_Click({
572
- # Handle Import menu item click
573
- Write-Debug " Import clicked"
574
- $sync [" SettingsPopup" ].IsOpen = $false
575
- Invoke-WPFImpex - type " import"
576
- $_.Handled = $false
582
+ # Handle Import menu item click
583
+ Write-Debug " Import clicked"
584
+ if ($sync.SettingsPopup -eq $null ) {
585
+ Write-Host " Either Settings is null, this's not allowed to happen in the first place. Please double check your UI code." - ForegroundColor Red
586
+ }
587
+ $sync.SettingsPopup.IsOpen = $false
588
+ Invoke-WPFImpex - type " import"
589
+ $_.Handled = $false
577
590
})
578
591
579
592
$sync [" ExportMenuItem" ].Add_Click({
580
593
# Handle Export menu item click
581
594
Write-Debug " Export clicked"
582
- $sync [" SettingsPopup" ].IsOpen = $false
595
+ if ($sync.SettingsPopup -eq $null ) {
596
+ Write-Host " Either Settings is null, this's not allowed to happen in the first place. Please double check your UI code." - ForegroundColor Red
597
+ }
598
+ $sync.SettingsPopup.IsOpen = $false
583
599
Invoke-WPFImpex - type " export"
584
600
$_.Handled = $false
585
601
})
586
602
587
603
$sync [" AboutMenuItem" ].Add_Click({
588
604
# Handle Export menu item click
589
605
Write-Debug " About clicked"
590
- $sync [" SettingsPopup" ].IsOpen = $false
606
+ if ($sync.SettingsPopup -eq $null ) {
607
+ Write-Host " Either Settings is null, this's not allowed to happen in the first place. Please double check your UI code." - ForegroundColor Red
608
+ }
609
+ $sync.SettingsPopup.IsOpen = $false
591
610
$authorInfo = @"
592
611
Author : <a href="https://github.com/ChrisTitusTech">@christitustech</a>
593
612
Runspace : <a href="https://github.com/DeveloperDurp">@DeveloperDurp</a>
@@ -602,7 +621,10 @@ Version : <a href="https://github.com/ChrisTitusTech/winutil/releases/tag/$($sy
602
621
$sync [" SponsorMenuItem" ].Add_Click({
603
622
# Handle Export menu item click
604
623
Write-Debug " Sponsors clicked"
605
- $sync [" SettingsPopup" ].IsOpen = $false
624
+ if ($sync.SettingsPopup -eq $null ) {
625
+ Write-Host " Either Settings is null, this's not allowed to happen in the first place. Please double check your UI code." - ForegroundColor Red
626
+ }
627
+ $sync.SettingsPopup.IsOpen = $false
606
628
$authorInfo = @"
607
629
<a href="https://github.com/sponsors/ChrisTitusTech">Current sponsors for ChrisTitusTech:</a>
608
630
"@
0 commit comments