mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-16 01:40:35 -06:00
hotfix
This commit is contained in:
parent
47e80010d1
commit
b15f31fdf8
@ -8,14 +8,12 @@ function Invoke-WPFUIElements {
|
|||||||
The name of the grid to which the UI elements should be added.
|
The name of the grid to which the UI elements should be added.
|
||||||
.PARAMETER columncount
|
.PARAMETER columncount
|
||||||
The number of columns to be used in the Grid. If not provided, a default value is used based on the panel.
|
The number of columns to be used in the Grid. If not provided, a default value is used based on the panel.
|
||||||
.PARAMETER categoryPanelMap
|
|
||||||
A hashtable that maps specific categories to specific panels.
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
$categoryPanelMap = @{
|
$categoryPanelMap = @{
|
||||||
"Essential Tweaks" = 0
|
"Essential Tweaks" = 0
|
||||||
"Customize Preferences" = 1
|
"Customize Preferences" = 1
|
||||||
}
|
}
|
||||||
Invoke-WPFUIElements -configVariable $sync.configs.applications -targetGridName "install" -columncount 4 -categoryPanelMap $categoryPanelMap
|
Invoke-WPFUIElements -configVariable $sync.configs.applications -targetGridName "install" -columncount 5
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param(
|
param(
|
||||||
@ -25,6 +23,7 @@ function Invoke-WPFUIElements {
|
|||||||
[Parameter(Mandatory)]
|
[Parameter(Mandatory)]
|
||||||
[string]$targetGridName,
|
[string]$targetGridName,
|
||||||
|
|
||||||
|
[Parameter(Mandatory)]
|
||||||
[int]$columncount
|
[int]$columncount
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -39,44 +38,41 @@ function Invoke-WPFUIElements {
|
|||||||
$organizedData = @{}
|
$organizedData = @{}
|
||||||
# Iterate through JSON data and organize by panel and category
|
# Iterate through JSON data and organize by panel and category
|
||||||
foreach ($entry in $configHashtable.Keys) {
|
foreach ($entry in $configHashtable.Keys) {
|
||||||
$appInfo = $configHashtable[$entry]
|
$entryInfo = $configHashtable[$entry]
|
||||||
|
|
||||||
# Create an object for the application
|
# Create an object for the application
|
||||||
$appObject = [PSCustomObject]@{
|
$entryObject = [PSCustomObject]@{
|
||||||
Name = $entry
|
Name = $entry.Name
|
||||||
Category = $appInfo.Category
|
Category = $entryInfo.Category
|
||||||
Content = $appInfo.Content
|
Content = $entryInfo.Content
|
||||||
Choco = $appInfo.choco
|
Choco = $entryInfo.choco
|
||||||
Winget = $appInfo.winget
|
Winget = $entryInfo.winget
|
||||||
Panel = if ($appInfo.Panel -ne $null) { $appInfo.Panel } else { "0" }
|
Panel = if ($entryInfo.Panel -ne $null) { $entryInfo.Panel } else { "0" }
|
||||||
Link = $appInfo.link
|
Link = $entryInfo.link
|
||||||
Description = $appInfo.description
|
Description = $entryInfo.description
|
||||||
Type = $appInfo.type
|
Type = $entryInfo.type
|
||||||
ComboItems = $appInfo.ComboItems
|
ComboItems = $entryInfo.ComboItems
|
||||||
Checked = $appInfo.Checked
|
Checked = $entryInfo.Checked
|
||||||
ButtonWidth = $appInfo.ButtonWidth
|
ButtonWidth = $entryInfo.ButtonWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not $organizedData.ContainsKey($appObject.Panel)) {
|
if (-not $organizedData.ContainsKey($entryObject.Panel)) {
|
||||||
$organizedData[$appObject.Panel] = @{}
|
$organizedData[$entryObject.Panel] = @{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not $organizedData[$appObject.Panel].ContainsKey($appObject.Category)) {
|
if (-not $organizedData[$entryObject.Panel].ContainsKey($entryObject.Category)) {
|
||||||
$organizedData[$appObject.Panel][$appObject.Category] = @{}
|
$organizedData[$entryObject.Panel][$entryObject.Category] = @{}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Store application data in a sub-array under the category
|
# Store application data in a sub-array under the category
|
||||||
$organizedData[$appObject.Panel][$appInfo.Category]["$($appInfo.order)$entry"] = $appObject
|
$organizedData[$entryObject.Panel][$entryInfo.Category]["$($entryInfo.order)$entry"] = $entryObject
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Retrieve the main window and the target Grid by name
|
# Retrieve the main window and the target Grid by name
|
||||||
$window = $sync["Form"]
|
$window = $sync["Form"]
|
||||||
$targetGrid = $window.FindName($targetGridName)
|
$targetGrid = $window.FindName($targetGridName)
|
||||||
|
|
||||||
if ($null -eq $targetGrid) {
|
|
||||||
throw "Grid '$targetGridName' not found."
|
|
||||||
}
|
|
||||||
|
|
||||||
# Calculate the needed number of panels and columns
|
# Calculate the needed number of panels and columns
|
||||||
$panelcount = 0
|
$panelcount = 0
|
||||||
$paneltotal = $columncount # Use columncount for even distribution
|
$paneltotal = $columncount # Use columncount for even distribution
|
||||||
@ -169,19 +165,20 @@ function Invoke-WPFUIElements {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$appInfo = $organizedData[$panelKey][$category][$entry]
|
$entryInfo = $organizedData[$panelKey][$category][$entry]
|
||||||
switch ($appInfo.Type) {
|
switch ($entryInfo.Type) {
|
||||||
"Toggle" {
|
"Toggle" {
|
||||||
$dockPanel = New-Object Windows.Controls.DockPanel
|
$dockPanel = New-Object Windows.Controls.DockPanel
|
||||||
$checkBox = New-Object Windows.Controls.CheckBox
|
$checkBox = New-Object Windows.Controls.CheckBox
|
||||||
$checkBox.Name = $appInfo.Name
|
$checkBox.Name = $entryInfo.Name
|
||||||
|
write-host $entryInfo.Name
|
||||||
$checkBox.HorizontalAlignment = "Right"
|
$checkBox.HorizontalAlignment = "Right"
|
||||||
$dockPanel.Children.Add($checkBox) | Out-Null
|
$dockPanel.Children.Add($checkBox) | Out-Null
|
||||||
$checkBox.Style = $window.FindResource("ColorfulToggleSwitchStyle")
|
$checkBox.Style = $window.FindResource("ColorfulToggleSwitchStyle")
|
||||||
|
|
||||||
$label = New-Object Windows.Controls.Label
|
$label = New-Object Windows.Controls.Label
|
||||||
$label.Content = $appInfo.Content
|
$label.Content = $entryInfo.Content
|
||||||
$label.ToolTip = $appInfo.Description
|
$label.ToolTip = $entryInfo.Description
|
||||||
$label.HorizontalAlignment = "Left"
|
$label.HorizontalAlignment = "Left"
|
||||||
$label.FontSize = $theme.FontSize
|
$label.FontSize = $theme.FontSize
|
||||||
# Implement for consistent theming later on $label.Style = $window.FindResource("labelfortweaks")
|
# Implement for consistent theming later on $label.Style = $window.FindResource("labelfortweaks")
|
||||||
@ -196,21 +193,21 @@ function Invoke-WPFUIElements {
|
|||||||
$horizontalStackPanel.Margin = "0,5,0,0"
|
$horizontalStackPanel.Margin = "0,5,0,0"
|
||||||
|
|
||||||
$label = New-Object Windows.Controls.Label
|
$label = New-Object Windows.Controls.Label
|
||||||
$label.Content = $appInfo.Content
|
$label.Content = $entryInfo.Content
|
||||||
$label.HorizontalAlignment = "Left"
|
$label.HorizontalAlignment = "Left"
|
||||||
$label.VerticalAlignment = "Center"
|
$label.VerticalAlignment = "Center"
|
||||||
$label.FontSize = $theme.ButtonFontSize
|
$label.FontSize = $theme.ButtonFontSize
|
||||||
$horizontalStackPanel.Children.Add($label) | Out-Null
|
$horizontalStackPanel.Children.Add($label) | Out-Null
|
||||||
|
|
||||||
$comboBox = New-Object Windows.Controls.ComboBox
|
$comboBox = New-Object Windows.Controls.ComboBox
|
||||||
$comboBox.Name = $appInfo.Name
|
$comboBox.Name = $entryInfo.Name
|
||||||
$comboBox.Height = $theme.ButtonHeight
|
$comboBox.Height = $theme.ButtonHeight
|
||||||
$comboBox.Width = $theme.ButtonWidth
|
$comboBox.Width = $theme.ButtonWidth
|
||||||
$comboBox.HorizontalAlignment = "Left"
|
$comboBox.HorizontalAlignment = "Left"
|
||||||
$comboBox.VerticalAlignment = "Center"
|
$comboBox.VerticalAlignment = "Center"
|
||||||
$comboBox.Margin = "5,5"
|
$comboBox.Margin = "5,5"
|
||||||
|
|
||||||
foreach ($comboitem in ($appInfo.ComboItems -split " ")) {
|
foreach ($comboitem in ($entryInfo.ComboItems -split " ")) {
|
||||||
$comboBoxItem = New-Object Windows.Controls.ComboBoxItem
|
$comboBoxItem = New-Object Windows.Controls.ComboBoxItem
|
||||||
$comboBoxItem.Content = $comboitem
|
$comboBoxItem.Content = $comboitem
|
||||||
$comboBoxItem.FontSize = $theme.ButtonFontSize
|
$comboBoxItem.FontSize = $theme.ButtonFontSize
|
||||||
@ -223,36 +220,36 @@ function Invoke-WPFUIElements {
|
|||||||
|
|
||||||
"Button" {
|
"Button" {
|
||||||
$button = New-Object Windows.Controls.Button
|
$button = New-Object Windows.Controls.Button
|
||||||
$button.Name = $appInfo.Name
|
$button.Name = $entryInfo.Name
|
||||||
$button.Content = $appInfo.Content
|
$button.Content = $entryInfo.Content
|
||||||
$button.HorizontalAlignment = "Left"
|
$button.HorizontalAlignment = "Left"
|
||||||
$button.Margin = "5"
|
$button.Margin = "5"
|
||||||
$button.Padding = "20,5"
|
$button.Padding = "20,5"
|
||||||
$button.FontSize = $theme.ButtonFontSize
|
$button.FontSize = $theme.ButtonFontSize
|
||||||
if ($appInfo.ButtonWidth -ne $null) {
|
if ($entryInfo.ButtonWidth -ne $null) {
|
||||||
$button.Width = $appInfo.ButtonWidth
|
$button.Width = $entryInfo.ButtonWidth
|
||||||
}
|
}
|
||||||
$stackPanel.Children.Add($button) | Out-Null
|
$stackPanel.Children.Add($button) | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
default {
|
default {
|
||||||
$checkBox = New-Object Windows.Controls.CheckBox
|
$checkBox = New-Object Windows.Controls.CheckBox
|
||||||
$checkBox.Name = $appInfo.Name
|
$checkBox.Name = $entryInfo.Name
|
||||||
$checkBox.Content = $appInfo.Content
|
$checkBox.Content = $entryInfo.Content
|
||||||
$checkBox.FontSize = $theme.FontSize
|
$checkBox.FontSize = $theme.FontSize
|
||||||
$checkBox.ToolTip = $appInfo.Description
|
$checkBox.ToolTip = $entryInfo.Description
|
||||||
$checkBox.Margin = $theme.CheckBoxMargin
|
$checkBox.Margin = $theme.CheckBoxMargin
|
||||||
if ($appInfo.Checked -ne $null) {
|
if ($entryInfo.Checked -ne $null) {
|
||||||
$checkBox.IsChecked = $appInfo.Checked
|
$checkBox.IsChecked = $entryInfo.Checked
|
||||||
}
|
}
|
||||||
if ($appInfo.Link -ne $null) {
|
if ($entryInfo.Link -ne $null) {
|
||||||
$horizontalStackPanel = New-Object Windows.Controls.StackPanel
|
$horizontalStackPanel = New-Object Windows.Controls.StackPanel
|
||||||
$horizontalStackPanel.Orientation = "Horizontal"
|
$horizontalStackPanel.Orientation = "Horizontal"
|
||||||
$horizontalStackPanel.Children.Add($checkBox) | Out-Null
|
$horizontalStackPanel.Children.Add($checkBox) | Out-Null
|
||||||
|
|
||||||
$textBlock = New-Object Windows.Controls.TextBlock
|
$textBlock = New-Object Windows.Controls.TextBlock
|
||||||
$textBlock.Text = "(?)"
|
$textBlock.Text = "(?)"
|
||||||
$textBlock.ToolTip = $appInfo.Link
|
$textBlock.ToolTip = $entryInfo.Link
|
||||||
$textBlock.Style = $window.FindResource("HoverTextBlockStyle")
|
$textBlock.Style = $window.FindResource("HoverTextBlockStyle")
|
||||||
|
|
||||||
# Add event handler for click to open link
|
# Add event handler for click to open link
|
||||||
|
Loading…
Reference in New Issue
Block a user