Skip to content

Commit

Permalink
run preprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
MyDrift-user committed Nov 2, 2024
1 parent c46a7ea commit 5514025
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 45 deletions.
20 changes: 10 additions & 10 deletions functions/private/Add-SelectedAppsMenuItem.ps1
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
function Add-SelectedAppsMenuItem {
<#
.SYNOPSIS
.SYNOPSIS
This is a helper function that generates and adds the Menu Items to the Selected Apps Popup.
.Parameter name
The actual Name of an App like "Chrome" or "Brave"
This name is contained in the "Content" property inside the applications.json
.PARAMETER key
The key which identifies an app object in applications.json
For Chrome this would be "WPFInstallchrome" because "WPFInstall" is prepended automatically for each key in applications.json
The key which identifies an app object in applications.json
For Chrome this would be "WPFInstallchrome" because "WPFInstall" is prepended automatically for each key in applications.json
#>

param ([string]$name, [string]$key)

$selectedAppGrid = New-Object Windows.Controls.Grid

$selectedAppGrid.ColumnDefinitions.Add((New-Object System.Windows.Controls.ColumnDefinition -Property @{Width = "*"}))
$selectedAppGrid.ColumnDefinitions.Add((New-Object System.Windows.Controls.ColumnDefinition -Property @{Width = "30"}))

# Sets the name to the Content as well as the Tooltip, because the parent Popup Border has a fixed width and text could "overflow".
# With the tooltip, you can still read the whole entry on hover
$selectedAppLabel = New-Object Windows.Controls.Label
Expand All @@ -30,13 +30,13 @@

$selectedAppRemoveButton = New-Object Windows.Controls.Button
$selectedAppRemoveButton.FontFamily = "Segoe MDL2 Assets"
$selectedAppRemoveButton.Content = [string]([char]0xE711)
$selectedAppRemoveButton.Content = [string]([char]0xE711)
$selectedAppRemoveButton.HorizontalAlignment = "Center"
$selectedAppRemoveButton.Tag = $key
$selectedAppRemoveButton.ToolTip = "Remove the App from Selection"
$selectedAppRemoveButton.SetResourceReference([Windows.Controls.Control]::ForegroundProperty, "MainForegroundColor")
$selectedAppRemoveButton.SetResourceReference([Windows.Controls.Control]::StyleProperty, "HoverButtonStyle")

# Highlight the Remove icon on Hover
$selectedAppRemoveButton.Add_MouseEnter({ $this.Foreground = "Red" })
$selectedAppRemoveButton.Add_MouseLeave({ $this.SetResourceReference([Windows.Controls.Control]::ForegroundProperty, "MainForegroundColor") })
Expand All @@ -46,5 +46,5 @@
[System.Windows.Controls.Grid]::SetColumn($selectedAppRemoveButton, 1)
$selectedAppGrid.Children.Add($selectedAppRemoveButton)
# Add new Element to Popup
$sync.selectedAppsstackPanel.Children.Add($selectedAppGrid)
}
$sync.selectedAppsstackPanel.Children.Add($selectedAppGrid)
}
10 changes: 5 additions & 5 deletions functions/private/Find-AppsByNameOrDescription.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
function Find-AppsByNameOrDescription {
<#
.SYNOPSIS
.SYNOPSIS
Searches through the Apps on the Install Tab and hides all entries that do not match the string
.PARAMETER SearchString
The string to be searched for
#>
param(
[Parameter(Mandatory=$false)]
[string]$SearchString = ""
[string]$SearchString = ""
)
# Reset the visibility if the search string is empty or the search is cleared
if ([string]::IsNullOrWhiteSpace($SearchString)) {
Expand All @@ -31,5 +31,5 @@ function Find-AppsByNameOrDescription {
}
}
}
}
}
}
}
6 changes: 3 additions & 3 deletions functions/private/Initalize-InstallAppEntry.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function Initialize-InstallAppEntry {
<#
.SYNOPSIS
Creates the app entry to be placed on the isntall tab for a given app
Creates the app entry to be placed on the isntall tab for a given app
Used to as part of the Install Tab UI generation
.PARAMETER TargetElement
The Element into which the Apps should be placed
.PARAMETER AppKey
The Key of the app inside the $sync.configs.applicationsHashtable
The Key of the app inside the $sync.configs.applicationsHashtable
#>
param(
[Windows.Controls.WrapPanel]$TargetElement,
Expand Down Expand Up @@ -194,4 +194,4 @@ function Initialize-InstallAppEntry {

# Add the border to the corresponding Category
$TargetElement.Children.Add($border) | Out-Null
}
}
8 changes: 4 additions & 4 deletions functions/private/Initialize-InstallAppArea.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<#
.SYNOPSIS
Creates a [Windows.Controls.ScrollViewer] containing a [Windows.Controls.ItemsControl] which is setup to use Virtualization to only load the visible elements for performance reasons.
This is used as the parent object for all category and app entries on the install tab
This is used as the parent object for all category and app entries on the install tab
Used to as part of the Install Tab UI generation
.PARAMETER TargetElement
The element to which the AppArea shoud be added
The element to which the AppArea shoud be added
#>
param($TargetElement)
Expand All @@ -33,4 +33,4 @@
[Windows.Controls.DockPanel]::SetDock($scrollViewer, [Windows.Controls.Dock]::Bottom)
$null = $TargetElement.Children.Add($scrollViewer)
return $itemsControl
}
}
6 changes: 3 additions & 3 deletions functions/private/Initialize-InstallAppsMainElement.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ function Initialize-InstallAppsMainElement {
Clears the given WPF Grid and creates a [Windows.Controls.Border] containing a [Windows.Controls.StackPanel]
Used to as part of the Install Tab UI generation
.PARAMETER TargetGridName
The WPF Grid name
The WPF Grid name
.OUTPUTS
Returns the created [Windows.Controls.StackPanel] element
#>
param(
[Parameter(Mandatory)]
[string]$TargetGridName
)
$targetGrid = $sync.Form.FindName($TargetGridName)
$targetGrid = $sync.Form.FindName($TargetGridName)
$null = $targetGrid.Children.Clear()

$Border = New-Object Windows.Controls.Border
Expand All @@ -25,4 +25,4 @@ function Initialize-InstallAppsMainElement {
$null = $targetGrid.Children.Add($Border)

return $dockPanel
}
}
10 changes: 5 additions & 5 deletions functions/private/Initialize-InstallCategoryAppList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ function Initialize-InstallCategoryAppList {
<#
.SYNOPSIS
Clears the Target Element and sets up a "Loading" message. This is done, because loading of all apps can take a bit of time in some scenarios
Iterates through all Categories and Apps and adds them to the UI
Iterates through all Categories and Apps and adds them to the UI
Used to as part of the Install Tab UI generation
.PARAMETER TargetElement
The Element into which the Categories and Apps should be placed
.PARAMETER Apps
The Hashtable of Apps to be added to the UI
The Categories are also extracted from the Apps Hashtable
#>
param(
$TargetElement,
Expand All @@ -20,7 +20,7 @@ function Initialize-InstallCategoryAppList {
[string]$Category,
[Windows.Controls.ItemsControl]$TargetElement
)

$toggleButton = New-Object Windows.Controls.Primitives.ToggleButton
$toggleButton.Content = "$Category"
$toggleButton.Tag = "CategoryToggleButton"
Expand Down Expand Up @@ -51,7 +51,7 @@ function Initialize-InstallCategoryAppList {
$null = $TargetElement.Items.Add($sync.LoadingLabel)
# Use the Dispatcher to make sure the Loading message is shown before the logic loading the apps starts, and only is removed when the loading is complete and the apps are added to the UI
$TargetElement.Dispatcher.Invoke([System.Windows.Threading.DispatcherPriority]::Background, [action]{

$TargetElement.Items.Clear() # Remove the loading message
$categories = $Apps.Values | Select-Object -ExpandProperty category -Unique | Sort-Object
foreach ($category in $categories) {
Expand All @@ -69,4 +69,4 @@ function Initialize-InstallCategoryAppList {
}
}
})
}
}
6 changes: 3 additions & 3 deletions functions/private/Initialize-InstallHeader.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Initialize-InstallHeader {
$selectedAppsButton.SetResourceReference([Windows.Controls.Control]::ForegroundProperty, "MainForegroundColor")
$selectedAppsButton.HorizontalAlignment = "Center"
$selectedAppsButton.VerticalAlignment = "Center"

$selectedAppsPopup = New-Object Windows.Controls.Primitives.Popup
$selectedAppsPopup.IsOpen = $false
$selectedAppsPopup.PlacementTarget = $selectedAppsButton
Expand All @@ -61,7 +61,7 @@ function Initialize-InstallHeader {
$selectedAppsBorder.Padding = 5
$selectedAppsPopup.Child = $selectedAppsBorder
$sync.selectedAppsPopup = $selectedAppsPopup

$sync.selectedAppsstackPanel = New-Object Windows.Controls.StackPanel
$selectedAppsBorder.Child = $sync.selectedAppsstackPanel

Expand All @@ -86,4 +86,4 @@ function Initialize-InstallHeader {

[Windows.Controls.DockPanel]::SetDock($wrapPanelTop, [Windows.Controls.Dock]::Top)
$null = $TargetElement.Children.Add($wrapPanelTop)
}
}
12 changes: 6 additions & 6 deletions functions/private/Set-CategoryVisibility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ function Set-CategoryVisibility {
<#
.SYNOPSIS
Used to expand or collapse categories and corresponding apps on the install tab
.PARAMETER Category
Can eigther be a specific category name like "Browsers" OR "*" to affect all categories at once
.PARAMETER overrideState
"Expand" => expands the corresponding elements
"Collapse" => collapses the corresponding elements
Expand All @@ -17,8 +17,8 @@ function Set-CategoryVisibility {
[ValidateSet("Expand", "Collapse")]
[string]$overrideState
)
switch ($overrideState){

switch ($overrideState) {
"Expand" {$state = $true}
"Collapse" {$state = $false}
default {$state = $sync.CompactView}
Expand All @@ -29,7 +29,7 @@ function Set-CategoryVisibility {
if ($category -eq "*") {
$items = $sync.ItemsControl.Items | Where-Object {($_.Tag -like "CategoryWrapPanel_*")}
$sync.ItemsControl.Items | Where-Object {($_.Tag -eq "CategoryToggleButton")} | Foreach-Object { $_.Visibility = [Windows.Visibility]::Visible; $_.IsChecked = $state }

} else {
$items = $sync.ItemsControl.Items | Where-Object {($_.Tag -eq "CategoryWrapPanel_$Category")}
}
Expand All @@ -41,4 +41,4 @@ function Set-CategoryVisibility {
$items.Children | ForEach-Object {
$_.Visibility = $elementVisibility
}
}
}
2 changes: 1 addition & 1 deletion functions/private/Show-OnlyCheckedApps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ function Show-OnlyCheckedApps {
}
Set-CategoryVisibility -Category "*"
}
}
}
8 changes: 4 additions & 4 deletions functions/public/Invoke-WPFSelectedAppsUpdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ function Invoke-WPFSelectedAppsUpdate {
$sync.selectedApps.Add($appKey)
# The List type needs to be specified again, because otherwise Sort-Object will convert the list to a string if there is only a single entry
[System.Collections.Generic.List[pscustomobject]]$sync.selectedApps = $sync.SelectedApps | Sort-Object

}
elseif ($type -eq "Remove") {
$sync.SelectedApps.Remove($appKey)
}
else{
Write-Error "Type: $type not implemented"
}

$count = $sync.SelectedApps.Count
$selectedAppsButton.Content = "Selected Apps: $count"
# On every change, remove all entries inside the Popup Menu. This is done, so we can keep the alphabetical order even if elements are selected in a random way
$sync.selectedAppsstackPanel.Children.Clear()
$sync.selectedAppsstackPanel.Children.Clear()
$sync.SelectedApps | Foreach-Object { Add-SelectedAppsMenuItem -name $($sync.configs.applicationsHashtable.$_.Content) -key $_ }

}
2 changes: 1 addition & 1 deletion functions/public/Invoke-WPFUIApps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function Invoke-WPFUIApps {
switch ($TargetGridName) {
"appspanel" {
$dockPanel = Initialize-InstallAppsMainElement -TargetGridName $TargetGridName
$null = Initialize-InstallHeader -TargetElement $dockPanel
$null = Initialize-InstallHeader -TargetElement $dockPanel
$sync.ItemsControl = Initialize-InstallAppArea -TargetElement $dockPanel
Initialize-InstallCategoryAppList -TargetElement $sync.ItemsControl -Apps $Apps
}
Expand Down

0 comments on commit 5514025

Please sign in to comment.