From bd730b5418c0cea37faef8c73d508e9b0f7fcbc1 Mon Sep 17 00:00:00 2001 From: Marterich <47688561+Marterich@users.noreply.github.com> Date: Tue, 20 Aug 2024 22:33:01 +0200 Subject: [PATCH] First Selector and Logic --- functions/private/Set-DownloadEngine.ps1 | 28 ++++++++++++++++++++++++ scripts/main.ps1 | 13 +++++++++++ xaml/inputXML.xaml | 5 +++++ 3 files changed, 46 insertions(+) create mode 100644 functions/private/Set-DownloadEngine.ps1 diff --git a/functions/private/Set-DownloadEngine.ps1 b/functions/private/Set-DownloadEngine.ps1 new file mode 100644 index 00000000..1b293a5d --- /dev/null +++ b/functions/private/Set-DownloadEngine.ps1 @@ -0,0 +1,28 @@ +function Set-DownloadEngine { + $CheckBoxes = $sync.GetEnumerator() | Where-Object { $_.Value -is [System.Windows.Controls.CheckBox] } + foreach ($CheckBox in $CheckBoxes) { + if ($CheckBox.Key.StartsWith("WPFInstall")) { + Switch ($sync.DownloadEngine) { + "Winget" { + if ($($sync.configs.applications.$($CheckBox.Name).winget) -eq "na"){ + $CheckBox.Value.Visibility = "Collapsed" + } + else{ + $CheckBox.Value.Visibility = "Visible" + } + } + "Chocolatey"{ + if ($($sync.configs.applications.$($CheckBox.Name).chocolatey) -eq "na"){ + $CheckBox.Value.Visibility = "Collapsed" + } + else { + $CheckBox.Value.Visibility = "Visible" + } + } + default{ + $CheckBox.Value.Visibility = "Visible" + } + } + } + } +} \ No newline at end of file diff --git a/scripts/main.ps1 b/scripts/main.ps1 index c1d476f4..809810dc 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -87,6 +87,19 @@ try { $xaml.SelectNodes("//*[@Name]") | ForEach-Object {$sync["$("$($psitem.Name)")"] = $sync["Form"].FindName($psitem.Name)} +#Initialize Download Engine +$selectedItem = $sync.WPFselectDownloadEngine.SelectedItem +$selectedText = $selectedItem.Content +$sync.DownloadEngine = $selectedText +Set-DownloadEngine + +$sync.WPFselectDownloadEngine.Add_SelectionChanged({ + $selectedItem = $sync.WPFselectDownloadEngine.SelectedItem + $selectedText = $selectedItem.Content + $sync.DownloadEngine = $selectedText + Set-DownloadEngine +}) + $sync.keys | ForEach-Object { if($sync.$psitem) { if($($sync["$psitem"].GetType() | Select-Object -ExpandProperty Name) -eq "CheckBox" ` diff --git a/xaml/inputXML.xaml b/xaml/inputXML.xaml index 332122b0..1370e2d4 100644 --- a/xaml/inputXML.xaml +++ b/xaml/inputXML.xaml @@ -793,6 +793,11 @@