mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
feat: Implement multi-select and editing for BYO apps
Introduces multi-selection capabilities to the "Bring Your Own" applications list, allowing users to select and remove multiple applications at once. This change also adds the ability to edit an existing application's details directly from the UI. The application list view is now dynamically generated to support these new features, including selectable rows. Key changes: - Adds "Edit Application" and "Remove Selected" buttons. - Enables/disables action buttons based on the number of selected items. - Modifies the "Add Application" form to function as an "Update" form when editing. - Implements selection via mouse click, checkboxes, and the spacebar.
This commit is contained in:
@@ -392,27 +392,6 @@
|
|||||||
|
|
||||||
<!-- Applications ListView -->
|
<!-- Applications ListView -->
|
||||||
<ListView x:Name="lstApplications" Grid.Column="0" Height="200">
|
<ListView x:Name="lstApplications" Grid.Column="0" Height="200">
|
||||||
<ListView.View>
|
|
||||||
<GridView>
|
|
||||||
<GridViewColumn Header="Priority" DisplayMemberBinding="{Binding Priority}" Width="60"/>
|
|
||||||
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="150"/>
|
|
||||||
<GridViewColumn Header="Command Line" DisplayMemberBinding="{Binding CommandLine}" Width="200"/>
|
|
||||||
<GridViewColumn Header="Arguments" DisplayMemberBinding="{Binding Arguments}" Width="200"/>
|
|
||||||
<GridViewColumn Header="Source" DisplayMemberBinding="{Binding Source}" Width="150"/>
|
|
||||||
<GridViewColumn Header="Exit Codes" DisplayMemberBinding="{Binding AdditionalExitCodes}" Width="100"/>
|
|
||||||
<GridViewColumn Header="Ignore Exit Codes" DisplayMemberBinding="{Binding IgnoreExitCodes}" Width="120"/>
|
|
||||||
<GridViewColumn Header="Copy Status" DisplayMemberBinding="{Binding CopyStatus}" Width="150"/>
|
|
||||||
<GridViewColumn Header="Action" Width="85">
|
|
||||||
<GridViewColumn.CellTemplate>
|
|
||||||
<DataTemplate>
|
|
||||||
<Grid HorizontalAlignment="Stretch">
|
|
||||||
<Button Content="Remove" Tag="{Binding Priority}" Width="70" HorizontalAlignment="Center" ToolTip="Remove this application from the list and reorder priorities"/>
|
|
||||||
</Grid>
|
|
||||||
</DataTemplate>
|
|
||||||
</GridViewColumn.CellTemplate>
|
|
||||||
</GridViewColumn>
|
|
||||||
</GridView>
|
|
||||||
</ListView.View>
|
|
||||||
</ListView>
|
</ListView>
|
||||||
|
|
||||||
<!-- Reorder Buttons -->
|
<!-- Reorder Buttons -->
|
||||||
@@ -429,9 +408,10 @@
|
|||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,0,0,10">
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,0,0,10">
|
||||||
<Button x:Name="btnSaveBYOApplications" Content="Save UserAppList.json" Margin="0,0,10,0" Padding="10,5" ToolTip="Save application list to JSON file"/>
|
<Button x:Name="btnSaveBYOApplications" Content="Save UserAppList.json" Margin="0,0,10,0" Padding="10,5" ToolTip="Save application list to JSON file"/>
|
||||||
<Button x:Name="btnLoadBYOApplications" Content="Import UserAppList.json" Margin="0,0,10,0" Padding="10,5" ToolTip="Import application list from JSON file"/>
|
<Button x:Name="btnLoadBYOApplications" Content="Import UserAppList.json" Margin="0,0,10,0" Padding="10,5" ToolTip="Import application list from JSON file"/>
|
||||||
|
<Button x:Name="btnEditApplication" Content="Edit Application" IsEnabled="False" Margin="0,0,10,0" Padding="10,5" ToolTip="Edit the selected application's details"/>
|
||||||
<Button x:Name="btnCopyBYOApps" Content="Copy Apps" IsEnabled="False" Margin="0,0,10,0" Padding="10,5" ToolTip="Copy applications with a specified source path to the AppsPath\Win32 folder"/>
|
<Button x:Name="btnCopyBYOApps" Content="Copy Apps" IsEnabled="False" Margin="0,0,10,0" Padding="10,5" ToolTip="Copy applications with a specified source path to the AppsPath\Win32 folder"/>
|
||||||
<Button x:Name="btnClearBYOApplications" Content="Clear List" Padding="10,5" ToolTip="Clear all applications from the list"/>
|
<Button x:Name="btnRemoveSelectedBYOApps" Content="Remove Selected" IsEnabled="False" Margin="0,0,10,0" Padding="10,5" ToolTip="Remove selected applications from the list"/>
|
||||||
</StackPanel>
|
<Button x:Name="btnClearBYOApplications" Content="Clear List" Padding="10,5" ToolTip="Clear all applications from the list"/> </StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<!-- AppsScriptVariables Section -->
|
<!-- AppsScriptVariables Section -->
|
||||||
|
|||||||
@@ -5,6 +5,85 @@
|
|||||||
This module contains all the functions that power the "Applications" tab in the BuildFFUVM_UI. It handles user interactions for managing custom application lists (BYO Apps), such as adding, removing, reordering, and saving/loading the list from a JSON file (UserAppList.json). It also includes the logic for copying the application source files to the designated staging directory in parallel. Additionally, it manages the UI for creating and removing key-value pairs for the AppsScriptVariables.json file, which allows for custom parameterization of user-provided scripts.
|
This module contains all the functions that power the "Applications" tab in the BuildFFUVM_UI. It handles user interactions for managing custom application lists (BYO Apps), such as adding, removing, reordering, and saving/loading the list from a JSON file (UserAppList.json). It also includes the logic for copying the application source files to the designated staging directory in parallel. Additionally, it manages the UI for creating and removing key-value pairs for the AppsScriptVariables.json file, which allows for custom parameterization of user-provided scripts.
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
# Function to update the enabled state of BYO Apps action buttons based on selection
|
||||||
|
function Update-BYOAppsActionButtonsState {
|
||||||
|
param(
|
||||||
|
[psobject]$State
|
||||||
|
)
|
||||||
|
$listView = $State.Controls.lstApplications
|
||||||
|
$removeButton = $State.Controls.btnRemoveSelectedBYOApps
|
||||||
|
$editButton = $State.Controls.btnEditApplication
|
||||||
|
|
||||||
|
if ($listView -and $removeButton -and $editButton) {
|
||||||
|
# Count selected items
|
||||||
|
$selectedItems = @($listView.Items | Where-Object { $_.IsSelected })
|
||||||
|
$selectedCount = $selectedItems.Count
|
||||||
|
|
||||||
|
# Enable the remove button if any item is selected
|
||||||
|
$removeButton.IsEnabled = ($selectedCount -gt 0)
|
||||||
|
|
||||||
|
# Enable the edit button only if exactly one item is selected
|
||||||
|
$editButton.IsEnabled = ($selectedCount -eq 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to remove all selected BYO applications
|
||||||
|
function Remove-SelectedBYOApplications {
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[psobject]$State
|
||||||
|
)
|
||||||
|
|
||||||
|
$listView = $State.Controls.lstApplications
|
||||||
|
$itemsToRemove = @($listView.Items | Where-Object { $_.IsSelected })
|
||||||
|
|
||||||
|
if ($itemsToRemove.Count -eq 0) {
|
||||||
|
# This should not happen if the button is correctly disabled, but as a safeguard:
|
||||||
|
[System.Windows.MessageBox]::Show("No applications are selected for removal.", "Remove Applications", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if the item being edited is among those being removed
|
||||||
|
if ($null -ne $State.Data.editingBYOApplication -and $itemsToRemove.Contains($State.Data.editingBYOApplication)) {
|
||||||
|
# Reset the edit state
|
||||||
|
$State.Data.editingBYOApplication = $null
|
||||||
|
$State.Controls.btnAddApplication.Content = "Add Application"
|
||||||
|
# Clear the form fields
|
||||||
|
$State.Controls.txtAppName.Clear()
|
||||||
|
$State.Controls.txtAppCommandLine.Clear()
|
||||||
|
$State.Controls.txtAppArguments.Clear()
|
||||||
|
$State.Controls.txtAppSource.Clear()
|
||||||
|
$State.Controls.txtAppAdditionalExitCodes.Clear()
|
||||||
|
$State.Controls.chkIgnoreExitCodes.IsChecked = $false
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($item in $itemsToRemove) {
|
||||||
|
$listView.Items.Remove($item)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Re-calculate priorities for the remaining items
|
||||||
|
Update-ListViewPriorities -ListView $listView
|
||||||
|
|
||||||
|
# Update button states (Copy and Remove)
|
||||||
|
Update-CopyButtonState -State $State
|
||||||
|
Update-BYOAppsActionButtonsState -State $State
|
||||||
|
|
||||||
|
# Update the header checkbox state
|
||||||
|
$headerChk = $State.Controls.chkSelectAllBYOApps
|
||||||
|
if ($null -ne $headerChk) {
|
||||||
|
Update-SelectAllHeaderCheckBoxState -ListView $listView -HeaderCheckBox $headerChk
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ask user if they want to save the changes
|
||||||
|
$result = [System.Windows.MessageBox]::Show("The selected applications have been removed from the list. Do you want to save these changes to UserAppList.json now?", "Save Changes", [System.Windows.MessageBoxButton]::YesNo, [System.Windows.MessageBoxImage]::Question)
|
||||||
|
|
||||||
|
if ($result -eq 'Yes') {
|
||||||
|
$userAppListPath = Join-Path -Path $State.Controls.txtApplicationPath.Text -ChildPath 'UserAppList.json'
|
||||||
|
Save-BYOApplicationList -Path $userAppListPath -State $State
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Function to update the enabled state of the Copy Apps button
|
# Function to update the enabled state of the Copy Apps button
|
||||||
function Update-CopyButtonState {
|
function Update-CopyButtonState {
|
||||||
param(
|
param(
|
||||||
@@ -40,6 +119,7 @@ function Remove-Application {
|
|||||||
Update-ListViewPriorities -ListView $listView
|
Update-ListViewPriorities -ListView $listView
|
||||||
# Update the Copy Apps button state
|
# Update the Copy Apps button state
|
||||||
Update-CopyButtonState -State $State
|
Update-CopyButtonState -State $State
|
||||||
|
Update-BYOAppsActionButtonsState -State $State
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,28 +143,62 @@ function Add-BYOApplication {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
$listView = $State.Controls.lstApplications
|
$listView = $State.Controls.lstApplications
|
||||||
# Check for duplicate names
|
|
||||||
$existingApp = $listView.Items | Where-Object { $_.Name -eq $name }
|
# Check if we are in edit mode
|
||||||
if ($existingApp) {
|
if ($null -ne $State.Data.editingBYOApplication) {
|
||||||
[System.Windows.MessageBox]::Show("An application with the name '$name' already exists.", "Duplicate Name", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
$itemToUpdate = $State.Data.editingBYOApplication
|
||||||
return
|
|
||||||
|
# Check for duplicate names, excluding the item being edited
|
||||||
|
$existingApp = $listView.Items | Where-Object { $_.Name -eq $name -and $_ -ne $itemToUpdate }
|
||||||
|
if ($existingApp) {
|
||||||
|
[System.Windows.MessageBox]::Show("An application with the name '$name' already exists.", "Duplicate Name", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# Update the properties of the existing object
|
||||||
|
$itemToUpdate.Name = $name
|
||||||
|
$itemToUpdate.CommandLine = $commandLine
|
||||||
|
$itemToUpdate.Arguments = $arguments
|
||||||
|
$itemToUpdate.Source = $source
|
||||||
|
$itemToUpdate.AdditionalExitCodes = $additionalExitCodes
|
||||||
|
$itemToUpdate.IgnoreNonZeroExitCodes = $ignoreNonZeroExitCodes
|
||||||
|
$itemToUpdate.IgnoreExitCodes = if ($ignoreNonZeroExitCodes) { "Yes" } else { "No" }
|
||||||
|
|
||||||
|
# Refresh the ListView to show the changes
|
||||||
|
$listView.Items.Refresh()
|
||||||
|
|
||||||
|
# Reset state
|
||||||
|
$State.Data.editingBYOApplication = $null
|
||||||
|
$State.Controls.btnAddApplication.Content = "Add Application"
|
||||||
}
|
}
|
||||||
$priority = 1
|
else {
|
||||||
if ($listView.Items.Count -gt 0) {
|
# This is a new application
|
||||||
$priority = ($listView.Items | Measure-Object -Property Priority -Maximum).Maximum + 1
|
# Check for duplicate names
|
||||||
|
$existingApp = $listView.Items | Where-Object { $_.Name -eq $name }
|
||||||
|
if ($existingApp) {
|
||||||
|
[System.Windows.MessageBox]::Show("An application with the name '$name' already exists.", "Duplicate Name", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
$priority = 1
|
||||||
|
if ($listView.Items.Count -gt 0) {
|
||||||
|
$priority = ($listView.Items | Measure-Object -Property Priority -Maximum).Maximum + 1
|
||||||
|
}
|
||||||
|
$application = [PSCustomObject]@{
|
||||||
|
IsSelected = $false
|
||||||
|
Priority = $priority
|
||||||
|
Name = $name
|
||||||
|
CommandLine = $commandLine
|
||||||
|
Arguments = $arguments
|
||||||
|
Source = $source
|
||||||
|
AdditionalExitCodes = $additionalExitCodes
|
||||||
|
IgnoreNonZeroExitCodes = $ignoreNonZeroExitCodes
|
||||||
|
IgnoreExitCodes = if ($ignoreNonZeroExitCodes) { "Yes" } else { "No" }
|
||||||
|
CopyStatus = ""
|
||||||
|
}
|
||||||
|
$listView.Items.Add($application)
|
||||||
}
|
}
|
||||||
$application = [PSCustomObject]@{
|
|
||||||
Priority = $priority
|
# Clear form and update button states for both add and update operations
|
||||||
Name = $name
|
|
||||||
CommandLine = $commandLine
|
|
||||||
Arguments = $arguments
|
|
||||||
Source = $source
|
|
||||||
AdditionalExitCodes = $additionalExitCodes
|
|
||||||
IgnoreNonZeroExitCodes = $ignoreNonZeroExitCodes
|
|
||||||
IgnoreExitCodes = if ($ignoreNonZeroExitCodes) { "Yes" } else { "No" }
|
|
||||||
CopyStatus = ""
|
|
||||||
}
|
|
||||||
$listView.Items.Add($application)
|
|
||||||
$State.Controls.txtAppName.Text = ""
|
$State.Controls.txtAppName.Text = ""
|
||||||
$State.Controls.txtAppCommandLine.Text = ""
|
$State.Controls.txtAppCommandLine.Text = ""
|
||||||
$State.Controls.txtAppArguments.Text = ""
|
$State.Controls.txtAppArguments.Text = ""
|
||||||
@@ -92,6 +206,38 @@ function Add-BYOApplication {
|
|||||||
$State.Controls.txtAppAdditionalExitCodes.Text = ""
|
$State.Controls.txtAppAdditionalExitCodes.Text = ""
|
||||||
$State.Controls.chkIgnoreExitCodes.IsChecked = $false
|
$State.Controls.chkIgnoreExitCodes.IsChecked = $false
|
||||||
Update-CopyButtonState -State $State
|
Update-CopyButtonState -State $State
|
||||||
|
Update-BYOAppsActionButtonsState -State $State
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to populate the form for editing a BYO application
|
||||||
|
function Start-EditBYOApplication {
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[psobject]$State
|
||||||
|
)
|
||||||
|
|
||||||
|
$listView = $State.Controls.lstApplications
|
||||||
|
$itemToEdit = @($listView.Items | Where-Object { $_.IsSelected }) | Select-Object -First 1
|
||||||
|
|
||||||
|
if ($null -eq $itemToEdit) {
|
||||||
|
[System.Windows.MessageBox]::Show("No application selected or multiple applications selected.", "Edit Error", "OK", "Warning")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# Store the item being edited in the state
|
||||||
|
$State.Data.editingBYOApplication = $itemToEdit
|
||||||
|
|
||||||
|
# Populate the form fields
|
||||||
|
$State.Controls.txtAppName.Text = $itemToEdit.Name
|
||||||
|
$State.Controls.txtAppCommandLine.Text = $itemToEdit.CommandLine
|
||||||
|
$State.Controls.txtAppArguments.Text = $itemToEdit.Arguments
|
||||||
|
$State.Controls.txtAppSource.Text = $itemToEdit.Source
|
||||||
|
$State.Controls.txtAppAdditionalExitCodes.Text = $itemToEdit.AdditionalExitCodes
|
||||||
|
$State.Controls.chkIgnoreExitCodes.IsChecked = $itemToEdit.IgnoreNonZeroExitCodes
|
||||||
|
|
||||||
|
# Change the Add button to Update
|
||||||
|
$State.Controls.btnAddApplication.Content = "Update App"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to add a new Apps Script Variable from the UI
|
# Function to add a new Apps Script Variable from the UI
|
||||||
@@ -211,6 +357,7 @@ function Import-BYOApplicationList {
|
|||||||
foreach ($app in $sortedApps) {
|
foreach ($app in $sortedApps) {
|
||||||
$ignoreNonZero = if ($app.PSObject.Properties['IgnoreNonZeroExitCodes']) { $app.IgnoreNonZeroExitCodes } else { $false }
|
$ignoreNonZero = if ($app.PSObject.Properties['IgnoreNonZeroExitCodes']) { $app.IgnoreNonZeroExitCodes } else { $false }
|
||||||
$appObject = [PSCustomObject]@{
|
$appObject = [PSCustomObject]@{
|
||||||
|
IsSelected = $false
|
||||||
Priority = $app.Priority
|
Priority = $app.Priority
|
||||||
Name = $app.Name
|
Name = $app.Name
|
||||||
CommandLine = $app.CommandLine
|
CommandLine = $app.CommandLine
|
||||||
@@ -228,7 +375,7 @@ function Import-BYOApplicationList {
|
|||||||
Update-ListViewPriorities -ListView $listView
|
Update-ListViewPriorities -ListView $listView
|
||||||
# Update the Copy Apps button state
|
# Update the Copy Apps button state
|
||||||
Update-CopyButtonState -State $State
|
Update-CopyButtonState -State $State
|
||||||
|
Update-BYOAppsActionButtonsState -State $State
|
||||||
[System.Windows.MessageBox]::Show("Applications imported successfully from `"$Path`".", "Import Applications", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
|
[System.Windows.MessageBox]::Show("Applications imported successfully from `"$Path`".", "Import Applications", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
|||||||
@@ -356,6 +356,13 @@ function Register-EventHandlers {
|
|||||||
Add-BYOApplication -State $localState
|
Add-BYOApplication -State $localState
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$State.Controls.btnEditApplication.Add_Click({
|
||||||
|
param($eventSource, $routedEventArgs)
|
||||||
|
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||||
|
$localState = $window.Tag
|
||||||
|
Start-EditBYOApplication -State $localState
|
||||||
|
})
|
||||||
|
|
||||||
$State.Controls.btnSaveBYOApplications.Add_Click({
|
$State.Controls.btnSaveBYOApplications.Add_Click({
|
||||||
param($eventSource, $routedEventArgs)
|
param($eventSource, $routedEventArgs)
|
||||||
$window = [System.Windows.Window]::GetWindow($eventSource)
|
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||||
@@ -398,12 +405,21 @@ function Register-EventHandlers {
|
|||||||
$window = [System.Windows.Window]::GetWindow($eventSource)
|
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||||
$localState = $window.Tag
|
$localState = $window.Tag
|
||||||
|
|
||||||
|
# Before clearing, check if we are in edit mode and reset the state
|
||||||
|
if ($null -ne $localState.Data.editingBYOApplication) {
|
||||||
|
$localState.Data.editingBYOApplication = $null
|
||||||
|
$localState.Controls.btnAddApplication.Content = "Add Application"
|
||||||
|
}
|
||||||
|
|
||||||
Clear-ListViewContent -State $localState `
|
Clear-ListViewContent -State $localState `
|
||||||
-ListViewControl $localState.Controls.lstApplications `
|
-ListViewControl $localState.Controls.lstApplications `
|
||||||
-ConfirmationTitle "Clear BYO Applications" `
|
-ConfirmationTitle "Clear BYO Applications" `
|
||||||
-ConfirmationMessage "Are you sure you want to clear all 'Bring Your Own' applications?" `
|
-ConfirmationMessage "Are you sure you want to clear all 'Bring Your Own' applications?" `
|
||||||
-StatusMessage "BYO application list cleared." `
|
-StatusMessage "BYO application list cleared." `
|
||||||
-PostClearAction { Update-CopyButtonState -State $State }
|
-PostClearAction {
|
||||||
|
Update-CopyButtonState -State $State
|
||||||
|
Update-BYOAppsActionButtonsState -State $State
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
$State.Controls.btnCopyBYOApps.Add_Click({
|
$State.Controls.btnCopyBYOApps.Add_Click({
|
||||||
@@ -413,6 +429,13 @@ function Register-EventHandlers {
|
|||||||
Invoke-CopyBYOApps -State $localState -Button $eventSource
|
Invoke-CopyBYOApps -State $localState -Button $eventSource
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$State.Controls.btnRemoveSelectedBYOApps.Add_Click({
|
||||||
|
param($eventSource, $routedEventArgs)
|
||||||
|
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||||
|
$localState = $window.Tag
|
||||||
|
Remove-SelectedBYOApplications -State $localState
|
||||||
|
})
|
||||||
|
|
||||||
$State.Controls.btnMoveTop.Add_Click({
|
$State.Controls.btnMoveTop.Add_Click({
|
||||||
param($eventSource, $routedEventArgs)
|
param($eventSource, $routedEventArgs)
|
||||||
$window = [System.Windows.Window]::GetWindow($eventSource)
|
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||||
@@ -441,6 +464,65 @@ function Register-EventHandlers {
|
|||||||
Move-ListViewItemBottom -ListView $localState.Controls.lstApplications
|
Move-ListViewItemBottom -ListView $localState.Controls.lstApplications
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$State.Controls.lstApplications.Add_PreviewKeyDown({
|
||||||
|
param($eventSource, $keyEvent)
|
||||||
|
if ($keyEvent.Key -eq 'Space') {
|
||||||
|
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||||
|
$localState = $window.Tag
|
||||||
|
Invoke-ListViewItemToggle -ListView $eventSource -State $localState -HeaderCheckBoxKeyName 'chkSelectAllBYOApps'
|
||||||
|
# Update button states after toggle
|
||||||
|
Update-BYOAppsActionButtonsState -State $localState
|
||||||
|
$keyEvent.Handled = $true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$State.Controls.lstApplications.Add_SelectionChanged({
|
||||||
|
param($eventSource, $selChangeEvent)
|
||||||
|
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||||
|
$localState = $window.Tag
|
||||||
|
$headerChk = $localState.Controls.chkSelectAllBYOApps
|
||||||
|
if ($null -ne $headerChk) {
|
||||||
|
Update-SelectAllHeaderCheckBoxState -ListView $localState.Controls.lstApplications -HeaderCheckBox $headerChk
|
||||||
|
}
|
||||||
|
# Update button states based on selection
|
||||||
|
Update-BYOAppsActionButtonsState -State $localState
|
||||||
|
})
|
||||||
|
|
||||||
|
# Add a routed event handler to catch checkbox clicks within the ListView
|
||||||
|
$State.Controls.lstApplications.AddHandler(
|
||||||
|
[System.Windows.Controls.Primitives.ButtonBase]::ClickEvent,
|
||||||
|
[System.Windows.RoutedEventHandler] {
|
||||||
|
param($eventSource, $e)
|
||||||
|
# Check if the original source of the click was a CheckBox
|
||||||
|
$clickedCheckBox = $e.OriginalSource
|
||||||
|
if ($clickedCheckBox -is [System.Windows.Controls.CheckBox]) {
|
||||||
|
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||||
|
$localState = $window.Tag
|
||||||
|
$dataItem = $clickedCheckBox.DataContext
|
||||||
|
|
||||||
|
if ($null -ne $dataItem) {
|
||||||
|
# Defensively add the 'IsSelected' property if it's missing from the data object.
|
||||||
|
# This can happen in some complex UI scenarios or if the object was created without it.
|
||||||
|
if ($null -eq $dataItem.PSObject.Properties['IsSelected']) {
|
||||||
|
$dataItem | Add-Member -MemberType NoteProperty -Name 'IsSelected' -Value $false
|
||||||
|
}
|
||||||
|
|
||||||
|
# Now that we're sure the property exists, set its value.
|
||||||
|
$dataItem.IsSelected = $clickedCheckBox.IsChecked
|
||||||
|
}
|
||||||
|
|
||||||
|
# Update the state of the action buttons based on the new selection.
|
||||||
|
Update-BYOAppsActionButtonsState -State $localState
|
||||||
|
|
||||||
|
# Also, update the header checkbox to reflect the change.
|
||||||
|
$headerChk = $localState.Controls.chkSelectAllBYOApps
|
||||||
|
if ($null -ne $headerChk) {
|
||||||
|
Update-SelectAllHeaderCheckBoxState -ListView $localState.Controls.lstApplications -HeaderCheckBox $headerChk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
# Apps Script Variables Event Handlers
|
# Apps Script Variables Event Handlers
|
||||||
# Attach the handler to the script variables checkbox
|
# Attach the handler to the script variables checkbox
|
||||||
$State.Controls.chkDefineAppsScriptVariables.Add_Checked($appPanelUpdateHandler)
|
$State.Controls.chkDefineAppsScriptVariables.Add_Checked($appPanelUpdateHandler)
|
||||||
|
|||||||
@@ -94,7 +94,9 @@ function Initialize-UIControls {
|
|||||||
$State.Controls.btnAddApplication = $window.FindName('btnAddApplication')
|
$State.Controls.btnAddApplication = $window.FindName('btnAddApplication')
|
||||||
$State.Controls.btnSaveBYOApplications = $window.FindName('btnSaveBYOApplications')
|
$State.Controls.btnSaveBYOApplications = $window.FindName('btnSaveBYOApplications')
|
||||||
$State.Controls.btnLoadBYOApplications = $window.FindName('btnLoadBYOApplications')
|
$State.Controls.btnLoadBYOApplications = $window.FindName('btnLoadBYOApplications')
|
||||||
|
$State.Controls.btnEditApplication = $window.FindName('btnEditApplication')
|
||||||
$State.Controls.btnClearBYOApplications = $window.FindName('btnClearBYOApplications')
|
$State.Controls.btnClearBYOApplications = $window.FindName('btnClearBYOApplications')
|
||||||
|
$State.Controls.btnRemoveSelectedBYOApps = $window.FindName('btnRemoveSelectedBYOApps')
|
||||||
$State.Controls.btnCopyBYOApps = $window.FindName('btnCopyBYOApps')
|
$State.Controls.btnCopyBYOApps = $window.FindName('btnCopyBYOApps')
|
||||||
$State.Controls.lstApplications = $window.FindName('lstApplications')
|
$State.Controls.lstApplications = $window.FindName('lstApplications')
|
||||||
$State.Controls.btnMoveTop = $window.FindName('btnMoveTop')
|
$State.Controls.btnMoveTop = $window.FindName('btnMoveTop')
|
||||||
@@ -456,6 +458,28 @@ function Initialize-DynamicUIElements {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# BYO Applications ListView setup
|
||||||
|
$byoAppsGridView = New-Object System.Windows.Controls.GridView
|
||||||
|
$State.Controls.lstApplications.View = $byoAppsGridView
|
||||||
|
|
||||||
|
# Set ListViewItem style to stretch content horizontally
|
||||||
|
$itemStyleBYOApps = New-Object System.Windows.Style([System.Windows.Controls.ListViewItem])
|
||||||
|
$itemStyleBYOApps.Setters.Add((New-Object System.Windows.Setter([System.Windows.Controls.ListViewItem]::HorizontalContentAlignmentProperty, [System.Windows.HorizontalAlignment]::Stretch)))
|
||||||
|
$State.Controls.lstApplications.ItemContainerStyle = $itemStyleBYOApps
|
||||||
|
|
||||||
|
# Add the selectable column
|
||||||
|
Add-SelectableGridViewColumn -ListView $State.Controls.lstApplications -State $State -HeaderCheckBoxKeyName "chkSelectAllBYOApps" -ColumnWidth 60
|
||||||
|
|
||||||
|
# Add other sortable columns
|
||||||
|
Add-SortableColumn -gridView $byoAppsGridView -header "Priority" -binding "Priority" -width 60 -headerHorizontalAlignment Left
|
||||||
|
Add-SortableColumn -gridView $byoAppsGridView -header "Name" -binding "Name" -width 150 -headerHorizontalAlignment Left
|
||||||
|
Add-SortableColumn -gridView $byoAppsGridView -header "Command Line" -binding "CommandLine" -width 200 -headerHorizontalAlignment Left
|
||||||
|
Add-SortableColumn -gridView $byoAppsGridView -header "Arguments" -binding "Arguments" -width 200 -headerHorizontalAlignment Left
|
||||||
|
Add-SortableColumn -gridView $byoAppsGridView -header "Source" -binding "Source" -width 150 -headerHorizontalAlignment Left
|
||||||
|
Add-SortableColumn -gridView $byoAppsGridView -header "Exit Codes" -binding "AdditionalExitCodes" -width 100 -headerHorizontalAlignment Left
|
||||||
|
Add-SortableColumn -gridView $byoAppsGridView -header "Ignore Exit Codes" -binding "IgnoreExitCodes" -width 120 -headerHorizontalAlignment Left
|
||||||
|
Add-SortableColumn -gridView $byoAppsGridView -header "Copy Status" -binding "CopyStatus" -width 150 -headerHorizontalAlignment Left
|
||||||
|
|
||||||
# Apps Script Variables ListView setup
|
# Apps Script Variables ListView setup
|
||||||
# Bind ItemsSource to the data list
|
# Bind ItemsSource to the data list
|
||||||
$State.Controls.lstAppsScriptVariables.ItemsSource = $State.Data.appsScriptVariablesDataList.ToArray()
|
$State.Controls.lstAppsScriptVariables.ItemsSource = $State.Data.appsScriptVariablesDataList.ToArray()
|
||||||
|
|||||||
Reference in New Issue
Block a user