mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
CmdPal: Linq clean-up (All Apps) (#41551)
Beginning the process of removing System.Linq from CmdPal. This PR removes it from the All Apps extension.
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ManagedCommon;
|
||||
@@ -62,7 +61,9 @@ public sealed partial class AllAppsPage : ListPage
|
||||
{
|
||||
// Build or update the list if needed
|
||||
BuildListItems();
|
||||
return pinnedApps.Concat(unpinnedApps).ToArray();
|
||||
|
||||
AppListItem[] allApps = [.. pinnedApps, .. unpinnedApps];
|
||||
return allApps;
|
||||
}
|
||||
|
||||
private void BuildListItems()
|
||||
@@ -93,16 +94,25 @@ public sealed partial class AllAppsPage : ListPage
|
||||
|
||||
private AppItem[] GetAllApps()
|
||||
{
|
||||
var uwpResults = _appCache.UWPs
|
||||
.Where((application) => application.Enabled)
|
||||
.Select(app => app.ToAppItem());
|
||||
List<AppItem> allApps = new();
|
||||
|
||||
var win32Results = _appCache.Win32s
|
||||
.Where((application) => application.Enabled && application.Valid)
|
||||
.Select(app => app.ToAppItem());
|
||||
foreach (var uwpApp in _appCache.UWPs)
|
||||
{
|
||||
if (uwpApp.Enabled)
|
||||
{
|
||||
allApps.Add(uwpApp.ToAppItem());
|
||||
}
|
||||
}
|
||||
|
||||
var allApps = uwpResults.Concat(win32Results).ToArray();
|
||||
return allApps;
|
||||
foreach (var win32App in _appCache.Win32s)
|
||||
{
|
||||
if (win32App.Enabled && win32App.Valid)
|
||||
{
|
||||
allApps.Add(win32App.ToAppItem());
|
||||
}
|
||||
}
|
||||
|
||||
return [.. allApps];
|
||||
}
|
||||
|
||||
internal (AppItem[] AllApps, AppListItem[] PinnedItems, AppListItem[] UnpinnedItems) GetPrograms()
|
||||
@@ -118,9 +128,7 @@ public sealed partial class AllAppsPage : ListPage
|
||||
|
||||
if (isPinned)
|
||||
{
|
||||
appListItem.Tags = appListItem.Tags
|
||||
.Concat([new Tag() { Icon = Icons.PinIcon }])
|
||||
.ToArray();
|
||||
appListItem.Tags = [.. appListItem.Tags, new Tag() { Icon = Icons.PinIcon }];
|
||||
pinned.Add(appListItem);
|
||||
}
|
||||
else
|
||||
@@ -129,15 +137,14 @@ public sealed partial class AllAppsPage : ListPage
|
||||
}
|
||||
}
|
||||
|
||||
pinned.Sort((a, b) => string.Compare(a.Title, b.Title, StringComparison.Ordinal));
|
||||
unpinned.Sort((a, b) => string.Compare(a.Title, b.Title, StringComparison.Ordinal));
|
||||
|
||||
return (
|
||||
allApps
|
||||
.ToArray(),
|
||||
pinned
|
||||
.OrderBy(app => app.Title)
|
||||
.ToArray(),
|
||||
unpinned
|
||||
.OrderBy(app => app.Title)
|
||||
.ToArray());
|
||||
allApps,
|
||||
pinned.ToArray(),
|
||||
unpinned.ToArray()
|
||||
);
|
||||
}
|
||||
|
||||
private void OnPinStateChanged(object? sender, PinStateChangedEventArgs e)
|
||||
@@ -147,44 +154,55 @@ public sealed partial class AllAppsPage : ListPage
|
||||
* So, instead, we'll just compare pinned items to move existing
|
||||
* items between the two lists.
|
||||
*/
|
||||
var existingAppItem = allApps.FirstOrDefault(f => f.AppIdentifier == e.AppIdentifier);
|
||||
AppItem? existingAppItem = null;
|
||||
|
||||
foreach (var app in allApps)
|
||||
{
|
||||
if (app.AppIdentifier == e.AppIdentifier)
|
||||
{
|
||||
existingAppItem = app;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (existingAppItem is not null)
|
||||
{
|
||||
var appListItem = new AppListItem(existingAppItem, true, e.IsPinned);
|
||||
|
||||
var newPinned = new List<AppListItem>(pinnedApps);
|
||||
var newUnpinned = new List<AppListItem>(unpinnedApps);
|
||||
|
||||
if (e.IsPinned)
|
||||
{
|
||||
// Remove it from the unpinned apps array
|
||||
this.unpinnedApps = this.unpinnedApps
|
||||
.Where(app => app.AppIdentifier != existingAppItem.AppIdentifier)
|
||||
.OrderBy(app => app.Title)
|
||||
.ToArray();
|
||||
|
||||
var newPinned = this.pinnedApps.ToList();
|
||||
newPinned.Add(appListItem);
|
||||
|
||||
this.pinnedApps = newPinned
|
||||
.OrderBy(app => app.Title)
|
||||
.ToArray();
|
||||
foreach (var app in newUnpinned)
|
||||
{
|
||||
if (app.AppIdentifier == e.AppIdentifier)
|
||||
{
|
||||
newUnpinned.Remove(app);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove it from the pinned apps array
|
||||
this.pinnedApps = this.pinnedApps
|
||||
.Where(app => app.AppIdentifier != existingAppItem.AppIdentifier)
|
||||
.OrderBy(app => app.Title)
|
||||
.ToArray();
|
||||
|
||||
var newUnpinned = this.unpinnedApps.ToList();
|
||||
newUnpinned.Add(appListItem);
|
||||
|
||||
this.unpinnedApps = newUnpinned
|
||||
.OrderBy(app => app.Title)
|
||||
.ToArray();
|
||||
foreach (var app in newPinned)
|
||||
{
|
||||
if (app.AppIdentifier == e.AppIdentifier)
|
||||
{
|
||||
newPinned.Remove(app);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RaiseItemsChanged(0);
|
||||
pinnedApps = newPinned.ToArray();
|
||||
unpinnedApps = newUnpinned.ToArray();
|
||||
}
|
||||
|
||||
RaiseItemsChanged(0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user