mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Add functionality to manage applications - implement Add and Remove buttons with priority handling in the UI
This commit is contained in:
@@ -753,6 +753,7 @@ function Invoke-ListViewSort {
|
|||||||
@($unselectedItems | Sort-Object -Property $property)
|
@($unselectedItems | Sort-Object -Property $property)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
#DO NOT CHANGE THIS LINE
|
||||||
@($unselectedItems | Sort-Object -Property $property -Descending)
|
@($unselectedItems | Sort-Object -Property $property -Descending)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1342,6 +1343,53 @@ $window.Add_Loaded({
|
|||||||
$window.FindName('txtPEDriversFolder').Text = $selectedPath
|
$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
|
# 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
|
# Button: Build FFU
|
||||||
$btnRun = $window.FindName('btnRun')
|
$btnRun = $window.FindName('btnRun')
|
||||||
$btnRun.Add_Click({
|
$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()
|
[void]$window.ShowDialog()
|
||||||
|
|||||||
@@ -702,6 +702,36 @@
|
|||||||
Margin="5,0,0,0"
|
Margin="5,0,0,0"
|
||||||
VerticalAlignment="Center"/>
|
VerticalAlignment="Center"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
<!-- Add Application Button -->
|
||||||
|
<Button x:Name="btnAddApplication"
|
||||||
|
Content="Add Application"
|
||||||
|
Width="120"
|
||||||
|
HorizontalAlignment="Left"
|
||||||
|
Margin="0,10,0,10"
|
||||||
|
Padding="10,5"
|
||||||
|
ToolTip="Add the application to the list"/>
|
||||||
|
|
||||||
|
<!-- Applications ListView -->
|
||||||
|
<ListView x:Name="lstApplications"
|
||||||
|
Height="200"
|
||||||
|
Margin="0,0,0,10">
|
||||||
|
<ListView.View>
|
||||||
|
<GridView>
|
||||||
|
<GridViewColumn Header="Priority" DisplayMemberBinding="{Binding Priority}" Width="60"/>
|
||||||
|
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="200"/>
|
||||||
|
<GridViewColumn Header="Command Line" DisplayMemberBinding="{Binding CommandLine}" Width="300"/>
|
||||||
|
<GridViewColumn Header="Source" DisplayMemberBinding="{Binding Source}" Width="250"/>
|
||||||
|
<GridViewColumn Header="Action" Width="80">
|
||||||
|
<GridViewColumn.CellTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<Button Content="Remove" Tag="{Binding Priority}" Width="70"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</GridViewColumn.CellTemplate>
|
||||||
|
</GridViewColumn>
|
||||||
|
</GridView>
|
||||||
|
</ListView.View>
|
||||||
|
</ListView>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
Reference in New Issue
Block a user