From 5f9bf376171e04b6f424bde1d69f3c807455d91c Mon Sep 17 00:00:00 2001
From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com>
Date: Fri, 21 Feb 2025 17:29:13 -0800
Subject: [PATCH] Add functionality to manage applications - implement Add and
Remove buttons with priority handling in the UI
---
FFUDevelopment/BuildFFUVM_UI.ps1 | 83 +++++++++++++++++++++++++++++++
FFUDevelopment/BuildFFUVM_UI.xaml | 30 +++++++++++
2 files changed, 113 insertions(+)
diff --git a/FFUDevelopment/BuildFFUVM_UI.ps1 b/FFUDevelopment/BuildFFUVM_UI.ps1
index bf01bee..9c0f052 100644
--- a/FFUDevelopment/BuildFFUVM_UI.ps1
+++ b/FFUDevelopment/BuildFFUVM_UI.ps1
@@ -753,6 +753,7 @@ function Invoke-ListViewSort {
@($unselectedItems | Sort-Object -Property $property)
}
else {
+ #DO NOT CHANGE THIS LINE
@($unselectedItems | Sort-Object -Property $property -Descending)
}
@@ -1342,6 +1343,53 @@ $window.Add_Loaded({
$window.FindName('txtPEDriversFolder').Text = $selectedPath
}
})
+
+ # Add button handler for Add Application
+ $script:btnAddApplication = $window.FindName('btnAddApplication')
+ $script:btnAddApplication.Add_Click({
+ $name = $window.FindName('txtAppName').Text
+ $commandLine = $window.FindName('txtAppCommandLine').Text
+ $source = $window.FindName('txtAppSource').Text
+
+ if ([string]::IsNullOrWhiteSpace($name) -or [string]::IsNullOrWhiteSpace($commandLine) -or [string]::IsNullOrWhiteSpace($source)) {
+ [System.Windows.MessageBox]::Show("Please fill in all fields (Name, Command Line, and Source)", "Missing Information", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
+ return
+ }
+
+ $listView = $window.FindName('lstApplications')
+
+ # Calculate the next priority number
+ $priority = 1
+ if ($listView.Items.Count -gt 0) {
+ $priority = ($listView.Items | Measure-Object -Property Priority -Maximum).Maximum + 1
+ }
+
+ # Create new application object
+ $application = [PSCustomObject]@{
+ Priority = $priority
+ Name = $name
+ CommandLine = $commandLine
+ Source = $source
+ }
+
+ # Add to ListView
+ $listView.Items.Add($application)
+
+ # Clear the input fields
+ $window.FindName('txtAppName').Text = ""
+ $window.FindName('txtAppCommandLine').Text = ""
+ $window.FindName('txtAppSource').Text = ""
+ })
+
+ # Add visibility handling for BYO Applications panel
+ $script:chkBringYourOwnApps = $window.FindName('chkBringYourOwnApps')
+ $script:byoApplicationPanel = $window.FindName('byoApplicationPanel')
+ $script:chkBringYourOwnApps.Add_Checked({
+ $script:byoApplicationPanel.Visibility = 'Visible'
+ })
+ $script:chkBringYourOwnApps.Add_Unchecked({
+ $script:byoApplicationPanel.Visibility = 'Collapsed'
+ })
})
# Function to search for Winget apps
@@ -1452,6 +1500,27 @@ function Import-WingetList {
}
}
+# Function to remove application and reorder priorities
+function Remove-Application {
+ param($priority)
+
+ $listView = $window.FindName('lstApplications')
+
+ # Remove the item with the specified priority
+ $itemToRemove = $listView.Items | Where-Object { $_.Priority -eq $priority } | Select-Object -First 1
+ $listView.Items.Remove($itemToRemove)
+
+ # Reorder priorities for remaining items
+ $currentPriority = 1
+ foreach ($item in $listView.Items) {
+ $item.Priority = $currentPriority
+ $currentPriority++
+ }
+
+ # Refresh the ListView
+ $listView.Items.Refresh()
+}
+
# Button: Build FFU
$btnRun = $window.FindName('btnRun')
$btnRun.Add_Click({
@@ -1619,4 +1688,18 @@ $btnLoadConfig.Add_Click({
}
})
+# Add handler for Remove button clicks
+$window.Add_SourceInitialized({
+ $listView = $window.FindName('lstApplications')
+ $listView.AddHandler(
+ [System.Windows.Controls.Button]::ClickEvent,
+ [System.Windows.RoutedEventHandler]{
+ param($buttonSender, $eventArgs)
+ if ($eventArgs.OriginalSource -is [System.Windows.Controls.Button] -and $eventArgs.OriginalSource.Content -eq "Remove") {
+ Remove-Application -priority $eventArgs.OriginalSource.Tag
+ }
+ }
+ )
+})
+
[void]$window.ShowDialog()
diff --git a/FFUDevelopment/BuildFFUVM_UI.xaml b/FFUDevelopment/BuildFFUVM_UI.xaml
index aa3e89c..89c6016 100644
--- a/FFUDevelopment/BuildFFUVM_UI.xaml
+++ b/FFUDevelopment/BuildFFUVM_UI.xaml
@@ -702,6 +702,36 @@
Margin="5,0,0,0"
VerticalAlignment="Center"/>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+