diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Assets/FileLocksmith.png b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Assets/FileLocksmith.png index ff20dfb146..7c2fcbdd3d 100644 Binary files a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Assets/FileLocksmith.png and b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Assets/FileLocksmith.png differ diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Commands/CopyColorCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Commands/CopyColorCommand.cs new file mode 100644 index 0000000000..1e7b37edc2 --- /dev/null +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Commands/CopyColorCommand.cs @@ -0,0 +1,70 @@ +// 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.Globalization; +using System.IO; +using System.Windows.Forms; +using Microsoft.CommandPalette.Extensions.Toolkit; + +namespace PowerToysExtension.Commands; + +/// +/// Copies the most recently picked color from the PowerToys Color Picker history if available. +/// +internal sealed partial class CopyColorCommand : InvokableCommand +{ + public CopyColorCommand() + { + Name = "Copy last picked color"; + } + + public override CommandResult Invoke() + { + try + { + var color = TryGetLastColor(); + if (string.IsNullOrEmpty(color)) + { + return CommandResult.ShowToast("No color found in Color Picker history."); + } + + System.Windows.Forms.Clipboard.SetText(color); + return CommandResult.ShowToast($"Copied {color}"); + } + catch (Exception ex) + { + return CommandResult.ShowToast($"Failed to copy color: {ex.Message}"); + } + } + + private static string? TryGetLastColor() + { + var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + var historyPath = Path.Combine(localAppData, "Microsoft", "PowerToys", "ColorPicker", "colorHistory.json"); + if (!File.Exists(historyPath)) + { + return null; + } + + var lines = File.ReadAllLines(historyPath); + + // crude parse: look for last occurrence of "#RRGGBB" in the file + for (var i = lines.Length - 1; i >= 0; i--) + { + var line = lines[i]; + var idx = line.IndexOf('#'); + if (idx >= 0 && line.Length >= idx + 7) + { + var candidate = line.Substring(idx, 7); + if (candidate.Length == 7 && candidate[0] == '#') + { + return candidate.ToUpper(CultureInfo.InvariantCulture); + } + } + } + + return null; + } +} diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helper/ModuleItemsHelper.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/ModuleItemsHelper.cs similarity index 89% rename from src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helper/ModuleItemsHelper.cs rename to src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/ModuleItemsHelper.cs index 9477768ba5..e063aae4c1 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helper/ModuleItemsHelper.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/ModuleItemsHelper.cs @@ -10,9 +10,9 @@ using Common.UI; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; using PowerToysExtension.Commands; -using PowerToysExtension.Helper; +using PowerToysExtension.Pages; -namespace PowerToysExtension.Helper; +namespace PowerToysExtension.Helpers; /// /// Builds the list of PowerToys module entries and supports basic fuzzy filtering. @@ -77,8 +77,8 @@ internal static class ModuleItemsHelper var settingsCommand = new OpenInSettingsCommand(module, $"Open {title} settings"); - // Module-specific extras - var more = new List(); + var more = new List(); + switch (module) { case SettingsDeepLink.SettingsWindow.Awake: @@ -89,12 +89,12 @@ internal static class ModuleItemsHelper break; case SettingsDeepLink.SettingsWindow.Workspaces: + more.Add(new CommandContextItem(new WorkspacesListPage())); more.Add(new CommandContextItem(new OpenWorkspaceEditorCommand())); - more.Add(new CommandContextItem(new OpenPowerToysSettingsCommand("Workspaces", "Workspaces"))); break; - case SettingsDeepLink.SettingsWindow.Overview: - // Overview just opens main settings + case SettingsDeepLink.SettingsWindow.ColorPicker: + more.Add(new CommandContextItem(new CopyColorCommand())); break; default: diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helper/PowerToysResourcesHelper.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/PowerToysResourcesHelper.cs similarity index 97% rename from src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helper/PowerToysResourcesHelper.cs rename to src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/PowerToysResourcesHelper.cs index d781efb25a..bdf1ed2c39 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helper/PowerToysResourcesHelper.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/PowerToysResourcesHelper.cs @@ -5,7 +5,7 @@ using Microsoft.CommandPalette.Extensions.Toolkit; using static Common.UI.SettingsDeepLink; -namespace PowerToysExtension.Helper; +namespace PowerToysExtension.Helpers; internal static class PowerToysResourcesHelper { @@ -18,7 +18,7 @@ internal static class PowerToysResourcesHelper SettingsWindow.ColorPicker => "Assets\\ColorPicker.png", SettingsWindow.FancyZones => "Assets\\FancyZones.png", SettingsWindow.Hosts => "Assets\\Hosts.png", - SettingsWindow.PowerOCR => "Assets\\PowerOcr.png", + SettingsWindow.PowerOCR => "Assets\\TextExtractor.png", SettingsWindow.RegistryPreview => "Assets\\RegistryPreview.png", SettingsWindow.MeasureTool => "Assets\\ScreenRuler.png", SettingsWindow.ShortcutGuide => "Assets\\ShortcutGuide.png", diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/WorkspaceItemsHelper.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/WorkspaceItemsHelper.cs index 8c282e5b90..865b0ebf65 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/WorkspaceItemsHelper.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/WorkspaceItemsHelper.cs @@ -78,6 +78,8 @@ internal static class WorkspaceItemsHelper return items.ToArray(); } + internal static IListItem[] FilteredItems(string searchText) => GetWorkspaceItems(searchText); + private static List LoadWorkspaces() { try diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Microsoft.CmdPal.Ext.PowerToys.csproj b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Microsoft.CmdPal.Ext.PowerToys.csproj index 77da19bc3f..6a27e8c08a 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Microsoft.CmdPal.Ext.PowerToys.csproj +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Microsoft.CmdPal.Ext.PowerToys.csproj @@ -8,6 +8,7 @@ app.manifest win-$(Platform).pubxml false + true true true $(SolutionDir)$(Platform)\$(Configuration)\WinUI3Apps\CmdPalExtensions\$(MSBuildProjectName)\ @@ -25,6 +26,7 @@ + @@ -56,6 +58,8 @@ + + true true diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Pages/PowerToysListPage.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Pages/PowerToysListPage.cs index d43a2d373c..d7163862e9 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Pages/PowerToysListPage.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Pages/PowerToysListPage.cs @@ -4,7 +4,7 @@ using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; -using PowerToysExtension.Helper; +using PowerToysExtension.Helpers; namespace PowerToysExtension.Pages; diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Pages/WorkspacesListPage.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Pages/WorkspacesListPage.cs index 79d3c19337..d5de42f19f 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Pages/WorkspacesListPage.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Pages/WorkspacesListPage.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation +// 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. @@ -10,36 +10,27 @@ namespace PowerToysExtension.Pages; internal sealed partial class WorkspacesListPage : DynamicListPage { - private readonly CommandItem _emptyContent; + private readonly CommandItem _emptyMessage; public WorkspacesListPage() { Icon = IconHelpers.FromRelativePath("Assets\\Workspaces.png"); - Title = "Workspaces"; - Name = "Workspaces"; - Id = "com.microsoft.powertoys.workspaces"; - - _emptyContent = new CommandItem() + Name = Title = "Workspaces"; + Id = "com.microsoft.cmdpal.powertoys.workspaces"; + _emptyMessage = new CommandItem() { - Title = "No workspaces found", - Subtitle = "Create a workspace in PowerToys to get started.", Icon = IconHelpers.FromRelativePath("Assets\\Workspaces.png"), + Title = "No workspaces found", + Subtitle = SearchText, }; - - EmptyContent = _emptyContent; + EmptyContent = _emptyMessage; } public override void UpdateSearchText(string oldSearch, string newSearch) { - _emptyContent.Subtitle = string.IsNullOrWhiteSpace(newSearch) - ? "Create a workspace in PowerToys to get started." - : $"No workspaces matching '{newSearch}'"; - + _emptyMessage.Subtitle = newSearch; RaiseItemsChanged(0); } - public override IListItem[] GetItems() - { - return WorkspaceItemsHelper.GetWorkspaceItems(SearchText); - } + public override IListItem[] GetItems() => WorkspaceItemsHelper.FilteredItems(SearchText); } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/app.manifest b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/app.manifest index 5e5e6201a2..0d1318e5eb 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/app.manifest +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/app.manifest @@ -8,10 +8,4 @@ - - - true/PM - PerMonitorV2 - -