Skip to content

Commit 23c9e06

Browse files
committed
Grouping by comment with ##
1 parent c169ed9 commit 23c9e06

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

chocolatey_install_all.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
choco install firefox --params "/NoDesktopShortcut /NoAutoUpdate" -y
33
choco install thunderbird --params "/NoDesktopShortcut /NoAutoUpdate" -y
44

5-
# cloud
5+
## cloud
66
choco install dropbox -y
77
choco install megasync -y
88
choco install pcloud -y
@@ -20,18 +20,18 @@ choco install bulk-crap-uninstaller -y
2020
choco install monitorian -y
2121
choco install sharex -y
2222

23-
# development
23+
## development
2424
choco install git --version -y
2525
choco install gitextensions.portable -y
2626
choco install powershell-core - --install-arguments='"DISABLE_TELEMETRY=1"' -y
2727

28-
# IDEs & editors
28+
## IDEs & editors
2929
choco install notepadplusplus -y
3030
choco install vscode -y
3131
choco install intellijidea-community -y
3232
choco install androidstudio -y
3333

34-
# java
34+
## java
3535
choco install temurin17 -y <# LTS SDK #>
3636
choco install temurin8 -y <# java 8 SDK #>
3737
choco install temurin -y <# Latest SDK #>

ui/form.ps1

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,52 +18,58 @@ $form.Controls.Add($label)
1818

1919
# Create checkboxes dynamically based on the content of the script
2020
$checkBoxes = @()
21-
$packages = @{}
22-
$currentCategory = ""
21+
# $packages = @{}
22+
# $currentCategory = ""
2323

2424
$scriptPath = Join-Path -Path $PSScriptRoot -ChildPath "..\chocolatey_install_all.ps1" # Set the correct relative path to the base script
2525

2626
# Read the content of the base script
2727
$scriptContent = Get-Content -Path $scriptPath
2828

2929
# Parse the content and extract package names and categories
30+
$groupLabels = $scriptContent | Select-String -Pattern "^##\s(.+)" | ForEach-Object { $_.Matches.Groups[1].Value }
31+
32+
$currentY = 50
33+
$checkBoxWidth = $form.ClientSize.Width - 60 # Adjusted width based on form width
34+
$groupPackages = @{}
35+
foreach ($groupLabel in $groupLabels) {
36+
# Initialize packages array for the group label
37+
$groupPackages[$groupLabel] = @()
38+
39+
}
40+
3041
foreach ($line in $scriptContent) {
31-
if ($line -match "^# (.+)$") {
42+
if ($line -match "^##\s(.+)$") {
3243
$currentCategory = $matches[1]
3344
} elseif ($line -match "choco install ([^\s]+)") {
3445
$packageName = $matches[1]
35-
$packages[$packageName] = $currentCategory
46+
$groupPackages[$currentCategory] += $packageName
3647
}
3748
}
3849

39-
$currentY = 50
40-
$checkBoxWidth = $form.ClientSize.Width - 60 # Adjusted width based on form width
41-
foreach ($package in $packages.GetEnumerator() | Sort-Object -Property Value) {
42-
$packageName = $package.Key
43-
$category = $package.Value
44-
45-
# Add category label if it's a new category
46-
if ($category -ne $currentCategory) {
47-
$currentY += 30
48-
$categoryLabel = New-Object System.Windows.Forms.Label
49-
$categoryLabel.Location = New-Object System.Drawing.Point(20, $currentY)
50-
$categoryLabel.AutoSize = $true # Adjusted to enable label resizing
51-
$categoryLabel.Text = $category
52-
$form.Controls.Add($categoryLabel)
53-
54-
$currentCategory = $category
50+
foreach ($groupLabel in $groupLabels) {
51+
# Add category label
52+
$currentY += 30
53+
$categoryLabel = New-Object System.Windows.Forms.Label
54+
$categoryLabel.Location = New-Object System.Drawing.Point(20, $currentY)
55+
$categoryLabel.AutoSize = $true # Adjusted to enable label resizing
56+
$categoryLabel.Text = $groupLabel
57+
$form.Controls.Add($categoryLabel)
58+
59+
# Find corresponding packages for the group label
60+
$groupPackages[$groupLabel] | ForEach-Object {
61+
$currentY += 25
62+
$checkBox = New-Object System.Windows.Forms.CheckBox
63+
$checkBox.Location = New-Object System.Drawing.Point(40, $currentY)
64+
$checkBox.Size = New-Object System.Drawing.Size($checkBoxWidth, 20) # Adjusted size based on form width
65+
$checkBox.Text = $_
66+
$checkBoxes += $checkBox
67+
$form.Controls.Add($checkBox)
5568
}
56-
57-
# Create checkbox for each package
58-
$currentY += 25
59-
$checkBox = New-Object System.Windows.Forms.CheckBox
60-
$checkBox.Location = New-Object System.Drawing.Point(40, $currentY)
61-
$checkBox.Size = New-Object System.Drawing.Size($checkBoxWidth, 20) # Adjusted size based on form width
62-
$checkBox.Text = $packageName
63-
$checkBoxes += $checkBox
64-
$form.Controls.Add($checkBox)
6569
}
6670

71+
72+
6773
# Create the "OK" button
6874
$okButton = New-Object System.Windows.Forms.Button
6975
$okButton.Location = New-Object System.Drawing.Point([int](($form.ClientSize.Width - $okButton.Width) / 2), [int]($currentY + 40))

0 commit comments

Comments
 (0)