mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +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;
|
||||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||||
using PowerToysExtension.Commands;
|
using PowerToysExtension.Commands;
|
||||||
using PowerToysExtension.Helper;
|
using PowerToysExtension.Pages;
|
||||||
|
|
||||||
namespace PowerToysExtension.Helper;
|
namespace PowerToysExtension.Helpers;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Builds the list of PowerToys module entries and supports basic fuzzy filtering.
|
/// 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");
|
var settingsCommand = new OpenInSettingsCommand(module, $"Open {title} settings");
|
||||||
|
|
||||||
// Module-specific extras
|
var more = new List<ICommandContextItem>();
|
||||||
var more = new List<CommandContextItem>();
|
|
||||||
switch (module)
|
switch (module)
|
||||||
{
|
{
|
||||||
case SettingsDeepLink.SettingsWindow.Awake:
|
case SettingsDeepLink.SettingsWindow.Awake:
|
||||||
@@ -89,12 +89,12 @@ internal static class ModuleItemsHelper
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SettingsDeepLink.SettingsWindow.Workspaces:
|
case SettingsDeepLink.SettingsWindow.Workspaces:
|
||||||
|
more.Add(new CommandContextItem(new WorkspacesListPage()));
|
||||||
more.Add(new CommandContextItem(new OpenWorkspaceEditorCommand()));
|
more.Add(new CommandContextItem(new OpenWorkspaceEditorCommand()));
|
||||||
more.Add(new CommandContextItem(new OpenPowerToysSettingsCommand("Workspaces", "Workspaces")));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SettingsDeepLink.SettingsWindow.Overview:
|
case SettingsDeepLink.SettingsWindow.ColorPicker:
|
||||||
// Overview just opens main settings
|
more.Add(new CommandContextItem(new CopyColorCommand()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||||
using static Common.UI.SettingsDeepLink;
|
using static Common.UI.SettingsDeepLink;
|
||||||
|
|
||||||
namespace PowerToysExtension.Helper;
|
namespace PowerToysExtension.Helpers;
|
||||||
|
|
||||||
internal static class PowerToysResourcesHelper
|
internal static class PowerToysResourcesHelper
|
||||||
{
|
{
|
||||||
@@ -18,7 +18,7 @@ internal static class PowerToysResourcesHelper
|
|||||||
SettingsWindow.ColorPicker => "Assets\\ColorPicker.png",
|
SettingsWindow.ColorPicker => "Assets\\ColorPicker.png",
|
||||||
SettingsWindow.FancyZones => "Assets\\FancyZones.png",
|
SettingsWindow.FancyZones => "Assets\\FancyZones.png",
|
||||||
SettingsWindow.Hosts => "Assets\\Hosts.png",
|
SettingsWindow.Hosts => "Assets\\Hosts.png",
|
||||||
SettingsWindow.PowerOCR => "Assets\\PowerOcr.png",
|
SettingsWindow.PowerOCR => "Assets\\TextExtractor.png",
|
||||||
SettingsWindow.RegistryPreview => "Assets\\RegistryPreview.png",
|
SettingsWindow.RegistryPreview => "Assets\\RegistryPreview.png",
|
||||||
SettingsWindow.MeasureTool => "Assets\\ScreenRuler.png",
|
SettingsWindow.MeasureTool => "Assets\\ScreenRuler.png",
|
||||||
SettingsWindow.ShortcutGuide => "Assets\\ShortcutGuide.png",
|
SettingsWindow.ShortcutGuide => "Assets\\ShortcutGuide.png",
|
||||||
@@ -78,6 +78,8 @@ internal static class WorkspaceItemsHelper
|
|||||||
return items.ToArray();
|
return items.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static IListItem[] FilteredItems(string searchText) => GetWorkspaceItems(searchText);
|
||||||
|
|
||||||
private static List<WorkspaceProject> LoadWorkspaces()
|
private static List<WorkspaceProject> LoadWorkspaces()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
|
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
|
||||||
<UseWinUI>false</UseWinUI>
|
<UseWinUI>false</UseWinUI>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<EnableMsixTooling>true</EnableMsixTooling>
|
<EnableMsixTooling>true</EnableMsixTooling>
|
||||||
<GenerateAppxPackageOnBuild>true</GenerateAppxPackageOnBuild>
|
<GenerateAppxPackageOnBuild>true</GenerateAppxPackageOnBuild>
|
||||||
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\WinUI3Apps\CmdPalExtensions\$(MSBuildProjectName)\</OutputPath>
|
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\WinUI3Apps\CmdPalExtensions\$(MSBuildProjectName)\</OutputPath>
|
||||||
@@ -25,6 +26,7 @@
|
|||||||
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
|
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
|
||||||
<Content Include="Assets\StoreLogo.png" />
|
<Content Include="Assets\StoreLogo.png" />
|
||||||
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
|
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
|
||||||
|
<Content Include="Assets\FileLocksmith.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -56,6 +58,8 @@
|
|||||||
<ProjectReference Include="..\..\..\..\common\Common.UI\Common.UI.csproj" />
|
<ProjectReference Include="..\..\..\..\common\Common.UI\Common.UI.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!-- Exclude legacy Helper folder in favor of Helpers -->
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||||
<PublishTrimmed>true</PublishTrimmed>
|
<PublishTrimmed>true</PublishTrimmed>
|
||||||
<PublishSingleFile>true</PublishSingleFile>
|
<PublishSingleFile>true</PublishSingleFile>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
using Microsoft.CommandPalette.Extensions;
|
using Microsoft.CommandPalette.Extensions;
|
||||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||||
using PowerToysExtension.Helper;
|
using PowerToysExtension.Helpers;
|
||||||
|
|
||||||
namespace PowerToysExtension.Pages;
|
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.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
@@ -10,36 +10,27 @@ namespace PowerToysExtension.Pages;
|
|||||||
|
|
||||||
internal sealed partial class WorkspacesListPage : DynamicListPage
|
internal sealed partial class WorkspacesListPage : DynamicListPage
|
||||||
{
|
{
|
||||||
private readonly CommandItem _emptyContent;
|
private readonly CommandItem _emptyMessage;
|
||||||
|
|
||||||
public WorkspacesListPage()
|
public WorkspacesListPage()
|
||||||
{
|
{
|
||||||
Icon = IconHelpers.FromRelativePath("Assets\\Workspaces.png");
|
Icon = IconHelpers.FromRelativePath("Assets\\Workspaces.png");
|
||||||
Title = "Workspaces";
|
Name = Title = "Workspaces";
|
||||||
Name = "Workspaces";
|
Id = "com.microsoft.cmdpal.powertoys.workspaces";
|
||||||
Id = "com.microsoft.powertoys.workspaces";
|
_emptyMessage = new CommandItem()
|
||||||
|
|
||||||
_emptyContent = new CommandItem()
|
|
||||||
{
|
{
|
||||||
Title = "No workspaces found",
|
|
||||||
Subtitle = "Create a workspace in PowerToys to get started.",
|
|
||||||
Icon = IconHelpers.FromRelativePath("Assets\\Workspaces.png"),
|
Icon = IconHelpers.FromRelativePath("Assets\\Workspaces.png"),
|
||||||
|
Title = "No workspaces found",
|
||||||
|
Subtitle = SearchText,
|
||||||
};
|
};
|
||||||
|
EmptyContent = _emptyMessage;
|
||||||
EmptyContent = _emptyContent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void UpdateSearchText(string oldSearch, string newSearch)
|
public override void UpdateSearchText(string oldSearch, string newSearch)
|
||||||
{
|
{
|
||||||
_emptyContent.Subtitle = string.IsNullOrWhiteSpace(newSearch)
|
_emptyMessage.Subtitle = newSearch;
|
||||||
? "Create a workspace in PowerToys to get started."
|
|
||||||
: $"No workspaces matching '{newSearch}'";
|
|
||||||
|
|
||||||
RaiseItemsChanged(0);
|
RaiseItemsChanged(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IListItem[] GetItems()
|
public override IListItem[] GetItems() => WorkspaceItemsHelper.FilteredItems(SearchText);
|
||||||
{
|
|
||||||
return WorkspaceItemsHelper.GetWorkspaceItems(SearchText);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,4 @@
|
|||||||
</application>
|
</application>
|
||||||
</compatibility>
|
</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>
|
</assembly>
|
||||||
|
|||||||
Reference in New Issue
Block a user