Skip to content

Commit a5d7005

Browse files
refactor foreach
1 parent 4296652 commit a5d7005

File tree

1 file changed

+32
-37
lines changed

1 file changed

+32
-37
lines changed

Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
63
using Flow.Launcher.Plugin.Program.Views.Models;
74

85
namespace Flow.Launcher.Plugin.Program.Views.Commands
@@ -20,43 +17,47 @@ internal static List<ProgramSource> LoadProgramSources()
2017

2118
internal static void DisplayAllPrograms()
2219
{
23-
Main._win32s
24-
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
25-
.ToList()
26-
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource(t1)));
20+
var win32 = Main._win32s
21+
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
22+
.Select(x => new ProgramSource(x));
2723

28-
Main._uwps
29-
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
30-
.ToList()
31-
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource(t1)));
24+
var uwp = Main._uwps
25+
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
26+
.Select(x => new ProgramSource(x));
27+
28+
ProgramSetting.ProgramSettingDisplayList.AddRange(win32);
29+
ProgramSetting.ProgramSettingDisplayList.AddRange(uwp);
3230
}
3331

3432
internal static void SetProgramSourcesStatus(List<ProgramSource> selectedProgramSourcesToDisable, bool status)
3533
{
36-
ProgramSetting.ProgramSettingDisplayList
37-
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
38-
.ToList()
39-
.ForEach(t1 => t1.Enabled = status);
34+
foreach(var program in ProgramSetting.ProgramSettingDisplayList)
35+
{
36+
if (selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == program.UniqueIdentifier && program.Enabled != status))
37+
{
38+
program.Enabled = status;
39+
}
40+
}
4041

41-
Main._win32s
42-
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
43-
.ToList()
44-
.ForEach(t1 => t1.Enabled = status);
42+
foreach(var program in Main._win32s)
43+
{
44+
if (selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == program.UniqueIdentifier && program.Enabled != status))
45+
{
46+
program.Enabled = status;
47+
}
48+
}
4549

46-
Main._uwps
47-
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
48-
.ToList()
49-
.ForEach(t1 => t1.Enabled = status);
50+
foreach (var program in Main._uwps)
51+
{
52+
if (selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == program.UniqueIdentifier && program.Enabled != status))
53+
{
54+
program.Enabled = status;
55+
}
56+
}
5057
}
5158

5259
internal static void StoreDisabledInSettings()
5360
{
54-
// no need since using refernce now
55-
//Main._settings.ProgramSources
56-
// .Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && !x.Enabled))
57-
// .ToList()
58-
// .ForEach(t1 => t1.Enabled = false);
59-
6061
// Disabled, not in DisabledProgramSources or ProgramSources
6162
var tmp = ProgramSetting.ProgramSettingDisplayList
6263
.Where(t1 => !t1.Enabled
@@ -68,13 +69,7 @@ internal static void StoreDisabledInSettings()
6869

6970
internal static void RemoveDisabledFromSettings()
7071
{
71-
//Main._settings.ProgramSources
72-
// .Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && x.Enabled))
73-
// .ToList()
74-
// .ForEach(t1 => t1.Enabled = true);
75-
76-
Main._settings.DisabledProgramSources
77-
.RemoveAll(t1 => t1.Enabled);
72+
Main._settings.DisabledProgramSources.RemoveAll(t1 => t1.Enabled);
7873
}
7974

8075
internal static bool IsReindexRequired(this List<ProgramSource> selectedItems)

0 commit comments

Comments
 (0)