diff --git a/winutil.ps1 b/winutil.ps1 index 5aaf9183..6f5e79a9 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -8,7 +8,7 @@ Author : Chris Titus @christitustech Runspace Author: @DeveloperDurp GitHub : https://github.com/ChrisTitusTech - Version : 24.06.29 + Version : 24.07.08 #> param ( [switch]$Debug, @@ -45,7 +45,7 @@ Add-Type -AssemblyName System.Windows.Forms # Variable to sync between runspaces $sync = [Hashtable]::Synchronized(@{}) $sync.PSScriptRoot = $PSScriptRoot -$sync.version = "24.06.29" +$sync.version = "24.07.08" $sync.configs = @{} $sync.ProcessRunning = $false @@ -206,8 +206,10 @@ function Get-TabXaml { It takes the tabname and the number of columns to display the applications in as input and returns the XAML for the tab as output .PARAMETER tabname The name of the tab to generate XAML for + Note: the 'tabname' parameter must equal one of the json files found in $sync.configs variable + Otherwise, it'll throw an exception .PARAMETER columncount - The number of columns to display the applications in + The number of columns to display the applications in, default is 0 .OUTPUTS The XAML for the tab .EXAMPLE @@ -215,10 +217,20 @@ function Get-TabXaml { #> - param( [Parameter(Mandatory=$true)] - $tabname, - $columncount = 0 + param( + [Parameter(Mandatory, position=0)] + [string]$tabname, + + [Parameter(position=1)] + [ValidateRange(0,10)] # 10 panels as max number is more then enough + [int]$columncount = 0 ) + + # Validate tabname + if ($sync.configs.$tabname -eq $null) { + throw "Invalid parameter passed, can't find '$tabname' in '`$sync.configs' variable, please double check any calls to 'Get-TabXaml' function." + } + $organizedData = @{} # Iterate through JSON data and organize by panel and category foreach ($appName in $sync.configs.$tabname.PSObject.Properties.Name) { @@ -239,6 +251,7 @@ function Get-TabXaml { ComboItems = $appInfo.ComboItems # Checked is the property to set startup checked status of checkbox (Default is false) Checked = $appInfo.Checked + ButtonWidth = $appInfo.ButtonWidth } if (-not $organizedData.ContainsKey($appObject.panel)) { @@ -253,7 +266,22 @@ function Get-TabXaml { # Add Order property to keep the original order of tweaks and features $organizedData[$appObject.panel][$appInfo.Category]["$($appInfo.order)$appName"] = $appObject } - $panelcount=0 + + # Same tab amount in last line of 'inputXML.xaml' file + # TODO: Get the base repeat (amount) of tabs from last line (or even lines) + # so it can dynamicly react to whatever is before this generated XML string. + # .. may be solve this even before calling this function, and pass the result as a parameter? + $tab_repeat = 7 + $spaces_per_tab = 4 # The convenction used across the code base + $tab_as_spaces = $(" " * $spaces_per_tab) + $precal_indent = $($tab_as_spaces * $tab_repeat) + $precal_indent_p1 = $($tab_as_spaces * ($tab_repeat + 1)) + $precal_indent_p2 = $($tab_as_spaces * ($tab_repeat + 2)) + $precal_indent_m1 = $($tab_as_spaces * ($tab_repeat - 1)) + $precal_indent_m2 = $($tab_as_spaces * ($tab_repeat - 2)) + + # Calculate the needed number of panels + $panelcount = 0 $paneltotal = $organizedData.Keys.Count if ($columncount -gt 0) { $appcount = $sync.configs.$tabname.PSObject.Properties.Name.count + $organizedData["0"].Keys.count @@ -261,19 +289,27 @@ function Get-TabXaml { $paneltotal = $columncount } # add ColumnDefinitions to evenly draw colums - $blockXml="`r`n"+("`r`n"*($paneltotal))+"`r`n" - # Iterate through organizedData by panel, category, and application + $blockXml = "" + $blockXml += $("`r`n" + " " * ($spaces_per_tab * $tab_repeat) + + "") * $paneltotal + $blockXml += $("`r`n" + " " * ($spaces_per_tab * ($tab_repeat - 1))) + + "" + "`r`n" + + # Iterate through 'organizedData' by panel, category, and application $count = 0 foreach ($panel in ($organizedData.Keys | Sort-Object)) { - $blockXml += "`r`n`r`n" + $blockXml += $precal_indent_m1 + "" + "`r`n" + $blockXml += $precal_indent + "" + "`r`n" $panelcount++ foreach ($category in ($organizedData[$panel].Keys | Sort-Object)) { $count++ if ($columncount -gt 0) { $panelcount2 = [Int](($count)/$maxcount-0.5) if ($panelcount -eq $panelcount2 ) { - $blockXml +="`r`n`r`n`r`n" - $blockXml += "`r`n`r`n" + $blockXml += $precal_indent_p2 + "" + "`r`n" + $blockXml += $precal_indent_p1 + "" + "`r`n" + $blockXml += $precal_indent_p1 + "" + "`r`n" + $blockXml += $precal_indent_p2 + "" + "`r`n" $panelcount++ } } @@ -283,49 +319,99 @@ function Get-TabXaml { $categorycontent = $($category -replace '^.__', '') $categoryname = Get-WPFObjectName -type "Label" -name $categorycontent - $blockXml += "`r`n`r`n" - $blockXml += "`r`n`r`n" + $blockXml += $precal_indent_m1 + + "" + "`r`n" + $blockXml += $precal_indent_m2 + + "" + "`r`n" + $blockXml += $precal_indent_m2 + + "" + "`r`n" + $blockXml += $precal_indent_m1 + + "" + "`r`n" $panelcount++ } } + $appInfo = $organizedData[$panel][$category][$appName] - if ("Toggle" -eq $appInfo.Type) { - $blockXml += "`r`n`r`n" - } elseif ("Combobox" -eq $appInfo.Type) { - $blockXml += "`r`n" - # If it is a digit, type is button and button length is digits - } elseif ($appInfo.Type -match "^[\d\.]+$") { - $blockXml += "