From 07306ff20989618a54aa4d967105994c89aaefd4 Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Tue, 17 Jun 2025 16:11:18 -0700 Subject: [PATCH] Refactors model filter event handling to core module Moves the `TextChanged` event handler for the driver model filter from the UI script to the core `Register-EventHandlers` function. This change centralizes the logic and makes the handler more generic by retrieving the UI state from the window's tag instead of relying on a global variable. --- FFUDevelopment/BuildFFUVM_UI.ps1 | 4 ---- FFUDevelopment/FFUUI.Core/FFUUI.Core.Initialize.psm1 | 6 ++++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/FFUDevelopment/BuildFFUVM_UI.ps1 b/FFUDevelopment/BuildFFUVM_UI.ps1 index 04a2ab1..be8c4ae 100644 --- a/FFUDevelopment/BuildFFUVM_UI.ps1 +++ b/FFUDevelopment/BuildFFUVM_UI.ps1 @@ -169,10 +169,6 @@ $window.Add_Loaded({ $script:uiState.Controls.spModelFilterSection.Visibility = 'Collapsed' $script:uiState.Controls.lstDriverModels.Visibility = 'Collapsed' $script:uiState.Controls.spDriverActionButtons.Visibility = 'Collapsed' - $script:uiState.Controls.txtModelFilter.Add_TextChanged({ - param($sourceObject, $textChangedEventArgs) - Search-DriverModels -filterText $script:uiState.Controls.txtModelFilter.Text -State $script:uiState - }) $script:uiState.Controls.btnDownloadSelectedDrivers.Add_Click({ param($buttonSender, $clickEventArgs) diff --git a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Initialize.psm1 b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Initialize.psm1 index c50dfe1..ef49c81 100644 --- a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Initialize.psm1 +++ b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Initialize.psm1 @@ -577,6 +577,12 @@ function Register-EventHandlers { $eventSource.IsEnabled = $true } }) + $State.Controls.txtModelFilter.Add_TextChanged({ + param($sourceObject, $textChangedEventArgs) + $window = [System.Windows.Window]::GetWindow($sourceObject) + $localState = $window.Tag + Search-DriverModels -filterText $localState.Controls.txtModelFilter.Text -State $localState + }) } Export-ModuleMember -Function *