2024-05-09 10:32:03 -04:00
|
|
|
|
// 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.
|
|
|
|
|
|
|
2025-11-05 16:13:55 +08:00
|
|
|
|
using System.Collections.Generic;
|
2024-05-09 10:32:03 -04:00
|
|
|
|
using System.Text.Json;
|
|
|
|
|
|
using System.Text.Json.Serialization;
|
2024-09-16 16:09:43 -04:00
|
|
|
|
|
2024-05-09 10:32:03 -04:00
|
|
|
|
using Settings.UI.Library.Attributes;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library
|
|
|
|
|
|
{
|
|
|
|
|
|
public class AdvancedPasteProperties
|
|
|
|
|
|
{
|
|
|
|
|
|
public static readonly HotkeySettings DefaultAdvancedPasteUIShortcut = new HotkeySettings(true, false, false, true, 0x56); // Win+Shift+V
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly HotkeySettings DefaultPasteAsPlainTextShortcut = new HotkeySettings(true, true, true, false, 0x56); // Ctrl+Win+Alt+V
|
|
|
|
|
|
|
|
|
|
|
|
public AdvancedPasteProperties()
|
|
|
|
|
|
{
|
|
|
|
|
|
AdvancedPasteUIShortcut = DefaultAdvancedPasteUIShortcut;
|
|
|
|
|
|
PasteAsPlainTextShortcut = DefaultPasteAsPlainTextShortcut;
|
|
|
|
|
|
PasteAsMarkdownShortcut = new();
|
|
|
|
|
|
PasteAsJsonShortcut = new();
|
2024-08-22 16:17:12 +02:00
|
|
|
|
CustomActions = new();
|
2024-10-18 15:34:09 +02:00
|
|
|
|
AdditionalActions = new();
|
2025-11-05 16:13:55 +08:00
|
|
|
|
IsAIEnabled = false;
|
2024-05-09 10:32:03 -04:00
|
|
|
|
ShowCustomPreview = true;
|
2024-06-24 16:03:46 +02:00
|
|
|
|
CloseAfterLosingFocus = false;
|
2025-11-05 16:13:55 +08:00
|
|
|
|
PasteAIConfiguration = new();
|
2024-05-09 10:32:03 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
2025-11-05 16:13:55 +08:00
|
|
|
|
public bool IsAIEnabled { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[JsonExtensionData]
|
|
|
|
|
|
public Dictionary<string, JsonElement> ExtensionData
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _extensionData;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
_extensionData = value;
|
|
|
|
|
|
|
|
|
|
|
|
if (_extensionData != null && _extensionData.TryGetValue("IsOpenAIEnabled", out var legacyElement) && legacyElement.ValueKind == JsonValueKind.Object && legacyElement.TryGetProperty("value", out var valueElement))
|
|
|
|
|
|
{
|
|
|
|
|
|
IsAIEnabled = valueElement.ValueKind switch
|
|
|
|
|
|
{
|
|
|
|
|
|
JsonValueKind.True => true,
|
|
|
|
|
|
JsonValueKind.False => false,
|
|
|
|
|
|
_ => IsAIEnabled,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_extensionData.Remove("IsOpenAIEnabled");
|
|
|
|
|
|
}
|
2025-11-12 16:24:21 +08:00
|
|
|
|
|
|
|
|
|
|
if (_extensionData != null && _extensionData.TryGetValue("IsAdvancedAIEnabled", out var legacyAdvancedElement))
|
|
|
|
|
|
{
|
|
|
|
|
|
bool? legacyValue = legacyAdvancedElement.ValueKind switch
|
|
|
|
|
|
{
|
|
|
|
|
|
JsonValueKind.True => true,
|
|
|
|
|
|
JsonValueKind.False => false,
|
|
|
|
|
|
JsonValueKind.Object when legacyAdvancedElement.TryGetProperty("value", out var advancedValueElement) => advancedValueElement.ValueKind switch
|
|
|
|
|
|
{
|
|
|
|
|
|
JsonValueKind.True => true,
|
|
|
|
|
|
JsonValueKind.False => false,
|
|
|
|
|
|
_ => null,
|
|
|
|
|
|
},
|
|
|
|
|
|
_ => null,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (legacyValue.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
LegacyAdvancedAIEnabled = legacyValue.Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_extensionData.Remove("IsAdvancedAIEnabled");
|
|
|
|
|
|
}
|
2025-11-05 16:13:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Dictionary<string, JsonElement> _extensionData;
|
2025-11-12 16:24:21 +08:00
|
|
|
|
private bool? _legacyAdvancedAIEnabled;
|
|
|
|
|
|
|
|
|
|
|
|
[JsonPropertyName("IsAdvancedAIEnabled")]
|
|
|
|
|
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
|
|
|
|
|
public BoolProperty LegacyAdvancedAIEnabledProperty
|
|
|
|
|
|
{
|
|
|
|
|
|
get => null;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value is not null)
|
|
|
|
|
|
{
|
|
|
|
|
|
LegacyAdvancedAIEnabled = value.Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
|
public bool? LegacyAdvancedAIEnabled
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _legacyAdvancedAIEnabled;
|
|
|
|
|
|
private set => _legacyAdvancedAIEnabled = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool TryConsumeLegacyAdvancedAIEnabled(out bool value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_legacyAdvancedAIEnabled is bool flag)
|
|
|
|
|
|
{
|
|
|
|
|
|
value = flag;
|
|
|
|
|
|
_legacyAdvancedAIEnabled = null;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
value = default;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2024-05-09 10:32:03 -04:00
|
|
|
|
|
|
|
|
|
|
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
2024-12-11 10:28:44 +01:00
|
|
|
|
public bool ShowCustomPreview { get; set; }
|
2024-05-09 10:32:03 -04:00
|
|
|
|
|
2024-06-24 16:03:46 +02:00
|
|
|
|
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
|
|
|
|
|
public bool CloseAfterLosingFocus { get; set; }
|
|
|
|
|
|
|
2024-05-09 10:32:03 -04:00
|
|
|
|
[JsonPropertyName("advanced-paste-ui-hotkey")]
|
|
|
|
|
|
public HotkeySettings AdvancedPasteUIShortcut { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[JsonPropertyName("paste-as-plain-hotkey")]
|
|
|
|
|
|
public HotkeySettings PasteAsPlainTextShortcut { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[JsonPropertyName("paste-as-markdown-hotkey")]
|
|
|
|
|
|
public HotkeySettings PasteAsMarkdownShortcut { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[JsonPropertyName("paste-as-json-hotkey")]
|
|
|
|
|
|
public HotkeySettings PasteAsJsonShortcut { get; set; }
|
|
|
|
|
|
|
2024-08-22 16:17:12 +02:00
|
|
|
|
[JsonPropertyName("custom-actions")]
|
|
|
|
|
|
[CmdConfigureIgnoreAttribute]
|
2024-10-18 15:34:09 +02:00
|
|
|
|
public AdvancedPasteCustomActions CustomActions { get; init; }
|
|
|
|
|
|
|
|
|
|
|
|
[JsonPropertyName("additional-actions")]
|
|
|
|
|
|
[CmdConfigureIgnoreAttribute]
|
|
|
|
|
|
public AdvancedPasteAdditionalActions AdditionalActions { get; init; }
|
2024-08-22 16:17:12 +02:00
|
|
|
|
|
2025-11-05 16:13:55 +08:00
|
|
|
|
[JsonPropertyName("paste-ai-configuration")]
|
|
|
|
|
|
[CmdConfigureIgnoreAttribute]
|
|
|
|
|
|
public PasteAIConfiguration PasteAIConfiguration { get; set; }
|
|
|
|
|
|
|
2024-05-09 10:32:03 -04:00
|
|
|
|
public override string ToString()
|
|
|
|
|
|
=> JsonSerializer.Serialize(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|