mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 19:27:56 +01:00
wire things up
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 12 KiB |
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Copies the most recently picked color from the PowerToys Color Picker history if available.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 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<CommandContextItem>();
|
||||
var more = new List<ICommandContextItem>();
|
||||
|
||||
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:
|
||||
@@ -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",
|
||||
@@ -78,6 +78,8 @@ internal static class WorkspaceItemsHelper
|
||||
return items.ToArray();
|
||||
}
|
||||
|
||||
internal static IListItem[] FilteredItems(string searchText) => GetWorkspaceItems(searchText);
|
||||
|
||||
private static List<WorkspaceProject> LoadWorkspaces()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
|
||||
<UseWinUI>false</UseWinUI>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<EnableMsixTooling>true</EnableMsixTooling>
|
||||
<GenerateAppxPackageOnBuild>true</GenerateAppxPackageOnBuild>
|
||||
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\WinUI3Apps\CmdPalExtensions\$(MSBuildProjectName)\</OutputPath>
|
||||
@@ -25,6 +26,7 @@
|
||||
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
|
||||
<Content Include="Assets\StoreLogo.png" />
|
||||
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
|
||||
<Content Include="Assets\FileLocksmith.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -56,6 +58,8 @@
|
||||
<ProjectReference Include="..\..\..\..\common\Common.UI\Common.UI.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Exclude legacy Helper folder in favor of Helpers -->
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<PublishTrimmed>true</PublishTrimmed>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
using Microsoft.CommandPalette.Extensions;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using PowerToysExtension.Helper;
|
||||
using PowerToysExtension.Helpers;
|
||||
|
||||
namespace PowerToysExtension.Pages;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -8,10 +8,4 @@
|
||||
</application>
|
||||
</compatibility>
|
||||
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
</assembly>
|
||||
|
||||
Reference in New Issue
Block a user