mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
Cmdpal extension: Powertoys extension for cmdpal (#44006)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [ ] Closes: #xxx <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Installer built, and every command works as expected, Now use sparse app deployment, so we don't need an extra msix --------- Co-authored-by: kaitao-ms <kaitao1105@gmail.com>
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CommandPalette.Extensions;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using PowerToysExtension.Commands;
|
||||
using PowerToysExtension.Helpers;
|
||||
|
||||
namespace PowerToysExtension.Pages;
|
||||
|
||||
internal sealed partial class FancyZonesLayoutsPage : DynamicListPage
|
||||
{
|
||||
private readonly CommandItem _emptyMessage;
|
||||
|
||||
public FancyZonesLayoutsPage()
|
||||
{
|
||||
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("FancyZones.png");
|
||||
Name = Title = "FancyZones Layouts";
|
||||
Id = "com.microsoft.cmdpal.powertoys.fancyzones.layouts";
|
||||
|
||||
_emptyMessage = new CommandItem()
|
||||
{
|
||||
Title = "No layouts found",
|
||||
Subtitle = "Open FancyZones Editor once to initialize layouts.",
|
||||
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("FancyZones.png"),
|
||||
};
|
||||
EmptyContent = _emptyMessage;
|
||||
|
||||
// Purge orphaned cache files in background (non-blocking)
|
||||
Task.Run(FancyZonesThumbnailRenderer.PurgeOrphanedCache);
|
||||
}
|
||||
|
||||
public override void UpdateSearchText(string oldSearch, string newSearch)
|
||||
{
|
||||
RaiseItemsChanged(0);
|
||||
}
|
||||
|
||||
public override IListItem[] GetItems()
|
||||
{
|
||||
try
|
||||
{
|
||||
var layouts = FancyZonesDataService.GetLayouts();
|
||||
if (!string.IsNullOrWhiteSpace(SearchText))
|
||||
{
|
||||
layouts = layouts
|
||||
.Where(l => l.Title.Contains(SearchText, StringComparison.CurrentCultureIgnoreCase) ||
|
||||
l.Subtitle.Contains(SearchText, StringComparison.CurrentCultureIgnoreCase))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
if (layouts.Count == 0)
|
||||
{
|
||||
return Array.Empty<IListItem>();
|
||||
}
|
||||
|
||||
_ = FancyZonesDataService.TryGetMonitors(out var monitors, out _);
|
||||
var fallbackIcon = PowerToysResourcesHelper.IconFromSettingsIcon("FancyZones.png");
|
||||
|
||||
var items = new List<IListItem>(layouts.Count);
|
||||
foreach (var layout in layouts)
|
||||
{
|
||||
var defaultCommand = new ApplyFancyZonesLayoutCommand(layout, monitor: null);
|
||||
|
||||
var item = new FancyZonesLayoutListItem(defaultCommand, layout, fallbackIcon)
|
||||
{
|
||||
MoreCommands = BuildLayoutContext(layout, monitors),
|
||||
};
|
||||
|
||||
items.Add(item);
|
||||
}
|
||||
|
||||
return items.ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_emptyMessage.Subtitle = ex.Message;
|
||||
return Array.Empty<IListItem>();
|
||||
}
|
||||
}
|
||||
|
||||
private static IContextItem[] BuildLayoutContext(FancyZonesLayoutDescriptor layout, IReadOnlyList<FancyZonesMonitorDescriptor> monitors)
|
||||
{
|
||||
var commands = new List<IContextItem>(monitors.Count);
|
||||
|
||||
for (var i = 0; i < monitors.Count; i++)
|
||||
{
|
||||
var monitor = monitors[i];
|
||||
commands.Add(new CommandContextItem(new ApplyFancyZonesLayoutCommand(layout, monitor))
|
||||
{
|
||||
Title = string.Format(CultureInfo.CurrentCulture, "Apply to {0}", monitor.Title),
|
||||
Subtitle = monitor.Subtitle,
|
||||
});
|
||||
}
|
||||
|
||||
return commands.ToArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user