From cb295bbd9053a743b696c9c1b31c376d3b52d078 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Mon, 24 Oct 2022 23:26:41 +0800 Subject: [PATCH] Refactor --- .../Views/Commands/ProgramSettingDisplay.cs | 27 +++++++------------ .../Views/ProgramSetting.xaml.cs | 12 ++++----- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs index 6fb6ce8f4..4ebca8cf3 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs @@ -9,24 +9,17 @@ namespace Flow.Launcher.Plugin.Program.Views.Commands { internal static class ProgramSettingDisplay { - internal static List LoadProgramSources(this List programSources) + internal static List LoadProgramSources() { - var list = new List(programSources); - // Even though these are disabled, we still want to display them so users can enable later on - Main._settings - .DisabledProgramSources - .Where(t1 => !Main._settings - .ProgramSources // program sourcces added above already, so exlcude - .Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)) - .Select(x => x) - .ToList() - .ForEach(x => list.Add(new ProgramSource(x))); - - return list; + return Main._settings + .DisabledProgramSources + .Select(s => new ProgramSource(s)) + .Union(Main._settings.ProgramSources) + .ToList(); } - internal static void LoadAllApplications(this List list) + internal static void DisplayAllPrograms() { Main._win32s .Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier)) @@ -39,7 +32,7 @@ namespace Flow.Launcher.Plugin.Program.Views.Commands .ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource(t1))); } - internal static void SetProgramSourcesStatus(this List list, List selectedProgramSourcesToDisable, bool status) + internal static void SetProgramSourcesStatus(List selectedProgramSourcesToDisable, bool status) { ProgramSetting.ProgramSettingDisplayList .Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status)) @@ -57,7 +50,7 @@ namespace Flow.Launcher.Plugin.Program.Views.Commands .ForEach(t1 => t1.Enabled = status); } - internal static void StoreDisabledInSettings(this List list) + internal static void StoreDisabledInSettings() { Main._settings.ProgramSources .Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && !x.Enabled)) @@ -72,7 +65,7 @@ namespace Flow.Launcher.Plugin.Program.Views.Commands .Add(new DisabledProgramSource(x))); } - internal static void RemoveDisabledFromSettings(this List list) + internal static void RemoveDisabledFromSettings() { Main._settings.ProgramSources .Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && x.Enabled)) diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs index a1c85087c..eaf953f9a 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs @@ -88,7 +88,7 @@ namespace Flow.Launcher.Plugin.Program.Views private void Setting_Loaded(object sender, RoutedEventArgs e) { - ProgramSettingDisplayList = _settings.ProgramSources.LoadProgramSources(); + ProgramSettingDisplayList = ProgramSettingDisplay.LoadProgramSources(); programSourceView.ItemsSource = ProgramSettingDisplayList; ViewRefresh(); @@ -221,7 +221,7 @@ namespace Flow.Launcher.Plugin.Program.Views private void btnLoadAllProgramSource_OnClick(object sender, RoutedEventArgs e) { - ProgramSettingDisplayList.LoadAllApplications(); + ProgramSettingDisplay.DisplayAllPrograms(); ViewRefresh(); } @@ -256,15 +256,15 @@ namespace Flow.Launcher.Plugin.Program.Views } else if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(selectedItems)) { - ProgramSettingDisplayList.SetProgramSourcesStatus(selectedItems, false); + ProgramSettingDisplay.SetProgramSourcesStatus(selectedItems, false); - ProgramSettingDisplayList.StoreDisabledInSettings(); + ProgramSettingDisplay.StoreDisabledInSettings(); } else { - ProgramSettingDisplayList.SetProgramSourcesStatus(selectedItems, true); + ProgramSettingDisplay.SetProgramSourcesStatus(selectedItems, true); - ProgramSettingDisplayList.RemoveDisabledFromSettings(); + ProgramSettingDisplay.RemoveDisabledFromSettings(); } if (selectedItems.IsReindexRequired())