/ src / settings-ui / Settings.UI.Library / AdvancedPasteProperties.cs
AdvancedPasteProperties.cs
  1  // Copyright (c) Microsoft Corporation
  2  // The Microsoft Corporation licenses this file to you under the MIT license.
  3  // See the LICENSE file in the project root for more information.
  4  
  5  using System.Collections.Generic;
  6  using System.Text.Json;
  7  using System.Text.Json.Serialization;
  8  
  9  using Settings.UI.Library.Attributes;
 10  
 11  namespace Microsoft.PowerToys.Settings.UI.Library
 12  {
 13      public class AdvancedPasteProperties
 14      {
 15          public static readonly HotkeySettings DefaultAdvancedPasteUIShortcut = new HotkeySettings(true, false, false, true, 0x56); // Win+Shift+V
 16  
 17          public static readonly HotkeySettings DefaultPasteAsPlainTextShortcut = new HotkeySettings(true, true, true, false, 0x56); // Ctrl+Win+Alt+V
 18  
 19          public AdvancedPasteProperties()
 20          {
 21              AdvancedPasteUIShortcut = DefaultAdvancedPasteUIShortcut;
 22              PasteAsPlainTextShortcut = DefaultPasteAsPlainTextShortcut;
 23              PasteAsMarkdownShortcut = new();
 24              PasteAsJsonShortcut = new();
 25              CustomActions = new();
 26              AdditionalActions = new();
 27              IsAIEnabled = false;
 28              ShowCustomPreview = true;
 29              CloseAfterLosingFocus = false;
 30              EnableClipboardPreview = true;
 31              AutoCopySelectionForCustomActionHotkey = false;
 32              PasteAIConfiguration = new();
 33          }
 34  
 35          [JsonConverter(typeof(BoolPropertyJsonConverter))]
 36          public bool IsAIEnabled { get; set; }
 37  
 38          private bool? _legacyAdvancedAIEnabled;
 39  
 40          [JsonPropertyName("IsAdvancedAIEnabled")]
 41          [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
 42          public BoolProperty LegacyAdvancedAIEnabledProperty
 43          {
 44              get => null;
 45              set
 46              {
 47                  if (value is not null)
 48                  {
 49                      LegacyAdvancedAIEnabled = value.Value;
 50                  }
 51              }
 52          }
 53  
 54          [JsonIgnore]
 55          public bool? LegacyAdvancedAIEnabled
 56          {
 57              get => _legacyAdvancedAIEnabled;
 58              private set => _legacyAdvancedAIEnabled = value;
 59          }
 60  
 61          public bool TryConsumeLegacyAdvancedAIEnabled(out bool value)
 62          {
 63              if (_legacyAdvancedAIEnabled is bool flag)
 64              {
 65                  value = flag;
 66                  _legacyAdvancedAIEnabled = null;
 67                  return true;
 68              }
 69  
 70              value = default;
 71              return false;
 72          }
 73  
 74          [JsonConverter(typeof(BoolPropertyJsonConverter))]
 75          public bool ShowCustomPreview { get; set; }
 76  
 77          [JsonConverter(typeof(BoolPropertyJsonConverter))]
 78          public bool CloseAfterLosingFocus { get; set; }
 79  
 80          [JsonConverter(typeof(BoolPropertyJsonConverter))]
 81          public bool EnableClipboardPreview { get; set; }
 82  
 83          [JsonConverter(typeof(BoolPropertyJsonConverter))]
 84          public bool AutoCopySelectionForCustomActionHotkey { get; set; }
 85  
 86          [JsonPropertyName("advanced-paste-ui-hotkey")]
 87          public HotkeySettings AdvancedPasteUIShortcut { get; set; }
 88  
 89          [JsonPropertyName("paste-as-plain-hotkey")]
 90          public HotkeySettings PasteAsPlainTextShortcut { get; set; }
 91  
 92          [JsonPropertyName("paste-as-markdown-hotkey")]
 93          public HotkeySettings PasteAsMarkdownShortcut { get; set; }
 94  
 95          [JsonPropertyName("paste-as-json-hotkey")]
 96          public HotkeySettings PasteAsJsonShortcut { get; set; }
 97  
 98          [JsonPropertyName("custom-actions")]
 99          [CmdConfigureIgnoreAttribute]
100          public AdvancedPasteCustomActions CustomActions { get; set; }
101  
102          [JsonPropertyName("additional-actions")]
103          [CmdConfigureIgnoreAttribute]
104          public AdvancedPasteAdditionalActions AdditionalActions { get; set; }
105  
106          [JsonPropertyName("paste-ai-configuration")]
107          [CmdConfigureIgnoreAttribute]
108          public PasteAIConfiguration PasteAIConfiguration { get; set; }
109  
110          public override string ToString()
111              => JsonSerializer.Serialize(this, SettingsSerializationContext.Default.AdvancedPasteProperties);
112      }
113  }