Compare commits

...

3 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
acccd2ed4f Fix search results navigation focus issue - conditional focus on primary links
Co-authored-by: yeelam-gordon <73506701+yeelam-gordon@users.noreply.github.com>
2025-08-26 06:23:43 +00:00
copilot-swe-agent[bot]
3aadeb771a Initial plan 2025-08-26 06:16:38 +00:00
PesBandi
8258f2ab6f [CmdPal] Eliminate CopyTextCommand duplicates (#41347)
## Summary of the Pull Request
Removes redundant CopyCommands and replaces their usage with
`CopyTextCommand` from the toolkit. This is actually recommend by the
[docs](https://learn.microsoft.com/en-us/windows/powertoys/command-palette/command-results#showtoast-command-result),
we should probably lead by example 😄
> Consider the CopyTextCommand in the helpers - this command will show a
toast with the text "Copied to clipboard", then dismiss the palette.

Only functionality change is that they now display *Copied to
clipboard!* after copying.
## PR Checklist

- [x] Closes: #41346
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** All pass
- [x] **Localization:** All end-user-facing strings can be localized
- [x] **Dev docs:** No need
- [x] **New binaries:** None
- [x] **Documentation updated:** No need
## Detailed Description of the Pull Request / Additional comments
Custom command names (e.g. *Copy path* instead of *Copy*) are preserved.
Strings put out of use have been deleted.
CopyCommands from the Registry and Clipboard plugins are left untouched,
as they contain special logic.
The error handling in `CopyPathCommand` from Apps was unnecessary, since
it's already taken care of by `ClipboardHelper`.
## Validation Steps Performed
Manual testing
2025-08-25 14:48:48 -05:00
8 changed files with 8 additions and 115 deletions

View File

@@ -1,47 +0,0 @@
// 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.Text;
using ManagedCommon;
using Microsoft.CmdPal.Ext.Apps.Properties;
using Microsoft.CommandPalette.Extensions.Toolkit;
namespace Microsoft.CmdPal.Ext.Apps.Commands;
internal sealed partial class CopyPathCommand : InvokableCommand
{
private readonly string _target;
public CopyPathCommand(string target)
{
Name = Resources.copy_path;
Icon = Icons.CopyIcon;
_target = target;
}
private static readonly CompositeFormat CopyFailedFormat = CompositeFormat.Parse(Resources.copy_failed);
public override CommandResult Invoke()
{
try
{
ClipboardHelper.SetText(_target);
}
catch (Exception ex)
{
Logger.LogError("Copy failed: " + ex.Message);
return CommandResult.ShowToast(
new ToastArgs
{
Message = string.Format(CultureInfo.CurrentCulture, CopyFailedFormat, ex.Message),
Result = CommandResult.KeepOpen(),
});
}
return CommandResult.ShowToast(Resources.copied_to_clipboard);
}
}

View File

@@ -95,7 +95,7 @@ public class UWPApplication : IUWPApplication
commands.Add(
new CommandContextItem(
new Commands.CopyPathCommand(Location))
new CopyTextCommand(Location) { Name = Resources.copy_path })
{
RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.C),
});

View File

@@ -202,7 +202,7 @@ public class Win32Program : IProgram
}
commands.Add(new CommandContextItem(
new Commands.CopyPathCommand(FullPath))
new CopyTextCommand(FullPath) { Name = Resources.copy_path })
{
RequestedShortcut = KeyChordHelpers.FromModifiers(ctrl: true, shift: true, vkey: VirtualKey.C),
});

View File

@@ -78,24 +78,6 @@ namespace Microsoft.CmdPal.Ext.Apps.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Copied to clipboard!.
/// </summary>
internal static string copied_to_clipboard {
get {
return ResourceManager.GetString("copied_to_clipboard", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Copy failed ({0}). Please try again..
/// </summary>
internal static string copy_failed {
get {
return ResourceManager.GetString("copy_failed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Copy path.
/// </summary>

View File

@@ -172,13 +172,6 @@
<data name="run_as_different_user" xml:space="preserve">
<value>Run as different user</value>
</data>
<data name="copy_failed" xml:space="preserve">
<value>Copy failed ({0}). Please try again.</value>
<comment>{0} is the error message</comment>
</data>
<data name="copied_to_clipboard" xml:space="preserve">
<value>Copied to clipboard!</value>
</data>
<data name="enable_start_menu_source" xml:space="preserve">
<value>Include apps found in the Start Menu</value>
</data>

View File

@@ -1,39 +0,0 @@
// 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.Diagnostics;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CmdPal.Ext.WindowsSettings.Classes;
using Microsoft.CmdPal.Ext.WindowsSettings.Properties;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;
using Windows.ApplicationModel.DataTransfer;
using Windows.Networking.NetworkOperators;
using Windows.UI;
namespace Microsoft.CmdPal.Ext.WindowsSettings.Commands;
internal sealed partial class CopySettingCommand : InvokableCommand
{
private readonly WindowsSetting _entry;
internal CopySettingCommand(WindowsSetting entry)
{
Name = Resources.CopyCommand;
Icon = Icons.CopyIcon;
_entry = entry;
}
public override CommandResult Invoke()
{
ClipboardHelper.SetText(_entry.Command);
return CommandResult.Dismiss();
}
}

View File

@@ -23,7 +23,7 @@ internal static class ContextMenuHelper
{
var list = new List<CommandContextItem>(1)
{
new(new CopySettingCommand(entry)),
new(new CopyTextCommand(entry.Command) { Name = Resources.CopyCommand }),
};
return list;

View File

@@ -71,7 +71,11 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
PrimaryLinksControl.Focus(FocusState.Programmatic);
// Only set focus to primary links if they exist and are visible
if (PrimaryLinks?.Count > 0 && PrimaryLinksControl.Visibility == Visibility.Visible)
{
PrimaryLinksControl.Focus(FocusState.Programmatic);
}
}
}
}