mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-07-01 10:32:35 -05:00
LETS GOOO (#12)
* Add Selected Apps Label, Reshuffel the nesting of the checkbox and the label to be able to reference the name from the actual checkbox * Add visual selection and allow click on the whole app section * Fix Theme definition to work with theme change * Fix Highlight on if label or icon is clicked * change applications.json to powershell object list and refactor UI Creation logic * Optimization and Add Collapsable Categories * Add Button functionality for install, uninstall, info, install selected, uninstall selected, clear and implement search * Rest application.json to Main * Reset Compile to main * Pretty much revamp_apps but without changes to applications.json * Small fixes
This commit is contained in:
102
scripts/main.ps1
102
scripts/main.ps1
@ -115,32 +115,34 @@ Invoke-WinutilThemeChange -init $true
|
||||
$noimage = "https://images.emojiterra.com/google/noto-emoji/unicode-15/color/512px/1f4e6.png"
|
||||
$noimage = [Windows.Media.Imaging.BitmapImage]::new([Uri]::new($noimage))
|
||||
|
||||
# Extract unique categories from the applications configuration
|
||||
$uniqueCategories = $sync.configs.applications.PSObject.Properties.Value |
|
||||
Where-Object { $_.Category } |
|
||||
Select-Object -Unique -ExpandProperty Category
|
||||
|
||||
# Create a custom PSCustomObject to simulate category-level checkboxes
|
||||
$categoryConfig = @{}
|
||||
|
||||
foreach ($category in $uniqueCategories) {
|
||||
# Sanitize the category name for use in the Name property (remove spaces, special characters)
|
||||
$sanitizedCategoryName = $category -replace '\W', '_'
|
||||
|
||||
$categoryConfig[$sanitizedCategoryName] = [PSCustomObject]@{
|
||||
Category = "Categories"
|
||||
Content = $category
|
||||
}
|
||||
$sync.configs.appnavigation | Add-Member -MemberType NoteProperty -Name $sanitizedCategoryName -Value $categoryConfig[$sanitizedCategoryName] -Force
|
||||
$sync.Buttons = @{}
|
||||
$SortedAppsHashtable = [ordered]@{}
|
||||
$sortedProperties = $sync.configs.applications.PSObject.Properties | Sort-Object { $_.Value.Content }
|
||||
$sortedProperties | ForEach-Object {
|
||||
$SortedAppsHashtable[$_.Name] = $_.Value
|
||||
}
|
||||
|
||||
# Now call the function with the final merged config
|
||||
Invoke-WPFUIElements -configVariable $sync.configs.appnavigation -targetGridName "appscategory" -columncount 1
|
||||
Invoke-WPFUIElements -configVariable $sync.configs.applications -targetGridName "appspanel" -columncount 1
|
||||
|
||||
Invoke-WPFUIApps -Apps $SortedAppsHashtable -targetGridName "appspanel"
|
||||
|
||||
Invoke-WPFUIElements -configVariable $sync.configs.tweaks -targetGridName "tweakspanel" -columncount 2
|
||||
Invoke-WPFUIElements -configVariable $sync.configs.feature -targetGridName "featurespanel" -columncount 2
|
||||
|
||||
$sync.SortbyCategory.Add_Checked({
|
||||
Write-Host "Sort By Category"
|
||||
$sync.Form.Dispatcher.BeginInvoke([System.Windows.Threading.DispatcherPriority]::Background, [action]{
|
||||
Invoke-WPFUIApps -Apps $SortedAppsHashtable -targetGridName "appspanel"
|
||||
}) | Out-Null
|
||||
})
|
||||
$sync.SortbyAlphabet.Add_Checked({
|
||||
Write-Host "Sort By Alphabet"
|
||||
$sync.Form.Dispatcher.BeginInvoke([System.Windows.Threading.DispatcherPriority]::Background, [action]{
|
||||
Invoke-WPFUIApps -Apps $SortedAppsHashtable -targetGridName "appspanel" -alphabetical $true
|
||||
})
|
||||
})
|
||||
|
||||
#===========================================================================
|
||||
# Store Form Objects In PowerShell
|
||||
#===========================================================================
|
||||
@ -450,73 +452,18 @@ if ($sync["ISOLanguage"].Items.Count -eq 1) {
|
||||
}
|
||||
$sync["ISOLanguage"].SelectedIndex = 0
|
||||
|
||||
|
||||
# Load Checkboxes and Labels outside of the Filter function only once on startup for performance reasons
|
||||
$filter = Get-WinUtilVariables -Type CheckBox
|
||||
$CheckBoxes = ($sync.GetEnumerator()).where{ $psitem.Key -in $filter }
|
||||
|
||||
$filter = Get-WinUtilVariables -Type Label
|
||||
$labels = @{}
|
||||
($sync.GetEnumerator()).where{$PSItem.Key -in $filter} | ForEach-Object {$labels[$_.Key] = $_.Value}
|
||||
|
||||
$allCategories = $checkBoxes.Name | ForEach-Object {$sync.configs.applications.$_} | Select-Object -Unique -ExpandProperty category
|
||||
|
||||
$sync["SearchBar"].Add_TextChanged({
|
||||
if ($sync.SearchBar.Text -ne "") {
|
||||
$sync.SearchBarClearButton.Visibility = "Visible"
|
||||
} else {
|
||||
$sync.SearchBarClearButton.Visibility = "Collapsed"
|
||||
}
|
||||
|
||||
$activeApplications = @()
|
||||
|
||||
$textToSearch = $sync.SearchBar.Text.ToLower()
|
||||
|
||||
foreach ($CheckBox in $CheckBoxes) {
|
||||
# Skip if the checkbox is null, it doesn't have content or it is the prefer Choco checkbox
|
||||
if ($CheckBox -eq $null -or $CheckBox.Value -eq $null -or $CheckBox.Value.Content -eq $null -or $CheckBox.Name -eq "WPFpreferChocolatey") {
|
||||
continue
|
||||
}
|
||||
|
||||
$checkBoxName = $CheckBox.Key
|
||||
$textBlockName = $checkBoxName + "Link"
|
||||
|
||||
# Retrieve the corresponding text block based on the generated name
|
||||
$textBlock = $sync[$textBlockName]
|
||||
|
||||
if ($CheckBox.Value.Content.ToString().ToLower().Contains($textToSearch)) {
|
||||
$CheckBox.Value.Visibility = "Visible"
|
||||
$activeApplications += $sync.configs.applications.$checkboxName
|
||||
# Set the corresponding text block visibility
|
||||
if ($textBlock -ne $null -and $textBlock -is [System.Windows.Controls.TextBlock]) {
|
||||
$textBlock.Visibility = "Visible"
|
||||
}
|
||||
} else {
|
||||
$CheckBox.Value.Visibility = "Collapsed"
|
||||
# Set the corresponding text block visibility
|
||||
if ($textBlock -ne $null -and $textBlock -is [System.Windows.Controls.TextBlock]) {
|
||||
$textBlock.Visibility = "Collapsed"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$activeCategories = $activeApplications | Select-Object -ExpandProperty category -Unique
|
||||
|
||||
foreach ($category in $activeCategories) {
|
||||
$sync[$category].Visibility = "Visible"
|
||||
}
|
||||
if ($activeCategories) {
|
||||
$inactiveCategories = Compare-Object -ReferenceObject $allCategories -DifferenceObject $activeCategories -PassThru
|
||||
} else {
|
||||
$inactiveCategories = $allCategories
|
||||
}
|
||||
foreach ($category in $inactiveCategories) {
|
||||
$sync[$category].Visibility = "Collapsed"
|
||||
}
|
||||
Search-AppsByNameOrDescription -SearchString $sync.SearchBar.Text
|
||||
})
|
||||
|
||||
$sync["Form"].Add_Loaded({
|
||||
param($e)
|
||||
$sync.Form.MinWidth = "1000"
|
||||
$sync["Form"].MaxWidth = [Double]::PositiveInfinity
|
||||
$sync["Form"].MaxHeight = [Double]::PositiveInfinity
|
||||
})
|
||||
@ -643,5 +590,10 @@ $sync["SponsorMenuItem"].Add_Click({
|
||||
Show-CustomDialog -Message $authorInfo -EnableScroll $true
|
||||
})
|
||||
|
||||
#Initialize List to store the Names of the selected Apps on the Install Tab
|
||||
$sync.selectedApps = [System.Collections.Generic.List[string]]::new()
|
||||
$sync.ShowOnlySeleced = $false
|
||||
|
||||
|
||||
$sync["Form"].ShowDialog() | out-null
|
||||
Stop-Transcript
|
||||
|
Reference in New Issue
Block a user