mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
## Summary of the Pull Request Allows users to set a preference for the primary action—Paste or Copy—when interacting with Clipboard History entries. - Introduce `ClipboardListItem` as a subclass of `ListItem` - Build the item's details panel lazily to improve performance - Order Paste/Copy commands based on the selected preference - Update icons to visually reflect the chosen primary action Pictures? Pictures! <img width="1802" height="1137" alt="image" src="https://github.com/user-attachments/assets/f4d09902-2538-4103-92d5-41c43b313952" /> <img width="1731" height="1084" alt="image" src="https://github.com/user-attachments/assets/08354312-6ef9-433a-9893-31fe3a233fbf" /> <img width="3324" height="742" alt="image" src="https://github.com/user-attachments/assets/0431145e-c084-4996-93d6-4eb84b7d6177" /> <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: #41661 - [ ] **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
69 lines
2.5 KiB
C#
69 lines
2.5 KiB
C#
// 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.IO;
|
|
using Microsoft.CmdPal.Ext.ClipboardHistory.Properties;
|
|
using Microsoft.CommandPalette.Extensions.Toolkit;
|
|
|
|
namespace Microsoft.CmdPal.Ext.ClipboardHistory.Helpers;
|
|
|
|
internal sealed class SettingsManager : JsonSettingsManager, ISettingOptions
|
|
{
|
|
private const string Namespace = "clipboardHistory";
|
|
|
|
private static string Namespaced(string propertyName) => $"{Namespace}.{propertyName}";
|
|
|
|
private readonly ToggleSetting _keepAfterPaste = new(
|
|
Namespaced(nameof(KeepAfterPaste)),
|
|
Resources.settings_keep_after_paste_title!,
|
|
Resources.settings_keep_after_paste_description!,
|
|
false);
|
|
|
|
private readonly ToggleSetting _confirmDelete = new(
|
|
Namespaced(nameof(DeleteFromHistoryRequiresConfirmation)),
|
|
Resources.settings_confirm_delete_title!,
|
|
Resources.settings_confirm_delete_description!,
|
|
true);
|
|
|
|
private readonly ChoiceSetSetting _primaryAction = new(
|
|
Namespaced(nameof(PrimaryAction)),
|
|
Resources.settings_primary_action_title!,
|
|
Resources.settings_primary_action_description!,
|
|
[
|
|
new ChoiceSetSetting.Choice(Resources.settings_primary_action_default!, PrimaryAction.Default.ToString("G")),
|
|
new ChoiceSetSetting.Choice(Resources.settings_primary_action_paste!, PrimaryAction.Paste.ToString("G")),
|
|
new ChoiceSetSetting.Choice(Resources.settings_primary_action_copy!, PrimaryAction.Copy.ToString("G"))
|
|
]);
|
|
|
|
public bool KeepAfterPaste => _keepAfterPaste.Value;
|
|
|
|
public bool DeleteFromHistoryRequiresConfirmation => _confirmDelete.Value;
|
|
|
|
public PrimaryAction PrimaryAction => Enum.TryParse<PrimaryAction>(_primaryAction.Value, out var action) ? action : PrimaryAction.Default;
|
|
|
|
private static string SettingsJsonPath()
|
|
{
|
|
var directory = Utilities.BaseSettingsPath("Microsoft.CmdPal");
|
|
Directory.CreateDirectory(directory);
|
|
|
|
// now, the state is just next to the exe
|
|
return Path.Combine(directory, "settings.json");
|
|
}
|
|
|
|
public SettingsManager()
|
|
{
|
|
FilePath = SettingsJsonPath();
|
|
|
|
Settings.Add(_keepAfterPaste);
|
|
Settings.Add(_confirmDelete);
|
|
Settings.Add(_primaryAction);
|
|
|
|
// Load settings from file upon initialization
|
|
LoadSettings();
|
|
|
|
Settings.SettingsChanged += (_, _) => SaveSettings();
|
|
}
|
|
}
|