refractor

- removed Get-TabXaml.ps1
- removed compilation part from compile.ps1
- removed existing changes from main.ps1
- added Invoke-WinUtilUIElements.ps1
- refractor existing changes into new function
- modified inputXML to call function
This commit is contained in:
MyDrift 2024-07-31 19:21:45 +02:00
parent 4402c5cf31
commit dfe7dc4044
5 changed files with 290 additions and 406 deletions

View File

@ -97,15 +97,6 @@ Get-ChildItem .\config | Where-Object {$psitem.extension -eq ".json"} | ForEach-
$xaml = (Get-Content .\xaml\inputXML.xaml).replace("'","''") $xaml = (Get-Content .\xaml\inputXML.xaml).replace("'","''")
# Dot-source the Get-TabXaml function
. .\functions\private\Get-TabXaml.ps1
Update-Progress "Building: Xaml " 75
$appXamlContent = Get-TabXaml "applications" 5
$tweaksXamlContent = Get-TabXaml "tweaks"
$featuresXamlContent = Get-TabXaml "feature"
Update-Progress "Adding: Xaml " 90 Update-Progress "Adding: Xaml " 90
# Replace the placeholder in $inputXML with the content of inputApp.xaml # Replace the placeholder in $inputXML with the content of inputApp.xaml
#$xaml = $xaml -replace "{{InstallPanel_applications}}", $appXamlContent #$xaml = $xaml -replace "{{InstallPanel_applications}}", $appXamlContent

View File

@ -1,217 +0,0 @@
function Get-TabXaml {
<#
.SYNOPSIS
Generates XAML for a tab in the WinUtil GUI
This function is used to generate the XAML for the applications tab in the WinUtil GUI
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, default is 0
.OUTPUTS
The XAML for the tab
.EXAMPLE
Get-TabXaml "applications" 3
#>
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) {
$appInfo = $sync.configs.$tabname.$appName
# Create an object for the application
$appObject = [PSCustomObject]@{
Name = $appName
Category = $appInfo.Category
Content = $appInfo.Content
Choco = $appInfo.choco
Winget = $appInfo.winget
Panel = if ($columncount -gt 0 ) { "0" } else {$appInfo.panel}
Link = $appInfo.link
Description = $appInfo.description
# Type is (Checkbox,Toggle,Button,Combobox ) (Default is Checkbox)
Type = $appInfo.type
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)) {
$organizedData[$appObject.panel] = @{}
}
if (-not $organizedData[$appObject.panel].ContainsKey($appObject.Category)) {
$organizedData[$appObject.panel][$appObject.Category] = @{}
}
# Store application data in a sub-array under the category
# Add Order property to keep the original order of tweaks and features
$organizedData[$appObject.panel][$appInfo.Category]["$($appInfo.order)$appName"] = $appObject
}
# 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
$maxcount = [Math]::Round( $appcount / $columncount + 0.5)
$paneltotal = $columncount
}
# add ColumnDefinitions to evenly draw colums
$blockXml = "<Grid.ColumnDefinitions>"
$blockXml += $("`r`n" + " " * ($spaces_per_tab * $tab_repeat) +
"<ColumnDefinition Width=""*""/>") * $paneltotal
$blockXml += $("`r`n" + " " * ($spaces_per_tab * ($tab_repeat - 1))) +
"</Grid.ColumnDefinitions>" + "`r`n"
# Iterate through 'organizedData' by panel, category, and application
$count = 0
foreach ($panel in ($organizedData.Keys | Sort-Object)) {
$blockXml += $precal_indent_m1 + "<Border Grid.Row=""1"" Grid.Column=""$panelcount"">" + "`r`n"
$blockXml += $precal_indent + "<StackPanel Background=""{MainBackgroundColor}"" SnapsToDevicePixels=""True"">" + "`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 += $precal_indent_p2 + "</StackPanel>" + "`r`n"
$blockXml += $precal_indent_p1 + "</Border>" + "`r`n"
$blockXml += $precal_indent_p1 + "<Border Grid.Row=""1"" Grid.Column=""$panelcount"">" + "`r`n"
$blockXml += $precal_indent_p2 + "<StackPanel Background=""{MainBackgroundColor}"" SnapsToDevicePixels=""True"">" + "`r`n"
$panelcount++
}
}
# Dot-source the Get-WPFObjectName function
. .\functions\private\Get-WPFObjectName
$categorycontent = $($category -replace '^.__', '')
$categoryname = Get-WPFObjectName -type "Label" -name $categorycontent
$blockXml += $("`r`n" + " " * ($spaces_per_tab * $tab_repeat)) +
"<Label Name=""$categoryname"" Content=""$categorycontent""" + " " +
"FontSize=""{FontSizeHeading}"" FontFamily=""{HeaderFontFamily}""/>" + "`r`n" + "`r`n"
$sortedApps = $organizedData[$panel][$category].Keys | Sort-Object
foreach ($appName in $sortedApps) {
$count++
if ($columncount -gt 0) {
$panelcount2 = [Int](($count)/$maxcount-0.5)
# Verify the indentation actually works...
if ($panelcount -eq $panelcount2 ) {
$blockXml += $precal_indent_m1 +
"</StackPanel>" + "`r`n"
$blockXml += $precal_indent_m2 +
"</Border>" + "`r`n"
$blockXml += $precal_indent_m2 +
"<Border Grid.Row=""1"" Grid.Column=""$panelcount"">" + "`r`n"
$blockXml += $precal_indent_m1 +
"<StackPanel Background=""{MainBackgroundColor}"" SnapsToDevicePixels=""True"">" + "`r`n"
$panelcount++
}
}
$appInfo = $organizedData[$panel][$category][$appName]
switch ($appInfo.Type) {
"Toggle" {
$blockXml += $precal_indent_m1 +
"<DockPanel LastChildFill=""True"">" + "`r`n"
$blockXml += $precal_indent +
"<CheckBox Name=""$($appInfo.Name)"" Style=""{StaticResource ColorfulToggleSwitchStyle}"" Margin=""4,0""" + " " +
"HorizontalAlignment=""Right"" FontSize=""{FontSize}""/>" + "`r`n"
$blockXml += $precal_indent +
"<Label Content=""$($appInfo.Content)"" ToolTip=""$($appInfo.Description)""" + " " +
"HorizontalAlignment=""Left"" FontSize=""{FontSize}""/>" + "`r`n"
$blockXml += $precal_indent_m1 +
"</DockPanel>" + "`r`n"
}
"Combobox" {
$blockXml += $precal_indent_m1 +
"<StackPanel Orientation=""Horizontal"" Margin=""0,5,0,0"">" + "`r`n"
$blockXml += $precal_indent + "<Label Content=""$($appInfo.Content)"" HorizontalAlignment=""Left""" + " " +
"VerticalAlignment=""Center"" FontSize=""{FontSize}""/>" + "`r`n"
$blockXml += $precal_indent +
"<ComboBox Name=""$($appInfo.Name)"" Height=""32"" Width=""186"" HorizontalAlignment=""Left""" + " " +
"VerticalAlignment=""Center"" Margin=""5,5"" FontSize=""{FontSize}"">" + "`r`n"
$addfirst="IsSelected=""True"""
foreach ($comboitem in ($appInfo.ComboItems -split " ")) {
$blockXml += $precal_indent_p1 +
"<ComboBoxItem $addfirst Content=""$comboitem"" FontSize=""{FontSize}""/>" + "`r`n"
$addfirst=""
}
$blockXml += $precal_indent_p1 + "</ComboBox>" + "`r`n"
$blockXml += $precal_indent + "</StackPanel>" + "`r`n"
}
"Button" {
if ($appInfo.ButtonWidth -ne $null) {
$ButtonWidthStr = "Width=""$($appInfo.ButtonWidth)"""
}
$blockXml += $precal_indent +
"<Button Name=""$($appInfo.Name)"" Content=""$($appInfo.Content)""" + " " +
"HorizontalAlignment=""Left"" Margin=""5"" Padding=""20,5"" $($ButtonWidthStr)/>" + "`r`n"
}
# else it is a checkbox
default {
$checkedStatus = If ($appInfo.Checked -eq $null) {""} Else {" IsChecked=""$($appInfo.Checked)"""}
if ($appInfo.Link -eq $null) {
$blockXml += $precal_indent +
"<CheckBox Name=""$($appInfo.Name)"" Content=""$($appInfo.Content)""$($checkedStatus) Margin=""5,0""" + " " +
"ToolTip=""$($appInfo.Description)""/>" + "`r`n"
} else {
$blockXml += $precal_indent +
"<StackPanel Orientation=""Horizontal"">" + "`r`n"
$blockXml += $precal_indent_p1 +
"<CheckBox Name=""$($appInfo.Name)"" Content=""$($appInfo.Content)""$($checkedStatus)" + " " +
"ToolTip=""$($appInfo.Description)"" Margin=""0,0,2,0""/>" + "`r`n"
$blockXml += $precal_indent_p1 +
"<TextBlock Name=""$($appInfo.Name)Link"" Style=""{StaticResource HoverTextBlockStyle}"" Text=""(?)""" + " " +
"ToolTip=""$($appInfo.Link)""/>" + "`r`n"
$blockXml += $precal_indent +
"</StackPanel>" + "`r`n"
}
}
}
}
}
$blockXml += $precal_indent_p1 + "</StackPanel>" + "`r`n"
$blockXml += $precal_indent + "</Border>" + "`r`n"
}
return ($blockXml)
}

View File

@ -0,0 +1,283 @@
function Invoke-WinUtilUIElements {
<#
.SYNOPSIS
Adds UI elements to a specified Grid in the WinUtil GUI based on a JSON configuration.
.PARAMETER configVariable
The variable/link containing the JSON configuration.
.PARAMETER panel
The name of the panel for which the UI elements should be added.
.EXAMPLE
Invoke-WinUtilUIElements -configVariable $sync.configs.applications -panel "install"
#>
param(
[Parameter(Mandatory)]
[PSCustomObject]$configVariable,
[Parameter(Mandatory)]
[ValidateSet("install", "tweaks", "features")]
[string]$panel
)
# Ensure configVariable is not null
if ($null -eq $configVariable) {
throw "The configuration variable is null."
}
# Determine target grid and column count based on the panel
switch ($panel) {
"install" {
$targetGridName = "appspanel"
$columncount = 5
}
"tweaks" {
$targetGridName = "tweakspanel"
$columncount = 2
}
"features" {
$targetGridName = "featurespanel"
$columncount = 2
}
}
# Convert PSCustomObject to Hashtable
$configHashtable = @{}
$configVariable.PSObject.Properties.Name | ForEach-Object {
$configHashtable[$_] = $configVariable.$_
}
$organizedData = @{}
# Iterate through JSON data and organize by panel and category
foreach ($appName in $configHashtable.Keys) {
$appInfo = $configHashtable[$appName]
# Create an object for the application
$appObject = [PSCustomObject]@{
Name = $appName
Category = $appInfo.Category
Content = $appInfo.Content
Choco = $appInfo.choco
Winget = $appInfo.winget
Panel = "0" # Set to 0 to force even distribution across columns
Link = $appInfo.link
Description = $appInfo.description
Type = $appInfo.type
ComboItems = $appInfo.ComboItems
Checked = $appInfo.Checked
ButtonWidth = $appInfo.ButtonWidth
}
if (-not $organizedData.ContainsKey($appObject.Panel)) {
$organizedData[$appObject.Panel] = @{}
}
if (-not $organizedData[$appObject.Panel].ContainsKey($appObject.Category)) {
$organizedData[$appObject.Panel][$appObject.Category] = @{}
}
# Store application data in a sub-array under the category
$organizedData[$appObject.Panel][$appInfo.Category]["$($appInfo.order)$appName"] = $appObject
}
# Retrieve the main window and the target Grid by name
$window = $sync["Form"]
$targetGrid = $window.FindName($targetGridName)
if ($null -eq $targetGrid) {
throw "Grid '$targetGridName' not found."
}
# Calculate the needed number of panels and columns
$panelcount = 0
$paneltotal = $columncount # Use columncount for even distribution
$appcount = $configHashtable.Keys.Count + $organizedData["0"].Keys.Count
$maxcount = [Math]::Round($appcount / $columncount + 0.5)
# Clear existing ColumnDefinitions and Children
$targetGrid.ColumnDefinitions.Clear() | Out-Null
$targetGrid.Children.Clear() | Out-Null
# Add ColumnDefinitions to the target Grid
for ($i = 0; $i -lt $paneltotal; $i++) {
$colDef = New-Object Windows.Controls.ColumnDefinition
$colDef.Width = New-Object Windows.GridLength(1, [Windows.GridUnitType]::Star)
$targetGrid.ColumnDefinitions.Add($colDef) | Out-Null
}
# Iterate through 'organizedData' by panel, category, and application
$count = 0
foreach ($panelKey in ($organizedData.Keys | Sort-Object)) {
# Create a Border for each column
$border = New-Object Windows.Controls.Border
$border.BorderBrush = [Windows.Media.Brushes]::Gray
$border.BorderThickness = [Windows.Thickness]::new(1)
$border.Margin = [Windows.Thickness]::new(5)
$border.VerticalAlignment = "Stretch" # Ensure the border stretches vertically
[System.Windows.Controls.Grid]::SetColumn($border, $panelcount)
$targetGrid.Children.Add($border) | Out-Null
# Create a StackPanel inside the Border
$stackPanel = New-Object Windows.Controls.StackPanel
$stackPanel.Background = [Windows.Media.Brushes]::Transparent
$stackPanel.SnapsToDevicePixels = $true
$stackPanel.VerticalAlignment = "Stretch" # Ensure the stack panel stretches vertically
$border.Child = $stackPanel
$panelcount++
foreach ($category in ($organizedData[$panelKey].Keys | Sort-Object)) {
$count++
if ($columncount -gt 0) {
$panelcount2 = [Int](($count) / $maxcount - 0.5)
if ($panelcount -eq $panelcount2) {
# Create a new Border for the new column
$border = New-Object Windows.Controls.Border
$border.BorderBrush = [Windows.Media.Brushes]::Gray
$border.BorderThickness = [Windows.Thickness]::new(1)
$border.Margin = [Windows.Thickness]::new(5)
$border.VerticalAlignment = "Stretch" # Ensure the border stretches vertically
[System.Windows.Controls.Grid]::SetColumn($border, $panelcount)
$targetGrid.Children.Add($border) | Out-Null
# Create a new StackPanel inside the Border
$stackPanel = New-Object Windows.Controls.StackPanel
$stackPanel.Background = [Windows.Media.Brushes]::Transparent
$stackPanel.SnapsToDevicePixels = $true
$stackPanel.VerticalAlignment = "Stretch" # Ensure the stack panel stretches vertically
$border.Child = $stackPanel
$panelcount++
}
}
$label = New-Object Windows.Controls.Label
$label.Content = $category
$label.FontSize = 16
$label.FontFamily = "Segoe UI"
$stackPanel.Children.Add($label) | Out-Null
$sortedApps = $organizedData[$panelKey][$category].Keys | Sort-Object
foreach ($appName in $sortedApps) {
$count++
if ($columncount -gt 0) {
$panelcount2 = [Int](($count) / $maxcount - 0.5)
if ($panelcount -eq $panelcount2) {
# Create a new Border for the new column
$border = New-Object Windows.Controls.Border
$border.BorderBrush = [Windows.Media.Brushes]::Gray
$border.BorderThickness = [Windows.Thickness]::new(1)
$border.Margin = [Windows.Thickness]::new(5)
$border.VerticalAlignment = "Stretch" # Ensure the border stretches vertically
[System.Windows.Controls.Grid]::SetColumn($border, $panelcount)
$targetGrid.Children.Add($border) | Out-Null
# Create a new StackPanel inside the Border
$stackPanel = New-Object Windows.Controls.StackPanel
$stackPanel.Background = [Windows.Media.Brushes]::Transparent
$stackPanel.SnapsToDevicePixels = $true
$stackPanel.VerticalAlignment = "Stretch" # Ensure the stack panel stretches vertically
$border.Child = $stackPanel
$panelcount++
}
}
$appInfo = $organizedData[$panelKey][$category][$appName]
switch ($appInfo.Type) {
"Toggle" {
$dockPanel = New-Object Windows.Controls.DockPanel
$checkBox = New-Object Windows.Controls.CheckBox
$checkBox.Name = $appInfo.Name
$checkBox.HorizontalAlignment = "Right"
$checkBox.FontSize = 14
$dockPanel.Children.Add($checkBox) | Out-Null
$label = New-Object Windows.Controls.Label
$label.Content = $appInfo.Content
$label.ToolTip = $appInfo.Description
$label.HorizontalAlignment = "Left"
$label.FontSize = 14
$dockPanel.Children.Add($label) | Out-Null
$stackPanel.Children.Add($dockPanel) | Out-Null
}
"Combobox" {
$horizontalStackPanel = New-Object Windows.Controls.StackPanel
$horizontalStackPanel.Orientation = "Horizontal"
$horizontalStackPanel.Margin = "0,5,0,0"
$label = New-Object Windows.Controls.Label
$label.Content = $appInfo.Content
$label.HorizontalAlignment = "Left"
$label.VerticalAlignment = "Center"
$label.FontSize = 14
$horizontalStackPanel.Children.Add($label) | Out-Null
$comboBox = New-Object Windows.Controls.ComboBox
$comboBox.Name = $appInfo.Name
$comboBox.Height = 32
$comboBox.Width = 186
$comboBox.HorizontalAlignment = "Left"
$comboBox.VerticalAlignment = "Center"
$comboBox.Margin = "5,5"
foreach ($comboitem in ($appInfo.ComboItems -split " ")) {
$comboBoxItem = New-Object Windows.Controls.ComboBoxItem
$comboBoxItem.Content = $comboitem
$comboBoxItem.FontSize = 14
$comboBox.Items.Add($comboBoxItem) | Out-Null
}
$horizontalStackPanel.Children.Add($comboBox) | Out-Null
$stackPanel.Children.Add($horizontalStackPanel) | Out-Null
}
"Button" {
$button = New-Object Windows.Controls.Button
$button.Name = $appInfo.Name
$button.Content = $appInfo.Content
$button.HorizontalAlignment = "Left"
$button.Margin = "5"
$button.Padding = "20,5"
if ($appInfo.ButtonWidth -ne $null) {
$button.Width = $appInfo.ButtonWidth
}
$stackPanel.Children.Add($button) | Out-Null
}
default {
$checkBox = New-Object Windows.Controls.CheckBox
$checkBox.Name = $appInfo.Name
$checkBox.Content = $appInfo.Content
$checkBox.ToolTip = $appInfo.Description
$checkBox.Margin = "5,0"
if ($appInfo.Checked -ne $null) {
$checkBox.IsChecked = $appInfo.Checked
}
if ($appInfo.Link -ne $null) {
$horizontalStackPanel = New-Object Windows.Controls.StackPanel
$horizontalStackPanel.Orientation = "Horizontal"
$horizontalStackPanel.Children.Add($checkBox) | Out-Null
$textBlock = New-Object Windows.Controls.TextBlock
$textBlock.Text = "(?)"
$textBlock.ToolTip = $appInfo.Link
$textBlock.Style = $window.FindResource("HoverTextBlockStyle")
# Add event handler for click to open link
$handler = [System.Windows.Input.MouseButtonEventHandler]{
param($sender, $e)
Start-Process $sender.ToolTip.ToString()
}
$textBlock.AddHandler([Windows.Controls.TextBlock]::MouseLeftButtonUpEvent, $handler)
$horizontalStackPanel.Children.Add($textBlock) | Out-Null
$stackPanel.Children.Add($horizontalStackPanel) | Out-Null
} else {
$stackPanel.Children.Add($checkBox) | Out-Null
}
}
}
}
}
}
}

View File

@ -84,182 +84,10 @@ try {
} }
# Load the configuration files
Invoke-WinUtilUIElements -configVariable $sync.configs.applications -panel "install"
Invoke-WinUtilUIElements -configVariable $sync.configs.tweaks -panel "tweaks"
Invoke-WinUtilUIElements -configVariable $sync.configs.feature -panel "features"
# Ensure we have a reference to the main window
$mainWindow = $sync["Form"]
# Reference to the Grid named 'appspanel'
$appspanel = $mainWindow.FindName("appspanel")
if ($appspanel -eq $null) {
throw "The Grid named 'appspanel' was not found in the main window."
}
# Clear any existing children from the Grid
$appspanel.Children.Clear()
$appspanel.ColumnDefinitions.Clear()
$appspanel.RowDefinitions.Clear()
# Set the number of columns
$columnCount = 5
# Create the required number of columns
for ($i = 0; $i -lt $columnCount; $i++) {
$colDef = New-Object System.Windows.Controls.ColumnDefinition
$colDef.Width = [System.Windows.GridLength]::new(1, [System.Windows.GridUnitType]::Star)
$appspanel.ColumnDefinitions.Add($colDef)
}
# Create a single row (since all columns will be in the same row)
$rowDef = New-Object System.Windows.Controls.RowDefinition
$rowDef.Height = [System.Windows.GridLength]::Auto
$appspanel.RowDefinitions.Add($rowDef)
# Create a StackPanel for each column
$columnPanels = @()
for ($i = 0; $i -lt $columnCount; $i++) {
$border = New-Object System.Windows.Controls.Border
$border.Margin = New-Object System.Windows.Thickness(10)
$border.BorderThickness = New-Object System.Windows.Thickness(1)
$border.BorderBrush = [System.Windows.Media.Brushes]::LightGray
$stackPanel = New-Object System.Windows.Controls.StackPanel
$stackPanel.Orientation = "Vertical"
$border.Child = $stackPanel
[System.Windows.Controls.Grid]::SetColumn($border, $i)
$appspanel.Children.Add($border) | Out-Null
$columnPanels += $stackPanel
}
# Group applications by category
$applicationsByCategory = @{}
foreach ($appName in $sync.configs.applications.PSObject.Properties.Name) {
$appInfo = $sync.configs.applications.$appName
if (-not $applicationsByCategory.ContainsKey($appInfo.Category)) {
$applicationsByCategory[$appInfo.Category] = @()
}
$applicationsByCategory[$appInfo.Category] += [PSCustomObject]@{
Name = $appName
Info = $appInfo
}
}
# Sort categories alphabetically
$sortedCategories = $applicationsByCategory.Keys | Sort-Object
# Collect all applications in sorted order by category
$allApplications = @()
foreach ($category in $sortedCategories) {
$allApplications += [PSCustomObject]@{
IsCategory = $true
Category = $category
App = $null
}
$allApplications += $applicationsByCategory[$category] | Sort-Object { $_.Info.Content } | ForEach-Object {
[PSCustomObject]@{
IsCategory = $false
Category = $category
App = $_
}
}
}
# Flatten the applications list to maintain the correct order
$flatAppsList = @()
foreach ($categoryGroup in $allApplications) {
# Add a label for the category
if ($categoryGroup.IsCategory) {
$flatAppsList += $categoryGroup
} else {
# Add the applications
$flatAppsList += $categoryGroup
}
}
# Calculate number of apps per column
$appsPerColumn = [math]::Ceiling($flatAppsList.Count / $columnCount)
# Distribute the flat apps list evenly across columns
$columnApps = @(@(), @(), @(), @(), @()) # Initialize an array of arrays for columns
$currentColumn = 0
$currentCount = 0
foreach ($item in $flatAppsList) {
if ($currentCount -ge $appsPerColumn) {
$currentColumn++
$currentCount = 0
}
$columnApps[$currentColumn] += $item
$currentCount++
}
# Add applications to the respective columns
for ($i = 0; $i -lt $columnApps.Count; $i++) {
foreach ($item in $columnApps[$i]) {
if ($item.IsCategory) {
$categoryLabel = New-Object System.Windows.Controls.Label
$categoryLabel.Content = $item.Category
$categoryLabel.FontSize = 16 # Adjust the font size as needed
$categoryLabel.FontFamily = "Arial" # Adjust the font family as needed
$categoryLabel.Margin = New-Object System.Windows.Thickness(5, 10, 5, 5)
$columnPanels[$i].Children.Add($categoryLabel) | Out-Null
} else {
$appInfo = $item.App.Info
# Create a new StackPanel for the app entry
$appStackPanel = New-Object System.Windows.Controls.StackPanel
$appStackPanel.Orientation = "Horizontal"
$appStackPanel.Margin = New-Object System.Windows.Thickness(2) # Reduced margin
# Create a new CheckBox for the app install option
$checkBox = New-Object System.Windows.Controls.CheckBox
$checkBox.Name = $item.App.Name
$checkBox.Content = $appInfo.Content
$checkBox.ToolTip = $appInfo.Description
$checkBox.Margin = New-Object System.Windows.Thickness(0, 0, 2, 0)
# Create a new Hyperlink for the app link
$hyperlink = New-Object System.Windows.Documents.Hyperlink
$hyperlink.Inlines.Add(" ?")
$hyperlink.NavigateUri = [Uri]$appInfo.Link
# Attach the RequestNavigate event handler
if ($hyperlink -ne $null) {
$hyperlink.AddHandler([System.Windows.Documents.Hyperlink]::RequestNavigateEvent,
[System.Windows.Navigation.RequestNavigateEventHandler]{
param($sender, $e)
[System.Diagnostics.Process]::Start("explorer.exe", $e.Uri.AbsoluteUri) | Out-Null
})
}
# Add the Hyperlink to a TextBlock
$hyperlinkBlock = New-Object System.Windows.Controls.TextBlock
$hyperlinkBlock.Inlines.Add($hyperlink)
$hyperlinkBlock.ToolTip = $appInfo.Link
$hyperlinkBlock.Margin = New-Object System.Windows.Thickness(0, 0, 0, 0)
# Add elements to the app StackPanel
$appStackPanel.Children.Add($checkBox) | Out-Null
$appStackPanel.Children.Add($hyperlinkBlock) | Out-Null
# Add the app StackPanel to the appropriate column StackPanel
$columnPanels[$i].Children.Add($appStackPanel) | Out-Null
}
}
}
#=========================================================================== #===========================================================================

View File

@ -750,7 +750,6 @@
<RowDefinition Height=".70*"/> <RowDefinition Height=".70*"/>
<RowDefinition Height=".10*"/> <RowDefinition Height=".10*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
{{InstallPanel_tweaks}}
<StackPanel Background="{MainBackgroundColor}" Orientation="Horizontal" HorizontalAlignment="Left" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="5"> <StackPanel Background="{MainBackgroundColor}" Orientation="Horizontal" HorizontalAlignment="Left" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="5">
<Label Content="Recommended Selections:" FontSize="{FontSize}" VerticalAlignment="Center" Margin="2"/> <Label Content="Recommended Selections:" FontSize="{FontSize}" VerticalAlignment="Center" Margin="2"/>
<Button Name="WPFstandard" Content=" Standard " Margin="2"/> <Button Name="WPFstandard" Content=" Standard " Margin="2"/>
@ -758,6 +757,8 @@
<Button Name="WPFclear" Content=" Clear " Margin="2"/> <Button Name="WPFclear" Content=" Clear " Margin="2"/>
<Button Name="WPFGetInstalledTweaks" Content=" Get Installed " Margin="2"/> <Button Name="WPFGetInstalledTweaks" Content=" Get Installed " Margin="2"/>
</StackPanel> </StackPanel>
<Grid Name="tweakspanel" Grid.Row="1">
</Grid>
<Border Grid.ColumnSpan="2" Grid.Row="2" Grid.Column="0"> <Border Grid.ColumnSpan="2" Grid.Row="2" Grid.Column="0">
<StackPanel Background="{MainBackgroundColor}" Orientation="Horizontal" HorizontalAlignment="Left"> <StackPanel Background="{MainBackgroundColor}" Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Padding="10"> <TextBlock Padding="10">
@ -766,14 +767,12 @@
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
</Border> </Border>
</Grid> </Grid>
</ScrollViewer> </ScrollViewer>
</TabItem> </TabItem>
<TabItem Header="Config" Visibility="Collapsed" Name="WPFTab3"> <TabItem Header="Config" Visibility="Collapsed" Name="WPFTab3">
<ScrollViewer VerticalScrollBarVisibility="Auto"> <ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid Background="Transparent"> <Grid Name="featurespanel" Grid.Row="1" Background="Transparent">
{{InstallPanel_features}}
</Grid> </Grid>
</ScrollViewer> </ScrollViewer>
</TabItem> </TabItem>