@@ -76,6 +76,8 @@ function Invoke-WPFUIElements {
7676 Description = $entryInfo.description
7777 Type = $entryInfo.type
7878 ComboItems = $entryInfo.ComboItems
79+ ComboDescriptions = $entryInfo.ComboDescriptions
80+ Registry = $entryInfo.registry
7981 Checked = $entryInfo.Checked
8082 ButtonWidth = $entryInfo.ButtonWidth
8183 GroupName = $entryInfo.GroupName # Added for RadioButton groupings
@@ -247,6 +249,7 @@ function Invoke-WPFUIElements {
247249 $label = New-Object Windows.Controls.Label
248250 $label.Content = $entryInfo.Content
249251 $label.HorizontalAlignment = " Left"
252+ $label.ToolTip = $entryInfo.Description
250253 $label.VerticalAlignment = " Center"
251254 $label.SetResourceReference ([Windows.Controls.Control ]::FontSizeProperty, " ButtonFontSize" )
252255 $label.UseLayoutRounding = $true
@@ -261,11 +264,27 @@ function Invoke-WPFUIElements {
261264 $comboBox.SetResourceReference ([Windows.Controls.Control ]::MarginProperty, " ButtonMargin" )
262265 $comboBox.SetResourceReference ([Windows.Controls.Control ]::FontSizeProperty, " ButtonFontSize" )
263266 $comboBox.UseLayoutRounding = $true
267+ $comboBox.Tag = [pscustomobject ]@ {
268+ Registry = $entryInfo.Registry
269+ State = $null
270+ }
264271 [System.Windows.Automation.AutomationProperties ]::SetName($comboBox , $entryInfo.Content )
265272
266- foreach ($comboitem in ($entryInfo.ComboItems -split " " )) {
273+ $comboItems = if ($entryInfo.ComboItems -is [string ]) {
274+ $entryInfo.ComboItems -split " "
275+ } else {
276+ @ ($entryInfo.ComboItems )
277+ }
278+
279+ foreach ($comboitem in $comboItems ) {
267280 $comboBoxItem = New-Object Windows.Controls.ComboBoxItem
268281 $comboBoxItem.Content = $comboitem
282+ if ($entryInfo.ComboDescriptions ) {
283+ $comboDescription = $entryInfo.ComboDescriptions.PSObject.Properties [$comboitem ].Value
284+ if ($comboDescription ) {
285+ $comboBoxItem.ToolTip = $comboDescription
286+ }
287+ }
269288 $comboBoxItem.SetResourceReference ([Windows.Controls.Control ]::FontSizeProperty, " ButtonFontSize" )
270289 $comboBoxItem.UseLayoutRounding = $true
271290 $comboBox.Items.Add ($comboBoxItem ) | Out-Null
@@ -274,22 +293,82 @@ function Invoke-WPFUIElements {
274293 $horizontalStackPanel.Children.Add ($comboBox ) | Out-Null
275294 $itemsControl.Items.Add ($horizontalStackPanel ) | Out-Null
276295
277- $comboBox.SelectedIndex = 0
296+ if ($entryInfo.Registry -and @ ($entryInfo.Registry )[0 ].Values) {
297+ try {
298+ $comboBox.Tag.State = Get-WinUtilRegistryComboState - Registry $entryInfo.Registry
299+ $comboBox.SelectedIndex = @ ($comboBox.Items.Content ).IndexOf([string ]$comboBox.Tag.State )
300+ } catch {
301+ $unknownStateItem = New-Object Windows.Controls.ComboBoxItem
302+ $unknownStateItem.Content = " Custom / Unknown - select a state"
303+ $unknownStateItem.IsEnabled = $false
304+ $unknownStateItem.ToolTip = " $ ( $_.Exception.Message ) Select one of the supported states to replace these values."
305+ $comboBox.Items.Add ($unknownStateItem ) | Out-Null
306+ $comboBox.SelectedItem = $unknownStateItem
307+ $comboBox.ToolTip = $unknownStateItem.ToolTip
308+ }
309+ } else {
310+ $comboBox.SelectedIndex = 0
311+ }
278312
279313 # Set initial text
280314 if ($comboBox.Items.Count -gt 0 ) {
281- $comboBox.Text = $comboBox.Items [ 0 ] .Content
315+ $comboBox.Text = $comboBox.SelectedItem .Content
282316 }
283317
318+ $sync [$entryInfo.Name ] = $comboBox
319+
284320 # Add SelectionChanged event handler to update the text property
285321 $comboBox.Add_SelectionChanged ({
286322 $selectedItem = $this.SelectedItem
287323 if ($selectedItem ) {
288324 $this.Text = $selectedItem.Content
325+ $registry = $this.Tag.Registry
326+ if ($registry -and $selectedItem.IsEnabled -and $selectedItem.Content -ne $this.Tag.State ) {
327+ try {
328+ Set-WinUtilRegistryComboState - Registry $registry - State $selectedItem.Content
329+ $this.Tag.State = $selectedItem.Content
330+ $this.ToolTip = $null
331+ $unknownStateItem = @ ($this.Items ) | Where-Object Content -EQ " Custom / Unknown - select a state" | Select-Object - First 1
332+ if ($unknownStateItem ) {
333+ $this.Items.Remove ($unknownStateItem )
334+ }
335+ } catch {
336+ $applyError = $_.Exception.Message
337+ if ([string ]::IsNullOrWhiteSpace($applyError )) {
338+ $applyError = " Unable to apply registry state '$ ( $selectedItem.Content ) '."
339+ }
340+ $previousState = if ($this.Tag.State ) { $this.Tag.State } else { " Custom / Unknown - select a state" }
341+ $this.SelectedItem = @ ($this.Items ) | Where-Object Content -EQ $previousState | Select-Object - First 1
342+ [System.Windows.MessageBox ]::Show(
343+ $applyError ,
344+ " WinUtil" ,
345+ [System.Windows.MessageBoxButton ]::OK,
346+ [System.Windows.MessageBoxImage ]::Warning
347+ ) | Out-Null
348+ }
349+ }
289350 }
290351 })
291352
292- $sync [$entryInfo.Name ] = $comboBox
353+ if ($entryInfo.Registry -and @ ($entryInfo.Registry )[0 ].Values -and $entryInfo.Link ) {
354+ $textBlock = New-Object Windows.Controls.TextBlock
355+ $textBlock.Name = $comboBox.Name + " Link"
356+ $textBlock.Text = " (?)"
357+ $textBlock.ToolTip = $entryInfo.Link
358+ $textBlock.Style = $HoverTextBlockStyle
359+ $textBlock.UseLayoutRounding = $true
360+ $textBlock.VerticalAlignment = " Center"
361+ $textBlock.SetResourceReference ([Windows.Controls.Control ]::FontSizeProperty, " FontSize" )
362+ $textBlock.Tag = $comboBox
363+
364+ $textBlock.Add_MouseUp ({
365+ [System.Object ]$Sender = $args [0 ]
366+ Start-Process $Sender.ToolTip - ErrorAction Stop
367+ })
368+
369+ $horizontalStackPanel.Children.Add ($textBlock ) | Out-Null
370+ $sync [$textBlock.Name ] = $textBlock
371+ }
293372 }
294373
295374 " Button" {
0 commit comments