@@ -77,66 +77,104 @@ function Show-AnyBox
7777 . OUTPUTS
7878 A hashtable of key-value pairs containing what input was received (e.g., text input, button clicked).
7979 #>
80- [cmdletbinding ()]
80+ [cmdletbinding (DefaultParameterSetName = ' obj ' )]
8181 param (
82- [ValidateSet ($null , ' Information' , ' Warning' , ' Error' , ' Question' )]
82+ [Parameter (ParameterSetName = ' obj' , ValueFromPipeline = $true )]
83+ [AnyBox.AnyBox ]$AnyBox ,
84+ [Parameter (ParameterSetName = ' create' )]
8385 [string ]$Icon ,
86+ [Parameter (ParameterSetName = ' create' )]
8487 [string ]$Title ,
88+ [Parameter (ParameterSetName = ' create' )]
8589 [string ]$Image ,
90+ [Parameter (ParameterSetName = ' create' )]
8691 [string []]$Message ,
92+ [Parameter (ParameterSetName = ' create' )]
8793 [Alias (' Prompt' )]
8894 [object []]$Prompts ,
95+ [Parameter (ParameterSetName = ' create' )]
8996 [object []]$Buttons ,
97+ [Parameter (ParameterSetName = ' create' )]
9098 [string ]$CancelButton ,
99+ [Parameter (ParameterSetName = ' create' )]
91100 [string ]$DefaultButton ,
101+ [Parameter (ParameterSetName = ' create' )]
92102 [ValidateScript ({$_ -gt 0 })]
93103 [uint16 ]$ButtonRows = 1 ,
104+ [Parameter (ParameterSetName = ' create' )]
94105 [string []]$Comment ,
106+ [Parameter (ParameterSetName = ' create' )]
95107 [ValidateSet (' Left' , ' Center' )]
96108 [string ]$ContentAlignment = ' Left' ,
109+ [Parameter (ParameterSetName = ' create' )]
97110 [switch ]$CollapsibleGroups ,
111+ [Parameter (ParameterSetName = ' create' )]
98112 [switch ]$CollapsedGroups ,
113+ [Parameter (ParameterSetName = ' create' )]
99114 [scriptblock ]$PrepScript ,
100115
116+ [Parameter (ParameterSetName = ' create' )]
101117 [ValidateNotNullOrEmpty ()]
102- [string ]$FontFamily = ' Segoe UI' ,
118+ [System.Windows.Media.FontFamily ]$FontFamily = ' Segoe UI' ,
119+ [Parameter (ParameterSetName = ' create' )]
103120 [ValidateScript ({$_ -gt 0 })]
104121 [uint16 ]$FontSize = 12 ,
122+ [Parameter (ParameterSetName = ' create' )]
105123 [ValidateNotNullOrEmpty ()]
106- [string ]$FontColor = ' Black' ,
107- [string ]$BackgroundColor ,
108- [string ]$AccentColor = ' Gainsboro' ,
109- [ValidateSet (' None' , ' SingleBorderWindow' , ' ThreeDBorderWindow' , ' ToolWindow' )]
124+ [System.Windows.Media.Brush ]$FontColor = ' Black' ,
125+ [Parameter (ParameterSetName = ' create' )]
126+ [System.Windows.Media.Brush ]$BackgroundColor ,
127+ [Parameter (ParameterSetName = ' create' )]
128+ [System.Windows.Media.Brush ]$AccentColor = ' Gainsboro' ,
129+ [Parameter (ParameterSetName = ' create' )]
110130 [System.Windows.WindowStyle ]$WindowStyle = ' SingleBorderWindow' ,
111- [ValidateSet ( ' NoResize ' , ' CanMinimize ' , ' CanResize ' , ' CanResizeWithGrip ' )]
131+ [Parameter ( ParameterSetName = ' create ' )]
112132 [System.Windows.ResizeMode ]$ResizeMode = ' CanMinimize' ,
133+ [Parameter (ParameterSetName = ' create' )]
113134 [switch ]$NoResize ,
135+ [Parameter (ParameterSetName = ' create' )]
114136 [ValidateScript ({$_ -gt 0 })]
115137 [uint16 ]$MinHeight = 50 ,
138+ [Parameter (ParameterSetName = ' create' )]
116139 [ValidateScript ({$_ -gt 0 })]
117140 [uint16 ]$MinWidth = 50 ,
141+ [Parameter (ParameterSetName = ' create' )]
118142 [uint16 ]$MaxHeight = 0 ,
143+ [Parameter (ParameterSetName = ' create' )]
119144 [uint16 ]$MaxWidth = 0 ,
145+ [Parameter (ParameterSetName = ' create' )]
120146 [switch ]$Topmost ,
147+ [Parameter (ParameterSetName = ' create' )]
121148 [switch ]$HideTaskbarIcon ,
149+ [Parameter (ParameterSetName = ' create' )]
122150 [uint32 ]$Timeout ,
151+ [Parameter (ParameterSetName = ' create' )]
123152 [switch ]$Countdown ,
153+ [Parameter (ParameterSetName = ' create' )]
124154 [System.Windows.Window ]$ParentWindow = $null ,
125-
126- [array ]$GridData ,
155+ [Parameter (ParameterSetName = ' create' )]
156+ [object []]$GridData ,
157+ [Parameter (ParameterSetName = ' create' )]
127158 [switch ]$GridAsList ,
128- [ValidateSet (' None' , ' SingleCell' , ' SingleRow' , ' MultiRow' )]
129- [string ]$SelectionMode = ' SingleCell' ,
159+ [Parameter (ParameterSetName = ' create' )]
160+ [AnyBox.DataGridSelectionMode ]$SelectionMode = ' SingleCell' ,
161+ [Parameter (ParameterSetName = ' create' )]
130162 [Alias (' HideGridSearch' )]
131163 [switch ]$NoGridSearch
132164 )
133165
166+ if ($AnyBox ) {
167+ $AnyBox.psobject.properties | ForEach-Object {
168+ Set-Variable - Name $_.Name - Value $_.Value - Force
169+ }
170+ }
171+
134172 if ($NoResize -or ($HideTaskbarIcon -and $ResizeMode -ne ' NoResize' -and @ (' None' , ' ToolWindow' ) -notcontains $WindowStyle )) {
135173 # No minimize button
136174 $ResizeMode = ' NoResize'
137175 }
138176
139- $form = @ {' Result' = @ {}} # [hashtable]::Synchronized(@{ 'Result' = @{})
177+ $form = @ {' Result' = @ {}}
140178
141179 [xml ]$xaml = @"
142180<Window
@@ -150,7 +188,7 @@ function Show-AnyBox
150188 <ColumnDefinition Width="*" />
151189 </Grid.ColumnDefinitions>
152190 <Grid.RowDefinitions>
153- <RowDefinition Height="* " />
191+ <RowDefinition Height="Auto " />
154192 <RowDefinition Height="*" />
155193 <RowDefinition Height="Auto" />
156194 </Grid.RowDefinitions>
@@ -282,7 +320,7 @@ function Show-AnyBox
282320 }
283321
284322 $tab_panel = $null
285- if ($Prompts | where { $_.Tab }) {
323+ if ($Prompts | Where-Object { $_.Tab }) {
286324 $tab_panel = New-Object System.Windows.Controls.TabControl
287325 $tab_panel.HorizontalAlignment = ' Stretch'
288326 $tab_panel.VerticalAlignment = ' Stretch'
@@ -292,7 +330,7 @@ function Show-AnyBox
292330 $form.Add (' Tabs' , $tab_panel )
293331 }
294332
295- $Prompts | Group-Object - Property ' Tab' | sort Name | foreach {
333+ $Prompts | Group-Object - Property ' Tab' | Sort-Object Name | ForEach-Object {
296334 $tabName = $_.Values [0 ]
297335
298336 $tab_stack = $null
@@ -304,7 +342,7 @@ function Show-AnyBox
304342 $tab_stack.Margin = ' 5, 0, 5, 0'
305343 }
306344
307- $_.Group | Group-Object - Property ' Group' | sort Name | foreach {
345+ $_.Group | Group-Object - Property ' Group' | Sort-Object Name | ForEach-Object {
308346
309347 $groupName = $_.Values [0 ]
310348
@@ -368,12 +406,12 @@ function Show-AnyBox
368406 $inBox.VerticalAlignment = ' Center'
369407 $inBox.VerticalContentAlignment = ' Center'
370408
371- $prmpt.ValidateSet | foreach {
409+ $prmpt.ValidateSet | ForEach-Object {
372410 $null = $inBox.Items.Add ((New-TextBlock - RefForm ([ref ]$form ) - Text $_ - FontFamily $prmpt.FontFamily - FontSize $prmpt.FontSize - FontColor ' Black' - Margin 0 - ContentAlignment $prmpt.Alignment ))
373411 }
374412
375413 if ($prmpt.DefaultValue ) {
376- $inBox.SelectedItem = $inBox.Items | where { $_.Text -eq $prmpt.DefaultValue } | select - First 1
414+ $inBox.SelectedItem = $inBox.Items | Where-Object { $_.Text -eq $prmpt.DefaultValue } | Select-Object - First 1
377415 }
378416
379417 $inBox.add_SelectionChanged ({
@@ -388,7 +426,7 @@ function Show-AnyBox
388426 $inBox.Orientation = ' Horizontal'
389427 }
390428
391- $prmpt.ValidateSet | foreach {
429+ $prmpt.ValidateSet | ForEach-Object {
392430 $r = New-Object System.Windows.Controls.RadioButton
393431 if ($prmpt.RadioGroup ) {
394432 $r.GroupName = $prmpt.RadioGroup
@@ -942,7 +980,7 @@ function Show-AnyBox
942980 }
943981 }
944982
945- $Buttons | where { $_ -is [string ] -or -not $_.OnClick } | ForEach-Object {
983+ $Buttons | Where-Object { $_ -is [string ] -or -not $_.OnClick } | ForEach-Object {
946984 if ($_ -is [AnyBox.Button ]) {
947985 if ($_.Name ) {
948986 $form.Result.Add ($_.Name , $false )
@@ -960,7 +998,7 @@ function Show-AnyBox
960998
961999 [uint16 ]$c = 0
9621000
963- 1 .. $ButtonRows | foreach {
1001+ 1 .. $ButtonRows | ForEach-Object {
9641002 # Create a horizontal stack-panel for buttons and populate it.
9651003 $btnStack = New-Object System.Windows.Controls.StackPanel
9661004 $btnStack.Orientation = ' Horizontal'
@@ -1073,7 +1111,7 @@ $form.Result | Foreach-Object -Process {{
10731111 }
10741112
10751113 if ($PrepScript ) {
1076- $null = $form | foreach - Process $PrepScript
1114+ $null = $form | ForEach-Object - Process $PrepScript
10771115 }
10781116
10791117 if ($GridData ) {
0 commit comments